Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:57:09

0001 // @(#)root/hist:$Id$
0002 // Author: Frank Filthaut F.Filthaut@science.ru.nl  20/05/2002
0003 
0004 #ifndef ROOT_TFractionFitter
0005 #define ROOT_TFractionFitter
0006 
0007 #ifndef ROOT_TVirtualFitter
0008 # include "TVirtualFitter.h"
0009 #endif
0010 
0011 #ifndef ROOT_TObjArray
0012 # include "TObjArray.h"
0013 #endif
0014 
0015 #include "TFitResultPtr.h"
0016 
0017 #include <vector>
0018 
0019 class TH1;
0020 
0021 namespace ROOT {
0022    namespace Fit  {
0023       class Fitter;
0024    }
0025 }
0026 
0027 class TFractionFitter: public TObject {
0028 public:
0029    TFractionFitter();
0030    TFractionFitter(TH1* data, TObjArray *MCs, Option_t *option="");
0031    ~TFractionFitter() override;
0032 
0033    //TVirtualFitter* GetFitter() const;
0034    ROOT::Fit::Fitter* GetFitter() const;
0035    void ErrorAnalysis(Double_t UP);
0036    void SetRangeX(Int_t low, Int_t high);
0037    void ReleaseRangeX();
0038    void SetRangeY(Int_t low, Int_t high);
0039    void ReleaseRangeY();
0040    void SetRangeZ(Int_t low, Int_t high);
0041    void ReleaseRangeZ();
0042    void ExcludeBin(Int_t bin);
0043    void IncludeBin(Int_t bin);
0044    void Constrain(Int_t parm, Double_t low, Double_t high);
0045    void UnConstrain(Int_t parm);
0046    void SetData(TH1 *data);
0047    void SetMC(Int_t parm, TH1 *MC);
0048    void SetWeight(Int_t parm, TH1* weight);
0049    TFitResultPtr Fit();
0050 
0051    void GetResult(Int_t parm, Double_t& value, Double_t& error) const;
0052    TH1* GetPlot();
0053 
0054    // This global function needs access to computeFCN()
0055    //friend void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
0056 
0057    // Goodness of fit
0058    Double_t GetChisquare() const;
0059    Int_t GetNDF() const;
0060    Double_t GetProb() const;
0061 
0062    // MC predictions (smeared templates)
0063    TH1* GetMCPrediction(Int_t parm) const;
0064 
0065    // FCN evaluation
0066    Double_t EvaluateFCN(const Double_t * par) {
0067       Double_t f = 0;
0068       ComputeFCN(f, par, 0);
0069       return f;
0070    }
0071 
0072 private:
0073    void CheckParNo(Int_t parm) const;
0074    void CheckConsistency();
0075    void FindPrediction(int bin, double& t_i, int& k_0, double& A_ki) const;
0076    void ComputeFCN(Double_t& f, const Double_t* par, Int_t flag);
0077    void GetRanges(Int_t& minX, Int_t& maxX, Int_t& minY, Int_t& maxY,
0078                   Int_t& minZ, Int_t& maxZ) const;
0079    void ComputeChisquareLambda();
0080    bool IsExcluded(Int_t bin) const;
0081 
0082 protected:
0083    Bool_t   fFitDone;                   ///< Flags whether a valid fit has been performed
0084    Int_t    fLowLimitX;                 ///< First bin in X dimension
0085    Int_t    fHighLimitX;                ///< Last  bin in X dimension
0086    Int_t    fLowLimitY;                 ///< First bin in Y dimension
0087    Int_t    fHighLimitY;                ///< Last  bin in Y dimension
0088    Int_t    fLowLimitZ;                 ///< First bin in Z dimension
0089    Int_t    fHighLimitZ;                ///< Last  bin in Z dimension
0090    std::vector<Int_t> fExcludedBins;    ///< Bins excluded from the fit
0091 
0092    Int_t    fNpfits;                    ///< Number of points used in the fit
0093    Int_t    fNDF;                       ///< Number of degrees of freedom in the fit
0094    Double_t fChisquare;                 ///< Template fit chisquare
0095 
0096    TObjArray fAji;                      ///< Array of pointers to predictions of real template distributions
0097 
0098    ///@name Histograms
0099    ///@{
0100    TH1*      fData;                     ///< Pointer to the "data" histogram to be fitted to
0101    TObjArray fMCs;                      ///< Array of pointers to template histograms
0102    TObjArray fWeights;                  ///< Array of pointers to corresponding weight factors (may be null)
0103    Double_t  fIntegralData;             ///< "data" histogram content integral over allowed fit range
0104    Double_t* fIntegralMCs;              ///< Same for template histograms (weights not taken into account)
0105    Double_t* fFractions;                ///< Template fractions scaled to the "data" histogram statistics
0106    TH1*      fPlot;                     ///< Pointer to histogram containing summed template predictions
0107    ROOT::Fit::Fitter *fFractionFitter;  ///< Pointer to Fitter class
0108    ///@}
0109 
0110    Int_t     fNpar;                     ///< number of fit parameters
0111 
0112    ClassDefOverride(TFractionFitter, 0); // Fits MC fractions to data histogram
0113 };
0114 
0115 //
0116 //  TFractionFitFCN
0117 //
0118 //  Computes negative log-likelihood for TFractionFitter
0119 //
0120 
0121 void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
0122 
0123 #endif // ROOT_TFractionFitter