StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TF1Fitter.h
1 #ifndef TH1Fitter_H
2 #define TH1Fitter_H 1
3 #include "TH1.h"
4 #include "TMath.h"
5 #include "TF1.h"
6 #include "TLegend.h"
7 #include "TCanvas.h"
8 #include "TNamed.h"
9 
10 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
11 class TF1Fitter : public TF1
12 {
13 public:
14 TF1Fitter(const char *name="",int nPars=0);
15  // methods
16  void SetHist(TH1 *hist);
17 virtual void Init()=0 ;
18 virtual double operator()(const double* x, const double* params = 0);
19 virtual double operator()(double x, double y = 0, double z = 0, double t = 0) const
20  {return TF1::operator()(x,y,z,t);}
21 virtual void Copy(TObject& f1) const;
22 virtual double EvalPar(const double *x,const double *par);
23 virtual void Draw (const char *opt="same");
24 protected:
25 TH1 *fTH1;
26 double fMean;
27 double fSigm;
28 
29 private:
30 
31  typedef Double_t(*DummyFuncPtr_t)(Double_t *, Double_t *) ;
32 
33 ClassDef(TF1Fitter,0)
34 };
35 
36 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
37 class TF1GausFitter : public TF1Fitter
38 {
39 public:
40  TF1GausFitter(const char *name="Gaus"):TF1Fitter(name,3) {}
41  // methods
42 virtual void Init();
43 
44 virtual double EvalPar(const double *x,const double *par);
45 ClassDef(TF1GausFitter,0)
46 };
47 
48 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
50 {
51 public:
52  TF1TwoGausFitter(const char *name="TwoGaus"):TF1Fitter(name,6) {}
53  // methods
54 virtual void Init();
55 
56 virtual double EvalPar(const double *x,const double *par);
57 ClassDef(TF1TwoGausFitter,0)
58 };
59 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
61 {
62 public:
63  TF1GausPol2Fitter(const char *name="GausPol2"):TF1Fitter(name,6) {}
64  // methods
65 virtual void Init();
66 
67 virtual double EvalPar(const double *x,const double *par);
68 ClassDef(TF1GausPol2Fitter,0)
69 };
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 #if 0
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 class TF1Gaus : public TF1
101 {
102 public:
103  TF1Gaus(const char *name="Gaus"):TF1(name,(void*)0,0,0,3) {}
104  // methods
105 
106 virtual double EvalPar(const double *x,const double *par)
107 {
108  double p1 = 1./(par[1]*par[1]);
109  return par[2]*exp(-0.5*p1*(x[0]-par[0])*(x[0]-par[0]));
110 }
111 KlassDef(TF1Gaus,0)
112 };
113 
114 
115 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
116 class TF1TwoGaus : public TF1
117 {
118 public:
119  TF1TwoGaus(const char *name="TwoGaus"):TF1(name,(void*)1,0,0,6) {}
120  // methods
121 virtual double EvalPar(const double *x,const double *par)
122 {
123  double p1 = 1./(par[1]*par[1]);
124  double p4 = 1./(par[1]+par[4])*par[1]+par[4]);
125  return par[2]*exp(-0.5*p1*(x[0]-par[0])*(x[0]-par[0]))
126  +par[5]*exp(-0.5*p4*(x[0]-par[3])*(x[0]-par[3]))
127 }
128 KlassDef(TF1Gaus,0)
129 };
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
144 class TF1AuxFitter: public TF1
145 {
146 public:
147  TF1AuxFitter(int nPars,int nTF,TF1 **tfList):TF1("AuxH1Fitter",(void*)1,0,0,nPars)
148  { mNTF=nTF; mTFList = tfList;}
149  // methods
150  TF1AuxFitter(){};
151 virtual void Copy(TObject& f1) const;
152 virtual double EvalPar(const double *x,const double *par);
153 protected:
154  int mNTF;
155  TF1 **mTFList;
156 
157 KlassDef(TF1AuxFitter,0)
158 };
159 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
160 class TH1Fitter: public TNamed
161 {
162 public:
163  TH1Fitter(TH1 *th,const char *name="");
164  ~TH1Fitter() {delete mTF1;}
165  void SetRange(double xMin,double xMax) {mXmin=xMin; mXmax=xMax;}
166  TF1 *GetTF1();
167  void Set(TH1 *th);
168  void Add(TF1 *fcn);
169 virtual double Fit (const char *opt="IRV");
170 virtual void Draw(const char *opt="");
171  int GetNPars() const { return mNPars;}
172 double *GetPars() { return mPars ;}
173 
174 
175 
176 protected:
177 
178 protected:
179 char mBeg[0];
180 TH1 *mTH1; // TH1 pointer
181 int mNPars; // number of parameters
182 int mNTF1s; // number of functors
183 TF1 *mTF1; //Sum of TF1 list
184 TF1 *mTF1s[10]; //List of functors
185 double mXmin;
186 double mXmax;
187 double mPars[100];
188 char mEnd[0];
189 KlassDef(TH1Fitter,0)
190 };
191 
192 
193 //_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
194 class TwoGausFitter: public TH1Fitter
195 {
196 public:
197  TwoGausFitter(TH1 *th,const char *name="TwoGauss");
198  ~TwoGausFitter(){;}
199 void Prep();
200 double Fit(const char *opt);
201 
202 
203 KlassDef(TwoGausFitter,0)
204 };
205 #endif //0
206 #endif