5 from G4DebuggerConfig
import *
8 print(
"setting ATLAS Style")
22 if cat
in catDict.keys()
and p
in catDict[cat].
keys():
23 h.SetBinContent(i,catDict[cat][p])
26 if not cat
in translate.keys():
27 h.GetXaxis().SetBinLabel(i, cat)
29 h.GetXaxis().SetBinLabel(i, translate[cat])
32 h.SetFillColor(hcolors[p])
33 if p
not in samecolor:
35 h.SetLineColor(linecolor[p])
37 h.SetLineColor(hcolors[p]+2)
39 h.SetLineColor(hcolors[p])
40 if p
in styles.keys():
41 h.SetFillStyle(styles[p])
44 h1 = hs1.GetStack().Last().Clone()
45 h2 = hs2.GetStack().Last().Clone()
46 name = h1.GetName()+
"ratio"
47 nHalf =
int(h1.GetNbinsX()/2)
48 h = ROOT.TH1F(name,name,nHalf,0,nHalf)
49 for i
in range(nHalf):
50 denum = h1.GetBinContent(1+2*i)
if h1.GetBinContent(1+2*i)!=0
else -1
51 h.SetBinContent(i+1,h2.GetBinContent(1+2*i+1)/denum)
52 binLabel =
rename(h1.GetXaxis().GetBinLabel(1+2*i))
53 h.GetXaxis().SetBinLabel(1+i, binLabel)
59 integral1 =
sum([
sum(dict1[cat].
values())
for cat
in dict1])
60 integral2 =
sum([
sum(dict2[cat].
values())
for cat
in dict2])
61 print(NCats,
" ",integral1,
" ",integral2)
62 sorted1 =
sorted(dict1.items(), key=
lambda kv:
sum(kv[1].
values()), reverse=
True)
63 uniqueName = name + sorted1[0][0]
69 leg = ROOT.TLegend(0.7,0.89-0.07*len(particles),0.92,0.89)
77 h1 = ROOT.TH1F(uniqueName+
"1"+p,uniqueName+
"1"+p,2*len(sorted1),0,2*len(sorted1))
78 h2 = ROOT.TH1F(uniqueName+
"2"+p,uniqueName+
"2"+p,2*len(sorted1),0,2*len(sorted1))
80 for i,a
in enumerate(sorted1):
85 fillHisto(h2,dict2,2*i_adjusted+1+1,p,cat)
87 if not xaxis ==
"Processes":
88 fillHisto(h1,dict1,2*len(sorted1)-1,p,
"other")
89 fillHisto(h2,dict2,2*len(sorted1),p,
"other")
96 hmap1[p].
Scale(1./nevents)
97 hmap2[p].
Scale(1./nevents)
102 for p
in reversed(particles):
103 if p
in translate.keys()
and p !=
'other':
104 leg.AddEntry(hmap1[p],
"#font[42]{%s}"%translate[p],
"f")
106 leg.AddEntry(hmap1[p],
"#font[42]{%s}"%p,
"f")
108 canv, pad1, pad2 = summary.getCanvas(uniqueName)
114 hs1.SetMaximum(hs1.GetStack().Last().GetBinContent(1)*1.2)
116 hs2.Draw(
"hist same")
117 if xaxis ==
"Processes":
118 hs1.GetXaxis().SetRangeUser(0,40)
119 hs2.GetXaxis().SetRangeUser(0,40)
121 hs1.GetYaxis().SetTitleOffset(0.7)
124 ROOT.ATLASLabel(0.3,0.84,
"Simulation Preliminary",1,0.06)
125 ROOT.myText(0.3,0.77,1,
"#sqrt{s}=13 TeV, 10k t#bar{t} events",0.06)
126 ROOT.myText(0.3,0.70,1,
"NRR (E = 1 MeV, w = 10)",0.06)
127 ROOT.myText(0.3,0.63,1,
"#oplus EM Range Cuts",0.06)
129 summary.configureUpperPad(hs1)
132 ymax = ROOT.gPad.GetUymax()*0.55
133 ymin = ROOT.gPad.GetUymin()
134 l1 = ROOT.TLine(6,ymin,6,ymax)
137 l2 = ROOT.TLine(7,ymin,7,ymax)
140 l3 = ROOT.TLine(8,ymin,8,ymax)
143 ROOT.myTextAbs(6.1, 0.8*ymax, 1,
"Non optimized", 0.055)
144 ROOT.myTextAbs(7.1, 0.6*ymax, 1,
"Optimized", 0.055)
150 if xaxis ==
"Processes":
151 h2.GetXaxis().SetRangeUser(0,20)
152 summary.configureLowerPad(h2, 0.5, 0.1, xaxis, v2+
" / "+v1)
154 canv.Print(os.path.join(directory,(
"%s.pdf" % xaxis)))
155 canv.Print(os.path.join(directory,(
"%s.png" % xaxis)))
160 leg = ROOT.TLegend(0.18,0.74-0.05*len(h1),0.4,0.74)
165 leg.SetTextSize(0.045)
178 if not p
in h1.keys():
continue
179 if not p
in h2.keys():
continue
180 uniqueName = h1[p].GetName()
183 h1[p].SetLineColor(colors[p]+2)
184 h2[p].SetLineColor(colorsNew[p])
185 underflow1 += h1[p].GetBinContent(0)
186 underflow2 += h2[p].GetBinContent(0)
195 hR.SetBinContent(0,1)
197 leg.AddEntry(h1[p],
"#font[42]{%s}"%p,
"l")
198 leg.AddEntry(h2[p],
"#font[42]{%s}"%p,
"l")
204 if hisType
in [
"numberOfSteps"]:
207 if hisType
in [
"CumulativeInitialE",
"CumulativeNumberOfStepsPerInitialE"]:
211 canv, pad1, pad2 = histograms.getCanvas(uniqueName+
"canv", nologx, nology)
214 frac1 = 100*underflow1/all1
215 frac2 = 100*underflow2/all2
218 hs.Draw(
"nostack hist")
220 hs.SetMaximum(hs.GetStack().Last().GetMaximum()*1e3)
222 ROOT.ATLASLabel(0.18,0.87,
"Simulation Internal",1)
223 ROOT.myText(0.18,0.81,1,
"#sqrt{s}=13 TeV, %s (%2.1f%s)" % (lab,frac,
"%"))
225 underTxt =
"under: %1.2E (%2.2f%s) %1.2E (%2.2f%s)" % (underflow1, frac1,
"%", underflow2, frac2,
"%")
226 ROOT.myText(0.51,0.81,1,underTxt)
227 ROOT.myText(0.58,0.87,1,
"%s %s" % (v1,v2))
228 if hisType
in [
"numberOfSteps"]:
230 legTemp = leg.Clone()
231 legTemp.SetX1(legTemp.GetX1()+shiftx)
232 legTemp.SetX2(legTemp.GetX2()+shiftx)
234 ROOT.myText(0.18+shiftx,0.75,1,
"%s: %s:" % (v1,v2))
237 ROOT.myText(0.18,0.75,1,
"%s: %s:" % (v1,v2))
239 if hisType
in [
"numberOfSteps",
"InitialE"]:
241 elif hisType
in [
"CumulativeInitialE"]:
242 yaxis =
"Cumulative tracks"
243 elif hisType
in [
"CumulativeNumberOfStepsPerInitialE"]:
244 yaxis =
"Cumulative steps"
245 elif hisType ==
"averageNumberOfStepsPerInitialE":
246 yaxis =
"Avg. number of steps in track"
247 histograms.configureUpperPad(hs, yaxis)
251 hsR.Draw(
"nostack hist")
252 histograms.configureLowerPad(hsR, 0.5
if "Leng" in hisType
else 1.0, labelAll[hisType], v2+
"/"+v1)
254 canv.Print(os.path.join(directory,hisType+
".pdf"))
255 canv.Print(os.path.join(directory,hisType+
".png"))
257 def plot2D(h,G4Version,v,ALL_STEPS,yaxis,directory):
260 uniqueName = h.GetName()+G4Version+v
261 canv = ROOT.TCanvas(uniqueName+
"c",uniqueName+
"c",800,600)
262 canv.SetRightMargin(0.20)
263 canv.SetTopMargin(0.07)
268 integral = h.Integral(0,nx+1,0,ny+1)
270 h.GetXaxis().SetTitle(
"z [mm]")
271 h.GetYaxis().SetTitle(
"r [mm]")
272 h.GetZaxis().SetTitle(
"Steps" if not yaxis
else yaxis)
273 h.GetZaxis().SetTitleOffset(1.2)
274 h.GetXaxis().SetNdivisions(505)
276 ROOT.ATLASLabel(0.18,0.87,
"Simulation Internal",1)
277 ROOT.myText(0.18,0.81,1,
"#sqrt{s}=13 TeV, G4.%s" % G4Version)
278 ROOT.myText(0.18,0.75,1,v + (
" (%2.1f%s)" % (100*integral/ALL_STEPS,
"%"))
if ALL_STEPS
else "")
279 ROOT.gPad.RedrawAxis()
281 canv.Print(os.path.join(directory,
"2DMapGeant4.%s.pdf" % G4Version))
282 canv.Print(os.path.join(directory,
"2DMapGeant4.%s.png" % G4Version))
284 canv.Print(os.path.join(directory,
"2DMapDiff.pdf"))
285 canv.Print(os.path.join(directory,
"2DMapDiff.png"))