120 fFoamType(kSeparate),
127 fFillFoamWithOrigWeights(
kFALSE),
128 fDTSeparation(kFoam),
174 if(strlen(name) > 128)
175 Log() << kFATAL <<
"Name too long " << name.Data() <<
Endl;
241 Log() << kFATAL <<
"COPY CONSTRUCTOR NOT IMPLEMENTED" <<
Endl;
254 Log() << kFATAL <<
"<SetDim>: Dimension is zero or negative!" <<
Endl;
269 Log() << kFATAL <<
"<SetXmin>: Dimension out of bounds!" <<
Endl;
280 Log() << kFATAL <<
"<SetXmax>: Dimension out of bounds!" <<
Endl;
298 if(
fPseRan==0)
Log() << kFATAL <<
"Random number generator not set" <<
Endl;
299 if(
fDistr==0)
Log() << kFATAL <<
"Distribution function not set" <<
Endl;
300 if(
fDim==0)
Log() << kFATAL <<
"Zero dimension not allowed" <<
Endl;
307 if(
fRvec==0)
Log() << kFATAL <<
"Cannot initialize buffer fRvec" <<
Endl;
311 if(
fAlpha==0)
Log() << kFATAL <<
"Cannot initialize buffer fAlpha" <<
Endl;
327 TString hname, htitle;
328 hname =
fName+TString(
"_HistEdge_");
330 htitle = TString(
"Edge Histogram No. ");
332 (*fHistEdg)[i] =
new TH1D(hname.Data(),htitle.Data(),
fNBin,0.0, 1.0);
367 Log() << kFATAL <<
"not enough memory to create " <<
fNCells 394 Log() << kFATAL <<
"Too many cells" <<
Endl;
400 cell->
Fill(status, parent, 0, 0);
453 cell->
GetHcub(cellPosi,cellSize);
463 for (
Int_t idim = 0; idim <
fDim; ++idim)
488 if (fDim>0)
for (j=0; j<
fDim; j++) xRand[j]= cellPosi[j] +
fAlpha[j]*(cellSize[j]);
490 wt = dx*
Eval(xRand, event_density);
491 totevents += event_density;
495 for (k=0; k<
fDim; k++) {
505 if (ceSum[3]>wt) ceSum[3]=wt;
506 if (ceSum[4]<wt) ceSum[4]=wt;
508 if (ceSum[1]>0) nevEff = ceSum[0]*ceSum[0]/ceSum[1];
514 if (fNSampl>0) totevents /=
fNSampl;
518 if (cell==
fCells[0] && ceSum[0]<=0.0){
520 Log() << kFATAL <<
"No events were found during exploration of " 521 <<
"root cell. Please check PDEFoam parameters nSampl " 522 <<
"and VolFrac." <<
Endl;
524 Log() << kWARNING <<
"Negative number of events found during " 525 <<
"exploration of root cell" <<
Endl;
530 for (k=0; k<
fDim;k++){
539 Double_t intTrue = ceSum[0]/(nevMC+0.000001);
542 if (kBest == -1)
Varedu(ceSum,kBest,xBest,yBest);
543 intDriv =
sqrt(ceSum[1]/nevMC) -intTrue;
554 for (parent = cell->
GetPare(); parent!=0; parent = parent->
GetPare()){
557 parent->
SetIntg( parIntg +intTrue -intOld );
558 parent->
SetDriv( parDriv +intDriv -driOld );
584 for(
Int_t kProj=0; kProj<
fDim; kProj++) {
595 aswIn += ((
TH1D *)(*
fHistEdg)[kProj])->GetBinContent(jUp);
602 else sswIn =
sqrt(asswIn) /
sqrt(nent*(xUp-xLo)) *(xUp-xLo);
605 else sswOut=
sqrt(sswAll-asswIn)/
sqrt(nent*(1.0-xUp+xLo)) *(1.0-xUp+xLo);
606 if( (sswIn+sswOut) < sswtBest) {
607 sswtBest = sswIn+sswOut;
624 if(iLo == 0) xBest=yBest;
625 if(iUp ==
fNBin) yBest=xBest;
630 if( (kBest >= fDim) || (kBest<0) )
631 Log() << kFATAL <<
"Something wrong with kBest" <<
Endl;
663 if(
fCells[i]->GetStat() == 1 ) {
684 if(driv > drivMax && bCutNmin && bCutMaxDepth) {
693 Log() << kVERBOSE <<
"Warning: No cell with more than " 695 else if (!bCutMaxDepth)
696 Log() << kVERBOSE <<
"Warning: Maximum depth reached: " 699 Log() << kWARNING <<
"<PDEFoam::PeekMax>: no more candidate cells (drivMax>0) found for further splitting." <<
Endl;
727 if( kBest<0 || kBest>=
fDim )
Log() << kFATAL <<
"Wrong kBest" <<
Endl;
754 std::vector<Double_t> xvec;
778 if ( (iCell<0) || (iCell>
fLastCe) ) {
779 Log() << kVERBOSE <<
"Break: "<<
fLastCe+1 <<
" cells created" <<
Endl;
790 if (
Divide( newCell )==0)
break;
805 if(
fDim==0)
Log() << kFATAL <<
"SetInhiDiv: fDim=0" <<
Endl;
811 if( ( 0<=iDim) && (iDim<
fDim)) {
814 Log() << kFATAL <<
"Wrong iDim" <<
Endl;
825 Int_t errors, warnings;
829 errors = 0; warnings = 0;
830 if (level==1)
Log() << kVERBOSE <<
"Performing consistency checks for created foam" <<
Endl;
831 for(iCell=1; iCell<=
fLastCe; iCell++) {
837 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d has only one daughter " << iCell <<
Endl;
841 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d has no daughter and is inactive " << iCell <<
Endl;
845 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d has two daughters and is active " << iCell <<
Endl;
852 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d parent not pointing to this cell " << iCell <<
Endl;
858 if(cell != (cell->
GetDau0())->GetPare()) {
860 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d daughter 0 not pointing to this cell " << iCell <<
Endl;
864 if(cell != (cell->
GetDau1())->GetPare()) {
866 if (level==1)
Log() << kFATAL <<
"ERROR: Cell's no %d daughter 1 not pointing to this cell " << iCell <<
Endl;
871 if(level==1)
Log() << kFATAL <<
"ERROR: Cell no. " << iCell <<
" has Volume of <1E-50" <<
Endl;
876 for(iCell=0; iCell<=
fLastCe; iCell++) {
880 if(level==1)
Log() << kFATAL <<
"ERROR: Cell no. " << iCell <<
" is active but Volume is 0 " <<
Endl;
885 Log() << kVERBOSE <<
"Check has found " << errors <<
" errors and " << warnings <<
" warnings." <<
Endl;
888 Info(
"CheckAll",
"Check - found total %d errors \n",errors);
898 if (iCell < 0 || iCell >
fLastCe) {
899 Log() << kWARNING <<
"<PrintCell(iCell=" << iCell
900 <<
")>: cell number " << iCell <<
" out of bounds!" 910 Log() <<
"Cell[" << iCell <<
"]={ ";
912 Log() <<
" Xdiv[abs. coord.]=" 915 Log() <<
" Abs. coord. = (";
917 Log() <<
"dim[" << idim <<
"]={" 927 Log() <<
"Elements: [";
931 if (i>0)
Log() <<
", ";
959 std::vector<Float_t> values = ev->
GetValues();
976 Log() << kVERBOSE <<
"Delete cell elements" <<
Endl;
1023 return kernel->
Estimate(
this, txvec, cv);
1047 std::map<Int_t,Float_t> txvec;
1048 for (std::map<Int_t,Float_t>::const_iterator it=xvec.begin(); it!=xvec.end(); ++it)
1049 txvec.insert(std::pair<Int_t, Float_t>(it->first,
VarTransform(it->first, it->second)));
1052 std::vector<PDEFoamCell*> cells =
FindCells(txvec);
1055 std::vector<Float_t> cell_values;
1056 cell_values.reserve(cells.size());
1057 for (std::vector<PDEFoamCell*>::const_iterator cell_it=cells.begin();
1058 cell_it != cells.end(); ++cell_it)
1091 cell0->
GetHcub(cellPosi0,cellSize0);
1093 if (xvec.at(idim)<=cellPosi0[idim]+cellSize0[idim])
1129 map<Int_t, Float_t>::const_iterator it = txvec.find(idim);
1131 if (it != txvec.end()){
1135 cell0->
GetHcub(cellPosi0,cellSize0);
1137 if (it->second <= cellPosi0[idim] + cellSize0[idim])
1148 cells.push_back(cell);
1169 std::map<Int_t, Float_t> txvec_map;
1170 for (
UInt_t i=0; i<txvec.size(); ++i)
1171 txvec_map.insert(std::pair<Int_t, Float_t>(i, txvec.at(i)));
1174 std::vector<PDEFoamCell*> cells(0);
1200 std::vector<PDEFoamCell*> cells(0);
1223 Log() << kFATAL <<
"<Draw1Dim>: function can only be used for 1-dimensional foams!" 1226 TString hname(
"h_1dim");
1229 h1=
new TH1D(hname,
"1-dimensional Foam", nbin,
fXmin[0],
fXmax[0]);
1231 if (!h1)
Log() << kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1236 std::vector<Float_t> txvec;
1239 if (kernel != NULL) {
1241 val = kernel->
Estimate(
this, txvec, cell_value);
1274 if ((idim1>=
GetTotDim()) || (idim1<0) ||
1277 Log() << kFATAL <<
"<Project2>: wrong dimensions given: " 1278 << idim1 <<
", " << idim2 <<
Endl;
1284 Log() << kWARNING <<
"Warning: number of bins too big: " << nbin
1285 <<
" Using 1000 bins for each dimension instead." <<
Endl;
1287 }
else if (nbin<1) {
1288 Log() << kWARNING <<
"Wrong bin number: " << nbin
1289 <<
"; set nbin=50" <<
Endl;
1294 TString hname(
Form(
"h_%d_vs_%d",idim1,idim2));
1299 h1=
new TH2D(hname.Data(),
Form(
"var%d vs var%d",idim1,idim2), nbin,
fXmin[idim1],
fXmax[idim1], nbin, fXmin[idim2], fXmax[idim2]);
1301 if (!h1)
Log() << kFATAL <<
"ERROR: Can not create histo" << hname <<
Endl;
1309 std::map<Int_t, Float_t> txvec;
1315 std::vector<TMVA::PDEFoamCell*> cells =
FindCells(txvec);
1320 for (std::vector<TMVA::PDEFoamCell*>::const_iterator it = cells.begin();
1321 it != cells.end(); ++it) {
1324 (*it)->GetHcub(cellPosi,cellSize);
1327 std::vector<Float_t> tvec;
1329 if ( i != idim1 && i != idim2 )
1330 tvec.push_back(cellPosi[i] + 0.5*cellSize[i]);
1332 tvec.push_back(txvec[i]);
1334 if (kernel != NULL) {
1336 sum_cv += kernel->
Estimate(
this, tvec, cell_value);
1368 case kValueDensity: {
1376 Log() << kWARNING <<
"<GetCellDensity(cell)>: ERROR: cell volume" 1377 <<
" negative or zero!" 1378 <<
" ==> return cell density 0!" 1379 <<
" cell volume=" << volume
1382 Log() << kWARNING <<
"<GetCellDensity(cell)>: WARNING: cell volume" 1383 <<
" close to zero!" 1384 <<
" cell volume: " << volume <<
Endl;
1406 Log() << kFATAL <<
"<GetCellValue>: unknown cell value" <<
Endl;
1448 Log() << kFATAL <<
"<SetCellElement> ERROR: cell element is not a TVectorD*" <<
Endl;
1516 Log() << kFATAL <<
"RootPlot2dim() can only be used with " 1517 <<
"two-dimensional foams!" <<
Endl;
1520 ECellValue cell_value = kValue;
1523 if (opt.Contains(
"cell_value")){
1524 cell_value = kValue;
1525 }
else if (opt.Contains(
"rms_ov_mean")){
1526 cell_value = kRmsOvMean;
1527 }
else if (opt.Contains(
"rms")){
1532 if (opt.Contains(
"cellnumber"))
1533 plotcellnumber =
kTRUE;
1536 std::ofstream outfile(filename, std::ios::out);
1538 outfile<<
"{" << std::endl;
1543 outfile <<
"TColor *graycolors[100];" << std::endl;
1544 outfile <<
"for (Int_t i=0.; i<100; i++)" << std::endl;
1545 outfile <<
" graycolors[i]=new TColor(1000+i, 1-(Float_t)i/100.,1-(Float_t)i/100.,1-(Float_t)i/100.);"<< std::endl;
1548 outfile <<
"cMap = new TCanvas(\"" <<
fName <<
"\",\"Cell Map for " 1549 <<
fName <<
"\",600,600);" << std::endl;
1551 outfile<<
"TBox*a=new TBox();"<<std::endl;
1552 outfile<<
"a->SetFillStyle(0);"<<std::endl;
1553 outfile<<
"a->SetLineWidth(4);"<<std::endl;
1554 outfile<<
"TBox *b1=new TBox();"<<std::endl;
1555 outfile<<
"TText*t=new TText();"<<std::endl;
1557 outfile << (colors ?
"gStyle->SetPalette(1, 0);" :
"gStyle->SetPalette(0);")
1559 outfile <<
"b1->SetFillStyle(1001);"<<std::endl;
1560 outfile<<
"TBox *b2=new TBox();"<<std::endl;
1561 outfile <<
"b2->SetFillStyle(0);"<<std::endl;
1564 outfile <<
"b1->SetFillStyle(0);"<<std::endl;
1577 if (
fCells[iCell]->GetStat() == 1) {
1585 outfile <<
"// observed minimum and maximum of distribution: " << std::endl;
1586 outfile <<
"// Float_t zmin = "<< zmin <<
";" << std::endl;
1587 outfile <<
"// Float_t zmax = "<< zmax <<
";" << std::endl;
1590 outfile <<
"// used minimum and maximum of distribution (taking into account log scale if applicable): " << std::endl;
1591 outfile <<
"Float_t zmin = "<< zmin <<
";" << std::endl;
1592 outfile <<
"Float_t zmax = "<< zmax <<
";" << std::endl;
1598 Float_t scale = (ncolors-1)/(zmax - zmin);
1603 outfile <<
"// =========== Rectangular cells ==========="<< std::endl;
1605 if (
fCells[iCell]->GetStat() == 1) {
1607 x1 = offs+lpag*(cellPosi[0]);
1608 y1 = offs+lpag*(cellPosi[1]);
1609 x2 = offs+lpag*(cellPosi[0]+cellSize[0]);
1610 y2 = offs+lpag*(cellPosi[1]+cellSize[1]);
1621 color = 1000+(
Int_t((value-zmin)*scale));
1624 outfile <<
"b1->SetFillColor(" << color <<
");" << std::endl;
1628 outfile<<
"b1->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1630 outfile<<
"b2->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1633 if (plotcellnumber) {
1634 outfile<<
"t->SetTextColor(4);"<<std::endl;
1636 outfile<<
"t->SetTextSize(0.025);"<<std::endl;
1638 outfile<<
"t->SetTextSize(0.015);"<<std::endl;
1640 outfile<<
"t->SetTextSize(0.008);"<<std::endl;
1641 x = offs+lpag*(cellPosi[0]+0.5*cellSize[0]);
1642 y = offs+lpag*(cellPosi[1]+0.5*cellSize[1]);
1643 outfile<<
"t->DrawText("<<x<<
","<<y<<
","<<
"\""<<iCell<<
"\""<<
");"<<std::endl;
1647 outfile<<
"// ============== End Rectangles ==========="<< std::endl;
1649 outfile <<
"}" << std::endl;
Bool_t fFillFoamWithOrigWeights
PDEFoamCell * GetDau1() const
void Varedu(Double_t [], Int_t &, Double_t &, Double_t &)
Internal subprogram 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.
This class is the abstract kernel interface for PDEFoam.
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 subprogram used by Create.
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 subprogram 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 subprogram 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.
Implementation of PDEFoam.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
returns pretty string with elapsed time
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.
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)
ostringstream derivative to redirect and format output
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)
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.
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
Timing information for training and evaluation of MVA methods.
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
UInt_t GetNActiveCells() const
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
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)}
UInt_t GetMaxDepth() const