136 fFillFoamWithOrigWeights(
kFALSE),
137 fDTSeparation(
kFoam),
140 fTimer(new
Timer(0, "PDEFoam", kTRUE)),
146 fVariableNames->SetOwner(kTRUE);
175 fFillFoamWithOrigWeights(
kFALSE),
176 fDTSeparation(
kFoam),
183 if(strlen(name) > 128)
250 Log() <<
kFATAL <<
"COPY CONSTRUCTOR NOT IMPLEMENTED" <<
Endl;
263 Log() <<
kFATAL <<
"<SetDim>: Dimension is zero or negative!" <<
Endl;
278 Log() <<
kFATAL <<
"<SetXmin>: Dimension out of bounds!" <<
Endl;
289 Log() <<
kFATAL <<
"<SetXmax>: Dimension out of bounds!" <<
Endl;
339 htitle = TString(
"Edge Histogram No. ");
409 cell->
Fill(status, parent, 0, 0);
462 cell->
GetHcub(cellPosi,cellSize);
472 for (
Int_t idim = 0; idim <
fDim; ++idim)
497 if (fDim>0)
for (j=0; j<
fDim; j++) xRand[j]= cellPosi[j] +
fAlpha[j]*(cellSize[j]);
499 wt = dx*
Eval(xRand, event_density);
500 totevents += event_density;
504 for (k=0; k<
fDim; k++) {
514 if (ceSum[3]>wt) ceSum[3]=wt;
515 if (ceSum[4]<wt) ceSum[4]=wt;
517 if (ceSum[1]>0) nevEff = ceSum[0]*ceSum[0]/ceSum[1];
523 if (fNSampl>0) totevents /=
fNSampl;
527 if (cell==
fCells[0] && ceSum[0]<=0.0){
529 Log() <<
kFATAL <<
"No events were found during exploration of " 530 <<
"root cell. Please check PDEFoam parameters nSampl " 531 <<
"and VolFrac." <<
Endl;
533 Log() <<
kWARNING <<
"Negative number of events found during " 534 <<
"exploration of root cell" <<
Endl;
539 for (k=0; k<
fDim;k++){
548 Double_t intTrue = ceSum[0]/(nevMC+0.000001);
551 if (kBest == -1)
Varedu(ceSum,kBest,xBest,yBest);
552 intDriv =
sqrt(ceSum[1]/nevMC) -intTrue;
563 for (parent = cell->
GetPare(); parent!=0; parent = parent->
GetPare()){
566 parent->
SetIntg( parIntg +intTrue -intOld );
567 parent->
SetDriv( parDriv +intDriv -driOld );
593 for(
Int_t kProj=0; kProj<
fDim; kProj++) {
604 aswIn += ((
TH1D *)(*
fHistEdg)[kProj])->GetBinContent(jUp);
611 else sswIn =
sqrt(asswIn) /
sqrt(nent*(xUp-xLo)) *(xUp-xLo);
614 else sswOut=
sqrt(sswAll-asswIn)/
sqrt(nent*(1.0-xUp+xLo)) *(1.0-xUp+xLo);
615 if( (sswIn+sswOut) < sswtBest) {
616 sswtBest = sswIn+sswOut;
633 if(iLo == 0) xBest=yBest;
634 if(iUp ==
fNBin) yBest=xBest;
639 if( (kBest >= fDim) || (kBest<0) )
672 if(
fCells[i]->GetStat() == 1 ) {
693 if(driv > drivMax && bCutNmin && bCutMaxDepth) {
702 Log() <<
kVERBOSE <<
"Warning: No cell with more than " 704 else if (!bCutMaxDepth)
705 Log() <<
kVERBOSE <<
"Warning: Maximum depth reached: " 708 Log() <<
kWARNING <<
"<PDEFoam::PeekMax>: no more candidate cells (drivMax>0) found for further splitting." <<
Endl;
763 std::vector<Double_t> xvec;
787 if ( (iCell<0) || (iCell>
fLastCe) ) {
799 if (
Divide( newCell )==0)
break;
820 if( ( 0<=iDim) && (iDim<
fDim)) {
834 Int_t errors, warnings;
838 errors = 0; warnings = 0;
839 if (level==1)
Log() <<
kVERBOSE <<
"Performing consistency checks for created foam" <<
Endl;
840 for(iCell=1; iCell<=
fLastCe; iCell++) {
846 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has only one daughter " << iCell <<
Endl;
850 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has no daughter and is inactive " << iCell <<
Endl;
854 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has two daughters and is active " << iCell <<
Endl;
861 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d parent not pointing to this cell " << iCell <<
Endl;
867 if(cell != (cell->
GetDau0())->GetPare()) {
869 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d daughter 0 not pointing to this cell " << iCell <<
Endl;
873 if(cell != (cell->
GetDau1())->GetPare()) {
875 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d daughter 1 not pointing to this cell " << iCell <<
Endl;
880 if(level==1)
Log() <<
kFATAL <<
"ERROR: Cell no. " << iCell <<
" has Volume of <1E-50" <<
Endl;
885 for(iCell=0; iCell<=
fLastCe; iCell++) {
889 if(level==1)
Log() <<
kFATAL <<
"ERROR: Cell no. " << iCell <<
" is active but Volume is 0 " <<
Endl;
894 Log() <<
kVERBOSE <<
"Check has found " << errors <<
" errors and " << warnings <<
" warnings." <<
Endl;
897 Info(
"CheckAll",
"Check - found total %d errors \n",errors);
907 if (iCell < 0 || iCell >
fLastCe) {
909 <<
")>: cell number " << iCell <<
" out of bounds!" 919 Log() <<
"Cell[" << iCell <<
"]={ ";
921 Log() <<
" Xdiv[abs. coord.]=" 924 Log() <<
" Abs. coord. = (";
926 Log() <<
"dim[" << idim <<
"]={" 936 Log() <<
"Elements: [";
940 if (i>0)
Log() <<
", ";
968 std::vector<Float_t> values = ev->
GetValues();
1032 return kernel->
Estimate(
this, txvec, cv);
1056 std::map<Int_t,Float_t> txvec;
1057 for (std::map<Int_t,Float_t>::const_iterator it=xvec.begin(); it!=xvec.end(); ++it)
1058 txvec.insert(std::pair<Int_t, Float_t>(it->first,
VarTransform(it->first, it->second)));
1061 std::vector<PDEFoamCell*> cells =
FindCells(txvec);
1064 std::vector<Float_t> cell_values;
1065 cell_values.reserve(cells.size());
1066 for (std::vector<PDEFoamCell*>::const_iterator cell_it=cells.begin();
1067 cell_it != cells.end(); ++cell_it)
1100 cell0->
GetHcub(cellPosi0,cellSize0);
1102 if (xvec.at(idim)<=cellPosi0[idim]+cellSize0[idim])
1138 map<Int_t, Float_t>::const_iterator it = txvec.find(idim);
1140 if (it != txvec.end()){
1144 cell0->
GetHcub(cellPosi0,cellSize0);
1146 if (it->second <= cellPosi0[idim] + cellSize0[idim])
1157 cells.push_back(cell);
1178 std::map<Int_t, Float_t> txvec_map;
1179 for (
UInt_t i=0; i<txvec.size(); ++i)
1180 txvec_map.insert(std::pair<Int_t, Float_t>(i, txvec.at(i)));
1183 std::vector<PDEFoamCell*> cells(0);
1209 std::vector<PDEFoamCell*> cells(0);
1232 Log() <<
kFATAL <<
"<Draw1Dim>: function can only be used for 1-dimensional foams!" 1238 h1=
new TH1D(hname,
"1-dimensional Foam", nbin,
fXmin[0],
fXmax[0]);
1240 if (!h1)
Log() <<
kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1245 std::vector<Float_t> txvec;
1248 if (kernel !=
NULL) {
1250 val = kernel->
Estimate(
this, txvec, cell_value);
1283 if ((idim1>=
GetTotDim()) || (idim1<0) ||
1286 Log() <<
kFATAL <<
"<Project2>: wrong dimensions given: " 1287 << idim1 <<
", " << idim2 <<
Endl;
1293 Log() <<
kWARNING <<
"Warning: number of bins too big: " << nbin
1294 <<
" Using 1000 bins for each dimension instead." <<
Endl;
1296 }
else if (nbin<1) {
1298 <<
"; set nbin=50" <<
Endl;
1308 h1=
new TH2D(hname.
Data(),
Form(
"var%d vs var%d",idim1,idim2), nbin,
fXmin[idim1],
fXmax[idim1], nbin, fXmin[idim2], fXmax[idim2]);
1310 if (!h1)
Log() <<
kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1318 std::map<Int_t, Float_t> txvec;
1324 std::vector<TMVA::PDEFoamCell*> cells =
FindCells(txvec);
1329 for (std::vector<TMVA::PDEFoamCell*>::const_iterator it = cells.begin();
1330 it != cells.end(); ++it) {
1333 (*it)->GetHcub(cellPosi,cellSize);
1336 std::vector<Float_t> tvec;
1338 if ( i != idim1 && i != idim2 )
1339 tvec.push_back(cellPosi[i] + 0.5*cellSize[i]);
1341 tvec.push_back(txvec[i]);
1343 if (kernel !=
NULL) {
1345 sum_cv += kernel->
Estimate(
this, tvec, cell_value);
1385 Log() <<
kWARNING <<
"<GetCellDensity(cell)>: ERROR: cell volume" 1386 <<
" negative or zero!" 1387 <<
" ==> return cell density 0!" 1388 <<
" cell volume=" << volume
1391 Log() <<
kWARNING <<
"<GetCellDensity(cell)>: WARNING: cell volume" 1392 <<
" close to zero!" 1393 <<
" cell volume: " << volume <<
Endl;
1415 Log() <<
kFATAL <<
"<GetCellValue>: unknown cell value" <<
Endl;
1457 Log() <<
kFATAL <<
"<SetCellElement> ERROR: cell element is not a TVectorD*" <<
Endl;
1525 Log() <<
kFATAL <<
"RootPlot2dim() can only be used with " 1526 <<
"two-dimensional foams!" <<
Endl;
1534 }
else if (opt.
Contains(
"rms_ov_mean")){
1542 plotcellnumber =
kTRUE;
1545 std::ofstream outfile(filename, std::ios::out);
1547 outfile<<
"{" << std::endl;
1552 outfile <<
"TColor *graycolors[100];" << std::endl;
1553 outfile <<
"for (Int_t i=0.; i<100; i++)" << std::endl;
1554 outfile <<
" graycolors[i]=new TColor(1000+i, 1-(Float_t)i/100.,1-(Float_t)i/100.,1-(Float_t)i/100.);"<< std::endl;
1557 outfile <<
"cMap = new TCanvas(\"" <<
fName <<
"\",\"Cell Map for " 1558 <<
fName <<
"\",600,600);" << std::endl;
1560 outfile<<
"TBox*a=new TBox();"<<std::endl;
1561 outfile<<
"a->SetFillStyle(0);"<<std::endl;
1562 outfile<<
"a->SetLineWidth(4);"<<std::endl;
1563 outfile<<
"TBox *b1=new TBox();"<<std::endl;
1564 outfile<<
"TText*t=new TText();"<<std::endl;
1566 outfile << (colors ?
"gStyle->SetPalette(1, 0);" :
"gStyle->SetPalette(0);")
1568 outfile <<
"b1->SetFillStyle(1001);"<<std::endl;
1569 outfile<<
"TBox *b2=new TBox();"<<std::endl;
1570 outfile <<
"b2->SetFillStyle(0);"<<std::endl;
1573 outfile <<
"b1->SetFillStyle(0);"<<std::endl;
1586 if (
fCells[iCell]->GetStat() == 1) {
1594 outfile <<
"// observed minimum and maximum of distribution: " << std::endl;
1595 outfile <<
"// Float_t zmin = "<< zmin <<
";" << std::endl;
1596 outfile <<
"// Float_t zmax = "<< zmax <<
";" << std::endl;
1599 outfile <<
"// used minimum and maximum of distribution (taking into account log scale if applicable): " << std::endl;
1600 outfile <<
"Float_t zmin = "<< zmin <<
";" << std::endl;
1601 outfile <<
"Float_t zmax = "<< zmax <<
";" << std::endl;
1607 Float_t scale = (ncolors-1)/(zmax - zmin);
1612 outfile <<
"// =========== Rectangular cells ==========="<< std::endl;
1614 if (
fCells[iCell]->GetStat() == 1) {
1616 x1 = offs+lpag*(cellPosi[0]);
1617 y1 = offs+lpag*(cellPosi[1]);
1618 x2 = offs+lpag*(cellPosi[0]+cellSize[0]);
1619 y2 = offs+lpag*(cellPosi[1]+cellSize[1]);
1630 color = 1000+(
Int_t((value-zmin)*scale));
1633 outfile <<
"b1->SetFillColor(" << color <<
");" << std::endl;
1637 outfile<<
"b1->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1639 outfile<<
"b2->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1642 if (plotcellnumber) {
1643 outfile<<
"t->SetTextColor(4);"<<std::endl;
1645 outfile<<
"t->SetTextSize(0.025);"<<std::endl;
1647 outfile<<
"t->SetTextSize(0.015);"<<std::endl;
1649 outfile<<
"t->SetTextSize(0.008);"<<std::endl;
1650 x = offs+lpag*(cellPosi[0]+0.5*cellSize[0]);
1651 y = offs+lpag*(cellPosi[1]+0.5*cellSize[1]);
1652 outfile<<
"t->DrawText("<<x<<
","<<y<<
","<<
"\""<<iCell<<
"\""<<
");"<<std::endl;
1656 outfile<<
"// ============== End Rectangles ==========="<< std::endl;
1658 outfile <<
"}" << std::endl;
Bool_t fFillFoamWithOrigWeights
PDEFoamCell * GetDau1() const
void Varedu(Double_t [], Int_t &, Double_t &, Double_t &)
Internal subrogram used by Create.
virtual void FillFoamCells(const Event *ev, Float_t wt)
This function fills a weight 'wt' into the PDEFoam cell, which corresponds to the given event 'ev'...
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Random number generator class based on M.
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
MsgLogger & Endl(MsgLogger &ml)
void SetElement(TObject *fobj)
void Print(Option_t *option) const
Printout of the cell geometry parameters for the debug purpose.
Long_t PeekMax()
Internal subprogram used by Create.
TObjArray * fVariableNames
timer for graphical output
Int_t * fInhiDiv
[fDim] Dynamic Mask for cell division
void OutputGrow(Bool_t finished=false)
message logger
Float_t VarTransform(Int_t idim, Float_t x) const
R__EXTERN TStyle * gStyle
Double_t GetVolume() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void Fill(Int_t, PDEFoamCell *, PDEFoamCell *, PDEFoamCell *)
Fills in certain data into newly allocated cell.
std::vector< TMVA::PDEFoamCell * > FindCells(const std::vector< Float_t > &) const
Find all cells, that contain txvec.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
void Grow()
Internal subrogram used by Create.
static const char * filename()
static Bool_t AddDirectoryStatus()
static function: cannot be inlined on Windows/NT
void SetXmin(Int_t idim, Double_t wmin)
set lower foam bound in dimension idim
Double_t GetCellElement(const PDEFoamCell *cell, UInt_t i) const
Returns cell element i of cell 'cell'.
void SetCellElement(PDEFoamCell *cell, UInt_t i, Double_t value)
Set cell element i of cell to value.
Int_t Divide(PDEFoamCell *)
Internal subrogram used by Create.
TH1D * Draw1Dim(ECellValue cell_value, Int_t nbin, PDEFoamKernelBase *kernel=NULL)
Draws 1-dimensional foam (= histogram)
PDEFoamCell * GetPare() const
void CheckAll(Int_t)
User utility, miscellaneous and debug.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Int_t CellFill(Int_t, PDEFoamCell *)
Internal subprogram used by Create.
void MakeAlpha()
Internal subrogram used by Create.
Timer * fTimer
distribution of training events
virtual Bool_t CellValueIsUndefined(PDEFoamCell *)
Returns true, if the value of the given cell is undefined.
static const double x2[5]
virtual Float_t Estimate(PDEFoam *, std::vector< Float_t > &, ECellValue)=0
virtual Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density)=0
void RootPlot2dim(const TString &filename, TString opt, Bool_t createCanvas=kTRUE, Bool_t colors=kTRUE)
Debugging tool which plots the cells of a 2-dimensional PDEFoam as rectangles in C++ format readable ...
PDEFoamCell * FindCell(const std::vector< Float_t > &) const
Find cell that contains 'xvec' (in foam coordinates [0,1]).
PDEFoamDensityBase * fDistr
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
void SetDau1(PDEFoamCell *Daug)
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
void ResetCellElements()
Remove the cell elements from all cells.
virtual void Explore(PDEFoamCell *Cell)
Internal subprogram used by Create.
static const Float_t kHigh
TVectorT< Double_t > TVectorD
void FillBinarySearchTree(const Event *ev)
This method inserts the given event 'ev' it into the binary search tree.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
void InitCells()
Internal subprogram used by Create.
void PrintCells()
Prints geometry of ALL cells of the FOAM.
Float_t VarTransformInvers(Int_t idim, Float_t x) const
void SetXdiv(Double_t Xdiv)
void SetXmax(Int_t idim, Double_t wmax)
set upper foam bound in dimension idim
void CalcVolume()
Calculates volume of the cell using size params which are calculated.
PDEFoamDensityBase * GetDistr() const
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TVectorT< Element > & Zero()
Set vector elements to zero.
char * Form(const char *fmt,...)
UInt_t GetDepth()
Get depth of cell in binary tree, where the root cell has depth 1.
void SetDriv(Double_t Driv)
TObject * GetElement() const
void SetDim(Int_t kDim)
Sets dimension of cubical space.
1-D histogram with a double per channel (see TH1 documentation)}
void PrintCell(Long_t iCell=0)
Prints geometry of and elements of 'iCell', as well as relations to parent and daughter cells...
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
EDTSeparation fDTSeparation
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Double_t Eval(Double_t *xRand, Double_t &event_density)
Internal subprogram.
static const double x1[5]
Int_t fNoAct
[fDim] Flags for inhibiting cell division
void Create()
Basic initialization of FOAM invoked by the user.
PDEFoamCell * GetDau0() const
virtual TH2D * Project2(Int_t idim1, Int_t idim2, ECellValue cell_value=kValue, PDEFoamKernelBase *kernel=NULL, UInt_t nbin=50)
Project foam variable idim1 and variable idim2 to histogram.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Float_t GetCellValue(const std::vector< Float_t > &xvec, ECellValue cv, PDEFoamKernelBase *)
This function finds the cell, which corresponds to the given untransformed event vector 'xvec' and re...
void SetSerial(Int_t Serial)
Mother of all ROOT objects.
void GetHcub(PDEFoamVect &, PDEFoamVect &) const
Provides size and position of the cell These parameter are calculated by analyzing information in all...
void SetIntg(Double_t Intg)
Abstract ClassifierFactory template that handles arbitrary types.
void DeleteBinarySearchTree()
Delete the foam's density estimator, which contains the binary search tree.
std::vector< Float_t > & GetValues()
void FillBinarySearchTree(const Event *ev)
Insert event to internal foam's density estimator PDEFoamDensityBase.
virtual ~PDEFoam()
Default destructor.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
void SetDau0(PDEFoamCell *Daug)
virtual Int_t GetNbinsX() const
static const Float_t kVlow
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
UInt_t GetNActiveCells() const
void SetInhiDiv(Int_t, Int_t)
This can be called before Create, after setting kDim It defines which variables are excluded in the p...
virtual Int_t GetNbinsY() const
PDEFoam()
Default constructor for streamer, user should not use it.
2-D histogram with a double per channel (see TH1 documentation)}
const char * Data() const
UInt_t GetMaxDepth() const