Belle II Software development
XT Class Reference

Class to perform fitting for each xt function. More...

#include <XT.h>

Public Member Functions

 XT (TProfile *h1)
 Initialized with TProfile histogram.
 
 XT (TProfile *h1, int mode)
 Initialized with TProfile histogram and mode.
 
 XT (TH1D *h1, int mode)
 Initialized with TH1D histogram and mode.
 
void setP6 (double p6)
 Set Parameter 6 for polynomial fit.
 
void setMode (int mode)
 Set XT mode.
 
void BField (bool bfield)
 set to use BField
 
void setXTParams (const double p[8])
 Set Parameters for fit.
 
void setXTParams (double p0, double p1, double p2, double p3, double p4, double p5, double p6, double p7)
 Set Initial parameters for fitting.
 
void setFitRange (double tmin, double tmax)
 Set Fit range.
 
void setSmallestEntryRequired (int min)
 Set minimum number of entry required for fit.
 
void setDebug (bool debug)
 Set Debug.
 
int getFitStatus ()
 get fitted flag.
 
double getProb ()
 Get the chi2 probability.
 
void getFittedXTParams (double pa[8])
 get fit parameters.
 
TF1 * getXTFunction (int mode)
 Get XT function.
 
TF1 * getXTFunction ()
 Get XT function.
 
TProfile * getFittedHisto ()
 Get histogram.
 
void FitXT ()
 Do fitting.
 
void FitXT (int mode)
 Do fitting.
 
void FitPol5 ()
 Fit xt histogram incase 5th order polynomial is used.
 
void FitChebyshev ()
 Fit xt histogram incase 5th order Chebeshev polynomial is used.
 

Private Attributes

TProfile * m_h1
 Histogram of xt relation.
 
TF1 * xtpol5 = new TF1("xtpol5", pol5pol1, 0.0, 700, 8)
 5th order polynomial function
 
TF1 * xtCheb5 = new TF1("xtCheb5", Cheb5pol1, 0.0, 700, 8)
 5th order Cheb.
 
int m_mode = 1
 XT mode, 0 is for 5th order polynomial, 1 is Chebshev polynomial.
 
bool m_debug = true
 Print debug durring fitting or not.
 
bool m_draw = false
 Draw and store png plot of each histo or not.
 
bool m_BField = true
 With magnetic field or not.
 
int m_minRequiredEntry = 800
 Minimum entry required for each histo.
 
double m_XTParam [8] = {}
 Parameter fo xt.
 
double m_FittedXTParams [8] = {}
 Fitted parameters.
 
int m_fitflag = 0
 Fit Flag =-1: low statitic =1: good =0: Fit failure =2: Error Outer =3: Error Inner part;.
 
double m_Prob = 0
 Chi2 prob of fitting.
 
double m_tmin = 20
 lower boundary of fit range
 
double m_tmax = m_XTParam[6] + 250
 upper boundary of fit range
 

Detailed Description

Class to perform fitting for each xt function.

Definition at line 60 of file XT.h.

Constructor & Destructor Documentation

◆ XT() [1/3]

XT ( TProfile *  h1)
inlineexplicit

Initialized with TProfile histogram.

Definition at line 65 of file XT.h.

66 {
67 m_h1 = (TProfile*)h1->Clone();
68 m_h1->SetDirectory(0);
69 }
TProfile * m_h1
Histogram of xt relation.
Definition: XT.h:224

◆ XT() [2/3]

XT ( TProfile *  h1,
int  mode 
)
inline

Initialized with TProfile histogram and mode.

Definition at line 73 of file XT.h.

74 {
75 m_h1 = (TProfile*)h1->Clone();
76 m_h1->SetDirectory(0);
77 m_mode = mode;
78 }
int m_mode
XT mode, 0 is for 5th order polynomial, 1 is Chebshev polynomial.
Definition: XT.h:228

◆ XT() [3/3]

XT ( TH1D *  h1,
int  mode 
)
inline

Initialized with TH1D histogram and mode.

Definition at line 83 of file XT.h.

84 {
85 m_h1 = (TProfile*)h1->Clone();
86 m_h1->SetDirectory(0);
87 m_mode = mode;
88 }

Member Function Documentation

◆ BField()

void BField ( bool  bfield)
inline

set to use BField

Definition at line 110 of file XT.h.

110{m_BField = bfield;}
bool m_BField
With magnetic field or not.
Definition: XT.h:231

