57def plotSummaryRatio(dict1, dict2, xaxis, v1, v2, directory="", name =""):
58 NCats = len(dict1)
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]
64 hmap1 = {}
65 hmap2 = {}
66
67 nevents = 1000.
68
69 leg = ROOT.TLegend(0.7,0.89-0.07*len(particles),0.92,0.89)
70 leg.SetNColumns(1)
71 leg.SetBorderSize(0)
72 leg.SetFillColor(0)
73 leg.SetFillStyle(0)
74 leg.SetTextSize(0.06)
75
76 for p in particles:
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))
79 i_adjusted = 0
80 for i,a in enumerate(sorted1):
81 cat = a[0]
82 if cat == "other":
83 continue
84 fillHisto(h1,dict1,2*i_adjusted+1,p,cat)
85 fillHisto(h2,dict2,2*i_adjusted+1+1,p,cat)
86 i_adjusted += 1
87 if not xaxis == "Processes":
88 fillHisto(h1,dict1,2*len(sorted1)-1,p,"other")
89 fillHisto(h2,dict2,2*len(sorted1),p,"other")
90 hmap1[p] = h1
91 hmap2[p] = h2
92
93 hs1 = ROOT.THStack()
94 hs2 = ROOT.THStack()
95 for p in particles:
96 hmap1[p].
Scale(1./nevents)
97 hmap2[p].
Scale(1./nevents)
98 hs1.Add(hmap1[p])
99 hs2.Add(hmap2[p])
100 setFillLineColor(hmap1[p],p, colors)
101 setFillLineColor(hmap2[p],p, colorsNew)
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")
105 else:
106 leg.AddEntry(hmap1[p],"#font[42]{%s}"%p,"f")
107
108 canv, pad1, pad2 = summary.getCanvas(uniqueName)
109
110 h2 = divide(hs1,hs2)
111
112 pad1.cd()
113
114 hs1.SetMaximum(hs1.GetStack().Last().GetBinContent(1)*1.2)
115 hs1.Draw("hist")
116 hs2.Draw("hist same")
117 if xaxis == "Processes":
118 hs1.GetXaxis().SetRangeUser(0,40)
119 hs2.GetXaxis().SetRangeUser(0,40)
120
121 hs1.GetYaxis().SetTitleOffset(0.7)
122 leg.Draw()
123 if AtlasStyle:
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)
128
129 summary.configureUpperPad(hs1)
130
131 pad1.Update()
132 ymax = ROOT.gPad.GetUymax()*0.55
133 ymin = ROOT.gPad.GetUymin()
134 l1 = ROOT.TLine(6,ymin,6,ymax)
135 l1.SetLineStyle(2)
136 l1.Draw()
137 l2 = ROOT.TLine(7,ymin,7,ymax)
138 l2.SetLineStyle(2)
139 l2.Draw()
140 l3 = ROOT.TLine(8,ymin,8,ymax)
141 l3.SetLineStyle(2)
142 l3.Draw()
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)
145
146
147 pad2.cd()
148 pad2.SetGridy()
149 h2.Draw("hist")
150 if xaxis == "Processes":
151 h2.GetXaxis().SetRangeUser(0,20)
152 summary.configureLowerPad(h2, 0.5, 0.1, xaxis, v2+" / "+v1)
153
154 canv.Print(os.path.join(directory,("%s.pdf" % xaxis)))
155 canv.Print(os.path.join(directory,("%s.png" % xaxis)))
156
157
void print(char *figname, TCanvas *c1)
void Scale(TH1 *h, double d=1)