File indexing completed on 2025-08-05 08:14:34
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 using namespace std;
0021
0022
0023
0024 TFile * _file0 = NULL;
0025 TTree * T = NULL;
0026 TString cuts = "";
0027
0028 double beam_momentum_selection = 120;
0029
0030 void
0031 DrawPrototype2MIPAnalysis(
0032 const TString infile =
0033 "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2016/Production_1101_EMCalSet2_HCalPR12/beam_00002187-0000_DSTReader.root",
0034 bool plot_all = false, const double momentum = 120)
0035 {
0036 beam_momentum_selection = momentum;
0037 gROOT->SetStyle("Modern");
0038
0039
0040
0041 gStyle->SetOptStat(0);
0042 gStyle->SetOptFit(1111);
0043 TVirtualFitter::SetDefaultFitter("Minuit2");
0044 gSystem->Load("libg4eval.so");
0045 gSystem->Load("libqa_modules.so");
0046 gSystem->Load("libPrototype2.so");
0047
0048
0049
0050 if (!_file0)
0051 {
0052 TString chian_str = infile;
0053 chian_str.ReplaceAll("ALL", "*");
0054
0055 TChain * t = new TChain("T");
0056 const int n = t->Add(chian_str);
0057
0058 cout << "Loaded " << n << " root files with " << chian_str << endl;
0059 assert(n > 0);
0060
0061 T = t;
0062
0063 _file0 = new TFile;
0064 _file0->SetName(infile);
0065 }
0066
0067 assert(_file0);
0068
0069 T->SetAlias("ActiveTower_LG",
0070 "TOWER_LG_CEMC[].get_binphi()<8 && TOWER_LG_CEMC[].get_bineta()<8");
0071 T->SetAlias("EnergySum_LG",
0072 "1*Sum$(TOWER_LG_CEMC[].get_energy() * ActiveTower_LG)");
0073
0074 T->SetAlias("ActiveTower_HG",
0075 "TOWER_HG_CEMC[].get_binphi()<8 && TOWER_HG_CEMC[].get_bineta()<8");
0076 T->SetAlias("EnergySum_HG",
0077 "1*Sum$(TOWER_HG_CEMC[].get_energy() * ActiveTower_HG)");
0078
0079
0080 T->SetAlias("C2_Inner_e", "1*abs(TOWER_RAW_C2[2].energy)");
0081 T->SetAlias("C2_Outer_e", "1*abs(TOWER_RAW_C2[3].energy)");
0082 T->SetAlias("C2_Sum_e", "C2_Inner_e + C2_Outer_e");
0083
0084
0085
0086 T->SetAlias("Average_column",
0087 "Sum$(TOWER_CALIB_CEMC.get_column() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
0088 T->SetAlias("Average_row",
0089 "Sum$(TOWER_CALIB_CEMC.get_row() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
0090
0091 T->SetAlias("Average_HODO_VERTICAL",
0092 "Sum$(TOWER_CALIB_HODO_VERTICAL.towerid * (abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))/Sum$((abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))");
0093
0094
0095
0096 T->SetAlias("Valid_HODO_VERTICAL",
0097 "Sum$(abs(TOWER_CALIB_HODO_VERTICAL.energy)>30 && TOWER_CALIB_HODO_VERTICAL.towerid==3 ) ");
0098
0099
0100 T->SetAlias("Average_HODO_HORIZONTAL",
0101 "Sum$(TOWER_CALIB_HODO_HORIZONTAL.towerid * (abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))/Sum$((abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))");
0102
0103
0104 T->SetAlias("Valid_HODO_HORIZONTAL",
0105 "Sum$(abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30)==1");
0106
0107 T->SetAlias("No_Triger_VETO",
0108 "Sum$(abs(TOWER_RAW_TRIGGER_VETO.energy)>15)==0");
0109
0110 T->SetAlias("Energy_Sum_col1_row2_3x3",
0111 "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-1)<=1 && abs(TOWER_CALIB_CEMC.get_row()-2)<=1 ) * TOWER_CALIB_CEMC.get_energy())");
0112 T->SetAlias("Energy_Sum_col1_row2_5x5",
0113 "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-1)<=2 && abs(TOWER_CALIB_CEMC.get_row()-2)<=2 ) * TOWER_CALIB_CEMC.get_energy())");
0114 T->SetAlias("Energy_Sum_col2_row2_5x5",
0115 "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-2)<=2 && abs(TOWER_CALIB_CEMC.get_row()-2)<=2 ) * TOWER_CALIB_CEMC.get_energy())");
0116 T->SetAlias("Energy_Sum_CEMC", "1*Sum$(TOWER_CALIB_CEMC.get_energy())");
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 T->SetAlias("Energy_Sum_Hadron_CEMC",
0128 "1.14*12./8.71776e+00*Sum$(TOWER_CALIB_CEMC.get_energy())");
0129
0130
0131 T->SetAlias("CEMC_MIP", "Energy_Sum_Hadron_CEMC<0.7");
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 T->SetAlias("Energy_Sum_Hadron_HCALIN",
0147 "12./6.99727e+00*Sum$(TOWER_CALIB_LG_HCALIN.get_energy())");
0148 T->SetAlias("HCALIN_MIP", "Energy_Sum_Hadron_HCALIN<0.5");
0149 T->SetAlias("Energy_Sum_Hadron_HCALOUT",
0150 "12./9.50430e+00*Sum$(TOWER_CALIB_LG_HCALOUT.get_energy())");
0151
0152 T->SetAlias("MIP_Count_Col2",
0153 "Sum$( abs( TOWER_RAW_CEMC.get_energy() )>20 && abs( TOWER_RAW_CEMC.get_energy() )<400 && TOWER_CALIB_CEMC.get_column() == 2)");
0154
0155 T->SetAlias("Pedestal_Count_AllCEMC",
0156 "Sum$( abs( TOWER_RAW_CEMC.get_energy() )<20 && TOWER_CALIB_CEMC.get_column() != 2)");
0157 T->SetAlias("TowerTimingGood_Count_AllCEMC",
0158 "Sum$( abs( TOWER_RAW_CEMC.get_time() )>6 && abs( TOWER_RAW_CEMC.get_time() )<13 && TOWER_CALIB_CEMC.get_column() == 2)");
0159
0160
0161 TCut event_sel = "1*1";
0162
0163 if (plot_all)
0164 {
0165
0166
0167
0168
0169 event_sel =
0170 "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO";
0171 cuts = "_Valid_HODO_Trigger_VETO";
0172 }
0173 else
0174 {
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 event_sel =
0189 "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO && (Pedestal_Count_AllCEMC >= 64 -8) && (TowerTimingGood_Count_AllCEMC == 8)";
0190 cuts = "_Valid_HODO_MIP_Col2_PedestalOther_TimingGood";
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218 }
0219
0220 cout << "Build event selection of " << (const char *) event_sel << endl;
0221
0222 T->Draw(">>EventList", event_sel);
0223 TEventList * elist = gDirectory->GetObjectChecked("EventList", "TEventList");
0224 cout << elist->GetN() << " / " << T->GetEntriesFast() << " events selected"
0225 << endl;
0226
0227 T->SetEventList(elist);
0228
0229
0230
0231
0232
0233
0234
0235 int rnd = rand();
0236 gDirectory->mkdir(Form("dir_%d", rnd));
0237 gDirectory->cd(Form("dir_%d", rnd));
0238
0239 EMCDistribution_Fast("RAW");
0240
0241 int rnd = rand();
0242 gDirectory->mkdir(Form("dir_%d", rnd));
0243 gDirectory->cd(Form("dir_%d", rnd));
0244
0245 EMCDistribution_PeakSample_Fast();
0246
0247 int rnd = rand();
0248 gDirectory->mkdir(Form("dir_%d", rnd));
0249 gDirectory->cd(Form("dir_%d", rnd));
0250 if (plot_all)
0251 EMCDistribution_Fast("CALIB", true);
0252
0253 int rnd = rand();
0254 gDirectory->mkdir(Form("dir_%d", rnd));
0255 gDirectory->cd(Form("dir_%d", rnd));
0256 if (plot_all)
0257 EMCDistribution_ADC();
0258
0259
0260
0261
0262
0263
0264 }
0265
0266 void
0267 EMCDistribution_Fast(TString gain = "CALIB", bool full_gain = false)
0268 {
0269 TString hname = "EMCDistribution_" + gain
0270 + TString(full_gain ? "_FullGain" : "") + cuts;
0271
0272 TH2 * h2 = NULL;
0273 if (gain.Contains("CALIB"))
0274 {
0275 if (full_gain)
0276 {
0277 h2 = new TH2F(hname,
0278 Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 100, .05,
0279 25, 64, -.5, 63.5);
0280 QAHistManagerDef::useLogBins(h2->GetXaxis());
0281 }
0282 else
0283 {
0284 h2 = new TH2F(hname,
0285 Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 260, -.2,
0286 5, 64, -.5, 63.5);
0287 }
0288 T->Draw(
0289 "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain
0290 + "_CEMC[].get_binphi():TOWER_" + gain + "_CEMC[].get_energy()>>"
0291 + hname, "", "goff");
0292 }
0293 else if (gain.Contains("RAW"))
0294 {
0295 if (full_gain)
0296 {
0297 h2 = new TH2F(hname,
0298 Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100,
0299 .05 * 100, 25 * 100, 64, -.5, 63.5);
0300 QAHistManagerDef::useLogBins(h2->GetXaxis());
0301 }
0302 else
0303 {
0304 h2 = new TH2F(hname,
0305 Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260,
0306 -.2 * 100, 5 * 100, 64, -.5, 63.5);
0307 }
0308 T->Draw(
0309 "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain
0310 + "_CEMC[].get_binphi():TOWER_" + gain
0311 + "_CEMC[].get_energy()*(-1)>>" + hname, "", "goff");
0312 }
0313
0314 TText * t;
0315 TCanvas *c1 = new TCanvas(
0316 "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts,
0317 "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts,
0318 1800, 950);
0319 c1->Divide(8, 8, 0., 0.01);
0320 int idx = 1;
0321 TPad * p;
0322
0323 for (int iphi = 8 - 1; iphi >= 0; iphi--)
0324 {
0325 for (int ieta = 0; ieta < 8; ieta++)
0326 {
0327 p = (TPad *) c1->cd(idx++);
0328 c1->Update();
0329
0330 p->SetLogy();
0331 if (full_gain)
0332 {
0333 p->SetLogx();
0334 }
0335 p->SetGridx(0);
0336 p->SetGridy(0);
0337
0338 TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi)
0339 + TString(full_gain ? "_FullGain" : "");
0340
0341 TH1 * h = h2->ProjectionX(hname, ieta + 8 * iphi + 1,
0342 ieta + 8 * iphi + 1);
0343
0344 h->SetLineWidth(0);
0345 h->SetLineColor(kBlue + 3);
0346 h->SetFillColor(kBlue + 3);
0347
0348 h->GetXaxis()->SetTitleSize(.09);
0349 h->GetXaxis()->SetLabelSize(.08);
0350 h->GetYaxis()->SetLabelSize(.08);
0351
0352 h->Draw();
0353
0354 if (full_gain)
0355 h->Fit("x*gaus", "M");
0356 else
0357 h->Fit("landau", "M");
0358
0359 double peak = -1;
0360
0361 TF1 * fit = ((TF1 *) (h->GetListOfFunctions()->At(0)));
0362 if (fit)
0363 {
0364
0365 fit->SetLineColor(kRed);
0366 peak = fit->GetParameter(1);
0367
0368 }
0369
0370 cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak)
0371 << endl;
0372
0373 TText *t = new TText(.9, .9,
0374 Form("<Col%d Row%d> = %.1f", ieta, iphi, peak));
0375 t->SetTextAlign(33);
0376 t->SetTextSize(.15);
0377 t->SetNDC();
0378 t->Draw();
0379 }
0380 }
0381
0382 SaveCanvas(c1,
0383 TString(_file0->GetName()) + TString("_DrawPrototype2MIPAnalysis_")
0384 + TString(c1->GetName()), false);
0385
0386 }
0387
0388 void
0389 EMCDistribution_PeakSample_Fast(bool full_gain = false)
0390 {
0391
0392 const TString gain = "RAW";
0393
0394 TString hname = "EMCDistribution_" + gain
0395 + TString(full_gain ? "_FullGain" : "") + cuts;
0396
0397 TH2 * h2 = NULL;
0398 {
0399 if (full_gain)
0400 {
0401 h2 = new TH2F(hname,
0402 Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100,
0403 .05 * 100, 25 * 100, 64, -.5, 63.5);
0404 QAHistManagerDef::useLogBins(h2->GetXaxis());
0405 }
0406 else
0407 {
0408 h2 = new TH2F(hname,
0409 Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260,
0410 -.2 * 100, 5 * 100, 64, -.5, 63.5);
0411 }
0412 T->Draw(
0413 "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain
0414 + "_CEMC[].get_binphi():(TOWER_RAW_CEMC[].signal_samples[10] - TOWER_RAW_CEMC[].signal_samples[0])*(-1)>>"
0415 + hname, "", "goff");
0416 }
0417
0418 TText * t;
0419 TCanvas *c1 = new TCanvas(
0420 "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "")
0421 + cuts,
0422 "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "")
0423 + cuts, 1800, 950);
0424 c1->Divide(8, 8, 0., 0.01);
0425 int idx = 1;
0426 TPad * p;
0427
0428 for (int iphi = 8 - 1; iphi >= 0; iphi--)
0429 {
0430 for (int ieta = 0; ieta < 8; ieta++)
0431 {
0432 p = (TPad *) c1->cd(idx++);
0433 c1->Update();
0434
0435 p->SetLogy();
0436 if (full_gain)
0437 {
0438 p->SetLogx();
0439 }
0440 p->SetGridx(0);
0441 p->SetGridy(0);
0442
0443 TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi)
0444 + TString(full_gain ? "_FullGain" : "");
0445
0446 TH1 * h = h2->ProjectionX(hname, ieta + 8 * iphi + 1,
0447 ieta + 8 * iphi + 1);
0448
0449 h->SetLineWidth(0);
0450 h->SetLineColor(kBlue + 3);
0451 h->SetFillColor(kBlue + 3);
0452
0453 h->GetXaxis()->SetTitleSize(.09);
0454 h->GetXaxis()->SetLabelSize(.08);
0455 h->GetYaxis()->SetLabelSize(.08);
0456
0457 h->Draw();
0458
0459 if (full_gain)
0460 h->Fit("x*gaus", "M");
0461 else
0462 h->Fit("landau", "M");
0463
0464 double peak = -1;
0465
0466 TF1 * fit = ((TF1 *) (h->GetListOfFunctions()->At(0)));
0467 if (fit)
0468 {
0469
0470 fit->SetLineColor(kRed);
0471 peak = fit->GetParameter(1);
0472
0473 }
0474
0475 cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak)
0476 << endl;
0477
0478 TText *t = new TText(.9, .9,
0479 Form("<Col%d Row%d> = %.1f", ieta, iphi, peak));
0480 t->SetTextAlign(33);
0481 t->SetTextSize(.15);
0482 t->SetNDC();
0483 t->Draw();
0484 }
0485 }
0486
0487 SaveCanvas(c1,
0488 TString(_file0->GetName()) + TString("_DrawPrototype2MIPAnalysis_")
0489 + TString(c1->GetName()), false);
0490
0491 }
0492
0493 void
0494 EMCDistribution_ADC(bool log_scale = true)
0495 {
0496 TString gain = "RAW";
0497
0498 TText * t;
0499 TCanvas *c1 = new TCanvas(
0500 "EMCDistribution_ADC_" + gain + TString(log_scale ? "_Log" : "") + cuts,
0501 "EMCDistribution_ADC_" + gain + TString(log_scale ? "_Log" : "") + cuts,
0502 1800, 1000);
0503 c1->Divide(8, 8, 0., 0.01);
0504 int idx = 1;
0505 TPad * p;
0506
0507 for (int iphi = 8 - 1; iphi >= 0; iphi--)
0508 {
0509 for (int ieta = 0; ieta < 8; ieta++)
0510 {
0511 p = (TPad *) c1->cd(idx++);
0512 c1->Update();
0513
0514 if (log_scale)
0515 {
0516 p->SetLogz();
0517 }
0518 p->SetGridx(0);
0519 p->SetGridy(0);
0520
0521 TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi)
0522 + TString(log_scale ? "_Log" : "");
0523
0524 TH1 * h = NULL;
0525
0526 if (log_scale)
0527 h = new TH2F(hname,
0528 Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 24, -.5,
0529 23.5,
0530
0531 550, 1500, 2050);
0532
0533
0534
0535
0536
0537 h->SetLineWidth(0);
0538 h->SetLineColor(kBlue + 3);
0539 h->SetFillColor(kBlue + 3);
0540 h->GetXaxis()->SetTitleSize(.09);
0541 h->GetXaxis()->SetLabelSize(.08);
0542 h->GetYaxis()->SetLabelSize(.08);
0543
0544
0545
0546
0547 TString sdraw = "TOWER_" + gain
0548 + "_CEMC[].signal_samples[]:fmod(Iteration$,24)>>" + hname;
0549 TString scut =
0550 Form(
0551 "TOWER_%s_CEMC[].get_bineta()==%d && TOWER_%s_CEMC[].get_binphi()==%d",
0552 gain.Data(), ieta, gain.Data(), iphi);
0553
0554 cout << "T->Draw(\"" << sdraw << "\",\"" << scut << "\");" << endl;
0555
0556 T->Draw(sdraw, scut, "colz");
0557
0558 TText *t = new TText(.9, .9, Form("Col%d Row%d", ieta, iphi));
0559 t->SetTextAlign(33);
0560 t->SetTextSize(.15);
0561 t->SetNDC();
0562 t->Draw();
0563
0564
0565 }
0566 }
0567
0568 SaveCanvas(c1,
0569 TString(_file0->GetName()) + TString("_DrawPrototype2MIPAnalysis_")
0570 + TString(c1->GetName()), false);
0571
0572 }
0573