◆ FitChebyshev()

void FitChebyshev ( )

Fit xt histogram incase 5th order Chebeshev polynomial is used.

Definition at line 332 of file XT.h.

333{
334 if (m_h1->GetEntries() < m_minRequiredEntry) {
335 m_fitflag = -1;
336 return;
337 }
338 // m_tmax = m_XTParam[6] + 100;
339 //xtCheb5->SetParameters(0.0, 0.005, 0., 0., 0., 0., m_XTParam[6], 0.001);
340 double p[6];
341 double par[8];
342 xtCheb5->SetParLimits(7, 0., 0.001);
343 m_h1->Fit("chebyshev5", "QME", "", m_tmin, m_XTParam[6]);
344 m_h1->GetFunction("chebyshev5")->GetParameters(p);
345 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5], m_XTParam[6], 0.000);
346
347 double stat;
348 for (int i = 0; i < 10; ++i) {
349 stat = m_h1->Fit("xtCheb5", "MQ", "0", m_tmin, m_tmax);
350 if (stat == 0) {
351 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5], m_XTParam[6] - 20, 0.000);
352 m_tmax -= 10;
353 continue;
354 }
355 xtCheb5->GetParameters(par);
356 /*Eval outer region,*/
357 double fp6 = xtCheb5->Eval(par[6]);
358 double fbehindp6 = xtCheb5->Eval(par[6] - 10) - 0.005;
359 if (fp6 < fbehindp6 || fp6 > 1) { /*may be change to good value*/
360 m_fitflag = 2;
361 // out += 1;
362 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5], par[6] - 20, 0.000);
363 xtCheb5->SetParLimits(6, par[6] - 50, par[6] - 10);
364 m_tmax -= 10;
365 // if (m_tmax < p6default + 30) {
366 // m_tmax = p6default + 30;
367 // }
368 } else {
369 break;
370 }
371 // m_tmax +=10;
372 //if (stat != 0) break;
373 }
374 xtCheb5->GetParameters(m_FittedXTParams);
375 m_Prob = xtCheb5->GetProb();
376 if (stat == 0)
377 m_fitflag = 0;
378 else
379 m_fitflag = 1;
380 // xtCheb5->DrawF1(0,400,"same");
381 if (m_draw) {
382 TString hname = m_h1->GetName();
383 TString name = hname + ".pdf";
384 TCanvas* c1 = new TCanvas("c1", "", 800, 600);
385 m_h1->Draw();
386 xtCheb5->SetLineColor(kBlack);
387 xtCheb5->DrawF1(0, 400, "same");
388 c1->SaveAs(name);
389 }
390}
int m_minRequiredEntry
Minimum entry required for each histo.
Definition: XT.h:232
double m_FittedXTParams[8]
Fitted parameters.
Definition: XT.h:234
int m_fitflag
Fit Flag =-1: low statitic =1: good =0: Fit failure =2: Error Outer =3: Error Inner part;.
Definition: XT.h:244
double m_Prob
Chi2 prob of fitting.
Definition: XT.h:245
TF1 * xtCheb5
5th order Cheb.
Definition: XT.h:226
double m_tmin
lower boundary of fit range
Definition: XT.h:246
double m_tmax
upper boundary of fit range
Definition: XT.h:247
bool m_draw
Draw and store png plot of each histo or not.
Definition: XT.h:230
double m_XTParam[8]
Parameter fo xt.
Definition: XT.h:233

◆ FitPol5()

void FitPol5 ( )

Fit xt histogram incase 5th order polynomial is used.

Definition at line 250 of file XT.h.

