Logo ROOT   6.10/09
Reference Guide
TFractionFitter.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Frank Filthaut F.Filthaut@science.ru.nl 20/05/2002
3 
4 #ifndef ROOT_TFractionFitter
5 #define ROOT_TFractionFitter
6 
7 #ifndef ROOT_TVirtualFitter
8 # include "TVirtualFitter.h"
9 #endif
10 
11 #ifndef ROOT_TObjArray
12 # include "TObjArray.h"
13 #endif
14 
15 #include "TFitResultPtr.h"
16 
17 #include <vector>
18 
19 class TH1;
20 
21 namespace ROOT {
22  namespace Fit {
23  class Fitter;
24  }
25 }
26 
27 class TFractionFitter: public TObject {
28 public:
30  TFractionFitter(TH1* data, TObjArray *MCs, Option_t *option="");
31  virtual ~TFractionFitter();
32 
33  //TVirtualFitter* GetFitter() const;
34  ROOT::Fit::Fitter* GetFitter() const;
35  void ErrorAnalysis(Double_t UP);
36  void SetRangeX(Int_t low, Int_t high);
37  void ReleaseRangeX();
38  void SetRangeY(Int_t low, Int_t high);
39  void ReleaseRangeY();
40  void SetRangeZ(Int_t low, Int_t high);
41  void ReleaseRangeZ();
42  void ExcludeBin(Int_t bin);
43  void IncludeBin(Int_t bin);
44  void Constrain(Int_t parm, Double_t low, Double_t high);
45  void UnConstrain(Int_t parm);
46  void SetData(TH1 *data);
47  void SetMC(Int_t parm, TH1 *MC);
48  void SetWeight(Int_t parm, TH1* weight);
50 
51  void GetResult(Int_t parm, Double_t& value, Double_t& error) const;
52  TH1* GetPlot();
53 
54  // This global function needs access to computeFCN()
55  //friend void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
56 
57  // Goodness of fit
58  Double_t GetChisquare() const;
59  Int_t GetNDF() const;
60  Double_t GetProb() const;
61 
62  // MC predictions (smeared templates)
63  TH1* GetMCPrediction(Int_t parm) const;
64 
65  // FCN evaluation
67  Double_t f = 0;
68  ComputeFCN(f, par, 0);
69  return f;
70  }
71 
72 private:
73  void CheckParNo(Int_t parm) const;
74  void CheckConsistency();
75  void FindPrediction(int bin, double& t_i, int& k_0, double& A_ki) const;
76  void ComputeFCN(Double_t& f, const Double_t* par, Int_t flag);
77  void GetRanges(Int_t& minX, Int_t& maxX, Int_t& minY, Int_t& maxY,
78  Int_t& minZ, Int_t& maxZ) const;
79  void ComputeChisquareLambda();
80  bool IsExcluded(Int_t bin) const;
81 
82 protected:
83  Bool_t fFitDone; // flags whether a valid fit has been performed
84  Int_t fLowLimitX; // first bin in X dimension
85  Int_t fHighLimitX; // last bin in X dimension
86  Int_t fLowLimitY; // first bin in Y dimension
87  Int_t fHighLimitY; // last bin in Y dimension
88  Int_t fLowLimitZ; // first bin in Z dimension
89  Int_t fHighLimitZ; // last bin in Z dimension
90  std::vector<Int_t> fExcludedBins; // bins excluded from the fit
91 
92  Int_t fNpfits; // Number of points used in the fit
93  Int_t fNDF; // Number of degrees of freedom in the fit
94  Double_t fChisquare; // Template fit chisquare
95 
96  TObjArray fAji; // array of pointers to predictions of real template distributions
97 
98  // Histograms
99  TH1* fData; // pointer to the "data" histogram to be fitted to
100  TObjArray fMCs; // array of pointers to template histograms
101  TObjArray fWeights; // array of pointers to corresponding weight factors (may be null)
102  Double_t fIntegralData; // "data" histogram content integral over allowed fit range
103  Double_t* fIntegralMCs; // same for template histograms (weights not taken into account)
104  Double_t* fFractions; // template fractions scaled to the "data" histogram statistics
105  TH1* fPlot; // pointer to histogram containing summed template predictions
106  ROOT::Fit::Fitter *fFractionFitter; // pointer to Fitter class
107 
108  Int_t fNpar; // number of fit parameters
109 
110  ClassDef(TFractionFitter, 0); // Fits MC fractions to data histogram
111 };
112 
113 //
114 // TFractionFitFCN
115 //
116 // Computes negative log-likelihood for TFractionFitter
117 //
118 
119 void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
120 
121 #endif // ROOT_TFractionFitter
Double_t EvaluateFCN(const Double_t *par)
double par[1]
Definition: unuranDistr.cxx:38
Double_t fIntegralData
An array of TObjects.
Definition: TObjArray.h:37
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
const char Option_t
Definition: RtypesCore.h:62
std::vector< Int_t > fExcludedBins
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:297
ROOT::Fit::Fitter * fFractionFitter
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Definition: TFitResultPtr.h:31
Double_t * fFractions
double f(double x)
double Double_t
Definition: RtypesCore.h:55
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
The TH1 histogram class.
Definition: TH1.h:56
Double_t * fIntegralMCs
Mother of all ROOT objects.
Definition: TObject.h:37
Fits MC fractions to data histogram.
RooCmdArg Constrain(const RooArgSet &params)