File: PDEFoamCell.cxx

package info (click to toggle)
root-system 5.34.19%2Bdfsg-1.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 210,548 kB
  • ctags: 209,442
  • sloc: cpp: 1,488,197; ansic: 345,435; sh: 19,468; fortran: 12,570; makefile: 7,873; python: 7,683; xml: 555; ruby: 553; csh: 356; perl: 329; objc: 38; sql: 14; tcl: 4
file content (253 lines) | stat: -rw-r--r-- 8,943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// @(#)root/tmva $Id$
// Author: S.Jadach, Tancredi Carli, Dominik Dannheim, Alexander Voigt

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Classes: PDEFoamCell                                                           *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Objects of this class are hyperrectangular cells organized in             *
 *      the binary tree. Special algoritm for encoding relalive                   *
 *      positioning of the cells saves total memory allocation needed             *
 *      for the system of cells.                                                  *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      S. Jadach        - Institute of Nuclear Physics, Cracow, Poland           *
 *      Tancredi Carli   - CERN, Switzerland                                      *
 *      Dominik Dannheim - CERN, Switzerland                                      *
 *      Alexander Voigt  - TU Dresden, Germany                                    *
 *                                                                                *
 * Copyright (c) 2008:                                                            *
 *      CERN, Switzerland                                                         *
 *      MPI-K Heidelberg, Germany                                                 *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#include <iostream>
#include <ostream>

#ifndef ROOT_TMVA_PDEFoamCell
#include "TMVA/PDEFoamCell.h"
#endif

using namespace std;

ClassImp(TMVA::PDEFoamCell)

//_____________________________________________________________________
TMVA::PDEFoamCell::PDEFoamCell()
   : TObject(),
     fDim(0),
     fSerial(0),
     fStatus(1),
     fParent(0),
     fDaught0(0),
     fDaught1(0),
     fXdiv(0.0),
     fBest(0),
     fVolume(0.0),
     fIntegral(0.0),
     fDrive(0.0),
     fElement(0)
{
   // Default constructor for streamer
}

//_____________________________________________________________________
TMVA::PDEFoamCell::PDEFoamCell(Int_t kDim)
   : TObject(),
     fDim(kDim),
     fSerial(0),
     fStatus(1),
     fParent(0),
     fDaught0(0),
     fDaught1(0),
     fXdiv(0.0),
     fBest(0),
     fVolume(0.0),
     fIntegral(0.0),
     fDrive(0.0),
     fElement(0)
{
   // User constructor allocating single empty Cell
   if ( kDim <= 0 )
      Error( "PDEFoamCell", "Dimension has to be >0" );
}

//_____________________________________________________________________
TMVA::PDEFoamCell::PDEFoamCell(const PDEFoamCell &cell)
   : TObject(),
     fDim     (cell.fDim),
     fSerial  (cell.fSerial),
     fStatus  (cell.fStatus),
     fParent  (cell.fParent),
     fDaught0 (cell.fDaught0),
     fDaught1 (cell.fDaught1),
     fXdiv    (cell.fXdiv),
     fBest    (cell.fBest),
     fVolume  (cell.fVolume),
     fIntegral(cell.fIntegral),
     fDrive   (cell.fDrive),
     fElement (cell.fElement)
{
   // Copy constructor
   Error( "PDEFoamCell", "COPY CONSTRUCTOR NOT IMPLEMENTED" );
}

//_____________________________________________________________________
TMVA::PDEFoamCell::~PDEFoamCell()
{
   // Destructor
}

//_____________________________________________________________________
void TMVA::PDEFoamCell::Fill(Int_t status, PDEFoamCell *parent, PDEFoamCell *daugh1, PDEFoamCell *daugh2)
{
   // Fills in certain data into newly allocated cell

   fStatus  = status;
   fParent  = parent;
   fDaught0 = daugh1;
   fDaught1 = daugh2;
}

////////////////////////////////////////////////////////////////////////////////
//              GETTERS/SETTERS
////////////////////////////////////////////////////////////////////////////////

//_____________________________________________________________________
void    TMVA::PDEFoamCell::GetHcub( PDEFoamVect &cellPosi, PDEFoamVect &cellSize)  const
{
   // Provides size and position of the cell
   // These parameter are calculated by analyzing information in all parents
   // cells up to the root cell. It takes time but saves memory.
   if(fDim<1) return;
   const PDEFoamCell *pCell,*dCell;
   cellPosi = 0.0; cellSize=1.0; // load all components
   dCell = this;
   while(dCell != 0) {
      pCell = dCell->GetPare();
      if( pCell== 0) break;
      Int_t    kDiv = pCell->fBest;
      Double_t xDivi = pCell->fXdiv;
      if(dCell == pCell->GetDau0()  ) {
         cellSize[kDiv] *=xDivi;
         cellPosi[kDiv] *=xDivi;
      } else if(   dCell == pCell->GetDau1()  ) {
         cellSize[kDiv] *=(1.0-xDivi);
         cellPosi[kDiv]  =cellPosi[kDiv]*(1.0-xDivi)+xDivi;
      } else {
         Error( "GetHcub ","Something wrong with linked tree \n");
      }
      dCell=pCell;
   }//while
}//GetHcub