251{
252 double max_dif = 0.12;
253 double max_dif2 = 0.05;
254 double par[8];
255 m_h1->Fit("pol1", "MQ", "", m_tmin, 50);
256 TF1* f1 = (TF1*)m_h1->GetFunction("pol1");
257 double p0 = f1->GetParameter(0);
258 double p1 = f1->GetParameter(1);
259 double f10 = f1->Eval(10);
260 /****************************/
261 int out = 0; /*how many time outer part change fit limit*/
262 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, m_XTParam[6], 0);
263 double p6default = m_XTParam[6];
264 if (m_BField) {
265 xtpol5->SetParLimits(7, 0.0, 0.001);
266 xtpol5->SetParLimits(1, 0.0, 0.01);
267 } else {
268 xtpol5->SetParLimits(7, 0.0, 0.01);
269 xtpol5->SetParLimits(1, 0.0, 0.01);
270 }
271 // xtpol5->SetParLimits(6, p6default - 30, p6default + 30);
272 for (int i = 0; i < 10; ++i) {
273 m_fitflag = 1;
274 std::cout << "Fitting" << std::endl;
275 double stat = m_h1->Fit(xtpol5, "M", "0", m_tmin, m_tmax);
276 xtpol5->GetParameters(par);
277
278 /*Eval outer region,*/
279 double fp6 = xtpol5->Eval(par[6]);
280 double fbehindp6 = xtpol5->Eval(par[6] - 12) - 0.01;
281 if (fp6 < fbehindp6 || fp6 > 1) { /*may be change to good value*/
282 m_fitflag = 2;
283 out += 1;
284 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
285 xtpol5->SetParLimits(6, p6default - 10, p6default + 10 - out / 2);
286 m_tmax += 2;
287 if (m_tmax < p6default + 30) {
288 m_tmax = p6default + 30;
289 }
290 }
291 /* EVal inner region*/
292 /* compare p0 of linear fit vs p0 of xtfun fit and eval point t=10)*/
293 if (fabs(par[0] - p0) > max_dif || fabs(f10 - xtpol5->Eval(10)) > max_dif2) {
294 m_fitflag = 3;
295 if (i == 9) std::cout << "ERROR XT FIT inner part" << std::endl;
296 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
297 xtpol5->SetParLimits(1, 0, 0.08);
298 m_tmin -= 0.5;
299
300 if (m_tmin < 14) {
301 m_tmin = 14; std::cout << "ERROR: tmin so small, fit iter: " << std::endl;
302 }
303 }
304
305 if (stat == 0) {
306 m_fitflag = 0;
307 if (m_debug) {std::cout << "FIT Failure; Layer: " << std::endl;}
308 }
309
310 if (m_debug) {printf("P6default= %3.2f, p6 fit = %3.2f", p6default, par[6]);}
311
312 if (m_fitflag == 1) {
313 if (m_debug) std::cout << "Fit success" << std::endl;
314 xtpol5->GetParameters(m_FittedXTParams);
315 m_Prob = xtpol5->GetProb();
316 break;
317 }
318
319 } //end loop of fitting
320 if (m_draw) {
321 TString hname = m_h1->GetName();
322 TString name = hname + ".pdf";
323 TCanvas* c1 = new TCanvas("c1", "", 800, 600);
324 m_h1->Draw();
325 xtpol5->SetLineColor(kBlack);
326 xtpol5->DrawF1(0, 400, "same");
327 c1->SaveAs(name);
328
329 }
330}
bool m_debug
Print debug durring fitting or not.
Definition: XT.h:229
TF1 * xtpol5
5th order polynomial function
Definition: XT.h:225

◆ FitXT() [1/2]

void FitXT ( )
inline

Do fitting.

Definition at line 200 of file XT.h.

201 {
202 if (m_mode == 0) FitPol5();
203 else FitChebyshev();
204 }
void FitChebyshev()
Fit xt histogram incase 5th order Chebeshev polynomial is used.
Definition: XT.h:332
void FitPol5()
Fit xt histogram incase 5th order polynomial is used.
Definition: XT.h:250

◆ FitXT() [2/2]

void FitXT ( int  mode)
inline

Do fitting.

Definition at line 209 of file XT.h.

210 {
211 if (mode == 0) FitPol5();
212 else FitChebyshev();
213 }

◆ getFitStatus()

int getFitStatus ( )
inline

get fitted flag.

Definition at line 157 of file XT.h.

158 {
159 return m_fitflag;
160 }

◆ getFittedHisto()

TProfile * getFittedHisto ( )
inline

Get histogram.

Definition at line 195 of file XT.h.

195{return m_h1;}

◆ getFittedXTParams()

void getFittedXTParams ( double  pa[8])
inline

get fit parameters.

Definition at line 172 of file XT.h.

173 {
174 for (int i = 0; i < 8; ++i) {pa[i] = m_FittedXTParams[i];}
175 }

◆ getProb()

double getProb ( )
inline

Get the chi2 probability.

Definition at line 165 of file XT.h.

166 {
167 return m_Prob;
168 }

◆ getXTFunction() [1/2]

TF1 * getXTFunction ( )
inline

Get XT function.

Definition at line 187 of file XT.h.

188 {
189 if (m_mode == 0) return xtpol5;
190 else return xtCheb5;
191 };

