Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
jpsi_invariant_mass_plot_exclusiveReco.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file jpsi_invariant_mass_plot_exclusiveReco.C
1 // ----------------------------------------------------------------------------
2 // TFiles and TTrees
3 // ----------------------------------------------------------------------------
4 
5 TFile *f_1 = new TFile("/sphenix/user/gregtom3/data/Summer2018/ExclusiveReco_studies/latest_run/10x100_1M_dvmp.root","READ");
6 //TFile *f_2 = new TFile("/sphenix/user/gregtom3/data/Summer2018/ExclusiveReco_studies/latest_run/10x100_1M_dvmp.root");
7 //TFile *f_3 = new TFile("/sphenix/user/gregtom3/data/Summer2018/ExclusiveReco_studies/latest_run/18x275_1M_dvmp.root");
8 
9 
10 TTree *t_1_exclusive = (TTree*)f_1->Get("event_exclusive");
11 TTree *t_1_reco = (TTree*)f_1->Get("event_reco");
12 TTree *t_1_truth = (TTree*)f_1->Get("event_truth");
13 
14 //TTree *t_2_exclusive = (TTree*)f_2->Get("event_exclusive");
15 //TTree *t_2_reco = (TTree*)f_2->Get("event_reco");
16 //TTree *t_2_truth = (TTree*)f_2->Get("event_truth");
17 
18 //TTree *t_3_exclusive = (TTree*)f_3->Get("event_exclusive");
19 //TTree *t_3_reco = (TTree*)f_3->Get("event_reco");
20 //TTree *t_3_truth = (TTree*)f_3->Get("event_truth");
21 
22 // ----------------------------------------------------------------------------
23 // Main Code
24 // ----------------------------------------------------------------------------
25 
27 {
28 
29  // ----------------------------------------
30  // Load Sphenix Style for Histogram Plots
31  // ----------------------------------------
32  gROOT->LoadMacro("/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C");
34  // ----------------------------------------
35  // Creating Histogram Base
36  // ----------------------------------------
37  TH1F * h1_inv_mass_base = new TH1F("","",100,0,10);
38  // ----------------------------------------
39  // Creating Invariant Mass Histograms
40  // ----------------------------------------
41  TH1F * h1_inv_mass_10x100_123456 = (TH1F*)h1_inv_mass_base->Clone();
42  TH1F * h1_inv_mass_10x100_1 = (TH1F*)h1_inv_mass_base->Clone();
43  TH1F * h1_inv_mass_10x100_2 = (TH1F*)h1_inv_mass_base->Clone();
44  TH1F * h1_inv_mass_10x100_3 = (TH1F*)h1_inv_mass_base->Clone();
45  TH1F * h1_inv_mass_10x100_4 = (TH1F*)h1_inv_mass_base->Clone();
46  TH1F * h1_inv_mass_10x100_5 = (TH1F*)h1_inv_mass_base->Clone();
47  TH1F * h1_inv_mass_10x100_6 = (TH1F*)h1_inv_mass_base->Clone();
48  // ----------------------------------------
49  // Setting Axes Titles
50  // ----------------------------------------
51  h1_inv_mass_10x100_123456->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
52  h1_inv_mass_10x100_123456->GetYaxis()->SetTitle("Counts");
53 
54  h1_inv_mass_10x100_1->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
55  h1_inv_mass_10x100_1->GetYaxis()->SetTitle("Counts");
56 
57  h1_inv_mass_10x100_2->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
58  h1_inv_mass_10x100_2->GetYaxis()->SetTitle("Counts");
59 
60  h1_inv_mass_10x100_3->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
61  h1_inv_mass_10x100_3->GetYaxis()->SetTitle("Counts");
62 
63  h1_inv_mass_10x100_4->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
64  h1_inv_mass_10x100_4->GetYaxis()->SetTitle("Counts");
65 
66  h1_inv_mass_10x100_5->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
67  h1_inv_mass_10x100_5->GetYaxis()->SetTitle("Counts");
68 
69  h1_inv_mass_10x100_6->GetXaxis()->SetTitle("Invariant Mass [GeV/c^{2}]");
70  h1_inv_mass_10x100_6->GetYaxis()->SetTitle("Counts");
71  // ----------------------------------------
72  // Filling Histograms and Saving Them (Individual)
73  // ----------------------------------------
74  std::vector<TString> types;
75  types.push_back("reco_inv");
76  types.push_back("true_inv");
77  types.push_back("reco_inv_decay");
78  types.push_back("reco_inv_scatter");
79  types.push_back("true_inv_decay");
80  types.push_back("true_inv_scatter");
81 
82  for(unsigned idx_type = 0 ; idx_type < types.size() ; idx_type++)
83  {
84  //fillHist(h1_inv_mass_10x100_123456, t_1_exclusive, types.at(idx_type));
85  //hist_to_png(h1_inv_mass_10x100_123456,"10x100", types.at(idx_type));
86  }
87 
88 
89  // --------------------------------------------
90  // Filling Histograms and Saving Them (Special)
91  // --------------------------------------------
92  fillHist(h1_inv_mass_10x100_1, t_1_exclusive, "reco_inv");
93  fillHist(h1_inv_mass_10x100_2, t_1_exclusive, "true_inv");
94  fillHist(h1_inv_mass_10x100_3, t_1_exclusive, "reco_inv_decay");
95  fillHist(h1_inv_mass_10x100_4, t_1_exclusive, "reco_inv_scatter");
96  fillHist(h1_inv_mass_10x100_5, t_1_exclusive, "true_inv_decay");
97  fillHist(h1_inv_mass_10x100_6, t_1_exclusive, "true_inv_scatter");
98 
99  hist_to_png_special(h1_inv_mass_10x100_1,
100  h1_inv_mass_10x100_2,
101  h1_inv_mass_10x100_3,
102  h1_inv_mass_10x100_4,
103  h1_inv_mass_10x100_5,
104  h1_inv_mass_10x100_6, "10x100");
105 
106  return 0;
107 }
108 
109 void fillHist(TH1F * h, TTree *t, TString type_TString)
110 {
111  std::vector<float> reco_inv;
112  std::vector<float> true_inv;
113  std::vector<float> reco_inv_decay;
114  std::vector<float> reco_inv_scatter;
115  std::vector<float> true_inv_decay;
116  std::vector<float> true_inv_scatter;
117 
118  std::vector<float>* reco_inv_pointer = &reco_inv;
119  std::vector<float>* true_inv_pointer = &true_inv;
120  std::vector<float>* reco_inv_decay_pointer = &reco_inv_decay;
121  std::vector<float>* reco_inv_scatter_pointer = &reco_inv_scatter;
122  std::vector<float>* true_inv_decay_pointer = &true_inv_decay;
123  std::vector<float>* true_inv_scatter_pointer = &true_inv_scatter;
124 
125  t->SetBranchAddress("reco_inv",&reco_inv_pointer);
126  t->SetBranchAddress("true_inv",&true_inv_pointer);
127  t->SetBranchAddress("reco_inv_decay",&reco_inv_decay_pointer);
128  t->SetBranchAddress("reco_inv_scatter",&reco_inv_scatter_pointer);
129  t->SetBranchAddress("true_inv_decay",&true_inv_decay_pointer);
130  t->SetBranchAddress("true_inv_scatter",&true_inv_scatter_pointer);
131 
132  h->Reset();
133  Int_t nentries = Int_t(t->GetEntries());
134  char * type = type_TString.Data();
135  for(Int_t entryInChain=0; entryInChain<nentries; entryInChain++)
136  {
137  Int_t entryInTree = t->LoadTree(entryInChain);
138  if (entryInTree < 0) break;
139  t->GetEntry(entryInChain);
140  if(strcmp(type,"reco_inv")==0)
141  {
142  for(unsigned i = 0 ; i<reco_inv.size() ; i++)
143  h->Fill(reco_inv.at(i));
144  }
145  else if(strcmp(type,"true_inv")==0)
146  {
147  for(unsigned i = 0 ; i<true_inv.size() ; i++)
148  h->Fill(true_inv.at(i));
149  }
150  else if(strcmp(type,"reco_inv_decay")==0)
151  {
152  for(unsigned i = 0 ; i<reco_inv_decay.size() ; i++)
153  h->Fill(reco_inv_decay.at(i));
154  }
155  else if(strcmp(type,"reco_inv_scatter")==0)
156  {
157  for(unsigned i = 0 ; i<reco_inv_scatter.size() ; i++)
158  h->Fill(reco_inv_scatter.at(i));
159  }
160  else if(strcmp(type,"true_inv_decay")==0)
161  {
162  for(unsigned i = 0 ; i<true_inv_decay.size() ; i++)
163  h->Fill(true_inv_decay.at(i));
164  }
165  else if(strcmp(type,"true_inv_scatter")==0)
166  {
167  for(unsigned i = 0 ; i<true_inv_scatter.size() ; i++)
168  h->Fill(true_inv_scatter.at(i));
169  }
170  }
171 }
172 
173 
174 
175 void hist_to_png(TH1F * h, TString saveTitle, TString type)
176 {
177  saveTitle = type + "_" + saveTitle+".png";
178  TCanvas *cPNG = new TCanvas(saveTitle,"",700,500);
179  TImage *img = TImage::Create();
180 
181  h->Draw();
182 
183  img->FromPad(cPNG);
184  img->WriteImage(saveTitle);
185  delete img;
186 }
187 
188 void hist_to_png_special(TH1F * h1, TH1F * h2, TH1F *h3,
189  TH1F * h4, TH1F * h5, TH1F *h6,
190  TString type)
191 {
192  //h1 reco
193  //h2 true
194  //h3 reco decay
195  //h4 reco scatter
196  //h5 true decay
197  //h6 true scatter
198 
199  // Plot 1: Reco Inv. Mass Full
200  TCanvas *cPNG_1 = new TCanvas("plot1","",700,500);
201  TImage *img_1 = TImage::Create();
202  auto legend_1 = new TLegend(0.6,0.75,0.9,0.9);
203  h1->SetLineColor(kRed);
204  h4->SetLineColor(kBlue);
205  legend_1->SetHeader("Reco Decay Particles");
206  legend_1->AddEntry(h1,"All e^{-}e^{+}","l");
207  legend_1->AddEntry(h4,"Background e^{-}e^{+}","l");
208  h1->Draw();
209  h4->Draw("SAME");
210  legend_1->Draw();
211  gPad->RedrawAxis();
212  gPad->SetLogy();
213  img_1->FromPad(cPNG_1);
214  img_1->WriteImage("plot1__"+type+"_dvmp_reco_inv_full.png");
215  delete img_1;
216 
217  // Plot 2: True Inv. Mass Split
218  TCanvas *cPNG_2 = new TCanvas("plot2","",700,500);
219  TImage *img_2 = TImage::Create();
220  h2->SetLineColor(kRed);
221  h6->SetLineColor(kBlue);
222  auto legend_2 = new TLegend(0.6,0.75,0.9,0.9);
223  legend_2->SetHeader("True Decay Particles");
224  legend_2->AddEntry(h2,"All e^{-}e^{+}","l");
225  legend_2->AddEntry(h6,"Background e^{-}e^{+}","l");
226  h2->Draw();
227  h6->Draw("SAME");
228  legend_2->Draw();
229  gPad->RedrawAxis();
230  gPad->SetLogy();
231  img_2->FromPad(cPNG_2);
232  img_2->WriteImage("plot2__"+type+"_dvmp_true_inv_full.png");
233  delete img_2;
234 
235  // Plot 3: Combine plots 1 and 2
236  TCanvas *cPNG_3 = new TCanvas("plot3","",1400,500);
237  TImage *img_3 = TImage::Create();
238 
239  cPNG_3->Divide(2,1);
240  cPNG_3->cd(1);
241  h1->Draw();
242  h4->Draw("same");
243  legend_1->Draw();
244  gPad->RedrawAxis();
245  gPad->SetLogy();
246 
247  cPNG_3->cd(2);
248  h2->Draw();
249  h6->Draw("same");
250  legend_2->Draw();
251  gPad->RedrawAxis();
252  gPad->SetLogy();
253 
254  img_3->FromPad(cPNG_3);
255  img_3->WriteImage("plot3__"+type+"_dvmp_inv_full.png");
256  delete img_3;
257 }