Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Volume.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : Volume *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header file for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
16  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
17  * *
18  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * U. of Victoria, Canada *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 /*! \class TMVA::Volume
29 \ingroup TMVA
30 Volume for BinarySearchTree
31 
32 volume element: variable space between upper and lower bonds of
33 nvar-dimensional variable space
34 */
35 
36 #include "TMVA/Volume.h"
37 
38 #include "TMVA/MsgLogger.h"
39 #include "TMVA/Tools.h"
40 #include "TMVA/Types.h"
41 
42 #include <stdexcept>
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// constructor specifying the volume by std::vectors of doubles
46 
47 TMVA::Volume::Volume( std::vector<Double_t>* l, std::vector<Double_t>* u )
48  : fLower( l ),
49  fUpper( u ),
50  fOwnerShip (kFALSE){
51  }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// constructor specifying the volume by std::vectors of floats
55 
56 TMVA::Volume::Volume( std::vector<Float_t>* l, std::vector<Float_t>* u )
57 {
58  fLower = new std::vector<Double_t>( l->size() );
59  fUpper = new std::vector<Double_t>( u->size() );
60  fOwnerShip = kTRUE;
61 
62  for (UInt_t ivar=0; ivar<l->size(); ivar++) {
63  (*fLower)[ivar] = Double_t((*l)[ivar]);
64  (*fUpper)[ivar] = Double_t((*u)[ivar]);
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// constructor specifying the volume by c-style arrays of doubles
70 
71 TMVA::Volume::Volume( Double_t* l, Double_t* u, Int_t nvar )
72 {
73  fLower = new std::vector<Double_t>( nvar );
74  fUpper = new std::vector<Double_t>( nvar );
75  fOwnerShip = kTRUE;
76 
77  for (int ivar=0; ivar<nvar; ivar++) {
78  (*fLower)[ivar] = l[ivar];
79  (*fUpper)[ivar] = u[ivar];
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// constructor specifying the volume by c-style arrays of floats
85 
86 TMVA::Volume::Volume( Float_t* l, Float_t* u, Int_t nvar )
87 {
88  fLower = new std::vector<Double_t>( nvar );
89  fUpper = new std::vector<Double_t>( nvar );
90  fOwnerShip = kTRUE;
91 
92  for (int ivar=0; ivar<nvar; ivar++) {
93  (*fLower)[ivar] = Double_t(l[ivar]);
94  (*fUpper)[ivar] = Double_t(u[ivar]);
95  }
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// simple constructors for 1 dimensional values (double)
100 
101 TMVA::Volume::Volume( Double_t l, Double_t u )
102 {
103  fLower = new std::vector<Double_t>(1);
104  fUpper = new std::vector<Double_t>(1);
105  fOwnerShip = kTRUE;
106  (*fLower)[0] = l;
107  (*fUpper)[0] = u;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// simple constructors for 1 dimensional values (float)
112 
113 TMVA::Volume::Volume( Float_t l, Float_t u )
114 {
115  fLower = new std::vector<Double_t>(1);
116  fUpper = new std::vector<Double_t>(1);
117  fOwnerShip = kTRUE;
118  (*fLower)[0] = Double_t(l);
119  (*fUpper)[0] = Double_t(u);
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// copy constructor
124 
125 TMVA::Volume::Volume( Volume& V )
126 {
127  fLower = new std::vector<Double_t>( *V.fLower );
128  fUpper = new std::vector<Double_t>( *V.fUpper );
129  fOwnerShip = kTRUE;
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// assignment operator
134 
135 TMVA::Volume& TMVA::Volume::operator=( const Volume& V )
136 {
137  if (fOwnerShip) {
138  if (fLower) delete fLower;
139  if (fUpper) delete fUpper;
140  fLower = new std::vector<Double_t>( *V.fLower );
141  fUpper = new std::vector<Double_t>( *V.fUpper );
142  }
143  else {
144  fLower = V.fLower;
145  fUpper = V.fUpper;
146  }
147  return *this;
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// destructor
152 
153 TMVA::Volume::~Volume( void )
154 {
155  // delete volume boundaries only if owned by the volume
156  if (fOwnerShip) this->Delete();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// delete array of volume bondaries
161 
162 void TMVA::Volume::Delete( void )
163 {
164  if (NULL != fLower) { delete fLower; fLower = NULL; }
165  if (NULL != fUpper) { delete fUpper; fUpper = NULL; }
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// "scale" the volume by multiplying each upper and lower boundary by "f"
170 
171 void TMVA::Volume::Scale( Double_t f )
172 {
173  gTools().Scale(*fLower,f);
174  gTools().Scale(*fUpper,f);
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// "scale" the volume by symmetrically blowing up the interval in each dimension
179 
180 void TMVA::Volume::ScaleInterval( Double_t f )
181 {
182  for (UInt_t ivar=0; ivar<fLower->size(); ivar++) {
183  Double_t lo = 0.5*((*fLower)[ivar]*(1.0 + f) + (*fUpper)[ivar]*(1.0 - f));
184  Double_t up = 0.5*((*fLower)[ivar]*(1.0 - f) + (*fUpper)[ivar]*(1.0 + f));
185  (*fLower)[ivar] = lo;
186  (*fUpper)[ivar] = up;
187  }
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// printout of the volume boundaries
192 
193 void TMVA::Volume::Print( void ) const
194 {
195  MsgLogger fLogger( "Volume" );
196  for (UInt_t ivar=0; ivar<fLower->size(); ivar++) {
197  fLogger << kINFO << "... Volume: var: " << ivar << "\t(fLower, fUpper) = ("
198  << (*fLower)[ivar] << "\t " << (*fUpper)[ivar] <<")"<< Endl;
199  }
200 }
201