◆ getXTFunction() [2/2]

TF1 * getXTFunction ( int  mode)
inline

Get XT function.

Definition at line 179 of file XT.h.

180 {
181 if (mode == 0) return xtpol5;
182 else return xtCheb5;
183 }

◆ setDebug()

void setDebug ( bool  debug)
inline

Set Debug.

Definition at line 150 of file XT.h.

151 {
152 m_debug = debug;
153 }

◆ setFitRange()

void setFitRange ( double  tmin,
double  tmax 
)
inline

Set Fit range.

Definition at line 135 of file XT.h.

136 {
137 m_tmin = tmin;
138 m_tmax = tmax;
139 }

◆ setMode()

void setMode ( int  mode)
inline

Set XT mode.

1 is 5th order Chebyshev polynomial. 0 is 5th order polynomial.

Definition at line 103 of file XT.h.

104 {
105 m_mode = mode;
106 }

◆ setP6()

void setP6 ( double  p6)
inline

Set Parameter 6 for polynomial fit.

Definition at line 93 of file XT.h.

94 {
95 m_XTParam[6] = p6;
96 }

◆ setSmallestEntryRequired()

void setSmallestEntryRequired ( int  min)
inline

Set minimum number of entry required for fit.

Definition at line 143 of file XT.h.

144 {
145 m_minRequiredEntry = min;
146 }

◆ setXTParams() [1/2]

void setXTParams ( const double  p[8])
inline

Set Parameters for fit.

Definition at line 115 of file XT.h.

116 {
117 for (int i = 0; i < 8; ++i) {m_XTParam[i] = p[i];}
118 m_tmax = p[6] + 250;
119 }

◆ setXTParams() [2/2]

void setXTParams ( double  p0,
double  p1,
double  p2,
double  p3,
double  p4,
double  p5,
double  p6,
double  p7 
)
inline

Set Initial parameters for fitting.

Definition at line 123 of file XT.h.

125 {
126 m_XTParam[0] = p0; m_XTParam[1] = p1; m_XTParam[2] = p2;
127 m_XTParam[3] = p3; m_XTParam[4] = p4; m_XTParam[5] = p5;
128 m_XTParam[6] = p6; m_XTParam[7] = p7;
129 m_tmax = p6 + 250;
130 }

Member Data Documentation

◆ m_BField

bool m_BField = true
private

With magnetic field or not.

Definition at line 231 of file XT.h.

◆ m_debug

bool m_debug = true
private

Print debug durring fitting or not.

Definition at line 229 of file XT.h.

◆ m_draw

bool m_draw = false
private

Draw and store png plot of each histo or not.

Definition at line 230 of file XT.h.

◆ m_fitflag

int m_fitflag = 0
private

Fit Flag =-1: low statitic =1: good =0: Fit failure =2: Error Outer =3: Error Inner part;.

Definition at line 244 of file XT.h.

◆ m_FittedXTParams

double m_FittedXTParams[8] = {}
private

Fitted parameters.

Definition at line 234 of file XT.h.

◆ m_h1

TProfile* m_h1
private

Histogram of xt relation.

Definition at line 224 of file XT.h.

◆ m_minRequiredEntry

int m_minRequiredEntry = 800
private

Minimum entry required for each histo.

Definition at line 232 of file XT.h.

◆ m_mode

int m_mode = 1
private

XT mode, 0 is for 5th order polynomial, 1 is Chebshev polynomial.

Definition at line 228 of file XT.h.

◆ m_Prob

double m_Prob = 0
private

Chi2 prob of fitting.

Definition at line 245 of file XT.h.

◆ m_tmax

double m_tmax = m_XTParam[6] + 250
private

upper boundary of fit range

Definition at line 247 of file XT.h.

◆ m_tmin

double m_tmin = 20
private

lower boundary of fit range

Definition at line 246 of file XT.h.

◆ m_XTParam

double m_XTParam[8] = {}
private

Parameter fo xt.

Definition at line 233 of file XT.h.

◆ xtCheb5

TF1* xtCheb5 = new TF1("xtCheb5", Cheb5pol1, 0.0, 700, 8)
private

5th order Cheb.

polynomial function

Definition at line 226 of file XT.h.

◆ xtpol5

TF1* xtpol5 = new TF1("xtpol5", pol5pol1, 0.0, 700, 8)
private

5th order polynomial function

Definition at line 225 of file XT.h.


The documentation for this class was generated from the following file: