ROOT  6.06/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 #ifndef ROOT_TFitResultPtr
16 #include "TFitResultPtr.h"
17 #endif
18 
19 #include <vector>
20 
21 class TH1;
22 
23 namespace ROOT {
24  namespace Fit {
25  class Fitter;
26  }
27 }
28 
29 class TFractionFitter: public TObject {
30 public:
32  TFractionFitter(TH1* data, TObjArray *MCs, Option_t *option="");
33  virtual ~TFractionFitter();
34 
35  //TVirtualFitter* GetFitter() const;
37  void ErrorAnalysis(Double_t UP);
38  void SetRangeX(Int_t low, Int_t high);
39  void ReleaseRangeX();
40  void SetRangeY(Int_t low, Int_t high);
41  void ReleaseRangeY();
42  void SetRangeZ(Int_t low, Int_t high);
43  void ReleaseRangeZ();
44  void ExcludeBin(Int_t bin);
45  void IncludeBin(Int_t bin);
46  void Constrain(Int_t parm, Double_t low, Double_t high);
47  void UnConstrain(Int_t parm);
48  void SetData(TH1 *data);
49  void SetMC(Int_t parm, TH1 *MC);
50  void SetWeight(Int_t parm, TH1* weight);
52 
53  void GetResult(Int_t parm, Double_t& value, Double_t& error) const;
54  TH1* GetPlot();
55 
56  // This global function needs access to computeFCN()
57  //friend void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
58 
59  // Goodness of fit
60  Double_t GetChisquare() const;
61  Int_t GetNDF() const;
62  Double_t GetProb() const;
63 
64  // MC predictions (smeared templates)
65  TH1* GetMCPrediction(Int_t parm) const;
66 
67  // FCN evaluation
69  Double_t f = 0;
70  ComputeFCN(f, par, 0);
71  return f;
72  }
73 
74 private:
75  void CheckParNo(Int_t parm) const;
76  void CheckConsistency();
77  void FindPrediction(int bin, double& t_i, int& k_0, double& A_ki) const;
78  void ComputeFCN(Double_t& f, const Double_t* par, Int_t flag);
79  void GetRanges(Int_t& minX, Int_t& maxX, Int_t& minY, Int_t& maxY,
80  Int_t& minZ, Int_t& maxZ) const;
82  bool IsExcluded(Int_t bin) const;
83 
84 protected:
85  Bool_t fFitDone; // flags whether a valid fit has been performed
86  Int_t fLowLimitX; // first bin in X dimension
87  Int_t fHighLimitX; // last bin in X dimension
88  Int_t fLowLimitY; // first bin in Y dimension
89  Int_t fHighLimitY; // last bin in Y dimension
90  Int_t fLowLimitZ; // first bin in Z dimension
91  Int_t fHighLimitZ; // last bin in Z dimension
92  std::vector<Int_t> fExcludedBins; // bins excluded from the fit
93 
94  Int_t fNpfits; // Number of points used in the fit
95  Int_t fNDF; // Number of degrees of freedom in the fit
96  Double_t fChisquare; // Template fit chisquare
97 
98  TObjArray fAji; // array of pointers to predictions of real template distributions
99 
100  // Histograms
101  TH1* fData; // pointer to the "data" histogram to be fitted to
102  TObjArray fMCs; // array of pointers to template histograms
103  TObjArray fWeights; // array of pointers to corresponding weight factors (may be null)
104  Double_t fIntegralData; // "data" histogram content integral over allowed fit range
105  Double_t* fIntegralMCs; // same for template histograms (weights not taken into account)
106  Double_t* fFractions; // template fractions scaled to the "data" histogram statistics
107  TH1* fPlot; // pointer to histogram containing summed template predictions
108  ROOT::Fit::Fitter *fFractionFitter; // pointer to Fitter class
109 
110  Int_t fNpar; // number of fit parameters
111 
112  ClassDef(TFractionFitter, 1) // Fits MC fractions to data histogram
113 };
114 
115 //
116 // TFractionFitFCN
117 //
118 // Computes negative log-likelihood for TFractionFitter
119 //
120 
121 void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
122 
123 #endif // ROOT_TFractionFitter
Double_t EvaluateFCN(const Double_t *par)
void GetResult(Int_t parm, Double_t &value, Double_t &error) const
Obtain the fit result for parameter (the parameter numbering follows that of the input templat...
double par[1]
Definition: unuranDistr.cxx:38
virtual ~TFractionFitter()
TFractionFitter default destructor.
void Constrain(Int_t parm, Double_t low, Double_t high)
Constrain the values of parameter number (the parameter numbering follows that of the input te...
Double_t fIntegralData
An array of TObjects.
Definition: TObjArray.h:39
void FindPrediction(int bin, double &t_i, int &k_0, double &A_ki) const
Function used internally to obtain the template prediction in the individual bins 'bin' <=> 'i' (pape...
void ReleaseRangeX()
Release restrictions on the X range of the histogram to be used in the fit.
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
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
TH1 * GetMCPrediction(Int_t parm) const
Return the adjusted MC template (Aji) for template (parm).
void ReleaseRangeY()
Release restrictions on the Y range of the histogram to be used in the fit.
void SetRangeZ(Int_t low, Int_t high)
Set the Z range of the histogram to be used in the fit (3D histograms only).
#define ClassDef(name, id)
Definition: Rtypes.h:254
void CheckConsistency()
Function used internally to check the consistency between the various histograms. ...
ROOT::Fit::Fitter * fFractionFitter
void UnConstrain(Int_t parm)
Remove the constraints on the possible values of parameter .
void SetData(TH1 *data)
Change the histogram to be fitted to.
void SetMC(Int_t parm, TH1 *MC)
Change the histogram for template number .
bool IsExcluded(Int_t bin) const
Function for internal use, checking whether the given bin is excluded from the fit or not...
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:94
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Definition: TFitResultPtr.h:33
void SetRangeX(Int_t low, Int_t high)
Set the X range of the histogram to be used in the fit.
Double_t GetProb() const
return the fit probability
Int_t GetNDF() const
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
void ComputeFCN(Double_t &f, const Double_t *par, Int_t flag)
Used internally to compute the likelihood value.
Double_t * fFractions
TH1 * GetPlot()
Return the "template prediction" corresponding to the fit result (this is not the same as the weighte...
double f(double x)
Double_t GetChisquare() const
Return the likelihood ratio Chi-squared (chi2) for the fit.
double Double_t
Definition: RtypesCore.h:55
void ComputeChisquareLambda()
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for detai...
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:132
void SetRangeY(Int_t low, Int_t high)
Set the Y range of the histogram to be used in the fit (2D or 3D histograms only).
The TH1 histogram class.
Definition: TH1.h:80
Double_t * fIntegralMCs
void ErrorAnalysis(Double_t UP)
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation.
Mother of all ROOT objects.
Definition: TObject.h:58
void CheckParNo(Int_t parm) const
Function for internal use, checking parameter validity An invalid parameter results in an error...
Fits MC fractions to data histogram.
TFitResultPtr Fit()
Perform the fit with the default UP value.
void GetRanges(Int_t &minX, Int_t &maxX, Int_t &minY, Int_t &maxY, Int_t &minZ, Int_t &maxZ) const
Used internally to obtain the bin ranges according to the dimensionality of the histogram and the lim...
void ExcludeBin(Int_t bin)
Exclude the given bin from the fit.
ROOT::Fit::Fitter * GetFitter() const
Give direct access to the underlying fitter class.
float value
Definition: math.cpp:443
void IncludeBin(Int_t bin)
Include the given bin in the fit, if it was excluded before using ExcludeBin().
void SetWeight(Int_t parm, TH1 *weight)
Set bin by bin weights for template number (the parameter numbering follows that of the input ...
void ReleaseRangeZ()
Release restrictions on the Z range of the histogram to be used in the fit.