CbmRoot
Loading...
Searching...
No Matches
fit_ybox.h
Go to the documentation of this file.
1/* Copyright (C) 2016-2020 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer] */
4
5// box with polynomial filling
6Double_t f1_xboxe(double* x, double* par)
7{
8 double xx = x[0];
9 double wx = 1. - par[4] * TMath::Power(xx + par[5], 2);
10 double xboxe = par[0] * 0.25 * (1. + TMath::Erf((xx + par[1] - par[3]) / par[2]))
11 * (1. + TMath::Erf((-xx + par[1] + par[3]) / par[2]));
12 return xboxe * wx;
13
14 /*
15 common/pawpar/p(6)
16 real wx
17 wx=1.-p(5)*(x+p(6))**2
18C wx=1.
19 xboxe=p(1)*0.25*(1.+erf(( x+p(2)-p(4))/p(3)))
20 & *(1.+erf((-x+p(2)+p(4))/p(3)))
21 xboxe=xboxe*wx
22 */
23}
24
25void fit_ybox(const char* hname, Double_t YLen)
26{
27 TH1* h1;
28 TH2* h2;
29 h1 = (TH1*) gROOT->FindObjectAny(hname);
30 if (NULL != h1) {
31 TAxis* xaxis = h1->GetXaxis();
32 Double_t Ymin = xaxis->GetXmin();
33 Double_t Ymax = xaxis->GetXmax();
34 TF1* f1 = new TF1("YBox", f1_xboxe, Ymin, Ymax, 6);
35 Double_t yini = (h1->GetMaximum() + h1->GetMinimum()) * 0.5;
36 Double_t dLini = Ymax * 0.8;
37 if (YLen != 0.) {
38 dLini = YLen * 0.5;
39 f1->SetParLimits(1, dLini, dLini);
40 }
41 f1->SetParameters(yini, dLini, 2., -1., 0., 0.);
42 f1->SetParLimits(2, 0.2, 3.);
43 f1->SetParLimits(3, -3., 3.);
44 h1->Fit("YBox", "SQM");
45
46 double res[10];
47 double err[10];
48 res[9] = f1->GetChisquare();
49
50 for (int i = 0; i < 6; i++) {
51 res[i] = f1->GetParameter(i);
52 err[i] = f1->GetParError(i);
53 //cout << " FPar "<< i << ": " << res[i] << ", " << err[i] << endl;
54 }
55 cout << "YBox Fit of " << hname << " ended with chi2 = " << res[9]
56 << Form(", strip length %7.2f +/- %5.2f, position resolution %7.2f "
57 "+/- %5.2f at y_cen = %7.2f +/- %5.2f",
58 2. * res[1], 2. * err[1], res[2], err[2], res[3], err[3])
59 << endl;
60 }
61}
62
63void fit_ybox(const char* hname)
64{
65 Double_t Ylen = 0.;
66 fit_ybox(hname, Ylen);
67}
void fit_ybox(const char *hname, Double_t YLen)
Definition fit_ybox.h:25
Double_t f1_xboxe(double *x, double *par)
Definition fit_ybox.h:6