76 fInterpolMethod(
PDF::kSpline2 ),
83 fHistAvgEvtPerBin ( 0 ),
84 fHistDefinedNBins ( 0 ),
87 fBorderMethodString( 0 ),
88 fInterpolateString ( 0 ),
228 if (defaultPDF != 0) {
263 if (hist == NULL)
Log() << kFATAL <<
"Called without valid histogram pointer!" <<
Endl;
270 Log()<< kDEBUG <<
"Create " 274 <<
"type KDE kernel for histogram: \"" << hist->
GetName() <<
"\"" 280 Log() << kFATAL <<
"PDF construction called with minnsmooth<0" <<
Endl;
284 Log() << kFATAL <<
"PDF construction called with maxnsmooth<minnsmooth" <<
Endl;
307 Log() << kFATAL <<
"No number of bins set for PDF" <<
Endl;
357 Log() << kWARNING <<
"No valid interpolation method given! Use Spline2" <<
Endl;
359 Log() << kFATAL <<
" Well.. .thinking about it, I better quit so you notice you are forced to fix the mistake " <<
Endl;
373 if (integral < 0)
Log() << kFATAL <<
"Integral: " << integral <<
" <= 0" <<
Endl;
396 fHist, histoLowEdge, histoUpperEdge,
415 if (i < fHist->GetNbinsX()/5 ) {
444 if (integral < 0)
Log() << kFATAL <<
"Integral: " << integral <<
" <= 0" <<
Endl;
468 ErrAvg +=
Err; ErrRMS += Err*
Err; num++;
474 Float_t MaxErr=ErrAvg+ErrRMS, MinErr=ErrAvg-ErrRMS;
494 Int_t MinBin=-1,MaxBin =-1;
497 if (MinBin==-1) MinBin = bin;
500 else if (MaxBin >= 0) {
501 #if ROOT_VERSION_CODE > ROOT_VERSION(5,19,2) 559 Log() << kFATAL <<
"<CheckHist> Called without valid histogram pointer!" <<
Endl;
566 for (
Int_t bin=1; bin<=nbins; bin++)
570 Log() << kWARNING <<
"More than 50% (" << (((
Float_t)emptyBins/(
Float_t)nbins)*100)
571 <<
"%) of the bins in hist '" 599 for (
Int_t bin=1; bin<=nbins; bin++) {
605 if (binPdfHist<0)
continue;
617 if (d > 1) { nc1++;
if (d > 2) { nc2++;
if (d > 3) { nc3++;
if (d > 6) nc6++; } } }
621 Log() << kDEBUG <<
"Validation result for PDF \"" << originalHist->
GetTitle() <<
"\"" <<
": " <<
Endl;
622 Log() << kDEBUG <<
Form(
" chi2/ndof(!=0) = %.1f/%i = %.2f (Prob = %.2f)",
624 if ((1.0 -
TMath::Prob( chi2, ndof )) > 0.9999994) {
625 Log() << kDEBUG <<
"Comparison of the original histogram \"" << originalHist->
GetTitle() <<
"\"" <<
Endl;
626 Log() << kDEBUG <<
"with the corresponding PDF gave a chi2/ndof of " << chi2/ndof <<
"," <<
Endl;
627 Log() << kDEBUG <<
"which corresponds to a deviation of more than 5 sigma! Please check!" <<
Endl;
629 Log() << kDEBUG <<
Form(
" #bins-found(#expected-bins) deviating > [1,2,3,6] sigmas: " \
630 "[%i(%i),%i(%i),%i(%i),%i(%i)]",
666 if (imin < 1) imin = 1;
669 for (
Int_t bini = imin; bini <= imax; bini++) {
674 if (dx < 0 && dx > -1.0
e-8) dx = 0;
677 <<
"dx = " << dx << std::endl
678 <<
"bini = " << bini << std::endl
679 <<
"xmin = " << xmin << std::endl
680 <<
"xmax = " << xmax << std::endl
681 <<
"imin = " << imin << std::endl
682 <<
"imax = " << imax << std::endl
685 Log() << kFATAL <<
"<GetIntegral> dx = " << dx <<
" < 0" <<
Endl;
739 Int_t lowerBin=0, higherBin=0;
740 Double_t lowerBinValue=0, higherBinValue=0;
741 FindBinInverse(
fPDFHist,lowerBin,higherBin,lowerBinValue,higherBinValue,y,isMonotonouslyIncreasingFunction);
746 Double_t length =(higherBinValue-lowerBinValue);
749 fraction=(y-lowerBinValue)/length;
751 Double_t lengthX =xValueHigherBin-xValueLowerBin;
752 Double_t x =xValueLowerBin+lengthX*fraction;
767 if (isMonotonouslyIncreasingFunction) {
771 Int_t bin=higherBin/2;
773 while (bin>lowerBin && bin<higherBin) {
778 higherBinValue=binContent;
780 else if (y>=binContent){
782 lowerBinValue =binContent;
784 bin=lowerBin+(higherBin-lowerBin)/2;
789 for (
Int_t bin=0, binEnd=histogram->
GetNbinsX(); bin<binEnd; ++bin) {
794 lowerBinValue =binContent;
795 higherBinValue=binContent;
799 higherBinValue=binContent;
826 "Number of smoothing iterations for the input histograms" );
828 "Min number of smoothing iterations, for bins with most data" );
831 "Max number of smoothing iterations, for bins with least data" );
834 "Average number of events per PDF bin" );
837 "Defined number of bins for the histogram from which the PDF is created" );
840 "Whether or not to check the source histogram of the PDF" );
843 "Interpolation method for reference histograms (e.g. Spline2 or KDE)" );
859 "Fine tuning factor for Adaptive KDE: Factor to multiply the width of the kernel");
862 "Border effects treatment (1=no treatment , 2=kernel renormalization, 3=sample mirroring)" );
881 if (fMaxNsmooth < fMinNsmooth && fMinNsmooth >= 0) {
882 Log() << kFATAL <<
"ERROR: MaxNsmooth = " 887 Log() << kFATAL <<
"ERROR: MaxNsmooth = " 899 Log() << kFATAL <<
"unknown setting for option 'InterpolateMethod': " <<
fKDEtypeString << ((
fSuffix==
"")?
"":
Form(
" for pdf with suffix %s",fSuffix.Data())) <<
Endl;
909 Log() << kFATAL <<
"unknown setting for option 'KDEiter': " <<
fKDEtypeString << ((fSuffix==
"")?
"":
Form(
" for pdf with suffix %s",fSuffix.Data())) <<
Endl;
915 Log() << kFATAL <<
"unknown setting for option 'KDEBorder': " <<
fKDEtypeString << ((fSuffix==
"")?
"":
Form(
" for pdf with suffix %s",fSuffix.Data())) <<
Endl;
940 gTools().
AddAttr(pdfhist,
"HasEquidistantBins", hasEquidistantBinning );
949 if (!hasEquidistantBinning) {
950 void* pdfhistbins =
gTools().
AddChild(pdfxml,
"HistogramBinning" );
979 Bool_t hasEquidistantBinning;
986 gTools().
ReadAttr( histch,
"HasEquidistantBins", hasEquidistantBinning );
990 if (hasEquidistantBinning) {
991 newhist =
new TH1F( hname, hname, nbins, xmin, xmax );
994 std::stringstream
s(content);
996 for (
UInt_t i=0; i<nbins; i++) {
1003 std::stringstream
s(content);
1009 if (nbinning != nbins) {
1010 Log() << kFATAL <<
"Number of bins in content and binning array differs"<<
Endl;
1013 std::stringstream sb(binString);
1014 for (
UInt_t i=0; i<=nbins; i++) sb >> binns[i];
1015 newhist =
new TH1F( hname, hname, nbins, binns.GetMatrixArray() );
1017 for (
UInt_t i=0; i<nbins; i++) {
1024 hnameSmooth.
ReplaceAll(
"_original",
"_smoothed" );
1041 Int_t dp = os.precision();
1042 os <<
"MinNSmooth " << pdf.
fMinNsmooth << std::endl;
1043 os <<
"MaxNSmooth " << pdf.
fMaxNsmooth << std::endl;
1045 os <<
"KDE_type " << pdf.
fKDEtype << std::endl;
1046 os <<
"KDE_iter " << pdf.
fKDEiter << std::endl;
1047 os <<
"KDE_border " << pdf.
fKDEborder << std::endl;
1048 os <<
"KDE_finefactor " << pdf.
fFineFactor << std::endl;
1063 os <<
"Weights " << std::endl;
1064 os << std::setprecision(8);
1065 for (
Int_t i=0; i<nBins; i++) {
1066 os << std::setw(15) << std::left << histToWrite->
GetBinContent(i+1) << std::right <<
" ";
1067 if ((i+1)%5==0) os << std::endl;
1070 os << std::setprecision(dp);
1085 while (!doneReading) {
1087 if (devnullS==
"NSmooth")
1089 else if (devnullS==
"MinNSmooth") istr >> pdf.
fMinNsmooth;
1090 else if (devnullS==
"MaxNSmooth") istr >> pdf.
fMaxNsmooth;
1096 else if (devnullS ==
"KDE_finefactor") {
1100 istr >> nbins >> xmin >>
xmax;
1101 doneReading =
kTRUE;
1104 else if (devnullS ==
"Histogram") { istr >> hname >> nbins >> xmin >>
xmax; }
1105 else if (devnullS ==
"Weights") { doneReading =
kTRUE; }
1109 hnameSmooth.
ReplaceAll(
"_original",
"_smoothed" );
1113 std::cout <<
"PDF, trying to create a histogram without defined binning"<< std::endl;
1116 TH1* newhist =
new TH1F( hname,hname, nbins, xmin,
xmax );
1119 for (
Int_t i=0; i<nbins; i++) {
virtual const char * GetName() const
Returns name of object.
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Double_t GetValInverse(Double_t y, Bool_t isMonotonouslyIncreasingFunction=kFALSE) const
returns value
TString fBorderMethodString
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
THist< 1, int, THistStatContent > TH1I
MsgLogger & Endl(MsgLogger &ml)
void ReadXML(void *pdfnode)
XML file reading.
Double_t GetIntegral() const
computes normalisation
static const Double_t fgEpsilon
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
MsgLogger & Log() const
message logger
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
TString & ReplaceAll(const TString &s1, const TString &s2)
void BuildPDF(const TH1 *theHist)
Double_t GetPdfHistBinWidth() const
virtual void SetName(const char *name)
Set the name of the TNamed.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
static const Int_t fgNbin_PdfHist
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
1-D histogram with a float per channel (see TH1 documentation)}
Short_t Min(Short_t a, Short_t b)
virtual void Smooth(Int_t ntimes=1, Option_t *option="")
Smooth bin contents of this histogram.
PDF(const TString &name, Bool_t norm=kTRUE)
default constructor needed for ROOT I/O
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
void CheckHist() const
sanity check: compare PDF with original histogram
UInt_t GetReadingVersion() const
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
TF1 * fIGetVal
needed to create PDF from histogram
TMVA::PDF::EInterpolateMethod fInterpolMethod
KDE Kernel for "smoothing" the PDFs.
static PDF * ThisPDF(void)
virtual TArrayD * GetSumw2()
PDF wrapper for histograms; uses user-defined spline interpolation.
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
const char * GetName() const
Returns name of object.
static const Bool_t fgManualIntegration
void BuildSplinePDF()
build the PDF from the original histograms
Bool_t UseHistogram() const
Int_t GetHistNBins(Int_t evtNum=0)
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...
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
char * Form(const char *fmt,...)
virtual Double_t Eval(Double_t x) const =0
Linear interpolation of TGraph.
MsgLogger * fLogger
the suffix for options
virtual void SetName(const char *name)
Change the name of this histogram.
void DeclareOptions()
define the options (their key words) that can be set in the option string
#define TMVA_VERSION(a, b, c)
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
void BuildKDEPDF()
creates high-binned reference histogram to be used instead of the PDF for speed reasons ...
static PDF *& GetThisPdfThreadLocal()
Float_t GetBinKernelIntegral(Float_t lowr, Float_t highr, Float_t mean, Int_t binnum)
calculates the integral of the Kernel
static constexpr double s
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
virtual Double_t GetEntries() const
Return the current number of entries.
void AddPreDefVal(const T &)
void AddXMLTo(void *parent)
XML file writing.
void FindBinInverse(const TH1 *histogram, Int_t &lowerBin, Int_t &higherBin, Double_t &lowerBinValue, Double_t &higherBinValue, Double_t y, Bool_t isMonotonouslyIncreasingFunction=kFALSE) const
find bin from value on ordinate
ostringstream derivative to redirect and format output
TH1 * fPDFHist
the used spline type
void SetConfigName(const char *n)
void ValidatePDF(TH1 *original=0) const
comparison of original histogram with reference PDF
void Err(int level, const char *msg, int size)
Short_t Max(Short_t a, Short_t b)
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
A Graph is a graphics object made of two arrays X and Y with npoints each.
TH1 * GetOriginalHist() const
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
static Double_t IGetVal(Double_t *, Double_t *)
static external auxiliary function (integrand)
Quadratic interpolation of TGraph.
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
std::istream & operator>>(std::istream &istr, BinaryTree &tree)
KDEKernel::EKernelIter fKDEiter
TString()
TString default ctor.
virtual void SetEntries(Double_t n)
void SetKernelType(EKernelType ktype=kGauss)
fIter == 1 —> nonadaptive KDE fIter == 2 —> adaptive KDE
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
TString fInterpolateString
virtual Int_t GetNbinsX() const
Double_t Sqrt(Double_t x)
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
void FillSplineToHist()
creates high-binned reference histogram to be used instead of the PDF for speed reasons ...
KDEKernel::EKernelBorder fKDEborder
KDEKernel::EKernelType fKDEtype
void FillHistToGraph()
Simple conversion.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual const char * GetTitle() const
Returns title of object.
Double_t GetVal(Double_t x) const
returns value PDF(x)
void SetConfigDescription(const char *d)
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
const char * Data() const