Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
prob_EMC_e_pi_plotMacro.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file prob_EMC_e_pi_plotMacro.C
1 #include <iostream>
2 #include <cstdlib>
3 
4 #include "TFile.h"
5 #include "TTree.h"
6 #include "TCanvas.h"
7 
8 TTree* loadTree(
9  TString FILE_NAME="",
10  TString TREE_NAME="",
11  const TString DIR_PATH = "/sphenix/user/gregtom3/data/Summer2018/ECAL_probability_studies/"
12  )
13 {
14  TFile *f = new TFile(DIR_PATH+FILE_NAME,"READ");
15  TTree *t = (TTree*)f->Get(TREE_NAME);
16  return t;
17 }
18 
19 TH1F* fillHist(TH1F *THE_HIST, TTree *THE_TREE)
20 {
21  std::vector<float> measured_energy;
22  std::vector<float> measured_ptotal;
23  std::vector<float> shower_probability; //integration of chi2 PDF, tells us likelihood of this specific cluster radius corresponds to that of an electron's
24  std::vector<float>* measured_energy_pointer = &measured_energy;
25  std::vector<float>* measured_ptotal_pointer = &measured_ptotal;
26  std::vector<float>* shower_probability_pointer = &shower_probability;
27  THE_TREE->SetBranchAddress("em_cluster_e",&measured_energy_pointer);
28  THE_TREE->SetBranchAddress("em_track_ptotal",&measured_ptotal_pointer);
29  THE_TREE->SetBranchAddress("em_cluster_prob",&shower_probability_pointer);
30 
31  Int_t nentries = Int_t(THE_TREE->GetEntries());
32  for(Int_t entryInChain=0; entryInChain<nentries; entryInChain++)
33  {
34  Int_t entryInTree = THE_TREE->LoadTree(entryInChain);
35  if (entryInTree < 0) break;
36  THE_TREE->GetEntry(entryInChain);
37  for(int i=0;i<shower_probability.size();i++)
38  {
39  if(measured_energy[i]>0.5) //Cuts
40  THE_HIST->Fill(shower_probability[i]);
41  }
42  }
43  THE_HIST->SetXTitle("P_{EM}");
44  THE_HIST->SetYTitle("Counts");
45 
46  return THE_HIST;
47 }
48 
49 void histToPNG(TH1F* h_p, TH1F* h_e, char * title, char * saveFileName)
50 {
51  TCanvas *cPNG = new TCanvas("cPNG",title); // 700 x 500 default
52  TImage *img = TImage::Create();
53 
54  h_p->Draw();
55  h_e->Draw("SAME");
56  h_p->GetXaxis()->SetNdivisions(6,2,0,false);
57  h_p->GetYaxis()->SetNdivisions(5,3,0,false);
58  h_p->GetYaxis()->SetRangeUser(0,5000);
59  auto legend = new TLegend(0.7,0.65,0.95,0.90,title);
60  legend->AddEntry(h_p,"Pions","l");
61  legend->AddEntry(h_e,"Electrons","l");
62  legend->SetTextSize(0.05);
63  legend->Draw();
64  gPad->RedrawAxis();
65  img->FromPad(cPNG);
66  img->WriteImage(saveFileName);
67 
68  delete img;
69  delete cPNG;
70 
71 }
72 
73 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74 / Main Code
75 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
76 
78  const TString DIR_PATH = "/sphenix/user/gregtom3/data/Summer2018/ECAL_probability_studies/"
79  )
80 {
81 
82  /* *
83  * sPHENIX Style
84  */
85 
86  gROOT->LoadMacro("/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C");
88  gROOT->SetBatch(kTRUE);
89 
90  /* *
91  * Base Histogram
92  */
93 
94  TH1F *h_base = new TH1F("h_base","",25,0,1.2);
95  TH1F *h_base_e = (TH1F*)h_base->Clone();
96  TH1F *h_base_p = (TH1F*)h_base->Clone();
97 
98  h_base_e->SetLineColor(kRed);
99  h_base_p->SetLineColor(kBlue);
100 
101  /* *
102  * Loading histograms and trees for electrons and pions [1, 2, 5, 10, 20] GeV
103  * CEMC Eta -0.5 0.5
104  * EEMC Eta -3 -2
105  * 10000 events per energy per particle per detector
106  */
107 
108  /* CEMC */
109  TH1F *h_P_1GeV_CEMC = (TH1F*)h_base_p->Clone();
110  TH1F *h_P_2GeV_CEMC = (TH1F*)h_base_p->Clone();
111  TH1F *h_P_5GeV_CEMC = (TH1F*)h_base_p->Clone();
112  TH1F *h_P_10GeV_CEMC = (TH1F*)h_base_p->Clone();
113  TH1F *h_P_20GeV_CEMC = (TH1F*)h_base_p->Clone();
114 
115  TH1F *h_E_1GeV_CEMC = (TH1F*)h_base_e->Clone();
116  TH1F *h_E_2GeV_CEMC = (TH1F*)h_base_e->Clone();
117  TH1F *h_E_5GeV_CEMC = (TH1F*)h_base_e->Clone();
118  TH1F *h_E_10GeV_CEMC = (TH1F*)h_base_e->Clone();
119  TH1F *h_E_20GeV_CEMC = (TH1F*)h_base_e->Clone();
120 
121  h_P_1GeV_CEMC->SetName("h_P_1GeV_CEMC");
122  h_P_2GeV_CEMC->SetName("h_P_2GeV_CEMC");
123  h_P_5GeV_CEMC->SetName("h_P_5GeV_CEMC");
124  h_P_10GeV_CEMC->SetName("h_P_10GeV_CEMC");
125  h_P_20GeV_CEMC->SetName("h_P_20GeV_CEMC");
126 
127  h_E_1GeV_CEMC->SetName("h_E_1GeV_CEMC");
128  h_E_2GeV_CEMC->SetName("h_E_2GeV_CEMC");
129  h_E_5GeV_CEMC->SetName("h_E_5GeV_CEMC");
130  h_E_10GeV_CEMC->SetName("h_E_10GeV_CEMC");
131  h_E_20GeV_CEMC->SetName("h_E_20GeV_CEMC");
132 
133  TTree *t_P_1GeV_CEMC = loadTree("Pions/Pions1C.root", "event_cluster");
134  TTree *t_P_2GeV_CEMC = loadTree("Pions/Pions2C.root", "event_cluster");
135  TTree *t_P_5GeV_CEMC = loadTree("Pions/Pions5C.root", "event_cluster");
136  TTree *t_P_10GeV_CEMC = loadTree("Pions/Pions10C.root", "event_cluster");
137  TTree *t_P_20GeV_CEMC = loadTree("Pions/Pions20C.root", "event_cluster");
138 
139  TTree *t_E_1GeV_CEMC = loadTree("Electrons/Electrons1C.root", "event_cluster");
140  TTree *t_E_2GeV_CEMC = loadTree("Electrons/Electrons2C.root", "event_cluster");
141  TTree *t_E_5GeV_CEMC = loadTree("Electrons/Electrons5C.root", "event_cluster");
142  TTree *t_E_10GeV_CEMC = loadTree("Electrons/Electrons10C.root", "event_cluster");
143  TTree *t_E_20GeV_CEMC = loadTree("Electrons/Electrons20C.root", "event_cluster");
144 
145  /* EEMC */
146  TH1F *h_P_1GeV_EEMC = (TH1F*)h_base_p->Clone();
147  TH1F *h_P_2GeV_EEMC = (TH1F*)h_base_p->Clone();
148  TH1F *h_P_5GeV_EEMC = (TH1F*)h_base_p->Clone();
149  TH1F *h_P_10GeV_EEMC = (TH1F*)h_base_p->Clone();
150  TH1F *h_P_20GeV_EEMC = (TH1F*)h_base_p->Clone();
151 
152  TH1F *h_E_1GeV_EEMC = (TH1F*)h_base_e->Clone();
153  TH1F *h_E_2GeV_EEMC = (TH1F*)h_base_e->Clone();
154  TH1F *h_E_5GeV_EEMC = (TH1F*)h_base_e->Clone();
155  TH1F *h_E_10GeV_EEMC = (TH1F*)h_base_e->Clone();
156  TH1F *h_E_20GeV_EEMC = (TH1F*)h_base_e->Clone();
157 
158  h_P_1GeV_EEMC->SetName("h_P_1GeV_EEMC");
159  h_P_2GeV_EEMC->SetName("h_P_2GeV_EEMC");
160  h_P_5GeV_EEMC->SetName("h_P_5GeV_EEMC");
161  h_P_10GeV_EEMC->SetName("h_P_10GeV_EEMC");
162  h_P_20GeV_EEMC->SetName("h_P_20GeV_EEMC");
163 
164  h_E_1GeV_EEMC->SetName("h_E_1GeV_EEMC");
165  h_E_2GeV_EEMC->SetName("h_E_2GeV_EEMC");
166  h_E_5GeV_EEMC->SetName("h_E_5GeV_EEMC");
167  h_E_10GeV_EEMC->SetName("h_E_10GeV_EEMC");
168  h_E_20GeV_EEMC->SetName("h_E_20GeV_EEMC");
169 
170  TTree *t_P_1GeV_EEMC = loadTree("Pions/Pions1E.root", "event_cluster");
171  TTree *t_P_2GeV_EEMC = loadTree("Pions/Pions2E.root", "event_cluster");
172  TTree *t_P_5GeV_EEMC = loadTree("Pions/Pions5E.root", "event_cluster");
173  TTree *t_P_10GeV_EEMC = loadTree("Pions/Pions10E.root", "event_cluster");
174  TTree *t_P_20GeV_EEMC = loadTree("Pions/Pions20E.root", "event_cluster");
175 
176  TTree *t_E_1GeV_EEMC = loadTree("Electrons/Electrons1E.root", "event_cluster");
177  TTree *t_E_2GeV_EEMC = loadTree("Electrons/Electrons2E.root", "event_cluster");
178  TTree *t_E_5GeV_EEMC = loadTree("Electrons/Electrons5E.root", "event_cluster");
179  TTree *t_E_10GeV_EEMC = loadTree("Electrons/Electrons10E.root", "event_cluster");
180  TTree *t_E_20GeV_EEMC = loadTree("Electrons/Electrons20E.root", "event_cluster");
181 
182  /* *
183  * Filling Histograms
184  */
185 
186  /* Pions CEMC */
187  h_P_1GeV_CEMC=fillHist(h_P_1GeV_CEMC,t_P_1GeV_CEMC);
188  h_P_2GeV_CEMC=fillHist(h_P_2GeV_CEMC,t_P_2GeV_CEMC);
189  h_P_5GeV_CEMC=fillHist(h_P_5GeV_CEMC,t_P_5GeV_CEMC);
190  h_P_10GeV_CEMC=fillHist(h_P_10GeV_CEMC,t_P_10GeV_CEMC);
191  h_P_20GeV_CEMC=fillHist(h_P_20GeV_CEMC,t_P_20GeV_CEMC);
192  /* Pions EEMC */
193  //Lots of Bugs currently with event_cluster info from EEMC
194  /*h_P_1GeV_EEMC=fillHist(h_P_1GeV_EEMC,t_P_1GeV_EEMC);
195  h_P_2GeV_EEMC=fillHist(h_P_2GeV_EEMC,t_P_2GeV_EEMC);
196  h_P_5GeV_EEMC=fillHist(h_P_5GeV_EEMC,t_P_5GeV_EEMC);
197  h_P_10GeV_EEMC=fillHist(h_P_10GeV_EEMC,t_P_10GeV_EEMC);
198  h_P_20GeV_EEMC=fillHist(h_P_20GeV_EEMC,t_P_20GeV_EEMC);*/
199 
200 
201  /* Electrons CEMC */
202  h_E_1GeV_CEMC=fillHist(h_E_1GeV_CEMC,t_E_1GeV_CEMC);
203  h_E_2GeV_CEMC=fillHist(h_E_2GeV_CEMC,t_E_2GeV_CEMC);
204  h_E_5GeV_CEMC=fillHist(h_E_5GeV_CEMC,t_E_5GeV_CEMC);
205  h_E_10GeV_CEMC=fillHist(h_E_10GeV_CEMC,t_E_10GeV_CEMC);
206  h_E_20GeV_CEMC=fillHist(h_E_20GeV_CEMC,t_E_20GeV_CEMC);
207  /* Electrons EEMC */
208  /*h_E_1GeV_EEMC=fillHist(h_E_1GeV_EEMC,t_E_1GeV_EEMC);
209  h_E_2GeV_EEMC=fillHist(h_E_2GeV_EEMC,t_E_2GeV_EEMC);
210  h_E_5GeV_EEMC=fillHist(h_E_5GeV_EEMC,t_E_5GeV_EEMC);
211  h_E_10GeV_EEMC=fillHist(h_E_10GeV_EEMC,t_E_10GeV_EEMC);
212  h_E_20GeV_EEMC=fillHist(h_E_20GeV_EEMC,t_E_20GeV_EEMC);*/
213 
214  /* *
215  * Drawing Histograms and Saving Them
216  */
217 
218  /* CEMC */
219  histToPNG(h_P_1GeV_CEMC,h_E_1GeV_CEMC,"1GeV CEMC","prob_e_pi_1GeV_CEMC.png");
220  histToPNG(h_P_2GeV_CEMC,h_E_2GeV_CEMC,"2GeV CEMC","prob_e_pi_2GeV_CEMC.png");
221  histToPNG(h_P_5GeV_CEMC,h_E_5GeV_CEMC,"5GeV CEMC","prob_e_pi_5GeV_CEMC.png");
222  histToPNG(h_P_10GeV_CEMC,h_E_10GeV_CEMC,"10GeV CEMC","prob_e_pi_10GeV_CEMC.png");
223  histToPNG(h_P_20GeV_CEMC,h_E_20GeV_CEMC,"20GeV CEMC","prob_e_pi_20GeV_CEMC.png");
224  /* EEMC */
225  /*histToPNG(h_P_1GeV_EEMC,h_E_1GeV_EEMC,"1GeV EEMC","prob_e_pi_1GeV_EEMC.png");
226  histToPNG(h_P_2GeV_EEMC,h_E_2GeV_EEMC,"2GeV EEMC","prob_e_pi_2GeV_EEMC.png");
227  histToPNG(h_P_5GeV_EEMC,h_E_5GeV_EEMC,"5GeV EEMC","prob_e_pi_5GeV_EEMC.png");
228  histToPNG(h_P_10GeV_EEMC,h_E_10GeV_EEMC,"10GeV EEMC","prob_e_pi_10GeV_EEMC.png");
229  histToPNG(h_P_20GeV_EEMC,h_E_20GeV_EEMC,"20GeV EEMC","prob_e_pi_20GeV_EEMC.png");*/
230 }
231 
232 
233