Logo ROOT   6.14/05
Reference Guide
HFitInterface.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: L. Moneta Thu Aug 31 10:40:20 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class HFitInterface
12 // set of free functions used to couple the ROOT data object with the fitting classes
13 
14 // avoid including this file when running CINT since free functions cannot be re-defined
15 
16 #ifndef ROOT_HFitInterface
17 #define ROOT_HFitInterface
18 
19 
20 class TH1;
21 class THnBase;
22 class TF1;
23 class TF2;
24 class TGraph;
25 class TGraphErrors;
26 class TGraph2D;
27 class TMultiGraph;
28 struct Foption_t;
29 
30 #include "TFitResultPtr.h"
31 
32 namespace ROOT {
33 
34  namespace Math {
35  class MinimizerOptions;
36  }
37 
38  namespace Fit {
39 
40  //class BinData;
41 
42  class FitResult;
43  class DataRange;
44  class BinData;
45  class UnBinData;
46  class SparseData;
47 
51  };
52 
53 
54  //#ifndef __CINT__ // does not link on Windows (why ??)
55 
56  /**
57  Decode list of options into fitOption
58  */
59  void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption);
60 
61  /**
62  fitting function for a TH1 (called from TH1::Fit)
63  */
64  TFitResultPtr FitObject(TH1 * h1, TF1 *f1, Foption_t & option, const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
65 
66  /**
67  fitting function for a TGraph (called from TGraph::Fit)
68  */
69  TFitResultPtr FitObject(TGraph * gr, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
70 
71  /**
72  fitting function for a MultiGraph (called from TMultiGraph::Fit)
73  */
74  TFitResultPtr FitObject(TMultiGraph * mg, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
75 
76  /**
77  fitting function for a TGraph2D (called from TGraph2D::Fit)
78  */
79  TFitResultPtr FitObject(TGraph2D * gr, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
80 
81  /**
82  fitting function for a THn / THnSparse (called from THnBase::Fit)
83  */
84  TFitResultPtr FitObject(THnBase * s1, TF1 *f1, Foption_t & option, const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
85 
86 
87  /**
88  fit an unbin data set (from tree or from histogram buffer)
89  using a TF1 pointer and fit options.
90  N.B. ownership of fit data is passed to the UnBinFit function which will be responsible of
91  deleting the data after the fit. User calling this function MUST NOT delete UnBinData after
92  calling it.
93  */
95 
96  /**
97  fill the data vector from a TH1. Pass also the TF1 function which is
98  needed in case of integral option and to reject points rejected by the function
99  */
100  void FillData ( BinData & dv, const TH1 * hist, TF1 * func = 0);
101 
102  /**
103  fill the data vector from a TH1 with sparse data. Pass also the TF1 function which is
104  needed in case of integral option and to reject points rejected by the function
105  */
106  void FillData ( SparseData & dv, const TH1 * hist, TF1 * func = 0);
107 
108  /**
109  fill the data vector from a THnBase. Pass also the TF1 function which is
110  needed in case of integral option and to reject points rejected by the function
111  */
112  void FillData ( SparseData & dv, const THnBase * hist, TF1 * func = 0);
113 
114  /**
115  fill the data vector from a THnBase. Pass also the TF1 function which is
116  needed in case of integral option and to reject points rejected by the function
117  */
118  void FillData ( BinData & dv, const THnBase * hist, TF1 * func = 0);
119 
120  /**
121  fill the data vector from a TGraph2D. Pass also the TF1 function which is
122  needed in case of integral option and to reject points rejected by the function
123  */
124  void FillData ( BinData & dv, const TGraph2D * gr, TF1 * func = 0);
125 
126 
127  /**
128  fill the data vector from a TGraph. Pass also the TF1 function which is
129  needed in case to exclude points rejected by the function
130  */
131  void FillData ( BinData & dv, const TGraph * gr, TF1 * func = 0 );
132  /**
133  fill the data vector from a TMultiGraph. Pass also the TF1 function which is
134  needed in case to exclude points rejected by the function
135  */
136  void FillData ( BinData & dv, const TMultiGraph * gr, TF1 * func = 0);
137 
138 
139  /**
140  compute initial parameter for an exponential function given the fit data
141  Set the constant and slope assuming a simple exponential going through xmin and xmax
142  of the data set
143  */
144  void InitExpo(const ROOT::Fit::BinData & data, TF1 * f1 );
145 
146 
147  /**
148  compute initial parameter for gaussian function given the fit data
149  Set the sigma limits for zero top 10* initial rms values
150  Set the initial parameter values in the TF1
151  */
152  void InitGaus(const ROOT::Fit::BinData & data, TF1 * f1 );
153 
154  /**
155  compute initial parameter for 2D gaussian function given the fit data
156  Set the sigma limits for zero top 10* initial rms values
157  Set the initial parameter values in the TF1
158  */
159  void Init2DGaus(const ROOT::Fit::BinData & data, TF1 * f1 );
160 
161  /**
162  compute confidence intervals at level cl for a fitted histogram h1 in a TGraphErrors gr
163  */
164  bool GetConfidenceIntervals(const TH1 * h1, const ROOT::Fit::FitResult & r, TGraphErrors * gr, double cl = 0.95);
165 
166  /**
167  compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation)
168  */
169  double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, bool usePL = false);
170 
171  /**
172  compute the chi2 value for a graph given a function (see TGraph::Chisquare)
173  */
174  double Chisquare(const TGraph & h1, TF1 & f1, bool useRange);
175 
176 
177  } // end namespace Fit
178 
179 } // end namespace ROOT
180 
181 
182 #endif /* ROOT_Fit_TH1Interface */
183 
184 
185 //#endif /* not CINT OR MAKE_CINT */
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:35
double Chisquare(const TGraph &h1, TF1 &f1, bool useRange)
compute the chi2 value for a graph given a function (see TGraph::Chisquare)
Definition: HFitImpl.cxx:1022
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Definition: UnBinData.h:42
static constexpr double mg
bool GetConfidenceIntervals(const TH1 *h1, const ROOT::Fit::FitResult &r, TGraphErrors *gr, double cl=0.95)
compute confidence intervals at level cl for a fitted histogram h1 in a TGraphErrors gr ...
TFitResultPtr UnBinFit(ROOT::Fit::UnBinData *data, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption)
fit an unbin data set (from tree or from histogram buffer) using a TF1 pointer and fit options...
Definition: HFitImpl.cxx:809
TH1F * h1
Definition: legend1.C:5
void FillData(BinData &dv, const TMultiGraph *gr, TF1 *func=0)
fill the data vector from a TMultiGraph.
TFitResultPtr FitObject(THnBase *s1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a THn / THnSparse (called from THnBase::Fit)
Definition: HFitImpl.cxx:997
Definition: Buttons.h:34
void InitGaus(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for gaussian function given the fit data Set the sigma limits for zero top ...
ROOT::R::TRInterface & r
Definition: Object.C:4
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Definition: TFitResultPtr.h:31
#define s1(x)
Definition: RSha256.hxx:91
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:53
A 2-Dim function with parameters.
Definition: TF2.h:29
void InitExpo(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for an exponential function given the fit data Set the constant and slope a...
TGraphErrors * gr
Definition: legend1.C:25
class containg the result of the fit and all the related information (fitted parameter values...
Definition: FitResult.h:48
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:34
void Init2DGaus(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for 2D gaussian function given the fit data Set the sigma limits for zero t...
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
int type
Definition: TGX11.cxx:120
The TH1 histogram class.
Definition: TH1.h:56
Namespace for new Math classes and functions.
void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption)
Decode list of options into fitOption.
Definition: HFitImpl.cxx:681
1-Dim function class
Definition: TF1.h:211
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
TF1 * f1
Definition: legend1.C:11
A TGraphErrors is a TGraph with error bars.
Definition: TGraphErrors.h:26
Multidimensional histogram base.
Definition: THnBase.h:43
Graphics object made of three arrays X, Y and Z with the same number of points each.
Definition: TGraph2D.h:40