File indexing completed on 2025-01-18 10:11:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef ROOT_TMVA_PDF
0034 #define ROOT_TMVA_PDF
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <iosfwd>
0045
0046 #include "TH1.h"
0047 #include "ThreadLocalStorage.h"
0048 #include "TMVA/KDEKernel.h"
0049 #include "TMVA/Configurable.h"
0050
0051 class TSpline;
0052 class TGraph;
0053 class TF1;
0054
0055 namespace TMVA {
0056
0057 class MsgLogger;
0058
0059 class PDF;
0060 std::ostream& operator<< ( std::ostream& os, const PDF& tree );
0061 std::istream& operator>> ( std::istream& istr, PDF& tree);
0062
0063 class PDF : public Configurable {
0064
0065 friend std::ostream& operator<< ( std::ostream& os, const PDF& tree );
0066 friend std::istream& operator>> ( std::istream& istr, PDF& tree);
0067
0068 public:
0069
0070 enum EInterpolateMethod { kSpline0, kSpline1, kSpline2, kSpline3, kSpline5, kKDE };
0071
0072 explicit PDF( const TString& name, Bool_t norm=kTRUE );
0073 explicit PDF( const TString& name, const TH1* theHist, EInterpolateMethod method = kSpline2,
0074 Int_t minnsmooth = 0, Int_t maxnsmooth = 0, Bool_t checkHist = kFALSE, Bool_t norm=kTRUE );
0075 explicit PDF( const TString& name, const TH1* theHist,
0076 KDEKernel::EKernelType ktype, KDEKernel::EKernelIter kiter, KDEKernel::EKernelBorder
0077 kborder, Float_t FineFactor, Bool_t norm=kTRUE );
0078 explicit PDF( const TString& name, const TString& options, const TString& suffix = "", PDF* defaultPDF = nullptr, Bool_t norm=kTRUE);
0079 virtual ~PDF();
0080
0081
0082 void BuildPDF (const TH1* theHist);
0083
0084
0085 Double_t GetVal ( Double_t x ) const;
0086 Double_t GetValInverse( Double_t y, Bool_t isMonotonouslyIncreasingFunction=kFALSE ) const;
0087
0088 void AddXMLTo( void* parent );
0089 void ReadXML( void* pdfnode );
0090
0091
0092 TH1* GetPDFHist() const { return fPDFHist; }
0093 TGraph* GetGraph() const { return fGraph; }
0094 TH1* GetOriginalHist() const { return fHistOriginal; }
0095 TH1* GetSmoothedHist() const { return fHist; }
0096 TH1* GetNSmoothHist() const { return fNSmoothHist; }
0097
0098
0099 Double_t GetIntegral( Double_t xmin, Double_t xmax );
0100
0101
0102 TSpline* GetSpline() const { return fSpline; }
0103 Int_t GetNBins () const { return fHist->GetNbinsX(); }
0104 Double_t GetXmin () const { return fHist->GetXaxis()->GetXmin(); }
0105 Double_t GetXmax () const { return fHist->GetXaxis()->GetXmax(); }
0106
0107
0108 void ValidatePDF( TH1* original = nullptr ) const;
0109
0110
0111 Int_t GetHistNBins ( Int_t evtNum = 0 );
0112
0113 TMVA::PDF::EInterpolateMethod GetInterpolMethod() { return fInterpolMethod;}
0114
0115
0116 const char* GetName() const { return fPDFName; }
0117
0118
0119 void SetReadingVersion( UInt_t rv ) { fReadingVersion = rv; }
0120 UInt_t GetReadingVersion() const { return fReadingVersion; }
0121
0122
0123 void ProcessOptions();
0124
0125
0126 void DeclareOptions();
0127
0128 private:
0129
0130
0131
0132 void CheckHist() const;
0133 void FillSplineToHist();
0134 void BuildKDEPDF();
0135 void SmoothHistogram();
0136 void FillHistToGraph();
0137 Double_t GetIntegral() const;
0138 Double_t GetPdfHistBinWidth() const {
0139 TH1* h = GetPDFHist();
0140 return (fPDFHist) ? (h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/h->GetNbinsX() : 1;
0141 }
0142
0143
0144 Bool_t UseHistogram() const { return fUseHistogram; }
0145
0146 void FindBinInverse( const TH1* histogram, Int_t& lowerBin, Int_t& higherBin, Double_t& lowerBinValue, Double_t& higherBinValue,
0147 Double_t y, Bool_t isMonotonouslyIncreasingFunction=kFALSE ) const;
0148
0149
0150 void BuildSplinePDF();
0151
0152
0153
0154
0155 Bool_t fUseHistogram;
0156
0157
0158
0159
0160
0161 static const Int_t fgNbin_PdfHist;
0162 static const Bool_t fgManualIntegration;
0163 static const Double_t fgEpsilon;
0164
0165
0166 TString fPDFName;
0167 Int_t fNsmooth;
0168 Int_t fMinNsmooth;
0169 Int_t fMaxNsmooth;
0170 TH1* fNSmoothHist;
0171
0172 TMVA::PDF::EInterpolateMethod fInterpolMethod;
0173 TSpline* fSpline;
0174 TH1* fPDFHist;
0175 TH1* fHist;
0176 TH1* fHistOriginal;
0177 TGraph* fGraph;
0178 TF1* fIGetVal;
0179
0180 Int_t fHistAvgEvtPerBin;
0181 Int_t fHistDefinedNBins;
0182
0183 TString fKDEtypeString;
0184 TString fKDEiterString;
0185 TString fBorderMethodString;
0186 TString fInterpolateString;
0187
0188 KDEKernel::EKernelType fKDEtype;
0189 KDEKernel::EKernelIter fKDEiter;
0190 KDEKernel::EKernelBorder fKDEborder;
0191 Float_t fFineFactor;
0192
0193 UInt_t fReadingVersion;
0194
0195 Bool_t fCheckHist;
0196 Bool_t fNormalize;
0197
0198 TString fSuffix;
0199 mutable MsgLogger* fLogger;
0200 MsgLogger& Log() const { return *fLogger; }
0201
0202
0203
0204
0205 static PDF*& GetThisPdfThreadLocal() { TTHREAD_TLS(PDF*) fgThisPDF(nullptr); return fgThisPDF; };
0206 static PDF* ThisPDF( void );
0207
0208
0209 static Double_t IGetVal( Double_t*, Double_t* );
0210
0211 ClassDef(PDF,1)
0212 };
0213
0214 }
0215
0216 #endif