Logo ROOT   6.08/07
Reference Guide
PDEFoamCell.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: S.Jadach, Tancredi Carli, Dominik Dannheim, Alexander Voigt
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Classes: PDEFoamCell *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Objects of this class are hyperrectangular cells organized in *
12  * the binary tree. Special algoritm for encoding relalive *
13  * positioning of the cells saves total memory allocation needed *
14  * for the system of cells. *
15  * *
16  * Authors (alphabetical): *
17  * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
18  * Tancredi Carli - CERN, Switzerland *
19  * Dominik Dannheim - CERN, Switzerland *
20  * Alexander Voigt - TU Dresden, Germany *
21  * *
22  * Copyright (c) 2008: *
23  * CERN, Switzerland *
24  * MPI-K Heidelberg, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://tmva.sourceforge.net/LICENSE) *
29  **********************************************************************************/
30 
31 #include "TMVA/PDEFoamCell.h"
32 
33 #include "TMVA/PDEFoamVect.h"
34 
35 #include <iostream>
36 #include <ostream>
37 
38 #include "Rtypes.h"
39 #include "TObject.h"
40 #include "TRef.h"
41 
42 using namespace std;
43 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Default constructor for streamer
48 
50 : TObject(),
51  fDim(0),
52  fSerial(0),
53  fStatus(1),
54  fParent(0),
55  fDaught0(0),
56  fDaught1(0),
57  fXdiv(0.0),
58  fBest(0),
59  fVolume(0.0),
60  fIntegral(0.0),
61  fDrive(0.0),
62  fElement(0)
63 {
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// User constructor allocating single empty Cell
68 
70  : TObject(),
71  fDim(kDim),
72  fSerial(0),
73  fStatus(1),
74  fParent(0),
75  fDaught0(0),
76  fDaught1(0),
77  fXdiv(0.0),
78  fBest(0),
79  fVolume(0.0),
80  fIntegral(0.0),
81  fDrive(0.0),
82  fElement(0)
83 {
84  if ( kDim <= 0 )
85  Error( "PDEFoamCell", "Dimension has to be >0" );
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Copy constructor
90 
92  : TObject(),
93  fDim (cell.fDim),
94  fSerial (cell.fSerial),
95  fStatus (cell.fStatus),
96  fParent (cell.fParent),
97  fDaught0 (cell.fDaught0),
98  fDaught1 (cell.fDaught1),
99  fXdiv (cell.fXdiv),
100  fBest (cell.fBest),
101  fVolume (cell.fVolume),
102  fIntegral(cell.fIntegral),
103  fDrive (cell.fDrive),
104  fElement (cell.fElement)
105 {
106  Error( "PDEFoamCell", "COPY CONSTRUCTOR NOT IMPLEMENTED" );
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Destructor
111 
113 {
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Fills in certain data into newly allocated cell
118 
119 void TMVA::PDEFoamCell::Fill(Int_t status, PDEFoamCell *parent, PDEFoamCell *daugh1, PDEFoamCell *daugh2)
120 {
121  fStatus = status;
122  fParent = parent;
123  fDaught0 = daugh1;
124  fDaught1 = daugh2;
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 // GETTERS/SETTERS
129 ////////////////////////////////////////////////////////////////////////////////
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Provides size and position of the cell
133 /// These parameter are calculated by analyzing information in all parents
134 /// cells up to the root cell. It takes time but saves memory.
135 
136 void TMVA::PDEFoamCell::GetHcub( PDEFoamVect &cellPosi, PDEFoamVect &cellSize) const
137 {
138  if(fDim<1) return;
139  const PDEFoamCell *pCell,*dCell;
140  cellPosi = 0.0; cellSize=1.0; // load all components
141  dCell = this;
142  while(dCell != 0) {
143  pCell = dCell->GetPare();
144  if( pCell== 0) break;
145  Int_t kDiv = pCell->fBest;
146  Double_t xDivi = pCell->fXdiv;
147  if(dCell == pCell->GetDau0() ) {
148  cellSize[kDiv] *=xDivi;
149  cellPosi[kDiv] *=xDivi;
150  } else if( dCell == pCell->GetDau1() ) {
151  cellSize[kDiv] *=(1.0-xDivi);
152  cellPosi[kDiv] =cellPosi[kDiv]*(1.0-xDivi)+xDivi;
153  } else {
154  Error( "GetHcub ","Something wrong with linked tree \n");
155  }
156  dCell=pCell;
157  }//while
158 }//GetHcub
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Provides size of the cell
162 /// Size parameters are calculated by analyzing information in all parents
163 /// cells up to the root cell. It takes time but saves memory.
164 
166 {
167  if(fDim<1) return;
168  const PDEFoamCell *pCell,*dCell;
169  cellSize=1.0; // load all components
170  dCell = this;
171  while(dCell != 0) {
172  pCell = dCell->GetPare();
173  if( pCell== 0) break;
174  Int_t kDiv = pCell->fBest;
175  Double_t xDivi = pCell->fXdiv;
176  if(dCell == pCell->GetDau0() ) {
177  cellSize[kDiv]=cellSize[kDiv]*xDivi;
178  } else if(dCell == pCell->GetDau1() ) {
179  cellSize[kDiv]=cellSize[kDiv]*(1.0-xDivi);
180  } else {
181  Error( "GetHSize ","Something wrong with linked tree \n");
182  }
183  dCell=pCell;
184  }//while
185 }//GetHSize
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Calculates volume of the cell using size params which are calculated
189 
191 {
192  Int_t k;
193  Double_t volu=1.0;
194  if(fDim>0) { // h-cubical subspace
195  PDEFoamVect cellSize(fDim);
196  GetHSize(cellSize);
197  for(k=0; k<fDim; k++) volu *= cellSize[k];
198  }
199  fVolume =volu;
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Get depth of cell in binary tree, where the root cell has depth
204 /// 1
205 
207 {
208  // check wheter we are in the root cell
209  if (fParent == 0)
210  return 1;
211 
212  UInt_t depth = 1;
213  PDEFoamCell *cell = this;
214  while ((cell=cell->GetPare()) != 0){
215  ++depth;
216  }
217  return depth;
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Get depth of cell tree, starting at this cell.
222 
224 {
225  if (GetStat() == 1) // this is an active cell
226  return depth + 1;
227 
228  UInt_t depth0 = 0, depth1 = 0;
229  if (GetDau0() != NULL)
230  depth0 = GetDau0()->GetTreeDepth(depth+1);
231  if (GetDau1() != NULL)
232  depth1 = GetDau1()->GetTreeDepth(depth+1);
233 
234  return (depth0 > depth1 ? depth0 : depth1);
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// Printout of the cell geometry parameters for the debug purpose
239 
241 {
242  if (!option) Error( "Print", "No option set\n");
243 
244  std::cout << " Status= "<< fStatus <<",";
245  std::cout << " Volume= "<< fVolume <<",";
246  std::cout << " TrueInteg= " << fIntegral <<",";
247  std::cout << " DriveInteg= "<< fDrive <<",";
248  std::cout << std::endl;;
249  std::cout << " Xdiv= "<<fXdiv<<",";
250  std::cout << " Best= "<<fBest<<",";
251  std::cout << " Parent= {"<< (GetPare() ? GetPare()->GetSerial() : -1) <<"} "; // extra DEBUG
252  std::cout << " Daught0= {"<< (GetDau0() ? GetDau0()->GetSerial() : -1 )<<"} "; // extra DEBUG
253  std::cout << " Daught1= {"<< (GetDau1() ? GetDau1()->GetSerial() : -1 )<<"} "; // extra DEBUG
254  std::cout << std::endl;;
255  //
256  //
257  if (fDim>0 ) {
258  PDEFoamVect cellPosi(fDim); PDEFoamVect cellSize(fDim);
259  GetHcub(cellPosi,cellSize);
260  std::cout <<" Posi= "; cellPosi.Print("1"); std::cout<<","<< std::endl;;
261  std::cout <<" Size= "; cellSize.Print("1"); std::cout<<","<< std::endl;;
262  }
263 }
PDEFoamCell * GetDau1() const
Definition: PDEFoamCell.h:101
void GetHSize(PDEFoamVect &) const
Provides size of the cell Size parameters are calculated by analyzing information in all parents cell...
void Print(Option_t *option) const
Printout of the cell geometry parameters for the debug purpose.
TObject * fElement
Definition: PDEFoamCell.h:71
const char Option_t
Definition: RtypesCore.h:62
void Fill(Int_t, PDEFoamCell *, PDEFoamCell *, PDEFoamCell *)
Fills in certain data into newly allocated cell.
void Print(Option_t *option) const
Printout of all vector components.
int Int_t
Definition: RtypesCore.h:41
virtual ~PDEFoamCell()
Destructor.
STL namespace.
PDEFoamCell * GetPare() const
Definition: PDEFoamCell.h:99
Double_t fIntegral
Definition: PDEFoamCell.h:68
const Int_t kDiv
Definition: TPCON.h:32
UInt_t GetTreeDepth(UInt_t depth=0)
Get depth of cell tree, starting at this cell.
void CalcVolume()
Calculates volume of the cell using size params which are calculated.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
UInt_t GetDepth()
Get depth of cell in binary tree, where the root cell has depth 1.
Double_t fVolume
Definition: PDEFoamCell.h:67
Int_t GetSerial() const
Definition: PDEFoamCell.h:106
#define ClassImp(name)
Definition: Rtypes.h:279
PDEFoamCell()
Default constructor for streamer.
Definition: PDEFoamCell.cxx:49
double Double_t
Definition: RtypesCore.h:55
PDEFoamCell * GetDau0() const
Definition: PDEFoamCell.h:100
Mother of all ROOT objects.
Definition: TObject.h:37
void GetHcub(PDEFoamVect &, PDEFoamVect &) const
Provides size and position of the cell These parameter are calculated by analyzing information in all...
Abstract ClassifierFactory template that handles arbitrary types.
Int_t GetStat() const
Definition: PDEFoamCell.h:97
#define NULL
Definition: Rtypes.h:82