Fit xt histogram incase 5th order polynomial is used.
251{
252 double max_dif = 0.12;
253 double max_dif2 = 0.05;
254 double par[8];
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;
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
272 for (int i = 0; i < 10; ++i) {
274 std::cout << "Fitting" << std::endl;
276 xtpol5->GetParameters(par);
277
278
279 double fp6 =
xtpol5->Eval(par[6]);
280 double fbehindp6 =
xtpol5->Eval(par[6] - 12) - 0.01;
281 if (fp6 < fbehindp6 || fp6 > 1) {
283 out += 1;
284 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
285 xtpol5->SetParLimits(6, p6default - 10, p6default + 10 - out / 2);
287 if (
m_tmax < p6default + 30) {
289 }
290 }
291
292
293 if (fabs(par[0] - p0) > max_dif || fabs(f10 -
xtpol5->Eval(10)) > max_dif2) {
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);
299
301 m_tmin = 14; std::cout <<
"ERROR: tmin so small, fit iter: " << std::endl;
302 }
303 }
304
305 if (stat == 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
313 if (
m_debug) std::cout <<
"Fit success" << std::endl;
316 break;
317 }
318
319 }
321 TString hname =
m_h1->GetName();
322 TString name = hname + ".pdf";
323 TCanvas* c1 = new TCanvas("c1", "", 800, 600);
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.
TF1 * xtpol5
5th order polynomial function