2 from optparse
import OptionParser
11 from plotUtil
import *
13 gROOT.LoadMacro(
'./sPHENIXStyle/sPhenixStyle.C')
14 gROOT.ProcessLine(
'SetsPhenixStyle()')
17 def Draw_1Dhist_datasimcomp(hdata, hsims, gpadmargin, norm, logy, ymaxscale, XaxisName, Ytitle_unit, prelim, simlegtex, outname):
24 binwidth = hdata.GetXaxis().GetBinWidth(1)
27 hdata.Scale(1. / hdata.Integral(-1, -1))
29 hsim.Scale(1. / hsim.Integral(-1, -1))
32 hsim.Scale(hdata.Integral(-1, -1) / hsim.Integral(-1, -1))
35 print(
'Invalid normalization option: {}'.
format(norm))
39 maxbincontent = max(hdata.GetMaximum(), hsim.GetMaximum())
41 c = TCanvas(
'c',
'c', 800, 700)
45 gPad.SetRightMargin(gpadmargin[0])
46 gPad.SetTopMargin(gpadmargin[1])
47 gPad.SetLeftMargin(gpadmargin[2])
48 gPad.SetBottomMargin(gpadmargin[3])
55 'Normalized entries / ({:g})'.
format(binwidth))
58 'Normalized entries / ({:g} {unit})'.
format(binwidth, unit=Ytitle_unit))
64 'Entries / ({:g} {unit})'.
format(binwidth, unit=Ytitle_unit))
67 hsim.GetYaxis().SetRangeUser(hsim.GetMinimum(0)*0.5, (hsim.GetMaximum()) * ymaxscale)
69 hsim.GetYaxis().SetRangeUser(0., (hsim.GetMaximum()) * ymaxscale)
72 hsim.GetXaxis().SetTitleOffset(1.1)
73 hsim.GetYaxis().SetTitleOffset(1.35)
74 hsim.SetLineColor(TColor.GetColor(hsimcolor[i]))
79 hsim.SetLineColor(TColor.GetColor(hsimcolor[i]))
82 hsim.Draw(
'histe same')
84 hdata.SetMarkerStyle(20)
85 hdata.SetMarkerSize(1)
86 hdata.SetMarkerColor(1)
89 hdata.Draw(
'same PE1')
90 shift = 0.45
if prelim
else 0.54
91 legylow = 0.2 + 0.04 * (len(hsims) - 1)
92 leg = TLegend((1-RightMargin)-shift, (1-TopMargin)-legylow,
93 (1-RightMargin)-0.1, (1-TopMargin)-0.03)
96 prelimtext =
'Preliminary' if prelim
else 'Work-in-progress'
97 leg.AddEntry(
'',
'#it{#bf{sPHENIX}} '+prelimtext,
'')
98 leg.AddEntry(
'',
'Au+Au #sqrt{s_{NN}}=200 GeV',
'')
99 leg.AddEntry(hdata,
'Data',
"PE1");
101 leg.AddEntry(hsims[i], lt,
"le");
105 c.SaveAs(outname+
'.pdf')
106 c.SaveAs(outname+
'.png')
109 gSystem.ProcessEvents()
114 def Draw_1Dhist_datasimcomp_v2(hdata1, hdata2, hsim, gpadmargin, norm, logy, ymaxscale, XaxisName, Ytitle_unit, legtext, prelim, outname):
118 binwidth = hdata1.GetXaxis().GetBinWidth(1)
120 hdata1.Scale(1. / hdata1.Integral(-1, -1))
121 hdata2.Scale(1. / hdata2.Integral(-1, -1))
122 hsim.Scale(1. / hsim.Integral(-1, -1))
124 hsim.Scale((hdata1.Integral(-1, -1)+hdata2.Integral(-1, -1)) / hsim.Integral(-1, -1))
127 print(
'Invalid normalization option: {}'.
format(norm))
130 c = TCanvas(
'c',
'c', 800, 700)
134 gPad.SetRightMargin(gpadmargin[0])
135 gPad.SetTopMargin(gpadmargin[1])
136 gPad.SetLeftMargin(gpadmargin[2])
137 gPad.SetBottomMargin(gpadmargin[3])
139 if Ytitle_unit ==
'':
141 'Normalized entries / ({:g})'.
format(binwidth))
144 'Normalized entries / ({:g} {unit})'.
format(binwidth, unit=Ytitle_unit))
146 if Ytitle_unit ==
'':
150 'Entries / ({:g} {unit})'.
format(binwidth, unit=Ytitle_unit))
153 hsim.GetYaxis().SetRangeUser(hsim.GetMinimum(0)*0.5, (hsim.GetMaximum()) * ymaxscale)
155 hsim.GetYaxis().SetRangeUser(0., (hsim.GetMaximum()) * ymaxscale)
157 hsim.GetXaxis().SetTitleOffset(1.1)
158 hsim.GetYaxis().SetTitleOffset(1.35)
162 hdata1.SetMarkerStyle(20)
163 hdata1.SetMarkerSize(1)
164 hdata1.SetMarkerColor(TColor.GetColor(
'#0B60B0'))
165 hdata1.SetLineColor(TColor.GetColor(
'#0B60B0'))
166 hdata1.SetLineWidth(2)
167 hdata1.Draw(
'same PE1')
168 hdata2.SetMarkerStyle(20)
169 hdata2.SetMarkerSize(1)
170 hdata2.SetMarkerColor(TColor.GetColor(
'#D24545'))
171 hdata2.SetLineColor(TColor.GetColor(
'#D24545'))
172 hdata2.SetLineWidth(2)
173 hdata2.Draw(
'same PE1')
174 shift = 0.45
if prelim
else 0.52
175 leg = TLegend((1-RightMargin)-shift, (1-TopMargin)-0.25,
176 (1-RightMargin)-0.1, (1-TopMargin)-0.03)
177 leg.SetTextSize(0.04)
179 prelimtext =
'Preliminary' if prelim
else 'Work-in-progress'
180 leg.AddEntry(
'',
'#it{#bf{sPHENIX}} '+prelimtext,
'')
181 leg.AddEntry(
'',
'Au+Au #sqrt{s_{NN}}=200 GeV',
'')
182 leg.AddEntry(hdata1, legtext[0],
"PE1");
183 leg.AddEntry(hdata2, legtext[1],
"PE1");
184 leg.AddEntry(hsim, legtext[2],
"l");
188 c.SaveAs(outname+
'.pdf')
189 c.SaveAs(outname+
'.png')
192 gSystem.ProcessEvents()
199 hdata.Scale(1. / hdata.Integral(-1, -1, -1, -1))
200 hsim.Scale(1. / hsim.Integral(-1, -1, -1, -1))
202 hsim.Scale(hdata.Integral(-1, -1, -1, -1) / hsim.Integral(-1, -1, -1, -1))
205 print(
'Invalid normalization option: {}'.
format(norm))
208 c = TCanvas(
'c',
'c', 800, 700)
212 gPad.SetRightMargin(rmargin)
213 gPad.SetTopMargin(TopMargin)
214 gPad.SetLeftMargin(LeftMargin)
215 gPad.SetBottomMargin(BottomMargin)
216 hdata.GetXaxis().
SetTitle(XaxisName)
217 hdata.GetYaxis().
SetTitle(YaxisName)
218 hdata.GetXaxis().SetTickSize(TickSize)
219 hdata.GetYaxis().SetTickSize(TickSize)
220 hdata.GetXaxis().SetTitleSize(AxisTitleSize)
221 hdata.GetYaxis().SetTitleSize(AxisTitleSize)
222 hdata.GetXaxis().SetLabelSize(AxisLabelSize)
223 hdata.GetYaxis().SetLabelSize(AxisLabelSize)
224 hdata.GetXaxis().SetTitleOffset(1.1)
225 hdata.GetYaxis().SetTitleOffset(1.3)
226 hdata.GetZaxis().SetLabelSize(AxisLabelSize)
227 hdata.SetLineColor(kBlack)
228 hdata.SetLineWidth(1)
230 hsim.SetLineColorAlpha(kRed, 0.5)
232 hsim.Draw(
'box same')
235 c.SaveAs(outname+
'.pdf')
236 c.SaveAs(outname+
'.png')
239 gSystem.ProcessEvents()
244 if __name__ ==
'__main__':
245 parser = OptionParser(usage=
'usage: %prog ver [options -h]')
246 parser.add_option(
'-d',
'--datahistdir', dest=
'datahistdir', type=
'string', default=
'/sphenix/user/hjheng/TrackletAna/analysis_INTT/plot/hists/data_run20869/Hists_RecoTracklets_merged.root', help=
'Histogram file name (data)')
247 parser.add_option(
'-s',
'--simhistdir', action=
'append', dest=
'simhistdir', type=
'string', help=
'Histogram file name (simulation). Example: /sphenix/user/hjheng/TrackletAna/analysis_INTT/plot/hists/ana382_zvtx-20cm_dummyAlignParams/Hists_RecoTracklets_merged.root')
248 parser.add_option(
'-l',
'--simlegtext', action=
'append', dest=
'simlegtext', type=
'string', help=
'Legend text for simulation. Example: HIJING/EPOS/AMPT)')
249 parser.add_option(
'-p',
'--plotdir', dest=
'plotdir', type=
'string', default=
'ana382_zvtx-20cm_dummyAlignParams', help=
'Plot directory')
251 (opt, args) = parser.parse_args()
255 datahistdir = opt.datahistdir
256 simhistdir = opt.simhistdir
257 simlegtext = opt.simlegtext
258 plotdir = opt.plotdir
260 if os.path.isfile(
"{}/hists_merged.root".
format(datahistdir)):
261 os.system(
"rm {}/hists_merged.root".
format(datahistdir))
262 os.system(
"hadd {}/hists_merged.root {}/hists_*.root".
format(datahistdir, datahistdir))
264 os.system(
"hadd {}/hists_merged.root {}/hists_*.root".
format(datahistdir, datahistdir))
266 for simhistd
in simhistdir:
267 if os.path.isfile(
"{}/hists_merged.root".
format(simhistd)):
268 os.system(
"rm {}/hists_merged.root".
format(simhistd))
269 os.system(
"hadd {}/hists_merged.root {}/hists_*.root".
format(simhistd, simhistd))
271 os.system(
"hadd {}/hists_merged.root {}/hists_*.root".
format(simhistd, simhistd))
273 os.makedirs(
'./DataSimComp/{}'.
format(plotdir), exist_ok=
True)
279 hM_dEta_reco_altrange_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dEta_reco_altrange')
280 hM_dEta_reco_altrange_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dEta_reco_altrange_Nclusle4000')
281 hM_dEta_reco_altrange_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dEta_reco_altrange_Nclusgt4000')
283 hM_dPhi_reco_altrange_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dPhi_reco_altrange')
284 hM_dPhi_reco_altrange_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dPhi_reco_altrange_Nclusle4000')
285 hM_dPhi_reco_altrange_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dPhi_reco_altrange_Nclusgt4000')
287 hM_dR_reco_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dR_reco_Nclusle4000')
288 hM_dR_reco_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_dR_reco_Nclusgt4000')
290 hM_Eta_reco_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_Eta_reco_Nclusle4000')
291 hM_Eta_reco_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_Eta_reco_Nclusgt4000')
293 hM_Phi_reco_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_Phi_reco_Nclusle4000')
294 hM_Phi_reco_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_Phi_reco_Nclusgt4000')
296 hM_RecoPVz_Nclusle4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_RecoPVz_Nclusle4000')
297 hM_RecoPVz_Nclusgt4000_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_RecoPVz_Nclusgt4000')
301 hM_cluseta_clusphisize_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_cluseta_clusphisize')
302 hM_clusphi_clusphisize_data =
GetHistogram(
"{}/hists_merged.root".
format(datahistdir),
'hM_clusphi_clusphisize')
304 l_hM_NClusLayer1_sim = []
305 l_hM_NPrototkl_sim = []
306 l_hM_NRecotkl_Raw_sim = []
307 l_hM_dEta_reco_sim = []
308 l_hM_dEta_reco_altrange_sim = []
309 l_hM_dPhi_reco_sim = []
310 l_hM_dPhi_reco_altrange_sim = []
311 l_hM_dR_reco_sim = []
312 l_hM_Eta_reco_sim = []
313 l_hM_Phi_reco_sim = []
314 l_hM_RecoPVz_sim = []
315 l_hM_clusphi_sim = []
316 l_hM_cluseta_sim = []
317 l_hM_clusphisize_sim = []
318 l_hM_cluseta_clusphisize_sim = []
319 l_hM_clusphi_clusphisize_sim = []
320 for i, simhistd
in enumerate(simhistdir):
321 l_hM_NClusLayer1_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_NClusLayer1'))
322 l_hM_NPrototkl_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_NPrototkl'))
323 l_hM_NRecotkl_Raw_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_NRecotkl_Raw'))
324 l_hM_dEta_reco_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_dEta_reco'))
325 l_hM_dEta_reco_altrange_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_dEta_reco_altrange'))
326 l_hM_dPhi_reco_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_dPhi_reco'))
327 l_hM_dPhi_reco_altrange_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_dPhi_reco_altrange'))
328 l_hM_dR_reco_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_dR_reco'))
329 l_hM_Eta_reco_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_Eta_reco'))
330 l_hM_Phi_reco_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_Phi_reco'))
331 l_hM_RecoPVz_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_RecoPVz'))
332 l_hM_clusphi_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_clusphi'))
333 l_hM_cluseta_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_cluseta'))
334 l_hM_clusphisize_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_clusphisize'))
335 l_hM_cluseta_clusphisize_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_cluseta_clusphisize'))
336 l_hM_clusphi_clusphisize_sim.append(
GetHistogram(
"{}/hists_merged.root".
format(simhistd),
'hM_clusphi_clusphisize'))
339 hM_NClusLayer1_data.GetXaxis().SetMaxDigits(2)
340 for hM_NClusLayer1_sim
in l_hM_NClusLayer1_sim:
341 hM_NClusLayer1_sim.GetXaxis().SetMaxDigits(2)
342 Draw_1Dhist_datasimcomp(hM_NClusLayer1_data, l_hM_NClusLayer1_sim, [0.1,0.08,0.15,0.13],
'data',
True, 10,
'Number of clusters (inner)',
'',
False, simlegtext,
'./DataSimComp/{}/NClusLayer1'.
format(plotdir))
343 hM_NPrototkl_data.GetXaxis().SetMaxDigits(2)
344 for hM_NPrototkl_sim
in l_hM_NPrototkl_sim:
345 hM_NPrototkl_sim.GetXaxis().SetMaxDigits(2)
346 Draw_1Dhist_datasimcomp(hM_NPrototkl_data, l_hM_NPrototkl_sim, [0.1,0.08,0.15,0.13],
'data',
True, 3,
'Number of proto-tracklets',
'',
False, simlegtext,
'./DataSimComp/{}/NProtoTracklets'.
format(plotdir))
347 hM_NRecotkl_Raw_data.GetXaxis().SetMaxDigits(2)
348 for hM_NRecotkl_Raw_sim
in l_hM_NRecotkl_Raw_sim:
349 hM_NRecotkl_Raw_sim.GetXaxis().SetMaxDigits(2)
350 Draw_1Dhist_datasimcomp(hM_NRecotkl_Raw_data, l_hM_NRecotkl_Raw_sim, [0.1,0.08,0.15,0.13],
'data',
True, 10,
'Number of reco-tracklets',
'',
False, simlegtext,
'./DataSimComp/{}/NRecoTracklets_Raw'.
format(plotdir))
351 Draw_1Dhist_datasimcomp(hM_RecoPVz_data, l_hM_RecoPVz_sim, [0.1,0.08,0.15,0.13],
'data',
True, 250,
'Reco PV z [cm]',
'cm',
False, simlegtext,
'./DataSimComp/{}/RecoPVz'.
format(plotdir))
353 Draw_1Dhist_datasimcomp(hM_clusphi_data, l_hM_clusphi_sim, [0.1,0.08,0.15,0.13],
'data',
False, 1.8,
'Cluster #phi',
'',
False, simlegtext,
'./DataSimComp/{}/Cluster_Phi'.
format(plotdir))
354 Draw_1Dhist_datasimcomp(hM_cluseta_data, l_hM_cluseta_sim, [0.1,0.08,0.15,0.13],
'data',
False, 1.8,
'Cluster #eta',
'',
False, simlegtext,
'./DataSimComp/{}/Cluster_Eta'.
format(plotdir))
355 Draw_1Dhist_datasimcomp(hM_clusphisize_data, l_hM_clusphisize_sim, [0.1,0.08,0.15,0.13],
'data',
True, 10,
'Cluster #phi size',
'',
False, simlegtext,
'./DataSimComp/{}/Cluster_PhiSize'.
format(plotdir))
357 Draw_1Dhist_datasimcomp(hM_dEta_reco_data, l_hM_dEta_reco_sim, [0.08,0.08,0.15,0.13],
'data',
True, 250,
'Reco-tracklet #Delta#eta',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_dEta'.
format(plotdir))
358 Draw_1Dhist_datasimcomp(hM_dEta_reco_altrange_data, l_hM_dEta_reco_altrange_sim, [0.08,0.08,0.15,0.13],
'data',
True, 250,
'Reco-tracklet #Delta#eta',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_dEta_altrange'.
format(plotdir))
360 Draw_1Dhist_datasimcomp(hM_dPhi_reco_data, l_hM_dPhi_reco_sim, [0.08,0.08,0.15,0.13],
'data',
True, 500,
'Reco-tracklet #Delta#phi',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_dPhi'.
format(plotdir))
361 hM_dPhi_reco_altrange_data.GetXaxis().SetMaxDigits(2)
362 for hM_dPhi_reco_altrange_sim
in l_hM_dPhi_reco_altrange_sim:
363 hM_dPhi_reco_altrange_sim.GetXaxis().SetMaxDigits(2)
364 Draw_1Dhist_datasimcomp(hM_dPhi_reco_altrange_data, l_hM_dPhi_reco_altrange_sim, [0.1,0.08,0.15,0.13],
'data',
True, 150,
'Reco-tracklet #Delta#phi',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_dPhi_altrange'.
format(plotdir))
366 Draw_1Dhist_datasimcomp(hM_dR_reco_data, l_hM_dR_reco_sim, [0.08,0.08,0.15,0.13],
'data',
True, 3,
'Reco-tracklet #DeltaR',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_dR'.
format(plotdir))
368 Draw_1Dhist_datasimcomp(hM_Eta_reco_data, l_hM_Eta_reco_sim, [0.08,0.08,0.15,0.13],
'data',
False, 1.8,
'Reco-tracklet #eta',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_Eta'.
format(plotdir))
370 Draw_1Dhist_datasimcomp(hM_Phi_reco_data, l_hM_Phi_reco_sim, [0.08,0.08,0.15,0.13],
'data',
False, 1.8,
'Reco-tracklet #phi',
'',
False, simlegtext,
'./DataSimComp/{}/RecoTracklet_Phi'.
format(plotdir))
371 hM_Phi_reco_Nclusle4000_data.GetYaxis().SetMaxDigits(2)
372 hM_Phi_reco_Nclusgt4000_data.GetYaxis().SetMaxDigits(2)
373 for hM_Phi_reco_sim
in l_hM_Phi_reco_sim:
374 hM_Phi_reco_sim.GetYaxis().SetMaxDigits(2)
378 Draw_2Dhist_datasimcomp(hM_cluseta_clusphisize_data, l_hM_cluseta_clusphisize_sim[0],
False,
'data', 0.1,
'Cluster #eta',
'Cluster #phi size',
'./DataSimComp/{}/ClusEta_ClusPhiSize'.
format(plotdir))
379 Draw_2Dhist_datasimcomp(hM_clusphi_clusphisize_data, l_hM_clusphi_clusphisize_sim[0],
False,
'data', 0.1,
'Cluster #phi',
'Cluster #phi size',
'./DataSimComp/{}/ClusPhi_ClusPhiSize'.
format(plotdir))