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);
134 const static double x0 = 6 - (2 + 7. / 16);
141 vector<double> res_err;
143 vector<double> res2_err;
145 for (
const auto &
data : datafiles)
147 cout << __PRETTY_FUNCTION__ <<
" "
148 <<
" processing x = " <<
data.first <<
" from " <<
data.second << endl;
150 TFile *
f = TFile::Open((TString(
basePath +
data.second.c_str()) +
"_TpcPrototypeGenFitTrkFitter.root_DrawJet_Resolution.root"));
153 TH1 *hresidual_cor = (TH1 *) f->GetObjectChecked(
"hresidual_cor",
"TH1");
155 TF1 *hresidual_dgaus = (TF1 *) hresidual_cor->GetListOfFunctions()->At(0);
158 if (hresidual_dgaus->GetParameter(2) < hresidual_dgaus->GetParameter(4))
160 res.push_back(hresidual_dgaus->GetParameter(2) * 1e4);
161 res_err.push_back(hresidual_dgaus->GetParError(2) * 1e4);
165 res.push_back(hresidual_dgaus->GetParameter(4) * 1e4);
166 res_err.push_back(hresidual_dgaus->GetParError(4) * 1e4);
168 x.push_back(
data.first);
169 x_cm.push_back((
data.first -
x0) * 2.54);
170 res2.push_back(res[res.size() - 1] * res[res.size() - 1]);
171 res2_err.push_back(2 * res[res.size() - 1] * res_err[res.size() - 1]);
173 cout <<
"x = " << x[res.size() - 1] <<
" x_cm = " << x_cm[res.size() - 1] <<
" res = " << res[res.size() - 1] <<
" res_err = " << res_err[res.size() - 1] << endl;
176 TGraphErrors *
g =
new TGraphErrors(x.size(), x_cm.data(), res.data(), 0, res_err.data());
177 g->SetMarkerColor(
color);
178 g->SetLineColor(
color);
181 TGraphErrors *g2 =
new TGraphErrors(x.size(), x.data(), res2.data(), 0, res2_err.data());
182 g2->SetMarkerColor(
color);
183 g2->SetLineColor(
color);
186 return pair<TGraph *, TGraph *>(
g, g2);
190 string basepath =
"/phenix/u/jinhuang/links/sPHENIX_work/TPC/fnal_June2019/SimPadPlaneIter5/")
195 const double max_res = 300;
196 const double field_off_trans_diffusion = 150;
197 const double field_on_trans_diffusion = 40;
200 TVirtualFitter::SetDefaultFitter(
"Minuit2");
201 gStyle->SetLegendTextSize(0);
203 TCanvas *c1 =
new TCanvas(
"DrawTpcPrototypeGenFitTrkFitter_Summary",
"DrawTpcPrototypeGenFitTrkFitter_Summary", 1800, 700);
208 p = (TPad *) c1->cd(idx++);
211 TH1 *frame = p->DrawFrame(2, 0, 20, max_res * max_res);
212 frame->SetTitle(
";Horizontal Position [in];Resolution^{2}, Cluster w/ 2+ pad [#mum^{2}]");
213 frame->GetYaxis()->SetTitleOffset(1.75);
214 TLine *l =
new TLine(
x0, 0,
x0, max_res * max_res);
217 TLegend *leg1 =
new TLegend(.35, .7, .9, .9,
"2019 TPC Beam Test Preview");
219 p = (TPad *) c1->cd(idx++);
221 p->DrawFrame(0, 50, 125, max_res)->SetTitle(
";Drift Length, L [cm];Resolution, Cluster w/ 2+ pad [#mum]");
222 TLegend *leg2 =
new TLegend(.42, .45, .92, .93,
"2019 TPC Beam Test Preview");
225 Color_t
color = kRed + 2;
226 const TString
name =
"Scan2: Gap 300V, GEM 370V";
229 {{6,
"tpc_beam_00000288-0000.evt"},
230 {6,
"tpc_beam_00000292-0000.evt"},
231 {10,
"tpc_beam_00000293-0000.evt"},
232 {14,
"tpc_beam_00000294-0000.evt"},
233 {18,
"tpc_beam_00000295-0000.evt"}},
237 scan2.second->Draw(
"p");
238 TF1 *fline_scan2 =
new TF1(
"fline_scan2",
"pol1",
x0, 20);
239 scan2.second->Fit(fline_scan2,
"MR0");
240 fline_scan2->SetLineColor(color);
241 fline_scan2->Draw(
"same");
243 leg1->AddEntry(scan2.second, name,
"p");
246 scan2.first->Draw(
"p");
247 TF1 *fdiff_scan2 =
new TF1(
"fline_scan2",
"sqrt([0]*[0] + ([1]*[1]/[2])*x)", 0, 40);
248 fdiff_scan2->SetParameters(70, field_off_trans_diffusion, 20);
249 fdiff_scan2->FixParameter(1, field_off_trans_diffusion);
250 scan2.first->Fit(fdiff_scan2,
"MR0");
251 fdiff_scan2->SetLineColor(color);
252 fdiff_scan2->Draw(
"same");
254 TF1 *fdiff_scan2_FieldON = (TF1 *) fdiff_scan2->Clone(
"fdiff_scan2_FieldON");
255 fdiff_scan2_FieldON->SetRange(0, 105);
256 fdiff_scan2_FieldON->SetParameter(1, field_on_trans_diffusion);
257 fdiff_scan2_FieldON->SetLineStyle(kDashed);
258 fdiff_scan2_FieldON->Draw(
"same");
261 leg2->AddEntry(scan2.first, name,
"pe");
262 leg2->AddEntry(fdiff_scan2, Form(
"#sqrt{(%.1f #mum)^{2} + (%.0f #mum/#sqrt{cm} #times#sqrt{L/%.1f})^{2}}", abs(fdiff_scan2->GetParameter(0)), abs(fdiff_scan2->GetParameter(1)), abs(fdiff_scan2->GetParameter(2))),
"l");
263 leg2->AddEntry(fdiff_scan2_FieldON, Form(
"Field = 1.4T, #sigma_{T, Diffusion} = %.0f #mum/#sqrt{cm}", field_on_trans_diffusion),
"l");
269 Color_t
color = kBlue + 2;
270 const TString
name =
"Scan3: Gap 150V, GEM 380V";
273 {{6,
"tpc_beam_00000297-0000.evt"},
274 {6,
"tpc_beam_00000298-0000.evt"},
275 {10,
"tpc_beam_00000299-0000.evt"},
276 {14,
"tpc_beam_00000300-0000.evt"},
277 {18,
"tpc_beam_00000301-0000.evt"}},
281 scan3.second->Draw(
"p");
282 TF1 *fline_scan3 =
new TF1(
"fline_scan3",
"pol1",
x0, 20);
283 scan3.second->Fit(fline_scan3,
"MR0");
284 fline_scan3->SetLineColor(color);
285 fline_scan3->Draw(
"same");
286 leg1->AddEntry(scan3.second, name,
"p");
289 scan3.first->Draw(
"p");
290 TF1 *fdiff_scan3 =
new TF1(
"fline_scan3",
"sqrt([0]*[0] + ([1]*[1]/[2])*x)", 0, 40);
291 fdiff_scan3->SetParameters(70, field_off_trans_diffusion, 20);
292 fdiff_scan3->FixParameter(1, field_off_trans_diffusion);
293 scan3.first->Fit(fdiff_scan3,
"MR0");
294 fdiff_scan3->SetLineColor(color);
295 fdiff_scan3->Draw(
"same");
297 TF1 *fdiff_scan3_FieldON = (TF1 *) fdiff_scan3->Clone(
"fdiff_scan3_FieldON");
298 fdiff_scan3_FieldON->SetRange(0, 105);
299 fdiff_scan3_FieldON->SetParameter(1, field_on_trans_diffusion);
300 fdiff_scan3_FieldON->SetLineStyle(kDashed);
301 fdiff_scan3_FieldON->Draw(
"same");
304 leg2->AddEntry(scan3.first, name,
"pe");
305 leg2->AddEntry(fdiff_scan3, Form(
"#sqrt{(%.1f #mum)^{2} + (%.0f #mum/#sqrt{cm} #times#sqrt{L/%.1f})^{2}}", abs(fdiff_scan3->GetParameter(0)), abs(fdiff_scan3->GetParameter(1)), abs(fdiff_scan3->GetParameter(2))),
"l");
306 leg2->AddEntry(fdiff_scan3_FieldON, Form(
"Field = 1.4T, #sigma_{T, Diffusion} = %.0f #mum/#sqrt{cm}", field_on_trans_diffusion),
"l");
313 Color_t
color = kGreen + 2;
316 {{6,
"tpc_beam_00000357-0000.evt"},
317 {6,
"tpc_beam_00000358-0000.evt"},
318 {10,
"tpc_beam_00000359-0000.evt"},
319 {10,
"tpc_beam_00000360-0000.evt"},
320 {13,
"tpc_beam_00000356-0000.evt"},
321 {14,
"tpc_beam_00000361-0000.evt"},
322 {14,
"tpc_beam_00000362-0000.evt"},
323 {18,
"tpc_beam_00000363-0000.evt"},
324 {18,
"tpc_beam_00000366-0000.evt"}},
328 scan4.second->Draw(
"p");
329 TF1 *fline_scan4 =
new TF1(
"fline_scan4",
"pol1",
x0, 16);
330 scan4.second->Fit(fline_scan4,
"MR0");
331 fline_scan4->SetLineColor(color);
332 fline_scan4->Draw(
"same");
335 scan4.first->Draw(
"p");
336 TF1 *fdiff_scan4 =
new TF1(
"fline_scan4",
"sqrt([0]*[0] + [1]*[1]*x)", 0, 30);
337 scan4.first->Fit(fdiff_scan4,
"MR0");
338 fdiff_scan4->SetLineColor(color);
339 fdiff_scan4->Draw(
"same");
349 TString(
basePath) + TString(c1->GetName()),
true);