Logo ROOT  
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 */
TGeant4Unit::mg
static constexpr double mg
Definition: TGeant4SystemOfUnits.h:210
HFit::Fit
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133
ROOT::Fit::BinData
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:62
Foption_t
Definition: Foption.h:24
ROOT::Fit::UnBinData
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Definition: UnBinData.h:52
ROOT::Fit::FitOptionsMake
void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption)
Decode list of options into fitOption.
Definition: HFitImpl.cxx:684
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Fit::FillData
void FillData(BinData &dv, const TH1 *hist, TF1 *func=0)
fill the data vector from a TH1.
Definition: HFitInterface.cxx:117
ROOT::Fit::Init2DGaus
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...
Definition: HFitInterface.cxx:395
ROOT::Fit::FitObject
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Definition: HFitImpl.cxx:971
ROOT::Fit::SparseData
Definition: SparseData.h:36
ROOT::Fit::UnBinFit
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:816
ROOT::Fit::kHistogram
@ kHistogram
Definition: HFitInterface.h:49
h1
TH1F * h1
Definition: legend1.C:5
ROOT::Fit::GetConfidenceIntervals
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
Definition: HFitInterface.cxx:972
TGraph2D
Definition: TGraph2D.h:41
TFitResultPtr
Definition: TFitResultPtr.h:32
gr
TGraphErrors * gr
Definition: legend1.C:25
s1
#define s1(x)
Definition: RSha256.hxx:109
ROOT::Fit::FitResult
class containg the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:52
ROOT::Fit::InitExpo
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...
Definition: HFitInterface.cxx:274
ROOT::Fit::DataRange
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:45
ROOT::Math::MinimizerOptions
Minimizer options.
Definition: MinimizerOptions.h:42
ROOT::Fit::Chisquare
double Chisquare(const TH1 &h1, TF1 &f1, bool useRange, bool usePL=false)
compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation)
Definition: HFitImpl.cxx:1025
TF2
Definition: TF2.h:29
TMultiGraph
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:36
f1
TF1 * f1
Definition: legend1.C:11
TGraph
Definition: TGraph.h:41
TGraphErrors
Definition: TGraphErrors.h:26
TFitResultPtr.h
ROOT::Fit::kGraph
@ kGraph
Definition: HFitInterface.h:50
TH1
Definition: TH1.h:57
ROOT::Fit::EFitObjectType
EFitObjectType
Definition: HFitInterface.h:48
type
int type
Definition: TGX11.cxx:121
TF1
1-Dim function class
Definition: TF1.h:212
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
THnBase
Definition: THnBase.h:43
ROOT::Fit::InitGaus
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 ...
Definition: HFitInterface.cxx:313