24 gROOT->SetBatch(kTRUE);
30 TFile *
f_1 =
new TFile(
"/sphenix/user/gregtom3/data/Summer2018/track2cluster_studies/e1DIS.root");
31 TTree *t_truth_1 = (TTree*)f_1->Get(
"event_truth");
32 TTree *t_cluster_1 = (TTree*)f_1->Get(
"event_cluster");
34 TFile *f_2 =
new TFile(
"/sphenix/user/gregtom3/data/Summer2018/track2cluster_studies/e2DIS.root");
35 TTree *t_truth_2 = (TTree*)f_2->Get(
"event_truth");
36 TTree *t_cluster_2 = (TTree*)f_2->Get(
"event_cluster");
38 TFile *f_5 =
new TFile(
"/sphenix/user/gregtom3/data/Summer2018/track2cluster_studies/e5DIS.root");
39 TTree *t_truth_5 = (TTree*)f_5->Get(
"event_truth");
40 TTree *t_cluster_5 = (TTree*)f_5->Get(
"event_cluster");
42 TFile *f_10 =
new TFile(
"/sphenix/user/gregtom3/data/Summer2018/track2cluster_studies/e10DIS.root");
43 TTree *t_truth_10 = (TTree*)f_10->Get(
"event_truth");
44 TTree *t_cluster_10 = (TTree*)f_10->Get(
"event_cluster");
54 const int nbins = 200;
55 TH2F *h2_phi_base =
new TH2F(
"",
"",nbins,-3.5,3.5,nbins,-3.5,3.5);
56 TH2F *h2_eta_base =
new TH2F(
"",
"",nbins,-10,10,nbins,-10,10);
57 TH2F *h2_theta_base =
new TH2F(
"",
"",nbins,-3.5,3.5,nbins,-3.5,3.5);
58 TH2F *h2_mom_base =
new TH2F(
"",
"",nbins,0,35,nbins,0,35);
59 TH2F *h2_posx_base =
new TH2F(
"",
"",nbins,-320,320,nbins,-320,320);
60 TH2F *h2_posy_base =
new TH2F(
"",
"",nbins,-320,320,nbins,-320,320);
61 TH2F *h2_posz_base =
new TH2F(
"",
"",nbins,-320,320,nbins,-320,320);
62 TH1F *h1_spatial_base =
new TH1F(
"",
"",nbins,0,30);
66 TH2F *h2_phi = (TH2F*)h2_phi_base->Clone();
67 TH2F *h2_eta = (TH2F*)h2_eta_base->Clone();
68 TH2F *h2_theta = (TH2F*)h2_theta_base->Clone();
69 TH2F *h2_mom = (TH2F*)h2_mom_base->Clone();
70 TH2F *h2_posx = (TH2F*)h2_posx_base->Clone();
71 TH2F *h2_posy = (TH2F*)h2_posy_base->Clone();
72 TH2F *h2_posz = (TH2F*)h2_posz_base->Clone();
73 TH1F *h1_spatial_cemc = (TH1F*)h1_spatial_base->Clone();
74 TH1F *h1_spatial_eemc = (TH1F*)h1_spatial_base->Clone();
75 TH1F *h1_spatial_femc = (TH1F*)h1_spatial_base->Clone();
76 h1_spatial_cemc->SetLineColor(kRed);
77 h1_spatial_eemc->SetLineColor(kBlue);
78 h1_spatial_femc->SetLineColor(kGreen);
82 std::vector<int> iter_p;
95 analyzeTree(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,t_truth_1,t_cluster_1,nEvents);
96 printHists(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,
"1GeV_electron.png");
98 analyzeTree(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,t_truth_2,t_cluster_2,nEvents);
99 printHists(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,
"2GeV_electron.png");
101 analyzeTree(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,t_truth_5,t_cluster_5,nEvents);
102 printHists(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,
"5GeV_electron.png");
104 analyzeTree(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,t_truth_10,t_cluster_10,nEvents);
105 printHists(h2_phi,h2_eta,h2_theta,h2_mom,h2_posx,h2_posy,h2_posz,h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,
"10GeV_electron.png");
108 void printHists(TH2F *h2_phi, TH2F* h2_eta, TH2F* h2_theta, TH2F* h2_mom, TH2F* h2_posx, TH2F* h2_posy, TH2F* h2_posz, TH1F* h1_spatial_cemc, TH1F *h1_spatial_eemc, TH1F* h1_spatial_femc,TString
save)
110 hist_to_png(h2_phi,TString(TString(
"phi_")+save),
"phi");
111 hist_to_png(h2_eta,TString(TString(
"eta_")+save),
"eta");
112 hist_to_png(h2_theta,TString(TString(
"theta_")+save),
"theta");
113 hist_to_png(h2_mom,TString(TString(
"mom_")+save),
"mom");
114 hist_to_png(h2_posx,TString(TString(
"posx_")+save),
"posx");
115 hist_to_png(h2_posy,TString(TString(
"posy_")+save),
"posy");
116 hist_to_png(h2_posz,TString(TString(
"posz_")+save),
"posz");
117 hist_to_png_h1(h1_spatial_cemc,h1_spatial_eemc,h1_spatial_femc,TString(TString(
"spatial_")+save),
"spatial");
119 void analyzeTree(TH2F *h2_phi, TH2F* h2_eta, TH2F* h2_theta, TH2F* h2_mom, TH2F* h2_posx, TH2F* h2_posy, TH2F* h2_posz, TH1F* h1_spatial_cemc, TH1F* h1_spatial_eemc, TH1F* h1_spatial_femc, TTree* t_truth, TTree* t_cluster,
const int nEvents)
128 h1_spatial_cemc->Reset();
129 h1_spatial_eemc->Reset();
130 h1_spatial_femc->Reset();
135 std::vector<float> track_phi; std::vector<float> cluster_phi;
136 std::vector<float> track_eta; std::vector<float> cluster_eta;
137 std::vector<float> track_theta; std::vector<float> cluster_theta;
138 std::vector<float> track_p; std::vector<float> cluster_p;
139 std::vector<float> track_posx; std::vector<float> cluster_posx;
140 std::vector<float> track_posy; std::vector<float> cluster_posy;
141 std::vector<float> track_posz; std::vector<float> cluster_posz;
143 std::vector<float> truth_phi; std::vector<float> truth_eta;
144 std::vector<float> truth_theta; std::vector<float> truth_p;
149 std::vector<float>* track_phi_pointer = &track_phi;
150 std::vector<float>* track_eta_pointer = &track_eta;
151 std::vector<float>* track_theta_pointer = &track_theta;
152 std::vector<float>* track_p_pointer = &track_p;
153 std::vector<float>* track_posx_pointer = &track_posx;
154 std::vector<float>* track_posy_pointer = &track_posy;
155 std::vector<float>* track_posz_pointer = &track_posz;
157 std::vector<float>* cluster_phi_pointer = &cluster_phi;
158 std::vector<float>* cluster_eta_pointer = &cluster_eta;
159 std::vector<float>* cluster_theta_pointer = &cluster_theta;
160 std::vector<float>* cluster_p_pointer = &cluster_p;
161 std::vector<float>* cluster_posx_pointer = &cluster_posx;
162 std::vector<float>* cluster_posy_pointer = &cluster_posy;
163 std::vector<float>* cluster_posz_pointer = &cluster_posz;
165 std::vector<float>* truth_phi_pointer = &truth_phi;
166 std::vector<float>* truth_eta_pointer = &truth_eta;
167 std::vector<float>* truth_theta_pointer = &truth_theta;
168 std::vector<float>* truth_p_pointer = &truth_p;
173 t_cluster->SetBranchAddress(
"em_track_phi2cluster",&track_phi_pointer);
174 t_cluster->SetBranchAddress(
"em_track_eta2cluster",&track_eta_pointer);
175 t_cluster->SetBranchAddress(
"em_track_theta2cluster",&track_theta_pointer);
176 t_cluster->SetBranchAddress(
"em_track_ptotal",&track_p_pointer);
177 t_cluster->SetBranchAddress(
"em_track_x2cluster",&track_posx_pointer);
178 t_cluster->SetBranchAddress(
"em_track_y2cluster",&track_posy_pointer);
179 t_cluster->SetBranchAddress(
"em_track_z2cluster",&track_posz_pointer);
181 t_cluster->SetBranchAddress(
"em_cluster_phi",&cluster_phi_pointer);
182 t_cluster->SetBranchAddress(
"em_cluster_eta",&cluster_eta_pointer);
183 t_cluster->SetBranchAddress(
"em_cluster_theta",&cluster_theta_pointer);
184 t_cluster->SetBranchAddress(
"em_cluster_e",&cluster_p_pointer);
185 t_cluster->SetBranchAddress(
"em_cluster_posx",&cluster_posx_pointer);
186 t_cluster->SetBranchAddress(
"em_cluster_posy",&cluster_posy_pointer);
187 t_cluster->SetBranchAddress(
"em_cluster_posz",&cluster_posz_pointer);
189 t_truth->SetBranchAddress(
"em_evtgen_phi",&truth_phi_pointer);
190 t_truth->SetBranchAddress(
"em_evtgen_eta",&truth_eta_pointer);
191 t_truth->SetBranchAddress(
"em_evtgen_theta",&truth_theta_pointer);
192 t_truth->SetBranchAddress(
"em_evtgen_ptotal",&truth_p_pointer);
196 Int_t nentries_truth = Int_t(t_truth->GetEntries());
197 Int_t nentries_cluster= Int_t(t_cluster->GetEntries());
201 if(nentries_truth!=nentries_cluster)
203 cout <<
"Warning: Entries in 'event_truth'("<<nentries_truth<<
") does not equal Entries in 'event_cluster'("<<nentries_cluster<<
"). Using the smaller of the two" << endl;
204 if(nentries_truth>nentries_cluster) nentries = nentries_cluster;
208 nentries = nentries_truth;
214 cout <<
"Warning : Number of Events specified to run is greater than entries in the tree, using all entries" << endl;
219 for(Int_t entryInChain=0; entryInChain<nentries; entryInChain++)
224 cout <<
"Processing event " << entryInChain <<
" of " << nentries << endl;
228 Int_t entryInTree_truth = t_truth->LoadTree(entryInChain);
229 if (entryInTree_truth < 0)
break;
230 Int_t entryInTree_cluster = t_cluster->LoadTree(entryInChain);
231 if (entryInTree_cluster < 0)
break;
235 t_truth->GetEntry(entryInChain);
236 t_cluster->GetEntry(entryInChain);
240 for(
unsigned k = 0;
k<cluster_p.size();
k++)
242 if(cluster_eta.at(
k)<-1.1)
244 h2_phi->Fill(track_phi.at(
k),cluster_phi.at(
k));
245 h2_eta->Fill(track_eta.at(
k),cluster_eta.at(
k));
246 h2_theta->Fill(track_theta.at(
k),cluster_theta.at(
k));
247 h2_mom->Fill(track_p.at(
k),cluster_p.at(
k));
248 h2_posx->Fill(track_posx.at(
k),cluster_posx.at(
k));
249 h2_posy->Fill(track_posy.at(
k),cluster_posy.at(
k));
250 h2_posz->Fill(track_posz.at(
k),cluster_posz.at(
k));
252 if(cluster_eta.at(
k)>1)
255 ->Fill(sqrt( (track_posx.at(
k)-cluster_posx.at(
k))*
256 (track_posx.at(
k)-cluster_posx.at(
k))
258 (track_posy.at(
k)-cluster_posy.at(
k))*
259 (track_posy.at(
k)-cluster_posy.at(
k))
261 (track_posz.at(
k)-cluster_posz.at(
k))*
262 (track_posz.at(
k)-cluster_posz.at(
k))));
264 else if(cluster_eta.at(
k)<1&&cluster_eta.at(
k)>-1.1)
267 ->Fill(sqrt( (track_posx.at(
k)-cluster_posx.at(
k))*
268 (track_posx.at(
k)-cluster_posx.at(
k))
270 (track_posy.at(
k)-cluster_posy.at(
k))*
271 (track_posy.at(
k)-cluster_posy.at(
k))
273 (track_posz.at(
k)-cluster_posz.at(
k))*
274 (track_posz.at(
k)-cluster_posz.at(
k))));
279 ->Fill(sqrt( (track_posx.at(
k)-cluster_posx.at(
k))*
280 (track_posx.at(
k)-cluster_posx.at(
k))
282 (track_posy.at(
k)-cluster_posy.at(
k))*
283 (track_posy.at(
k)-cluster_posy.at(
k))
285 (track_posz.at(
k)-cluster_posz.at(
k))*
286 (track_posz.at(
k)-cluster_posz.at(
k))));
304 TAxis *axis = h->GetXaxis();
305 int bins = axis->GetNbins();
307 Axis_t from = axis->GetXmin();
308 Axis_t to = axis->GetXmax();
309 Axis_t
width = (to - from) / bins;
310 Axis_t *new_bins =
new Axis_t[bins + 1];
312 for (
int i = 0;
i <=
bins;
i++) {
313 new_bins[
i] = TMath::Power(10, from +
i * width);
315 axis->Set(bins, new_bins);
317 TAxis *axis2 = h->GetYaxis();
318 int bins2 = axis2->GetNbins();
320 Axis_t from2 = axis2->GetXmin();
321 Axis_t to2 = axis2->GetXmax();
322 Axis_t width2 = (to2 - from2) / bins2;
323 Axis_t *new_bins2 =
new Axis_t[bins2 + 1];
325 for (
int i = 0;
i <= bins2;
i++) {
326 new_bins2[
i] = TMath::Power(10, from2 +
i * width2);
328 axis2->Set(bins2, new_bins2);
334 void hist_to_png_h1(TH1F * h_c, TH1F* h_e, TH1F* h_f, TString saveTitle, TString type_string)
336 TCanvas *cPNG =
new TCanvas(saveTitle,
"",700,500);
337 TImage *img = TImage::Create();
338 char *
type = type_string.Data();
339 gStyle->SetOptStat(0);
341 auto legend =
new TLegend(0.7,0.7,0.9,0.9);
342 legend->SetTextSize(0.06);
343 legend->AddEntry(h_c,
"CEMC",
"l");
344 legend->AddEntry(h_e,
"EEMC",
"l");
345 legend->AddEntry(h_f,
"FEMC",
"l");
347 if(strcmp(type,
"spatial")==0)
349 h_e->GetXaxis()->SetTitle(
"Extrapolation distance from cluster [cm]");
350 h_e->GetYaxis()->SetTitle(
"Counts");
357 img->WriteImage(saveTitle);
361 TCanvas *cPNG =
new TCanvas(saveTitle,
"",700,500);
362 TImage *img = TImage::Create();
363 char *
type = type_string.Data();
365 gStyle->SetOptStat(0);
366 if(strcmp(type,
"phi")==0)
368 h->GetXaxis()->SetTitle(
"Track Phi");
369 h->GetYaxis()->SetTitle(
"Cluster Phi");
371 else if(strcmp(type,
"eta")==0)
373 h->GetXaxis()->SetTitle(
"Track Eta");
374 h->GetYaxis()->SetTitle(
"Cluster Eta");
376 else if(strcmp(type,
"theta")==0)
378 h->GetXaxis()->SetTitle(
"Track Theta");
379 h->GetYaxis()->SetTitle(
"Cluster Theta");
381 else if(strcmp(type,
"mom")==0)
383 h->GetXaxis()->SetTitle(
"Track Momentum [GeV]");
384 h->GetYaxis()->SetTitle(
"Cluster Momentum [GeV]");
386 else if(strcmp(type,
"posx")==0)
388 h->GetXaxis()->SetTitle(
"Track Position X [cm]");
389 h->GetYaxis()->SetTitle(
"Cluster Position X [cm]");
391 else if(strcmp(type,
"posy")==0)
393 h->GetXaxis()->SetTitle(
"Track Position Y [cm]");
394 h->GetYaxis()->SetTitle(
"Cluster Position Y [cm]");
396 else if(strcmp(type,
"posz")==0)
398 h->GetXaxis()->SetTitle(
"Track Position Z [cm]");
399 h->GetYaxis()->SetTitle(
"Cluster Position Z [cm]");
403 img->WriteImage(saveTitle);