Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DrawEMCalTower_Resolution.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DrawEMCalTower_Resolution.C
1 // $Id: $
2 
11 #include <cmath>
12 #include <TFile.h>
13 #include <TString.h>
14 #include <TLine.h>
15 #include <TTree.h>
16 #include <TLatex.h>
17 #include <TGraphErrors.h>
18 #include <cassert>
19 #include "SaveCanvas.C"
20 #include "SetOKStyle.C"
21 using namespace std;
22 
23 void
25  const TString base =
26  "../../sPHENIX_work/Prototype_2016/EMCal_sim/15Degree_1Col_LightCollection/")
27 {
28  SetOKStyle();
29  gStyle->SetOptStat(0);
30  gStyle->SetOptFit(1111);
31  TVirtualFitter::SetDefaultFitter("Minuit2");
32 
33  const int N = 7;
34  const double Es[] =
35  { 1, 2, 4, 8, 12, 16, 24 };
36  double mean[1000];
37  double dmean[1000];
38  double res[1000];
39  double dres[1000];
40 
41  for (int i = 0; i < N; ++i)
42  {
43  const double E = Es[i];
44 
45  vector<double> v(4);
46 
47  const TString sE = Form("%.0f", E);
48  v = GetOnePlot(base, "e-", sE);
49 
50  mean[i] = v[0];
51  dmean[i] = v[1];
52  res[i] = v[2] / v[0];
53  dres[i] = v[3] / v[0];
54 
55  cout << "mean[i] = " << mean[i] << ", " //
56  << "dmean[i] = " << dmean[i] << ", " //
57  << "res[i] = " << res[i] << ", " //
58  << "dres[i] = " << dres[i] << endl;
59  }
60 
61  TGraphErrors * ge_linear = new TGraphErrors(N, Es, mean, 0, dmean);
62  TGraphErrors * ge_res = new TGraphErrors(N, Es, res, 0, dres);
63 
64  ge_linear->SetLineColor(kBlue + 3);
65  ge_linear->SetMarkerColor(kBlue + 3);
66  ge_linear->SetLineWidth(2);
67  ge_linear->SetMarkerStyle(kFullCircle);
68  ge_linear->SetMarkerSize(1.5);
69 
70  ge_res->SetLineColor(kBlue + 3);
71  ge_res->SetMarkerColor(kBlue + 3);
72  ge_res->SetLineWidth(2);
73  ge_res->SetMarkerStyle(kFullCircle);
74  ge_res->SetMarkerSize(1.5);
75 
76  TF1 * f_calo_r = new TF1("f_calo_r", "sqrt([0]*[0]+[1]*[1]/x)/100", 0.5, 60);
77  TF1 * f_calo_l = new TF1("f_calo_l", "pol2", 0.5, 60);
78 
79  TText * t;
80  TCanvas *c1 = new TCanvas("DrawEMCalTower_Resolution",
81  "DrawEMCalTower_Resolution", 1300, 600);
82  c1->Divide(2, 1);
83  int idx = 1;
84  TPad * p;
85 
86  p = (TPad *) c1->cd(idx++);
87  c1->Update();
88 // p->SetLogy();
89  p->SetGridx(0);
90  p->SetGridy(0);
91 
92  p->DrawFrame(0, 0, 30, 30,
93  Form("Linearity;Input energy (GeV);Measured Energy (GeV)", E));
94  TLine * l = new TLine(0, 0, 30, 30);
95  l->SetLineColor(kGray);
96  l->Draw();
97 
98  ge_linear->Draw("p");
99  ge_linear->Fit(f_calo_l, "RM0");
100  f_calo_l->Draw("same");
101 
102  p = (TPad *) c1->cd(idx++);
103  c1->Update();
104 // p->SetLogy();
105  p->SetGridx(0);
106  p->SetGridy(0);
107 
108  TH1 * hframe = p->DrawFrame(0, 0, 30, 0.2,
109  Form("Resolution;Input energy (GeV);#DeltaE/<E>", E));
110 
111  ge_res->Draw("p");
112  ge_res->Fit(f_calo_r, "RM0");
113  f_calo_r->Draw("same");
114 
115  hframe->SetTitle(
116  Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
117  f_calo_r->GetParameter(0), f_calo_r->GetParameter(1)));
118 
119  SaveCanvas(c1, base + TString(c1->GetName()), kTRUE);
120 }
121 
122 vector<double>
123 GetOnePlot(const TString base, const TString particle, const TString sE)
124 {
125 
126  TString fname =
127  base + TString("Prototype_") + particle + "_" + sE
128  + "_SegALL_DSTReader.root_DrawEMCalTower_EMCDistribution_SUM_all_event.root";
129 // Prototype_e-_2_Seg0_DSTReader.root_DrawEMCalTower_EMCDistribution_SUMall_event.root
130 
131  cout << "Process " << fname << endl;
132  TFile * f = new TFile(fname);
133  assert(f->IsOpen());
134 
135  TH1 * hEnergySum = (TH1 *) f->GetObjectChecked("EnergySum_LG", "TH1");
136  assert(hEnergySum);
137  new TCanvas();
138  hEnergySum->DrawClone();
139 
140  hEnergySum->Scale(1. / hEnergySum->Integral(1, -1));
141  TF1 * fgaus = hEnergySum->GetFunction("fgaus_LG");
142  assert(fgaus);
143 
144  vector<double> v(4);
145  v[0] = fgaus->GetParameter(1);
146  v[1] = fgaus->GetParError(1);
147  v[2] = fgaus->GetParameter(2);
148  v[3] = fgaus->GetParError(2);
149 
150  return v;
151 }
152 
153 void
155 {
156  gStyle->SetOptStat(0);
157 
158  TFile * f1 =
159  new TFile(
160  "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2016/EMCal_sim/15Degree_1Col/DrawEMCalTower_Resolution.root");
161 
162  TGraphErrors * g1 = f1->GetObjectChecked("Graph", "TGraphErrors");
163  TF1 * f_calo_r1 = f1->GetObjectChecked("f_calo_r", "TF1");
164 
165  g1->SetLineColor(kBlue + 3);
166  g1->SetMarkerColor(kBlue + 3);
167  f_calo_r1->SetLineColor(kBlue + 3);
168 // g1->GetHistogram()->SetStats(0);
169  g1->FindObject("stats")->Delete();
170 
171  TFile * f2 =
172  new TFile(
173  "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2016/EMCal_sim/15Degree_1Col_LightCollection/DrawEMCalTower_Resolution.root");
174 
175  TGraphErrors * g2 = f2->GetObjectChecked("Graph", "TGraphErrors");
176  TF1 * f_calo_r2 = f2->GetObjectChecked("f_calo_r", "TF1");
177 
178  g2->SetLineColor(kRed + 3);
179  g2->SetMarkerColor(kRed + 3);
180  f_calo_r2->SetLineColor(kRed + 3);
181 // g2->GetHistogram()->SetStats(false);
182  g2->FindObject("stats")->Delete();
183 
184  TCanvas *c1 = new TCanvas("DrawEMCalTower_Resolution_Compare",
185  "DrawEMCalTower_Resolution_Compare", 700, 600);
186  c1->Divide(1, 1);
187  int idx = 1;
188  TPad * p;
189 
190  TLegend * leg = new TLegend(0.3, 0.5, 0.9, 0.9);
191 
192  p = (TPad *) c1->cd(idx++);
193  c1->Update();
194 // p->SetLogy();
195  p->SetGridx(0);
196  p->SetGridy(0);
197 
198  TH1 * hframe = p->DrawFrame(0, 0, 30, 0.2,
199  Form("Resolution Comparison;Input energy (GeV);#DeltaE/<E>"));
200 
201  g1->Draw("ep");
202  f_calo_r1->Draw("same");
203 
204  leg->AddEntry(g1, "Pre-test beam simulation", "p");
205  leg->AddEntry(f_calo_r1,
206  Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
207  f_calo_r1->GetParameter(0), f_calo_r1->GetParameter(1)), "l");
208 
209  g2->Draw("ep");
210  f_calo_r2->Draw("same");
211 
212  leg->AddEntry(g2, "Pre-test beam simulation", "p");
213  leg->AddEntry(f_calo_r2,
214  Form("#DeltaE/E = %.1f%% #oplus %.1f%%/#sqrt{E}",
215  f_calo_r2->GetParameter(0), f_calo_r2->GetParameter(1)), "l");
216 
217  leg->Draw();
218 
219  SaveCanvas(c1, TString(c1->GetName()), kTRUE);
220 }
221