1 #include "SaveCanvas.C"
2 #include "sPhenixStyle.C"
6 #include <TEfficiency.h>
8 #include <TGraphAsymmErrors.h>
9 #include <TGraphErrors.h>
12 #include <TPolyLine.h>
23 #include <TDirectory.h>
28 #include <TVirtualFitter.h>
43 cout << "Assert (" << #exp << ") failed at " << __FILE__ << " line " << __LINE__ << endl; \
52 assert(axis->GetXmin() > 0);
53 assert(axis->GetXmax() > 0);
55 const int bins = axis->GetNbins();
57 Axis_t from = log10(axis->GetXmin());
58 Axis_t to = log10(axis->GetXmax());
59 Axis_t
width = (to - from) / bins;
60 vector<Axis_t> new_bins(bins + 1);
64 new_bins[
i] = TMath::Power(10, from +
i * width);
66 axis->Set(bins, new_bins.data());
72 TProfile *p2 = h2->ProfileX();
80 for (
int i = 1;
i <= h2->GetNbinsX();
i++)
82 TH1D *
h1 = h2->ProjectionY(Form(
"htmp_%d", rand()),
i,
i);
84 if (h1->GetSum() < 30)
86 cout <<
"FitProfile - ignore bin " <<
i << endl;
94 TF1 fgaus(
"fgaus",
"gaus", -p2->GetBinError(
i) * 4,
95 p2->GetBinError(
i) * 4);
100 fgaus.SetParameter(1, p2->GetBinContent(
i));
101 fgaus.SetParameter(2, p2->GetBinError(
i));
103 h1->Fit(&fgaus,
"MQ");
105 TF1
f2(Form(
"dgaus"),
"gaus + [3]",
106 -fgaus.GetParameter(2) * 1.5, fgaus.GetParameter(2) * 1.5);
108 f2.SetParameters(fgaus.GetParameter(0), fgaus.GetParameter(1),
109 fgaus.GetParameter(2), 0);
118 x[
n] = p2->GetBinCenter(
i);
119 ex[
n] = (p2->GetBinCenter(2) - p2->GetBinCenter(1)) / 2;
120 y[
n] = fgaus.GetParameter(1);
121 ey[
n] = fgaus.GetParError(1);
130 return new TGraphErrors(n, x, y, ex, ey);
137 void Resolution(
const TCut &cut =
"Iteration$ >= 5 && Iteration$ <= 10 && TPCTrack.nCluster>=12 && TPCTrack.clusterSizePhi > 3.5",
138 const double phi_start = -2.905,
const double phi_end = -2.885
142 TH2 *hresidual_phi =
new TH2F(
"hresidual_phi",
"hresidual_phi", 60, phi_start, phi_end, 60, -.2, .2);
143 T->Draw(
"TPCTrack.clusterResidualPhi:TPCTrack.clusterProjectionPhi>>hresidual_phi",
145 hresidual_phi->SetTitle(
";Global Phi [rad];Phi Residual [cm]");
147 TH2 *hresidual_phi_highres =
new TH2F(
"hresidual_phi_highres",
"hresidual_phi", 500, phi_start, phi_end, 1000, -.2, .2);
148 T->Draw(
"TPCTrack.clusterResidualPhi:TPCTrack.clusterProjectionPhi>>hresidual_phi_highres",
150 hresidual_phi_highres->SetTitle(
";Global Phi [rad];Phi Residual [cm]");
152 TCanvas *c1 =
new TCanvas(
"Resolution",
"Resolution", 1800, 860);
157 p = (TPad *) c1->cd(idx++);
160 TGraphErrors *gcenter =
FitProfile(hresidual_phi);
162 hresidual_phi->Draw(
"colz");
168 TF1 *fPeriod =
new TF1(
"fPeriod",
169 "([0]+[1]*x) * sin(2*pi*x/(2*pi/12/8/16)) + ([1]+[2]*x) * cos(2*pi*x/(2*pi/12/8/16)) + [3] + [4]*x + [5]*x*x + ([6]+[7]*x) * sin(4*pi*x/(2*pi/12/8/16)) + ([8]+[9]*x) * cos(4*pi*x/(2*pi/12/8/16))+ ([10] + [11]*x) * sin(3*pi*x/(2*pi/12/8/16)) + ([12]+[13]*x) * cos(3*pi*x/(2*pi/12/8/16))+ ([14]+[15]*x) * sin(pi*x/(5*pi/12/8/16)) + ([16]+[17]*x) * cos(pi*x/(5*pi/12/8/16)) + ([18]+[19]*x) * x*x*x", -3, 0);
170 gcenter->Fit(fPeriod,
"M");
172 p = (TPad *) c1->cd(idx++);
175 TH2 *hresidual_phi_cor = (TH2 *) hresidual_phi->Clone(
"hresidual_phi_cor");
176 hresidual_phi_cor->Reset();
177 hresidual_phi_cor->SetTitle(
";Global Phi [rad];Modulation-Corrected Phi Residual [cm]");
180 for (
int binx = 1; binx <= hresidual_phi_highres->GetNbinsX(); ++binx)
181 for (
int biny = 1; biny <= hresidual_phi_highres->GetNbinsY(); ++biny)
183 const double x = hresidual_phi_highres->GetXaxis()->GetBinCenter(binx);
184 const double y = hresidual_phi_highres->GetYaxis()->GetBinCenter(biny);
185 const double value = hresidual_phi_highres->GetBinContent(binx, biny);
189 const double y_cor = y - fPeriod->Eval(x);
191 hresidual_phi_cor->Fill(x, y_cor, value);
193 cout << __PRETTY_FUNCTION__ <<
" sum = " << sum << endl;
195 hresidual_phi_cor->Draw(
"colz");
197 p = (TPad *) c1->cd(idx++);
199 TH1 *hresidual_cor = hresidual_phi_cor->ProjectionY(
"hresidual_cor", 1, hresidual_phi_cor->GetNbinsX());
201 hresidual_cor->Draw();
203 TH1 *hresidual = hresidual_phi->ProjectionY(
"hresidual", 1, hresidual_phi->GetNbinsX());
205 hresidual->SetLineColor(kRed - 3);
206 hresidual->Draw(
"same");
208 TF1 *hresidual_fgaus =
new TF1(
"hresidual_fgaus",
"gaus", -.2, .2);
210 TF1 *hresidual_dgaus =
new TF1(Form(
"hresidual_dgaus"),
"gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
213 hresidual_fgaus->SetParameter(1, hresidual->GetMean());
214 hresidual_fgaus->SetParameter(2, hresidual->GetRMS());
216 hresidual_cor->Fit(hresidual_fgaus,
"MQ");
221 hresidual_dgaus->SetParameters(hresidual_fgaus->GetParameter(0),
222 hresidual_fgaus->GetParameter(1),
223 hresidual_fgaus->GetParameter(2) / 2,
224 hresidual_fgaus->GetParameter(0) / 20,
225 hresidual_fgaus->GetParameter(2) * 10, 0);
227 hresidual_cor->Fit(hresidual_dgaus,
"M");
228 hresidual_dgaus->SetLineColor(kBlue + 2);
229 const double resolution = TMath::Min(hresidual_dgaus->GetParameter(2), hresidual_dgaus->GetParameter(4));
231 cout << __PRETTY_FUNCTION__ <<
" hresidual_fgaus->GetParameter(2) = " << hresidual_dgaus->GetParameter(2)
232 <<
" hresidual_fgaus->GetParameter(4) = " << hresidual_dgaus->GetParameter(4) <<
" resolution = " << resolution << endl;
244 gPad->SetTopMargin(.3);
245 TLegend *
leg =
new TLegend(.03, .7, .98, .99,
description +
": 1-removed residual");
246 leg->AddEntry(hresidual,
"Raw residual",
"l");
247 leg->AddEntry(hresidual_cor,
"Position dependence corected residual",
"p");
248 leg->AddEntry(hresidual_dgaus, Form(
"resolution = %.0f #mum", resolution * 1e4),
"l");
252 TString(
_file0->GetName()) + TString(c1->GetName()), kFALSE);
257 TCanvas *c1 =
new TCanvas(
"TrackQA",
"TrackQA", 1800, 860);
262 p = (TPad *) c1->cd(idx++);
265 TH1 *hnTrack =
new TH1F(
"hnTrack",
";# track per event", 17, -.5, 16.5);
266 T->Draw(
"nTrack>>hnTrack");
268 p = (TPad *) c1->cd(idx++);
271 TH1 *hCluster =
new TH1F(
"hCluster",
";# cluster per track", 16, .5, 16.5);
272 T->Draw(
"TPCTrack.nCluster>>hCluster");
274 p = (TPad *) c1->cd(idx++);
277 TH1 *hclusterSizePhi =
new TH1F(
"hclusterSizePhi",
";Cluster phi size", 16, .5, 16.5);
278 T->Draw(
"TPCTrack.clusterSizePhi>>hclusterSizePhi");
280 p = (TPad *) c1->cd(idx++);
283 TH1 *hclusterProjectionPhi =
new TH1F(
"hclusterProjectionPhi",
";Cluster phi [rad]", 100, -3.5, -2.5);
284 T->Draw(
"TPCTrack.clusterProjectionPhi>>hclusterProjectionPhi");
286 p = (TPad *) c1->cd(idx++);
289 TH1 *hAngle =
new TH1F(
"hAngle",
";Horizontal angle [degree]", 100, -30, 30);
290 T->Draw(
"atan(TPCTrack.pz/ TPCTrack.px)/pi*180>>hAngle");
292 p = (TPad *) c1->cd(idx++);
295 TH1 *hAngleV =
new TH1F(
"hAngleV",
";Vertical angle [degree]", 100, -30, 30);
296 T->Draw(
"(atan(TPCTrack.py/ TPCTrack.px) - 2*pi/12/2 )/pi*180>>hAngleV");
301 TString(
_file0->GetName()) + TString(c1->GetName()), kFALSE);
306 TCanvas *c1 =
new TCanvas(
"Track3D",
"Track3D", 1800, 900);
311 p = (TPad *) c1->cd(idx++);
316 TH3F *h3ClusterOverlay =
new TH3F(
"h3ClusterOverlay",
"h3ClusterOverlay", 128, -40, 10, 64, 35, 65, 128, -15, 15);
318 T->SetAlias(
"PhiCenter",
"pi/12 + pi");
319 T->Draw(
"TPCTrack.clusterX*cos(PhiCenter + pi/2) + TPCTrack.clusterY*sin(PhiCenter + pi/2):TPCTrack.clusterX*cos(PhiCenter) + TPCTrack.clusterY*sin(PhiCenter):TPCTrack.clusterZ>>h3ClusterOverlay",
"",
"BOX2");
321 h3ClusterOverlay->SetTitle(
";Drift Direction [cm];Pad Row Direction [cm];Azimuth Direction [cm]");
322 h3ClusterOverlay->SetLineWidth(0);
324 p = (TPad *) c1->cd(idx++);
329 TH1 *h2ClusterOverlay = h3ClusterOverlay->Project3D(
"zx");
330 h2ClusterOverlay->Draw(
"colz");
337 TLegend *
leg =
new TLegend(.15, .9, .95, .99,
description +
": accumulated clusters on tracks");
341 TString(
_file0->GetName()) + TString(c1->GetName()),
false);
346 TCanvas *c1 =
new TCanvas(
"TrackDistortion",
"TrackDistortion", 1800, 860);
351 p = (TPad *) c1->cd(idx++);
354 TH2 *hPhiDistortion =
new TH2F(
"hPhiDistortion",
";Pad Layers;Phi Residual [cm]", 16, -.5, 15.5, 200, -3, 3);
355 T->Draw(
"TPCTrack.clusterResidualPhi:Iteration$>>hPhiDistortion", cut,
"goff");
356 TGraph *gPhiDistortion =
FitProfile(hPhiDistortion);
357 hPhiDistortion->Draw(
"colz");
358 gPhiDistortion->Draw(
"p");
360 p = (TPad *) c1->cd(idx++);
363 TH2 *hZDistortion =
new TH2F(
"hZDistortion",
";Pad Layers;Z Residual [cm]", 16, -.5, 15.5, 200, -3, 3);
364 T->Draw(
"TPCTrack.clusterResidualZ:Iteration$>>hZDistortion", cut,
"goff");
365 TGraph *gZDistortion =
FitProfile(hZDistortion);
366 hZDistortion->Draw(
"colz");
367 gZDistortion->Draw(
"p");
370 TString(
_file0->GetName()) + TString(c1->GetName()), kFALSE);
387 Double_t invsq2pi = 0.3989422804014;
388 Double_t mpshift = -0.22278298;
404 mpc = par[1] - mpshift * par[0];
407 xlow = x[0] - sc * par[3];
408 xupp = x[0] + sc * par[3];
410 step = (xupp - xlow) / np;
413 for (i = 1.0; i <= np / 2; i++)
415 xx = xlow + (i - .5) *
step;
416 fland = TMath::Landau(xx, mpc, par[0]) / par[0];
417 sum += fland * TMath::Gaus(x[0], xx, par[3]);
419 xx = xupp - (i - .5) *
step;
420 fland = TMath::Landau(xx, mpc, par[0]) / par[0];
421 sum += fland * TMath::Gaus(x[0], xx, par[3]);
424 return (par[2] * step * sum * invsq2pi / par[3]);
428 const vector<double> &fitrange,
429 const vector<double> &startvalues,
430 const vector<double> &parlimitslo,
const vector<double> &parlimitshi
456 sprintf(FunName,
"Fitfcn_%s", his->GetName());
458 TF1 *ffitold = (TF1 *) gROOT->GetListOfFunctions()->FindObject(FunName);
459 if (ffitold)
delete ffitold;
461 TF1 *ffit =
new TF1(FunName,
langaufun, fitrange[0], fitrange[1], 4);
462 ffit->SetParameters(startvalues.data());
463 ffit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
465 for (i = 0; i < 4; i++)
467 ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);
470 his->Fit(FunName,
"RB0");
484 TCanvas *c1 =
new TCanvas(
"TrackClusterEnergy",
"TrackClusterEnergy", 1200, 860);
489 p = (TPad *) c1->cd(idx++);
493 TH1 *hClusterEnergy =
new TH1F(
"hClusterEnergy",
";Cluster Energy on good track [ADU];Count / bin", 2500, 0, 5000);
494 T->Draw(
"TPCTrack.clusterE>>hClusterEnergy", cut,
"goff");
499 {200, 500, (
double)
T->GetEntries(cut) * 10, 200},
501 {5000, 5000, 1e10, 5000});
502 fit->SetLineColor(kBlue + 2);
504 hClusterEnergy->Draw();
508 TLegend *
leg =
new TLegend(.3, .7, .95, .9,
description +
": Cluster Energy on good track");
509 leg->AddEntry(hClusterEnergy, TString(
"Data: ") + cut.GetTitle(),
"l");
511 Form(
"Langdau * Gauss Fit, #mu= %.0f ADU", fit->GetParameter(1)),
"l");
515 TString(
_file0->GetName()) + TString(c1->GetName()), kFALSE);
519 const TString
infile =
"data/tpc_beam/tpc_beam_00000292-0000.evt_TpcPrototypeGenFitTrkFitter.root",
const TString desc =
"Run 292"
522 gSystem->Load(
"libtpc2019.so");
525 TVirtualFitter::SetDefaultFitter(
"Minuit2");
526 gStyle->SetLegendTextSize(0);
530 TString chian_str =
infile;
531 chian_str.ReplaceAll(
"ALL",
"*");
533 TChain *
t =
new TChain(
"T");
534 const int n = t->Add(chian_str);
536 cout <<
"Loaded " << n <<
" root files with eventT in " << chian_str << endl;
552 Resolution(
"Iteration$ >= 5 && Iteration$ <= 10 && TPCTrack.nCluster>=12 && TPCTrack.clusterSizePhi > 7");