File indexing completed on 2025-08-05 08:14:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cmath>
0012 #include <TFile.h>
0013 #include <TString.h>
0014 #include <TLine.h>
0015 #include <TTree.h>
0016 #include <TLatex.h>
0017 #include <TGraphErrors.h>
0018 #include <cassert>
0019 #include "SaveCanvas.C"
0020 #include "SetOKStyle.C"
0021 using namespace std;
0022
0023
0024
0025 TCut event_sel;
0026 TString cuts;
0027 TFile * _file0 = NULL;
0028 TTree * T = NULL;
0029
0030 class lin_res
0031 {
0032 public:
0033 TString name;
0034 TGraphErrors * linearity;
0035 TGraphErrors * resolution;
0036 TF1 * f_res;
0037 };
0038
0039 void
0040 DrawPrototype3ShowerCalib(
0041 const TString infile =
0042 "/sphenix/user/jinhuang/Prototype_2017/ShowerCalib/JointEnergyScan1_Neg.lst_EMCalCalib.root"
0043
0044
0045
0046
0047
0048
0049 )
0050 {
0051
0052 SetOKStyle();
0053 gStyle->SetOptStat(0);
0054 gStyle->SetOptFit(1111);
0055 gStyle->SetPadGridX(0);
0056 gStyle->SetPadGridY(0);
0057 TVirtualFitter::SetDefaultFitter("Minuit2");
0058
0059 gSystem->Load("libPrototype3.so");
0060 gSystem->Load("libProto3ShowCalib.so");
0061
0062
0063
0064 if (!_file0)
0065 {
0066 TString chian_str = infile;
0067 chian_str.ReplaceAll("ALL", "*");
0068
0069 TChain * t = new TChain("T");
0070 const int n = t->Add(chian_str);
0071
0072 cout << "Loaded " << n << " root files with " << chian_str << endl;
0073 assert(n > 0);
0074
0075 T = t;
0076
0077 _file0 = new TFile;
0078 _file0->SetName(infile);
0079 }
0080
0081 assert(_file0);
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 event_sel = "good_e && info.hodo_h==3 && info.hodo_v==6";
0122 cuts = "_good_data_h3_v6";
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 T->SetAlias("SimEnergyScale", "1*1");
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 cout << "Build event selection of " << (const char *) event_sel << endl;
0197
0198 T->Draw(">>EventList", event_sel);
0199 TEventList * elist = gDirectory->GetObjectChecked("EventList", "TEventList");
0200 cout << elist->GetN() << " / " << T->GetEntriesFast() << " events selected"
0201 << endl;
0202
0203 T->SetEventList(elist);
0204
0205
0206 PositionDependenceData("clus_5x5_prod.sum_E");
0207
0208 HodoscopeCheck();
0209
0210
0211
0212
0213 Get_Res_linear_Summmary("sum_E");
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225 }
0226
0227 void
0228 PositionDependenceData(TString sTOWER = "clus_5x5_prod.sum_E",
0229 const double z_shift = 0, const int n_div = 1)
0230 {
0231 TH3F * EnergySum_LG3 =
0232 new TH3F("EnergySum_LG3",
0233 ";Horizontal Hodoscope (5 mm);Vertical Hodoscope (5 mm);5x5 Cluster Energy (GeV)",
0234 8, -.5, 7.5,
0235 8, -.5, 7.5,
0236 200, 1, 20);
0237
0238 T->Draw(sTOWER + ":7-hodo_v:hodo_h>>EnergySum_LG3", "", "goff");
0239
0240 TProfile2D * EnergySum_LG3_prof_xy = EnergySum_LG3->Project3DProfile("yx");
0241 TH2 * EnergySum_LG3_yx = EnergySum_LG3->Project3D("yx");
0242 TH2 * EnergySum_LG3_zx = EnergySum_LG3->Project3D("zx");
0243 TH2 * EnergySum_LG3_zy = EnergySum_LG3->Project3D("zy");
0244
0245 TGraphErrors * ge_EnergySum_LG3_zx = FitProfile(EnergySum_LG3_zx);
0246 TGraphErrors * ge_EnergySum_LG3_zy = FitProfile(EnergySum_LG3_zy);
0247
0248 TText * t;
0249 TCanvas *c1 = new TCanvas(
0250 TString(Form("EMCDistributionVSBeam_SUM_NDiv%d_", n_div)) + sTOWER + cuts,
0251 TString(Form("EMCDistributionVSBeam_SUM_NDiv%d_", n_div)) + sTOWER + cuts,
0252 1000, 960);
0253 c1->Divide(2, 2);
0254 int idx = 1;
0255 TPad * p;
0256
0257 p = (TPad *) c1->cd(idx++);
0258 c1->Update();
0259
0260 p->SetGridx(0);
0261 p->SetGridy(0);
0262
0263 EnergySum_LG3_prof_xy->SetMinimum(0);
0264
0265 EnergySum_LG3_prof_xy->Draw("colz");
0266 EnergySum_LG3_prof_xy->SetTitle(
0267 "Energy response;Horizontal Hodoscope (5 mm);7 - Vertical Hodoscope (5 mm)");
0268
0269 p = (TPad *) c1->cd(idx++);
0270 c1->Update();
0271
0272 p->SetGridx(0);
0273 p->SetGridy(0);
0274
0275 EnergySum_LG3_yx->SetMinimum(0);
0276 EnergySum_LG3_yx->Draw("colz");
0277 EnergySum_LG3_yx->SetTitle(
0278 "Event counts;Horizontal Hodoscope (5 mm);7 - Vertical Hodoscope (5 mm)");
0279
0280 p = (TPad *) c1->cd(idx++);
0281 c1->Update();
0282
0283 p->SetGridx(0);
0284 p->SetGridy(0);
0285
0286 EnergySum_LG3_zx->Draw("colz");
0287 EnergySum_LG3_zx->SetTitle(
0288 "Position scan;Horizontal Hodoscope (5 mm);5x5 Cluster Energy (GeV)");
0289
0290 ge_EnergySum_LG3_zx->SetLineWidth(2);
0291 ge_EnergySum_LG3_zx->SetMarkerStyle(kFullCircle);
0292 ge_EnergySum_LG3_zx->Draw("pe");
0293
0294 p = (TPad *) c1->cd(idx++);
0295 c1->Update();
0296
0297 p->SetGridx(0);
0298 p->SetGridy(0);
0299
0300 EnergySum_LG3_zy->Draw("colz");
0301 EnergySum_LG3_zy->SetTitle(
0302 "Position scan;7 - Vertical Hodoscope (5 mm);5x5 Cluster Energy (GeV)");
0303
0304 ge_EnergySum_LG3_zy->SetLineWidth(2);
0305 ge_EnergySum_LG3_zy->SetMarkerStyle(kFullCircle);
0306 ge_EnergySum_LG3_zy->Draw("pe");
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 SaveCanvas(c1,
0337 TString(_file0->GetName()) + TString("_DrawPrototype3ShowerCalib_")
0338 + TString(c1->GetName()), kTRUE);
0339 }
0340
0341 void
0342 PositionDependenceSim(TString sTOWER = "clus_5x5_prod.sum_E",
0343 const double z_shift = 0, const int n_div = 1)
0344 {
0345 TH3F * EnergySum_LG3 =
0346 new TH3F("EnergySum_LG3",
0347 ";Beam Horizontal Pos (cm);Beam Vertical Pos (cm);5x5 Cluster Energy (GeV)",
0348 20 * n_div, z_shift - 5, z_shift + 5,
0349 20 * n_div, -5, 5,
0350 200, 1, 20);
0351
0352 T->Draw(sTOWER + ":info.truth_y:info.truth_z>>EnergySum_LG3", "", "goff");
0353
0354 TProfile2D * EnergySum_LG3_xy = EnergySum_LG3->Project3DProfile("yx");
0355 TH2 * EnergySum_LG3_zx = EnergySum_LG3->Project3D("zx");
0356 TH2 * EnergySum_LG3_zy = EnergySum_LG3->Project3D("zy");
0357
0358 TGraphErrors * ge_EnergySum_LG3_zx = FitProfile(EnergySum_LG3_zx);
0359 TGraphErrors * ge_EnergySum_LG3_zy = FitProfile(EnergySum_LG3_zy);
0360
0361 TText * t;
0362 TCanvas *c1 = new TCanvas(
0363 TString(Form("EMCDistributionVSBeam_SUM_NDiv%d_", n_div)) + sTOWER + cuts,
0364 TString(Form("EMCDistributionVSBeam_SUM_NDiv%d_", n_div)) + sTOWER + cuts,
0365 1000, 960);
0366 c1->Divide(2, 2);
0367 int idx = 1;
0368 TPad * p;
0369
0370 p = (TPad *) c1->cd(idx++);
0371 c1->Update();
0372
0373 p->SetGridx(0);
0374 p->SetGridy(0);
0375
0376 EnergySum_LG3_xy->Draw("colz");
0377 EnergySum_LG3_xy->SetTitle(
0378 "Position scan;Beam Horizontal Pos (cm);Beam Vertical Pos (cm)");
0379
0380 p = (TPad *) c1->cd(idx++);
0381 c1->Update();
0382
0383 p->SetGridx(0);
0384 p->SetGridy(0);
0385
0386 EnergySum_LG3_zx->Draw("colz");
0387 EnergySum_LG3_zx->SetTitle(
0388 "Position scan;Beam Horizontal Pos (cm);5x5 Cluster Energy (GeV)");
0389
0390 ge_EnergySum_LG3_zx->SetLineWidth(2);
0391 ge_EnergySum_LG3_zx->SetMarkerStyle(kFullCircle);
0392 ge_EnergySum_LG3_zx->Draw("pe");
0393
0394 p = (TPad *) c1->cd(idx++);
0395 c1->Update();
0396
0397 p->SetGridx(0);
0398 p->SetGridy(0);
0399
0400 EnergySum_LG3_zy->Draw("colz");
0401 EnergySum_LG3_zy->SetTitle(
0402 "Position scan;Beam Vertical Pos (cm);5x5 Cluster Energy (GeV)");
0403
0404 ge_EnergySum_LG3_zy->SetLineWidth(2);
0405 ge_EnergySum_LG3_zy->SetMarkerStyle(kFullCircle);
0406 ge_EnergySum_LG3_zy->Draw("pe");
0407
0408 p = (TPad *) c1->cd(idx++);
0409 c1->Update();
0410
0411 p->SetGridx(0);
0412 p->SetGridy(0);
0413
0414 TH1 * h = (TH1 *) EnergySum_LG3->ProjectionZ();
0415
0416 TF1 * fgaus = new TF1("fgaus_LG", "gaus", 0, 100);
0417 fgaus->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0418 h->GetMean() + 2 * h->GetRMS());
0419 h->Fit(fgaus, "M");
0420
0421 h->Sumw2();
0422 h->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0423 h->GetMean() + 4 * h->GetRMS());
0424 EnergySum_LG3_zx->GetYaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0425 h->GetMean() + 4 * h->GetRMS());
0426 EnergySum_LG3_zy->GetYaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0427 h->GetMean() + 4 * h->GetRMS());
0428
0429 h->SetLineWidth(2);
0430 h->SetMarkerStyle(kFullCircle);
0431
0432 h->SetTitle(
0433 Form("#DeltaE/<E> = %.1f%%",
0434 100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0435
0436 SaveCanvas(c1,
0437 TString(_file0->GetName()) + TString("_DrawPrototype3ShowerCalib_")
0438 + TString(c1->GetName()), kTRUE);
0439 }
0440
0441 void
0442 LineShapeData(TCut c2_h = "abs(info.C2_sum)<100", TCut c2_e =
0443 "(info.C2_sum)>500 && (info.C2_sum)<1300")
0444 {
0445
0446 vector<double> mom;
0447
0448 TText * t;
0449 TCanvas *c1 = new TCanvas("LineShapeData" + cuts, "LineShapeData" + cuts,
0450 1800, 950);
0451
0452 c1->Divide(2, 2);
0453 int idx = 1;
0454 TPad * p;
0455
0456 p = (TPad *) c1->cd(idx++);
0457 c1->Update();
0458
0459
0460 p->SetLogy();
0461
0462 T->Draw("info.C2_sum>>h_c2_sum(300,-500,2500)");
0463 h_c2_sum->SetTitle("Cherenkov Checks;Sum C2 (ADC)");
0464 T->Draw("info.C2_sum>>h_c2_h(300,-500,2500)", c2_h, "same");
0465 T->Draw("info.C2_sum>>h_c2_e(300,-500,2500)", c2_e, "same");
0466
0467 h_c2_h->SetLineColor(kBlue);
0468 h_c2_e->SetLineColor(kRed);
0469
0470 h_c2_sum->SetLineWidth(2);
0471 h_c2_h->SetLineWidth(2);
0472 h_c2_e->SetLineWidth(2);
0473
0474 p = (TPad *) c1->cd(idx++);
0475 c1->Update();
0476 p->SetLogy();
0477
0478 T->Draw("clus_5x5_recalib.sum_E>>h_5x5sum_c2_sum(170,-1,16)");
0479 h_5x5sum_c2_sum->SetTitle(
0480 "Cluster spectrum decomposition;5x5 cluster energy (GeV)");
0481 T->Draw("clus_5x5_recalib.sum_E>>h_5x5sum_c2_h(170,-1,16)", c2_h, "same");
0482 T->Draw("clus_5x5_recalib.sum_E>>h_5x5sum_c2_rej_h(170,-1,16)", !c2_h,
0483 "same");
0484 T->Draw("clus_5x5_recalib.sum_E>>h_5x5sum_c2_e(170,-1,16)", c2_e, "same");
0485
0486 h_5x5sum_c2_h->SetLineColor(kBlue);
0487 h_5x5sum_c2_rej_h->SetLineColor(kMagenta);
0488 h_5x5sum_c2_e->SetLineColor(kRed);
0489
0490 h_5x5sum_c2_sum->SetLineWidth(2);
0491 h_5x5sum_c2_h->SetLineWidth(2);
0492 h_5x5sum_c2_rej_h->SetLineWidth(2);
0493 h_5x5sum_c2_e->SetLineWidth(2);
0494
0495 p = (TPad *) c1->cd(idx++);
0496 c1->Update();
0497 p->SetLogy();
0498
0499 TH1 * h_5x5sum_c2_h2 = h_5x5sum_c2_h->DrawClone();
0500 h_5x5sum_c2_h2->Sumw2();
0501 h_5x5sum_c2_h2->SetMarkerColor(kBlue);
0502 h_5x5sum_c2_h2->SetMarkerStyle(kFullCircle);
0503 h_5x5sum_c2_h2->SetTitle(";5x5 cluster energy (GeV)");
0504
0505 TH1 * h_5x5sum_c2_e2 = h_5x5sum_c2_e->DrawClone("same");
0506 h_5x5sum_c2_e2->Sumw2();
0507 h_5x5sum_c2_e2->SetMarkerColor(kRed);
0508 h_5x5sum_c2_e2->SetMarkerStyle(kFullCircle);
0509 h_5x5sum_c2_e2->SetTitle(";5x5 cluster energy (GeV)");
0510
0511 p = (TPad *) c1->cd(idx++);
0512 c1->Update();
0513 p->SetLogy();
0514
0515 TH1F * h_5x5sum_c2_h3 = h_5x5sum_c2_h->DrawClone();
0516 h_5x5sum_c2_h3->SetName("h_5x5sum_c2_h3");
0517 h_5x5sum_c2_h3->Sumw2();
0518 h_5x5sum_c2_h3->Scale(1. / h_5x5sum_c2_h3->GetSum());
0519 h_5x5sum_c2_h3->SetMarkerColor(kBlue);
0520 h_5x5sum_c2_h3->SetMarkerStyle(kFullCircle);
0521 h_5x5sum_c2_h3->SetTitle(";5x5 cluster energy (GeV);Probability / bin");
0522
0523 SaveCanvas(c1,
0524 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0525 + TString(c1->GetName()), kTRUE);
0526 }
0527
0528 void
0529 LineShapeSim()
0530 {
0531 vector<double> mom;
0532
0533 TText * t;
0534 TCanvas *c1 = new TCanvas("LineShapeSim" + cuts, "LineShapeSim" + cuts, 1000,
0535 650);
0536
0537
0538 int idx = 1;
0539 TPad * p;
0540
0541 p = (TPad *) c1->cd(idx++);
0542 c1->Update();
0543 p->SetLogy();
0544
0545 T->Draw("clus_5x5_prod.sum_E*SimEnergyScale>>h_5x5sum_c2_sum(170,-1,16)");
0546 h_5x5sum_c2_sum->SetTitle(
0547 "Cluster spectrum decomposition;5x5 cluster energy (GeV)");
0548 h_5x5sum_c2_sum->SetLineWidth(2);
0549
0550 SaveCanvas(c1,
0551 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0552 + TString(c1->GetName()), kTRUE);
0553
0554 }
0555
0556 void
0557 HodoscopeCheck()
0558 {
0559 vector<double> mom;
0560
0561 TText * t;
0562 TCanvas *c1 = new TCanvas("HodoscopeCheck" + cuts, "HodoscopeCheck" + cuts,
0563 1300, 950);
0564
0565 c1->Divide(2, 1);
0566 int idx = 1;
0567 TPad * p;
0568
0569 p = (TPad *) c1->cd(idx++);
0570 c1->Update();
0571 p->SetGridx(1);
0572 p->SetGridy(1);
0573 p->SetLogz();
0574
0575 T->Draw("clus_5x5_prod.average_col:hodo_h>>h2_h(8,-.5,7.5,160,-.5,7.5)",
0576 "good_e", "colz");
0577 h2_h->SetTitle(
0578 "Horizontal hodoscope check;Horizontal Hodoscope;5x5 cluster mean col");
0579
0580 p = (TPad *) c1->cd(idx++);
0581 c1->Update();
0582 p->SetGridx(1);
0583 p->SetGridy(1);
0584 p->SetLogz();
0585
0586 T->Draw("clus_5x5_prod.average_row:hodo_v>>h2_v(8,-.5,7.5,160,-.5,7.5)",
0587 "good_e", "colz");
0588 h2_v->SetTitle(
0589 "Vertical hodoscope check;Vertical Hodoscope;5x5 cluster mean row");
0590
0591 SaveCanvas(c1,
0592 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0593 + TString(c1->GetName()), kTRUE);
0594
0595 return mom;
0596 }
0597
0598 void
0599 SimPositionCheck(const double shift_z = 0)
0600 {
0601 vector<double> mom;
0602
0603 TText * t;
0604 TCanvas *c1 = new TCanvas("SimPositionCheck" + cuts,
0605 "SimPositionCheck" + cuts, 1300, 950);
0606
0607 c1->Divide(2, 1);
0608 int idx = 1;
0609 TPad * p;
0610
0611 p = (TPad *) c1->cd(idx++);
0612 c1->Update();
0613 p->SetGridx(1);
0614 p->SetGridy(1);
0615 p->SetLogz();
0616
0617 T->Draw(
0618 Form("clus_5x5_prod.average_col:truth_z>>h2_h(30,%f,%f,160,-.5,7.5)",
0619 shift_z - 1.5, shift_z + 1.5), "1", "colz");
0620 h2_h->SetTitle(
0621 "Horizontal hodoscope check;Horizontal beam pos;5x5 cluster mean col");
0622
0623 p = (TPad *) c1->cd(idx++);
0624 c1->Update();
0625 p->SetGridx(1);
0626 p->SetGridy(1);
0627 p->SetLogz();
0628
0629 T->Draw("clus_5x5_prod.average_row:truth_y>>h2_v(30,-1.5,1.5,160,-.5,7.5)",
0630 "1", "colz");
0631 h2_v->SetTitle(
0632 "Vertical hodoscope check;Vertical beam pos;5x5 cluster mean row");
0633
0634 SaveCanvas(c1,
0635 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0636 + TString(c1->GetName()), kTRUE);
0637
0638 return;
0639 }
0640
0641 void
0642 Get_Res_linear_Summmary(TString e_sum = "sum_E")
0643 {
0644
0645 vector<double> beam_mom(GetBeamMom());
0646
0647
0648
0649 lin_res ges_clus_5x5_prod = GetResolution("clus_5x5_prod", beam_mom, kBlue,e_sum);
0650
0651
0652
0653
0654
0655
0656
0657 TCanvas *c1 = new TCanvas(Form("Res_linear") + cuts,
0658 Form("Res_linear") + cuts, 1300, 600);
0659 c1->Divide(2, 1);
0660 int idx = 1;
0661 TPad * p;
0662
0663 p = (TPad *) c1->cd(idx++);
0664 c1->Update();
0665
0666
0667 TLegend* leg = new TLegend(.15, .7, .6, .85);
0668
0669 p->DrawFrame(0, 0, 25, 25,
0670 Form("Electron Linearity;Input energy (GeV);Measured Energy (GeV)"));
0671 TLine * l = new TLine(0, 0, 25, 25);
0672 l->SetLineColor(kGray);
0673
0674
0675 TF1 * f_calo_l_sim = new TF1("f_calo_l", "pol2", 0.5, 25);
0676
0677 f_calo_l_sim->SetParameters(-0., 1, -0.);
0678
0679 f_calo_l_sim->SetLineColor(kGreen + 2);
0680 f_calo_l_sim->SetLineWidth(3);
0681
0682 f_calo_l_sim->Draw("same");
0683 ges_clus_5x5_prod.linearity->Draw("p");
0684
0685
0686
0687
0688
0689
0690 leg->AddEntry(ges_clus_5x5_prod.linearity, ges_clus_5x5_prod.name, "ep");
0691
0692
0693
0694 leg->AddEntry(f_calo_l_sim, "Unity", "l");
0695 leg->Draw();
0696
0697 p = (TPad *) c1->cd(idx++);
0698 c1->Update();
0699
0700 p->SetGridx(0);
0701 p->SetGridy(0);
0702
0703 TF1 * f_calo_sim = new TF1("f_calo_sim", "sqrt([0]*[0]+[1]*[1]/x)/100", 0.5,
0704 25);
0705 f_calo_sim->SetParameters(3.7, 12.8);
0706 f_calo_sim->SetLineWidth(3);
0707 f_calo_sim->SetLineColor(kGreen + 2);
0708
0709 TH1 * hframe = p->DrawFrame(0, 0, 25, 0.2,
0710 Form("Resolution;Input energy (GeV);#DeltaE/<E>"));
0711
0712 TLegend* leg = new TLegend(.2, .6, .85, .9);
0713
0714 ges_clus_5x5_prod.f_res->Draw("same");
0715 ges_clus_5x5_prod.resolution->Draw("ep");
0716
0717
0718
0719
0720
0721
0722 f_calo_sim->Draw("same");
0723
0724 leg->AddEntry(ges_clus_5x5_prod.resolution, ges_clus_5x5_prod.name, "ep");
0725 leg->AddEntry(ges_clus_5x5_prod.f_res,
0726 Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
0727 ges_clus_5x5_prod.f_res->GetParameter(0),
0728 ges_clus_5x5_prod.f_res->GetParameter(1)), "l");
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750 leg->Draw();
0751
0752 TLegend* leg = new TLegend(.1, .15, .85, .25);
0753
0754 leg->AddEntry(f_calo_sim,
0755 Form(
0756 "#splitline{Simulation w/ flat light collection}{#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}}",
0757 f_calo_sim->GetParameter(0), f_calo_sim->GetParameter(1)), "l");
0758 leg->Draw();
0759
0760 hframe->SetTitle("Electron Resolution");
0761
0762 SaveCanvas(c1,
0763 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0764 + TString(c1->GetName()), kTRUE);
0765 }
0766
0767 void
0768 Get_Res_linear_Summmary_Sim()
0769 {
0770
0771 vector<double> beam_mom(GetBeamMom());
0772
0773
0774
0775 lin_res ges_clus_5x5_prod = GetResolution("clus_5x5_prod", beam_mom, kBlue,"sum_E");
0776 lin_res ges_clus_3x3_prod = GetResolution("clus_3x3_prod", beam_mom,
0777 kBlue + 3,"sum_E");
0778
0779 TCanvas *c1 = new TCanvas(Form("Res_linear") + cuts,
0780 Form("Res_linear") + cuts, 1300, 600);
0781 c1->Divide(2, 1);
0782 int idx = 1;
0783 TPad * p;
0784
0785 p = (TPad *) c1->cd(idx++);
0786 c1->Update();
0787
0788
0789 TLegend* leg = new TLegend(.15, .7, .6, .85);
0790
0791 p->DrawFrame(0, 0, 25, 25,
0792 Form("Electron Linearity;Input energy (GeV);Measured Energy (GeV)"));
0793 TLine * l = new TLine(0, 0, 25, 25);
0794 l->SetLineColor(kGray);
0795
0796
0797 TF1 * f_calo_l_sim = new TF1("f_calo_l", "pol2", 0.5, 25);
0798
0799 f_calo_l_sim->SetParameters(-0., 1, -0.);
0800
0801 f_calo_l_sim->SetLineColor(kGreen + 2);
0802 f_calo_l_sim->SetLineWidth(3);
0803
0804 f_calo_l_sim->Draw("same");
0805 ges_clus_5x5_prod.linearity->Draw("p");
0806 ges_clus_3x3_prod.linearity->Draw("p");
0807
0808
0809
0810 leg->AddEntry(ges_clus_5x5_prod.linearity, ges_clus_5x5_prod.name, "ep");
0811 leg->AddEntry(ges_clus_3x3_prod.linearity, ges_clus_3x3_prod.name, "ep");
0812 leg->AddEntry(f_calo_l_sim, "Unity", "l");
0813 leg->Draw();
0814
0815 p = (TPad *) c1->cd(idx++);
0816 c1->Update();
0817
0818 p->SetGridx(0);
0819 p->SetGridy(0);
0820
0821 TF1 * f_calo_sim = new TF1("f_calo_sim", "sqrt([0]*[0]+[1]*[1]/x)/100", 0.5,
0822 25);
0823 f_calo_sim->SetParameters(2.4, 11.8);
0824 f_calo_sim->SetLineWidth(3);
0825 f_calo_sim->SetLineColor(kGreen + 2);
0826
0827 TH1 * hframe = p->DrawFrame(0, 0, 25, 0.3,
0828 Form("Resolution;Input energy (GeV);#DeltaE/<E>"));
0829
0830 TLegend* leg = new TLegend(.2, .6, .85, .9);
0831
0832 ges_clus_5x5_prod.f_res->Draw("same");
0833 ges_clus_5x5_prod.resolution->Draw("ep");
0834 ges_clus_3x3_prod.f_res->Draw("same");
0835 ges_clus_3x3_prod.resolution->Draw("ep");
0836 f_calo_sim->Draw("same");
0837
0838 leg->AddEntry(ges_clus_5x5_prod.resolution, ges_clus_5x5_prod.name, "ep");
0839 leg->AddEntry(ges_clus_5x5_prod.f_res,
0840 Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
0841 ges_clus_5x5_prod.f_res->GetParameter(0),
0842 ges_clus_5x5_prod.f_res->GetParameter(1)), "l");
0843
0844 leg->AddEntry(ges_clus_3x3_prod.resolution, ges_clus_3x3_prod.name, "ep");
0845 leg->AddEntry(ges_clus_3x3_prod.f_res,
0846 Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
0847 ges_clus_3x3_prod.f_res->GetParameter(0),
0848 ges_clus_3x3_prod.f_res->GetParameter(1)), "l");
0849
0850
0851
0852
0853 leg->Draw();
0854
0855 TLegend* leg = new TLegend(.2, .1, .85, .3);
0856
0857 leg->AddEntry(f_calo_sim,
0858 Form("Prelim. Sim., #DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
0859 f_calo_sim->GetParameter(0), f_calo_sim->GetParameter(1)), "l");
0860 leg->Draw();
0861
0862 hframe->SetTitle("Electron Resolution");
0863
0864 SaveCanvas(c1,
0865 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0866 + TString(c1->GetName()), kTRUE);
0867 }
0868
0869 vector<double>
0870 GetBeamMom()
0871 {
0872 vector<double> mom;
0873
0874 TH1F * hbeam_mom = new TH1F("hbeam_mom", ";beam momentum (GeV)", 32, .5,
0875 32.5);
0876
0877 TText * t;
0878 TCanvas *c1 = new TCanvas("GetBeamMom" + cuts, "GetBeamMom" + cuts, 1800,
0879 900);
0880
0881 T->Draw("abs(info.beam_mom)>>hbeam_mom");
0882
0883 for (int bin = 1; bin < hbeam_mom->GetNbinsX(); bin++)
0884 {
0885 if (hbeam_mom->GetBinContent(bin) > 40)
0886 {
0887 const double momentum = hbeam_mom->GetBinCenter(bin);
0888
0889 if (momentum == 1 || momentum == 2 || momentum == 3 || momentum == 4
0890 || momentum == 6 || momentum == 8 || momentum == 12
0891 || momentum == 16 || momentum == 24 || momentum == 32)
0892 {
0893 mom.push_back(momentum);
0894
0895 cout << "GetBeamMom - " << momentum << " GeV for "
0896 << hbeam_mom->GetBinContent(bin) << " event" << endl;
0897 }
0898 }
0899 }
0900
0901 SaveCanvas(c1,
0902 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0903 + TString(c1->GetName()), kTRUE);
0904
0905 return mom;
0906 }
0907
0908 lin_res
0909 GetResolution(TString cluster_name, vector<double> beam_mom, Color_t col,TString e_sum = "sum_E")
0910 {
0911 vector<double> mean;
0912 vector<double> mean_err;
0913 vector<double> res;
0914 vector<double> res_err;
0915
0916 TCanvas *c1 = new TCanvas("GetResolution_LineShape_" + cluster_name + cuts,
0917 "GetResolution_LineShape_" + cluster_name + cuts, 1800, 900);
0918
0919 c1->Divide(4, 2);
0920 int idx = 1;
0921 TPad * p;
0922
0923 for (int i = 0; i < beam_mom.size(); ++i)
0924 {
0925 p = (TPad *) c1->cd(idx++);
0926 c1->Update();
0927
0928 const double momemtum = beam_mom[i];
0929 const TString histname = Form("hLineShape%.0fGeV_", momemtum)
0930 + cluster_name;
0931
0932 TH1F * h = new TH1F(histname, histname + ";Observed energy (GeV)",
0933 (momemtum <= 8 ? 25 : 50), momemtum / 2, momemtum * 1.5);
0934 T->Draw(cluster_name + "."+e_sum+">>" + histname,
0935 Form("abs(abs(info.beam_mom)-%f)/%f<.06", momemtum, momemtum));
0936
0937 h->Sumw2();
0938
0939 TF1 * fgaus_g = new TF1("fgaus_LG_g_" + cluster_name, "gaus",
0940 h->GetMean() - 1 * h->GetRMS(), h->GetMean() + 4 * h->GetRMS());
0941 fgaus_g->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0942 h->GetMean() + 2 * h->GetRMS());
0943 h->Fit(fgaus_g, "MR0N");
0944
0945 TF1 * fgaus = new TF1("fgaus_LG_" + cluster_name, "gaus",
0946 fgaus_g->GetParameter(1) - 3 * fgaus_g->GetParameter(2),
0947 fgaus_g->GetParameter(1) + 3 * fgaus_g->GetParameter(2));
0948 fgaus->SetParameters(fgaus_g->GetParameter(0), fgaus_g->GetParameter(1),
0949 fgaus_g->GetParameter(2));
0950 h->Fit(fgaus, "MR");
0951
0952 h->SetLineWidth(2);
0953 h->SetMarkerStyle(kFullCircle);
0954 fgaus->SetLineWidth(2);
0955
0956 h->SetTitle(
0957 Form("%.0f GeV/c: #DeltaE/<E> = %.1f%%", momemtum,
0958 100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0959
0960 mean.push_back(fgaus->GetParameter(1));
0961 mean_err.push_back(fgaus->GetParError(1));
0962 res.push_back(fgaus->GetParameter(2) / fgaus->GetParameter(1));
0963 res_err.push_back(fgaus->GetParError(2) / fgaus->GetParameter(1));
0964
0965 }
0966
0967 SaveCanvas(c1,
0968 TString(_file0->GetName()) + "_DrawPrototype3ShowerCalib_"
0969 + TString(c1->GetName()), kTRUE);
0970
0971 TGraphErrors * ge_linear = new TGraphErrors(beam_mom.size(), &beam_mom[0],
0972 &mean[0], 0, &mean_err[0]);
0973
0974 TGraphErrors * ge_res = new TGraphErrors(beam_mom.size(), &beam_mom[0],
0975 &res[0], 0, &res_err[0]);
0976 ge_res->GetHistogram()->SetStats(0);
0977 ge_res->Print();
0978
0979 lin_res ret;
0980 ret.name = cluster_name;
0981 ret.linearity = ge_linear;
0982 ret.resolution = ge_res;
0983 ret.f_res = new TF1("f_calo_r_" + cluster_name, "sqrt([0]*[0]+[1]*[1]/x)/100",
0984 0.5, 25);
0985 ge_res->Fit(ret.f_res, "RM0QN");
0986
0987 ge_linear->SetLineColor(col);
0988 ge_linear->SetMarkerColor(col);
0989 ge_linear->SetLineWidth(2);
0990 ge_linear->SetMarkerStyle(kFullCircle);
0991 ge_linear->SetMarkerSize(1.5);
0992
0993 ge_res->SetLineColor(col);
0994 ge_res->SetMarkerColor(col);
0995 ge_res->SetLineWidth(2);
0996 ge_res->SetMarkerStyle(kFullCircle);
0997 ge_res->SetMarkerSize(1.5);
0998
0999 ge_res->GetHistogram()->SetStats(0);
1000
1001 ret.f_res->SetLineColor(col);
1002 ret.f_res->SetLineWidth(3);
1003
1004 return ret;
1005 }
1006
1007 TGraphErrors *
1008 FitProfile(const TH2 * h2)
1009 {
1010
1011 TProfile * p2 = h2->ProfileX();
1012
1013 int n = 0;
1014 double x[1000];
1015 double ex[1000];
1016 double y[1000];
1017 double ey[1000];
1018
1019 for (int i = 1; i <= h2->GetNbinsX(); i++)
1020 {
1021 TH1D * h1 = h2->ProjectionY(Form("htmp_%d", rand()), i, i);
1022
1023 if (h1->GetSum() < 30)
1024 {
1025 cout << "FitProfile - ignore bin " << i << endl;
1026 continue;
1027 }
1028 else
1029 {
1030 cout << "FitProfile - fit bin " << i << endl;
1031 }
1032
1033 TF1 fgaus("fgaus", "gaus", -p2->GetBinError(i) * 4,
1034 p2->GetBinError(i) * 4);
1035
1036 TF1 f2(Form("dgaus"), "gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
1037 -p2->GetBinError(i) * 4, p2->GetBinError(i) * 4);
1038
1039 fgaus.SetParameter(1, p2->GetBinContent(i));
1040 fgaus.SetParameter(2, p2->GetBinError(i));
1041
1042 h1->Fit(&fgaus, "MQ");
1043
1044 f2.SetParameters(fgaus.GetParameter(0) / 2, fgaus.GetParameter(1),
1045 fgaus.GetParameter(2), fgaus.GetParameter(0) / 2,
1046 fgaus.GetParameter(2) / 4, 0);
1047
1048 h1->Fit(&f2, "MQ");
1049
1050
1051
1052
1053
1054
1055 x[n] = p2->GetBinCenter(i);
1056 ex[n] = (p2->GetBinCenter(2) - p2->GetBinCenter(1)) / 2;
1057 y[n] = fgaus.GetParameter(1);
1058 ey[n] = fgaus.GetParError(1);
1059
1060
1061
1062
1063 n++;
1064 delete h1;
1065 }
1066
1067 return new TGraphErrors(n, x, y, ex, ey);
1068 }
1069