//_____________________________________________________________________
void    TMVA::PDEFoamCell::GetHSize( PDEFoamVect &cellSize)  const
{
   // Provides size of the cell
   // Size parameters are calculated by analyzing information in all parents
   // cells up to the root cell. It takes time but saves memory.
   if(fDim<1) return;
   const PDEFoamCell *pCell,*dCell;
   cellSize=1.0; // load all components
   dCell = this;
   while(dCell != 0) {
      pCell = dCell->GetPare();
      if( pCell== 0) break;
      Int_t    kDiv = pCell->fBest;
      Double_t xDivi = pCell->fXdiv;
      if(dCell == pCell->GetDau0() ) {
         cellSize[kDiv]=cellSize[kDiv]*xDivi;
      } else if(dCell == pCell->GetDau1()  ) {
         cellSize[kDiv]=cellSize[kDiv]*(1.0-xDivi);
      } else {
         Error( "GetHSize ","Something wrong with linked tree \n");
      }
      dCell=pCell;
   }//while
}//GetHSize

//_____________________________________________________________________
void TMVA::PDEFoamCell::CalcVolume(void)
{
   // Calculates volume of the cell using size params which are calculated

   Int_t k;
   Double_t volu=1.0;
   if(fDim>0) {         // h-cubical subspace
      PDEFoamVect cellSize(fDim);
      GetHSize(cellSize);
      for(k=0; k<fDim; k++) volu *= cellSize[k];
   }
   fVolume =volu;
}

//_____________________________________________________________________
UInt_t TMVA::PDEFoamCell::GetDepth()
{
   // Get depth of cell in binary tree, where the root cell has depth
   // 1

   // check whether we are in the root cell
   if (fParent == 0)
      return 1;

   UInt_t depth = 1;
   PDEFoamCell *cell = this;
   while ((cell=cell->GetPare()) != 0){
      ++depth;
   }
   return depth;
}

//_____________________________________________________________________
UInt_t TMVA::PDEFoamCell::GetTreeDepth(UInt_t depth)
{
   // Get depth of cell tree, starting at this cell.

   if (GetStat() == 1)    // this is an active cell
      return depth + 1;

   UInt_t depth0 = 0, depth1 = 0;
   if (GetDau0() != NULL)
      depth0 = GetDau0()->GetTreeDepth(depth+1);
   if (GetDau1() != NULL)
      depth1 = GetDau1()->GetTreeDepth(depth+1);

   return (depth0 > depth1 ? depth0 : depth1);
}

//_____________________________________________________________________
void TMVA::PDEFoamCell::Print(Option_t *option) const
{
   // Printout of the cell geometry parameters for the debug purpose

   if (!option) Error( "Print", "No option set\n");

   std::cout <<  " Status= "<<     fStatus   <<",";
   std::cout <<  " Volume= "<<     fVolume   <<",";
   std::cout <<  " TrueInteg= " << fIntegral <<",";
   std::cout <<  " DriveInteg= "<< fDrive    <<",";
   std::cout << std::endl;;
   std::cout <<  " Xdiv= "<<fXdiv<<",";
   std::cout <<  " Best= "<<fBest<<",";
   std::cout <<  " Parent=  {"<< (GetPare() ? GetPare()->GetSerial() : -1) <<"} "; // extra DEBUG
   std::cout <<  " Daught0= {"<< (GetDau0() ? GetDau0()->GetSerial() : -1 )<<"} "; // extra DEBUG
   std::cout <<  " Daught1= {"<< (GetDau1() ? GetDau1()->GetSerial()  : -1 )<<"} "; // extra DEBUG
   std::cout << std::endl;;
   //
   //
   if (fDim>0 ) {
      PDEFoamVect cellPosi(fDim); PDEFoamVect cellSize(fDim);
      GetHcub(cellPosi,cellSize);
      std::cout <<"   Posi= "; cellPosi.Print("1"); std::cout<<","<< std::endl;;
      std::cout <<"   Size= "; cellSize.Print("1"); std::cout<<","<< std::endl;;
   }
}