95using std::numeric_limits, std::nothrow, std::map;
116 fFoamType(kSeparate),
123 fFillFoamWithOrigWeights(
kFALSE),
124 fDTSeparation(kFoam),
155 fFoamType(kSeparate),
162 fFillFoamWithOrigWeights(
kFALSE),
163 fDTSeparation(kFoam),
171 Log() << kFATAL <<
"Name too long " <<
name.Data() <<
Endl;
183 delete fVariableNames;
185 if (fDistr)
delete fDistr;
186 if (fPseRan)
delete fPseRan;
187 if (fXmin) {
delete [] fXmin; fXmin=0; }
188 if (fXmax) {
delete [] fXmax; fXmax=0; }
192 for(
Int_t i=0; i<fNCells; i++)
delete fCells[i];
222 , fFoamType(kSeparate)
229 , fFillFoamWithOrigWeights(
kFALSE)
230 , fDTSeparation(kFoam)
237 Log() << kFATAL <<
"COPY CONSTRUCTOR NOT IMPLEMENTED" <<
Endl;
250 Log() << kFATAL <<
"<SetDim>: Dimension is zero or negative!" <<
Endl;
253 if (fXmin)
delete [] fXmin;
254 if (fXmax)
delete [] fXmax;
265 Log() << kFATAL <<
"<SetXmin>: Dimension out of bounds!" <<
Endl;
276 Log() << kFATAL <<
"<SetXmax>: Dimension out of bounds!" <<
Endl;
294 if(fPseRan==0) Log() << kFATAL <<
"Random number generator not set" <<
Endl;
295 if(fDistr==0) Log() << kFATAL <<
"Distribution function not set" <<
Endl;
296 if(fDim==0) Log() << kFATAL <<
"Zero dimension not allowed" <<
Endl;
303 if(fRvec==0) Log() << kFATAL <<
"Cannot initialize buffer fRvec" <<
Endl;
307 if(fAlpha==0) Log() << kFATAL <<
"Cannot initialize buffer fAlpha" <<
Endl;
312 fInhiDiv =
new Int_t[fDim];
313 for(
Int_t i=0; i<fDim; i++) fInhiDiv[i]=0;
317 fMaskDiv =
new Int_t[fDim];
318 for(
Int_t i=0; i<fDim; i++) fMaskDiv[i]=1;
322 for(
Int_t i=0; i<fDim; i++){
329 ((
TH1D*)(*fHistEdg)[i])->Sumw2();
357 for(
Int_t i=0; i<fNCells; i++)
delete fCells[i];
363 Log() << kFATAL <<
"not enough memory to create " << fNCells
366 for(
Int_t i=0; i<fNCells; i++){
368 fCells[i]->SetSerial(i);
378 Explore( fCells[
iCell] );
389 if (fLastCe==fNCells){
390 Log() << kFATAL <<
"Too many cells" <<
Endl;
394 cell = fCells[fLastCe];
396 cell->Fill(status, parent, 0, 0);
477 for (i=0;i<fDim;i++) ((
TH1D *)(*fHistEdg)[i])->Reset();
491 for (k=0; k<fDim; k++) {
506 if (
nevEff >= fNBin*fEvPerBin)
break;
516 Log() << kFATAL <<
"No events were found during exploration of "
517 <<
"root cell. Please check PDEFoam parameters nSampl "
518 <<
"and VolFrac." <<
Endl;
520 Log() << kWARNING <<
"Negative number of events found during "
521 <<
"exploration of root cell" <<
Endl;
526 for (k=0; k<fDim;k++){
528 if ( fInhiDiv[k]==1) fMaskDiv[k] =0;
550 for (parent =
cell->GetPare(); parent!=0; parent = parent->
GetPare()){
581 if( fMaskDiv[
kProj]) {
598 if ( (
xUp-
xLo) < std::numeric_limits<double>::epsilon())
sswIn=0.;
600 if ( (1.0-
xUp+
xLo) < std::numeric_limits<double>::epsilon())
sswOut=0.;
628 Log() << kFATAL <<
"Something wrong with kBest" <<
Endl;
638 fPseRan->RndmArray(fDim,fRvec);
639 for(
Int_t k=0; k<fDim; k++) fAlpha[k] = fRvec[k];
659 for(i=0; i<=fLastCe; i++) {
660 if( fCells[i]->GetStat() == 1 ) {
662 driv = fCells[i]->GetDriv();
663 if (
driv < std::numeric_limits<float>::epsilon())
668 if (
xDiv <= std::numeric_limits<Double_t>::epsilon() ||
669 xDiv >= 1.0 - std::numeric_limits<Double_t>::epsilon())
673 if (GetMaxDepth() > 0)
678 bCutNmin = GetCellElement(fCells[i], 0) > GetNmin();
690 Log() << kVERBOSE <<
"Warning: No cell with more than "
691 << GetNmin() <<
" events found!" <<
Endl;
693 Log() << kVERBOSE <<
"Warning: Maximum depth reached: "
694 << GetMaxDepth() <<
Endl;
696 Log() << kWARNING <<
"<PDEFoam::PeekMax>: no more candidate cells (drivMax>0) found for further splitting." <<
Endl;
717 if(fLastCe+1 >= fNCells) Log() << kFATAL <<
"Buffer limit is reached, fLastCe=fnBuf" <<
Endl;
732 cell->SetDau0((fCells[
d1]));
733 cell->SetDau1((fCells[
d2]));
735 Explore( (fCells[
d1]) );
736 Explore( (fCells[
d2]) );
751 std::vector<Double_t> xvec;
752 xvec.reserve(GetTotDim());
767 fTimer->Init(fNCells);
772 while ( (fLastCe+2) < fNCells ) {
776 Log() << kVERBOSE <<
"Break: "<< fLastCe+1 <<
" cells created" <<
Endl;
779 delete fCells[
jCell];
787 if ( Divide(
newCell )==0)
break;
792 Log() << kVERBOSE << GetNActiveCells() <<
" active cells created" <<
Endl;
802 if(fDim==0) Log() << kFATAL <<
"SetInhiDiv: fDim=0" <<
Endl;
804 fInhiDiv =
new Int_t[ fDim ];
805 for(
Int_t i=0; i<fDim; i++) fInhiDiv[i]=0;
811 Log() << kFATAL <<
"Wrong iDim" <<
Endl;
827 if (level==1) Log() << kVERBOSE <<
"Performing consistency checks for created foam" <<
Endl;
831 if( ((
cell->GetDau0()==0) && (
cell->GetDau1()!=0) ) ||
832 ((
cell->GetDau1()==0) && (
cell->GetDau0()!=0) ) ) {
834 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d has only one daughter " <<
iCell <<
Endl;
836 if( (
cell->GetDau0()==0) && (
cell->GetDau1()==0) && (
cell->GetStat()==0) ) {
838 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d has no daughter and is inactive " <<
iCell <<
Endl;
840 if( (
cell->GetDau0()!=0) && (
cell->GetDau1()!=0) && (
cell->GetStat()==1) ) {
842 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d has two daughters and is active " <<
iCell <<
Endl;
846 if( (
cell->GetPare())!=fCells[0] ) {
847 if ( (
cell !=
cell->GetPare()->GetDau0()) && (
cell !=
cell->GetPare()->GetDau1()) ) {
849 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d parent not pointing to this cell " <<
iCell <<
Endl;
854 if(
cell->GetDau0()!=0) {
855 if(
cell != (
cell->GetDau0())->GetPare()) {
857 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d daughter 0 not pointing to this cell " <<
iCell <<
Endl;
860 if(
cell->GetDau1()!=0) {
861 if(
cell != (
cell->GetDau1())->GetPare()) {
863 if (level==1) Log() << kFATAL <<
"ERROR: Cell's no %d daughter 1 not pointing to this cell " <<
iCell <<
Endl;
866 if(
cell->GetVolume()<1E-50) {
868 if(level==1) Log() << kFATAL <<
"ERROR: Cell no. " <<
iCell <<
" has Volume of <1E-50" <<
Endl;
875 if( (
cell->GetStat()==1) && (
cell->GetVolume()<1E-11) ) {
877 if(level==1) Log() << kFATAL <<
"ERROR: Cell no. " <<
iCell <<
" is active but Volume is 0 " <<
Endl;
882 Log() << kVERBOSE <<
"Check has found " <<
errors <<
" errors and " <<
warnings <<
" warnings." <<
Endl;
885 Info(
"CheckAll",
"Check - found total %d errors \n",
errors);
896 Log() << kWARNING <<
"<PrintCell(iCell=" <<
iCell
897 <<
")>: cell number " <<
iCell <<
" out of bounds!"
907 Log() <<
"Cell[" <<
iCell <<
"]={ ";
908 Log() <<
" " << fCells[
iCell] <<
" " <<
Endl;
909 Log() <<
" Xdiv[abs. coord.]="
912 Log() <<
" Abs. coord. = (";
914 Log() <<
"dim[" <<
idim <<
"]={"
921 Log() <<
")" <<
Endl;
924 Log() <<
"Elements: [";
927 for (
Int_t i=0; i<
vec->GetNrows(); i++){
928 if (i>0) Log() <<
", ";
929 Log() << GetCellElement(fCells[
iCell], i);
933 Log() <<
"]" <<
Endl;
956 std::vector<Float_t> values =
ev->GetValues();
957 std::vector<Float_t>
tvalues = VarTransform(values);
962 SetCellElement(
cell, 0, GetCellElement(
cell, 0) +
wt);
963 SetCellElement(
cell, 1, GetCellElement(
cell, 1) +
wt*
wt);
973 Log() << kVERBOSE <<
"Delete cell elements" <<
Endl;
1016 std::vector<Float_t>
txvec(VarTransform(xvec));
1018 return GetCellValue(FindCell(
txvec),
cv);
1044 std::map<Int_t,Float_t>
txvec;
1045 for (std::map<Int_t,Float_t>::const_iterator it=xvec.begin(); it!=xvec.end(); ++it)
1046 txvec.insert(std::pair<Int_t, Float_t>(it->first, VarTransform(it->first, it->second)));
1049 std::vector<PDEFoamCell*>
cells = FindCells(
txvec);
1085 while (
cell->GetStat()!=1) {
1122 while (
cell->GetStat()!=1) {
1126 map<Int_t, Float_t>::const_iterator it =
txvec.find(
idim);
1171 std::vector<PDEFoamCell*>
cells(0);
1197 std::vector<PDEFoamCell*>
cells(0);
1219 if ( GetTotDim()!=1 )
1220 Log() << kFATAL <<
"<Draw1Dim>: function can only be used for 1-dimensional foams!"
1228 if (!
h1) Log() << kFATAL <<
"ERROR: Can not create histo" <<
hname <<
Endl;
1233 std::vector<Float_t>
txvec;
1240 val = GetCellValue(FindCell(
txvec), cell_value);
1274 Log() << kFATAL <<
"<Project2>: wrong dimensions given: "
1281 Log() << kWARNING <<
"Warning: number of bins too big: " <<
nbin
1282 <<
" Using 1000 bins for each dimension instead." <<
Endl;
1284 }
else if (
nbin<1) {
1285 Log() << kWARNING <<
"Wrong bin number: " <<
nbin
1286 <<
"; set nbin=50" <<
Endl;
1298 if (!
h1) Log() << kFATAL <<
"ERROR: Can not create histo" <<
hname <<
Endl;
1306 std::map<Int_t, Float_t>
txvec;
1312 std::vector<TMVA::PDEFoamCell*>
cells = FindCells(
txvec);
1317 for (std::vector<TMVA::PDEFoamCell*>::const_iterator it =
cells.
begin();
1324 std::vector<Float_t>
tvec;
1325 for (
Int_t i=0; i<GetTotDim(); ++i) {
1335 sum_cv += GetCellValue(FindCell(
tvec), cell_value);
1360 return GetCellElement(
cell, 0);
1363 return GetCellElement(
cell, 1);
1365 case kValueDensity: {
1368 if (volume > numeric_limits<double>::epsilon()) {
1369 return GetCellValue(
cell, kValue)/volume;
1373 Log() << kWARNING <<
"<GetCellDensity(cell)>: ERROR: cell volume"
1374 <<
" negative or zero!"
1375 <<
" ==> return cell density 0!"
1376 <<
" cell volume=" << volume
1377 <<
" cell entries=" << GetCellValue(
cell, kValue) <<
Endl;
1379 Log() << kWARNING <<
"<GetCellDensity(cell)>: WARNING: cell volume"
1380 <<
" close to zero!"
1381 <<
" cell volume: " << volume <<
Endl;
1388 return cell->GetIntg();
1391 return cell->GetDriv();
1394 if (
cell->GetIntg() != 0)
1395 return cell->GetDriv()/
cell->GetIntg();
1400 return cell->GetVolume();
1403 Log() << kFATAL <<
"<GetCellValue>: unknown cell value" <<
Endl;
1445 Log() << kFATAL <<
"<SetCellElement> ERROR: cell element is not a TVectorD*" <<
Endl;
1461 Log() << kINFO <<
"Elapsed time: " + fTimer->GetElapsedTime()
1469 if (fLastCe%
modulo == 0) fTimer->DrawProgressBar( fLastCe );
1512 if (GetTotDim() != 2)
1513 Log() << kFATAL <<
"RootPlot2dim() can only be used with "
1514 <<
"two-dimensional foams!" <<
Endl;
1517 ECellValue cell_value = kValue;
1521 cell_value = kValue;
1522 }
else if (opt.
Contains(
"rms_ov_mean")){
1523 cell_value = kRmsOvMean;
1540 outfile <<
"TColor *graycolors[100];" << std::endl;
1541 outfile <<
"for (Int_t i=0.; i<100; i++)" << std::endl;
1542 outfile <<
" graycolors[i]=new TColor(1000+i, 1-(Float_t)i/100.,1-(Float_t)i/100.,1-(Float_t)i/100.);"<< std::endl;
1545 outfile <<
"cMap = new TCanvas(\"" << fName <<
"\",\"Cell Map for "
1546 << fName <<
"\",600,600);" << std::endl;
1548 outfile<<
"TBox*a=new TBox();"<<std::endl;
1549 outfile<<
"a->SetFillStyle(0);"<<std::endl;
1550 outfile<<
"a->SetLineWidth(4);"<<std::endl;
1551 outfile<<
"TBox *b1=new TBox();"<<std::endl;
1552 outfile<<
"TText*t=new TText();"<<std::endl;
1554 outfile << (
colors ?
"gStyle->SetPalette(1, 0);" :
"gStyle->SetPalette(0);")
1556 outfile <<
"b1->SetFillStyle(1001);"<<std::endl;
1557 outfile<<
"TBox *b2=new TBox();"<<std::endl;
1558 outfile <<
"b2->SetFillStyle(0);"<<std::endl;
1561 outfile <<
"b1->SetFillStyle(0);"<<std::endl;
1574 if ( fCells[
iCell]->GetStat() == 1) {
1582 outfile <<
"// observed minimum and maximum of distribution: " << std::endl;
1583 outfile <<
"// Float_t zmin = "<< zmin <<
";" << std::endl;
1584 outfile <<
"// Float_t zmax = "<< zmax <<
";" << std::endl;
1587 outfile <<
"// used minimum and maximum of distribution (taking into account log scale if applicable): " << std::endl;
1588 outfile <<
"Float_t zmin = "<< zmin <<
";" << std::endl;
1589 outfile <<
"Float_t zmax = "<< zmax <<
";" << std::endl;
1600 outfile <<
"// =========== Rectangular cells ==========="<< std::endl;
1602 if ( fCells[
iCell]->GetStat() == 1) {
1621 outfile <<
"b1->SetFillColor(" << color <<
");" << std::endl;
1625 outfile<<
"b1->DrawBox("<<
x1<<
","<<
y1<<
","<<
x2<<
","<<
y2<<
");"<<std::endl;
1627 outfile<<
"b2->DrawBox("<<
x1<<
","<<
y1<<
","<<
x2<<
","<<
y2<<
");"<<std::endl;
1631 outfile<<
"t->SetTextColor(4);"<<std::endl;
1633 outfile<<
"t->SetTextSize(0.025);"<<std::endl;
1634 else if(fLastCe<251)
1635 outfile<<
"t->SetTextSize(0.015);"<<std::endl;
1637 outfile<<
"t->SetTextSize(0.008);"<<std::endl;
1640 outfile<<
"t->DrawText("<<
x<<
","<<
y<<
","<<
"\""<<
iCell<<
"\""<<
");"<<std::endl;
1644 outfile<<
"// ============== End Rectangles ==========="<< std::endl;
1657 GetDistr()->FillBinarySearchTree(
ev);
1666 if(fDistr)
delete fDistr;
static const Float_t kVlow
static const Float_t kHigh
int Int_t
Signed integer 4 bytes (int)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
float Float_t
Float 4 bytes (float)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmin
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmax
Option_t Option_t TPoint TPoint const char y1
Double_t GetBinError(Int_t bin) const override
Int_t Fill(Double_t x) override
R__EXTERN TStyle * gStyle
TVectorT< Double_t > TVectorD
const_iterator begin() const
const_iterator end() const
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
1-D histogram with a double per channel (see TH1 documentation)
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
virtual Int_t GetNbinsY() const
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
virtual Int_t GetNbinsX() 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...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
2-D histogram with a double per channel (see TH1 documentation)
ostringstream derivative to redirect and format output
PDEFoamCell * GetPare() const
void SetDriv(Double_t Driv)
void SetIntg(Double_t Intg)
This class is the abstract kernel interface for PDEFoam.
Implementation of PDEFoam.
Double_t GetCellElement(const PDEFoamCell *cell, UInt_t i) const
Returns cell element i of cell 'cell'.
void DeleteBinarySearchTree()
Delete the foam's density estimator, which contains the binary search tree.
void MakeAlpha()
Internal subprogram used by Create.
TObjArray * fVariableNames
collection of all variable names
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 OutputGrow(Bool_t finished=false)
Overridden function of PDEFoam to avoid native foam output.
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.
void PrintCell(Long_t iCell=0)
Prints geometry of and elements of 'iCell', as well as relations to parent and daughter cells.
void ResetCellElements()
Remove the cell elements from all cells.
void Grow()
Internal subprogram used by Create.
TH1D * Draw1Dim(ECellValue cell_value, Int_t nbin, PDEFoamKernelBase *kernel=nullptr)
Draws 1-dimensional foam (= histogram)
Double_t Eval(Double_t *xRand, Double_t &event_density)
Internal subprogram.
void PrintCells()
Prints geometry of ALL cells of the FOAM.
void SetXmax(Int_t idim, Double_t wmax)
set upper foam bound in dimension idim
virtual ~PDEFoam()
Default destructor.
PDEFoam()
Default constructor for streamer, user should not use it.
virtual TH2D * Project2(Int_t idim1, Int_t idim2, ECellValue cell_value=kValue, PDEFoamKernelBase *kernel=nullptr, UInt_t nbin=50)
Project foam variable idim1 and variable idim2 to histogram.
virtual Bool_t CellValueIsUndefined(PDEFoamCell *)
Returns true, if the value of the given cell is undefined.
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'.
void Create()
Basic initialization of FOAM invoked by the user.
void SetInhiDiv(Int_t, Int_t)
This can be called before Create, after setting kDim It defines which variables are excluded in the p...
void InitCells()
Internal subprogram used by Create.
PDEFoamCell * FindCell(const std::vector< Float_t > &) const
Find cell that contains 'xvec' (in foam coordinates [0,1]).
void FillBinarySearchTree(const Event *ev)
Insert event to internal foam's density estimator PDEFoamDensityBase.
virtual void Explore(PDEFoamCell *Cell)
Internal subprogram used by Create.
void SetXmin(Int_t idim, Double_t wmin)
set lower foam bound in dimension idim
std::vector< TMVA::PDEFoamCell * > FindCells(const std::vector< Float_t > &) const
Find all cells, that contain txvec.
void Varedu(Double_t[5], Int_t &, Double_t &, Double_t &)
Internal subprogram used by Create.
Int_t CellFill(Int_t, PDEFoamCell *)
Internal subprogram used by Create.
Long_t PeekMax()
Internal subprogram used by Create.
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 ...
void CheckAll(Int_t)
User utility, miscellaneous and debug.
void SetDim(Int_t kDim)
Sets dimension of cubical space.
Timing information for training and evaluation of MVA methods.
Mother of all ROOT objects.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Random number generator class based on M.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
MsgLogger & Endl(MsgLogger &ml)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.