126 fFillFoamWithOrigWeights(
kFALSE),
127 fDTSeparation(
kFoam),
130 fTimer(new
Timer(0, "PDEFoam", kTRUE)),
136 fVariableNames->SetOwner(kTRUE);
165 fFillFoamWithOrigWeights(
kFALSE),
166 fDTSeparation(
kFoam),
173 if(strlen(name) > 128)
240 Log() <<
kFATAL <<
"COPY CONSTRUCTOR NOT IMPLEMENTED" <<
Endl;
253 Log() <<
kFATAL <<
"<SetDim>: Dimension is zero or negative!" <<
Endl;
268 Log() <<
kFATAL <<
"<SetXmin>: Dimension out of bounds!" <<
Endl;
279 Log() <<
kFATAL <<
"<SetXmax>: Dimension out of bounds!" <<
Endl;
326 TString hname, htitle;
327 hname =
fName+TString(
"_HistEdge_");
329 htitle = TString(
"Edge Histogram No. ");
331 (*fHistEdg)[i] =
new TH1D(hname.Data(),htitle.Data(),
fNBin,0.0, 1.0);
399 cell->
Fill(status, parent, 0, 0);
452 cell->
GetHcub(cellPosi,cellSize);
462 for (
Int_t idim = 0; idim <
fDim; ++idim)
487 if (fDim>0)
for (j=0; j<
fDim; j++) xRand[j]= cellPosi[j] +
fAlpha[j]*(cellSize[j]);
489 wt = dx*
Eval(xRand, event_density);
490 totevents += event_density;
494 for (k=0; k<
fDim; k++) {
504 if (ceSum[3]>wt) ceSum[3]=wt;
505 if (ceSum[4]<wt) ceSum[4]=wt;
507 if (ceSum[1]>0) nevEff = ceSum[0]*ceSum[0]/ceSum[1];
513 if (fNSampl>0) totevents /=
fNSampl;
517 if (cell==
fCells[0] && ceSum[0]<=0.0){
519 Log() <<
kFATAL <<
"No events were found during exploration of " 520 <<
"root cell. Please check PDEFoam parameters nSampl " 521 <<
"and VolFrac." <<
Endl;
523 Log() <<
kWARNING <<
"Negative number of events found during " 524 <<
"exploration of root cell" <<
Endl;
529 for (k=0; k<
fDim;k++){
538 Double_t intTrue = ceSum[0]/(nevMC+0.000001);
541 if (kBest == -1)
Varedu(ceSum,kBest,xBest,yBest);
542 intDriv =
sqrt(ceSum[1]/nevMC) -intTrue;
553 for (parent = cell->
GetPare(); parent!=0; parent = parent->
GetPare()){
556 parent->
SetIntg( parIntg +intTrue -intOld );
557 parent->
SetDriv( parDriv +intDriv -driOld );
583 for(
Int_t kProj=0; kProj<
fDim; kProj++) {
594 aswIn += ((
TH1D *)(*
fHistEdg)[kProj])->GetBinContent(jUp);
601 else sswIn =
sqrt(asswIn) /
sqrt(nent*(xUp-xLo)) *(xUp-xLo);
604 else sswOut=
sqrt(sswAll-asswIn)/
sqrt(nent*(1.0-xUp+xLo)) *(1.0-xUp+xLo);
605 if( (sswIn+sswOut) < sswtBest) {
606 sswtBest = sswIn+sswOut;
623 if(iLo == 0) xBest=yBest;
624 if(iUp ==
fNBin) yBest=xBest;
629 if( (kBest >= fDim) || (kBest<0) )
662 if(
fCells[i]->GetStat() == 1 ) {
683 if(driv > drivMax && bCutNmin && bCutMaxDepth) {
692 Log() <<
kVERBOSE <<
"Warning: No cell with more than " 694 else if (!bCutMaxDepth)
695 Log() <<
kVERBOSE <<
"Warning: Maximum depth reached: " 698 Log() <<
kWARNING <<
"<PDEFoam::PeekMax>: no more candidate cells (drivMax>0) found for further splitting." <<
Endl;
753 std::vector<Double_t> xvec;
777 if ( (iCell<0) || (iCell>
fLastCe) ) {
789 if (
Divide( newCell )==0)
break;
810 if( ( 0<=iDim) && (iDim<
fDim)) {
824 Int_t errors, warnings;
828 errors = 0; warnings = 0;
829 if (level==1)
Log() <<
kVERBOSE <<
"Performing consistency checks for created foam" <<
Endl;
830 for(iCell=1; iCell<=
fLastCe; iCell++) {
836 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has only one daughter " << iCell <<
Endl;
840 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has no daughter and is inactive " << iCell <<
Endl;
844 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d has two daughters and is active " << iCell <<
Endl;
851 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d parent not pointing to this cell " << iCell <<
Endl;
857 if(cell != (cell->
GetDau0())->GetPare()) {
859 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d daughter 0 not pointing to this cell " << iCell <<
Endl;
863 if(cell != (cell->
GetDau1())->GetPare()) {
865 if (level==1)
Log() <<
kFATAL <<
"ERROR: Cell's no %d daughter 1 not pointing to this cell " << iCell <<
Endl;
870 if(level==1)
Log() <<
kFATAL <<
"ERROR: Cell no. " << iCell <<
" has Volume of <1E-50" <<
Endl;
875 for(iCell=0; iCell<=
fLastCe; iCell++) {
879 if(level==1)
Log() <<
kFATAL <<
"ERROR: Cell no. " << iCell <<
" is active but Volume is 0 " <<
Endl;
884 Log() <<
kVERBOSE <<
"Check has found " << errors <<
" errors and " << warnings <<
" warnings." <<
Endl;
887 Info(
"CheckAll",
"Check - found total %d errors \n",errors);
897 if (iCell < 0 || iCell >
fLastCe) {
899 <<
")>: cell number " << iCell <<
" out of bounds!" 909 Log() <<
"Cell[" << iCell <<
"]={ ";
911 Log() <<
" Xdiv[abs. coord.]=" 914 Log() <<
" Abs. coord. = (";
916 Log() <<
"dim[" << idim <<
"]={" 926 Log() <<
"Elements: [";
930 if (i>0)
Log() <<
", ";
958 std::vector<Float_t> values = ev->
GetValues();
1022 return kernel->
Estimate(
this, txvec, cv);
1046 std::map<Int_t,Float_t> txvec;
1047 for (std::map<Int_t,Float_t>::const_iterator it=xvec.begin(); it!=xvec.end(); ++it)
1048 txvec.insert(std::pair<Int_t, Float_t>(it->first,
VarTransform(it->first, it->second)));
1051 std::vector<PDEFoamCell*> cells =
FindCells(txvec);
1054 std::vector<Float_t> cell_values;
1055 cell_values.reserve(cells.size());
1056 for (std::vector<PDEFoamCell*>::const_iterator cell_it=cells.begin();
1057 cell_it != cells.end(); ++cell_it)
1090 cell0->
GetHcub(cellPosi0,cellSize0);
1092 if (xvec.at(idim)<=cellPosi0[idim]+cellSize0[idim])
1128 map<Int_t, Float_t>::const_iterator it = txvec.find(idim);
1130 if (it != txvec.end()){
1134 cell0->
GetHcub(cellPosi0,cellSize0);
1136 if (it->second <= cellPosi0[idim] + cellSize0[idim])
1147 cells.push_back(cell);
1168 std::map<Int_t, Float_t> txvec_map;
1169 for (
UInt_t i=0; i<txvec.size(); ++i)
1170 txvec_map.insert(std::pair<Int_t, Float_t>(i, txvec.at(i)));
1173 std::vector<PDEFoamCell*> cells(0);
1199 std::vector<PDEFoamCell*> cells(0);
1222 Log() <<
kFATAL <<
"<Draw1Dim>: function can only be used for 1-dimensional foams!" 1225 TString hname(
"h_1dim");
1228 h1=
new TH1D(hname,
"1-dimensional Foam", nbin,
fXmin[0],
fXmax[0]);
1230 if (!h1)
Log() <<
kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1235 std::vector<Float_t> txvec;
1238 if (kernel !=
NULL) {
1240 val = kernel->
Estimate(
this, txvec, cell_value);
1273 if ((idim1>=
GetTotDim()) || (idim1<0) ||
1276 Log() <<
kFATAL <<
"<Project2>: wrong dimensions given: " 1277 << idim1 <<
", " << idim2 <<
Endl;
1283 Log() <<
kWARNING <<
"Warning: number of bins too big: " << nbin
1284 <<
" Using 1000 bins for each dimension instead." <<
Endl;
1286 }
else if (nbin<1) {
1288 <<
"; set nbin=50" <<
Endl;
1293 TString hname(
Form(
"h_%d_vs_%d",idim1,idim2));
1298 h1=
new TH2D(hname.Data(),
Form(
"var%d vs var%d",idim1,idim2), nbin,
fXmin[idim1],
fXmax[idim1], nbin, fXmin[idim2], fXmax[idim2]);
1300 if (!h1)
Log() <<
kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1308 std::map<Int_t, Float_t> txvec;
1314 std::vector<TMVA::PDEFoamCell*> cells =
FindCells(txvec);
1319 for (std::vector<TMVA::PDEFoamCell*>::const_iterator it = cells.begin();
1320 it != cells.end(); ++it) {
1323 (*it)->GetHcub(cellPosi,cellSize);
1326 std::vector<Float_t> tvec;
1328 if ( i != idim1 && i != idim2 )
1329 tvec.push_back(cellPosi[i] + 0.5*cellSize[i]);
1331 tvec.push_back(txvec[i]);
1333 if (kernel !=
NULL) {
1335 sum_cv += kernel->
Estimate(
this, tvec, cell_value);
1375 Log() <<
kWARNING <<
"<GetCellDensity(cell)>: ERROR: cell volume" 1376 <<
" negative or zero!" 1377 <<
" ==> return cell density 0!" 1378 <<
" cell volume=" << volume
1381 Log() <<
kWARNING <<
"<GetCellDensity(cell)>: WARNING: cell volume" 1382 <<
" close to zero!" 1383 <<
" cell volume: " << volume <<
Endl;
1405 Log() <<
kFATAL <<
"<GetCellValue>: unknown cell value" <<
Endl;
1447 Log() <<
kFATAL <<
"<SetCellElement> ERROR: cell element is not a TVectorD*" <<
Endl;
1515 Log() <<
kFATAL <<
"RootPlot2dim() can only be used with " 1516 <<
"two-dimensional foams!" <<
Endl;
1522 if (opt.Contains(
"cell_value")){
1524 }
else if (opt.Contains(
"rms_ov_mean")){
1526 }
else if (opt.Contains(
"rms")){
1531 if (opt.Contains(
"cellnumber"))
1532 plotcellnumber =
kTRUE;
1535 std::ofstream outfile(filename, std::ios::out);
1537 outfile<<
"{" << std::endl;
1542 outfile <<
"TColor *graycolors[100];" << std::endl;
1543 outfile <<
"for (Int_t i=0.; i<100; i++)" << std::endl;
1544 outfile <<
" graycolors[i]=new TColor(1000+i, 1-(Float_t)i/100.,1-(Float_t)i/100.,1-(Float_t)i/100.);"<< std::endl;
1547 outfile <<
"cMap = new TCanvas(\"" <<
fName <<
"\",\"Cell Map for " 1548 <<
fName <<
"\",600,600);" << std::endl;
1550 outfile<<
"TBox*a=new TBox();"<<std::endl;
1551 outfile<<
"a->SetFillStyle(0);"<<std::endl;
1552 outfile<<
"a->SetLineWidth(4);"<<std::endl;
1553 outfile<<
"TBox *b1=new TBox();"<<std::endl;
1554 outfile<<
"TText*t=new TText();"<<std::endl;
1556 outfile << (colors ?
"gStyle->SetPalette(1, 0);" :
"gStyle->SetPalette(0);")
1558 outfile <<
"b1->SetFillStyle(1001);"<<std::endl;
1559 outfile<<
"TBox *b2=new TBox();"<<std::endl;
1560 outfile <<
"b2->SetFillStyle(0);"<<std::endl;
1563 outfile <<
"b1->SetFillStyle(0);"<<std::endl;
1576 if (
fCells[iCell]->GetStat() == 1) {
1584 outfile <<
"// observed minimum and maximum of distribution: " << std::endl;
1585 outfile <<
"// Float_t zmin = "<< zmin <<
";" << std::endl;
1586 outfile <<
"// Float_t zmax = "<< zmax <<
";" << std::endl;
1589 outfile <<
"// used minimum and maximum of distribution (taking into account log scale if applicable): " << std::endl;
1590 outfile <<
"Float_t zmin = "<< zmin <<
";" << std::endl;
1591 outfile <<
"Float_t zmax = "<< zmax <<
";" << std::endl;
1597 Float_t scale = (ncolors-1)/(zmax - zmin);
1602 outfile <<
"// =========== Rectangular cells ==========="<< std::endl;
1604 if (
fCells[iCell]->GetStat() == 1) {
1606 x1 = offs+lpag*(cellPosi[0]);
1607 y1 = offs+lpag*(cellPosi[1]);
1608 x2 = offs+lpag*(cellPosi[0]+cellSize[0]);
1609 y2 = offs+lpag*(cellPosi[1]+cellSize[1]);
1620 color = 1000+(
Int_t((value-zmin)*scale));
1623 outfile <<
"b1->SetFillColor(" << color <<
");" << std::endl;
1627 outfile<<
"b1->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1629 outfile<<
"b2->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1632 if (plotcellnumber) {
1633 outfile<<
"t->SetTextColor(4);"<<std::endl;
1635 outfile<<
"t->SetTextSize(0.025);"<<std::endl;
1637 outfile<<
"t->SetTextSize(0.015);"<<std::endl;
1639 outfile<<
"t->SetTextSize(0.008);"<<std::endl;
1640 x = offs+lpag*(cellPosi[0]+0.5*cellSize[0]);
1641 y = offs+lpag*(cellPosi[1]+0.5*cellSize[1]);
1642 outfile<<
"t->DrawText("<<x<<
","<<y<<
","<<
"\""<<iCell<<
"\""<<
");"<<std::endl;
1646 outfile<<
"// ============== End Rectangles ==========="<< std::endl;
1648 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 histogram.
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.
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
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.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
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.
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.
tomato 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.
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
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.
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
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.
tomato 2-D histogram with a double per channel (see TH1 documentation)}
UInt_t GetMaxDepth() const