118def plotStack(name,histo,index,indexName,histoIntLumi,lumiBool,resStack,resCanvas,resLegend,recovBool = True,compBool = False,approvedPlots = False):
119
120
121
122
123
124
125
126
127
128
129
130 if (lumiBool):
131 unit = "pb^{-1}"
132 unitAux = "%%"
133 else:
134 unit = "%%"
135 unitAux = "pb^{-1}"
136
137 nameSplitted = name.split("--")
138 xAxisTitle = nameSplitted[1]
139 if unit == "%%":
140 yAxisTitle = "Lost luminosity due to %s [%%]"%(nameSplitted[0])
141 else:
142 yAxisTitle = "Lost luminosity due to %s [%s]"%(nameSplitted[0],unit)
143 legendHeader = "%s - %s"%(nameSplitted[2],time.strftime("%d %b", time.localtime()))
144
145 resCanvas[name] = TCanvas(name,"%s - %s"%(yAxisTitle,xAxisTitle),100, 10, 1350, 500)
146 resCanvas[name].SetLeftMargin(0.08)
147 resCanvas[name].SetRightMargin(0.35)
148 resCanvas[name].SetGridy(1)
149 resStack[name] = THStack("%s_stack"%name,"")
150 resLegend[name] = MakeLegend(0.66,0.8,0.98,0.95)
151 resLegend[name].AddEntry(0, "", "")
152
153 first = True
154
155 nBinsX = histoIntLumi.GetNbinsX()
156 totalIneff = 0.
157 if (compBool):
158 totalIneff_comp = nBinsX * [0.]
159
160 totalIntegratedLumi = histoIntLumi.GetBinContent(nBinsX)
161 if lumiBool:
162 auxScaleFactor = 100./totalIntegratedLumi
163 else:
164 auxScaleFactor = totalIntegratedLumi/100.
165
166 tmpColor = [kBlue-4,kOrange-7,kTeal+1,kMagenta-4,kPink-3,kGreen+3,kSpring-3,kViolet+4,kAzure-8,kCyan+1]
167 tmpColorIndex = 0
168
169 for iIndex in sorted(index,reverse=True):
170 if first:
171 resStack["%s__recov"%name] = MakeTH1("h1_%s__recovTotal"%(name),"Recoverable","",-0.5,-0.5+nBinsX,nBinsX,1)
172 resStack["%s__recov"%name].SetMarkerStyle(23)
173 first = False
174 iIndexName = iIndex.split("_")[0]
175
176
177
178
179 if (histo[iIndex].GetFillColor() == kBlack and tmpColorIndex < len(tmpColor) and histo[iIndex].GetBinContent(histo[iIndex].GetNbinsX()) != 0):
180 histo[iIndex].SetFillColor(tmpColor[tmpColorIndex])
181 tmpColorIndex = tmpColorIndex + 1
182
183
184
185 if (histo[iIndex]).
IsA().InheritsFrom(
"TProfile"):
186 histo['%s_toStack'%iIndex] = histo[iIndex].ProjectionX()
187 histo['%s_toStack'%iIndex].SetFillColor(histo[iIndex].GetFillColor())
188 else:
189 histo['%s_toStack'%iIndex] = histo[iIndex]
190 if lumiBool:
191 histo['%s_toStack'%iIndex].Multiply(histo['%s_toStack'%iIndex],histoIntLumi,0.01)
192 histo['%s_toStack'%iIndex].LabelsOption("v")
193 resStack[name].Add(histo['%s_toStack'%iIndex])
194
195 entryNb = 0
196 for iIndex in sorted(index):
197 iIndexName = iIndex.split("__")[0]
198 baseEntry = "%s"%(strLumi(histo['%s_toStack'%iIndex].GetBinContent(nBinsX),unit))
199 auxEntry = "%s"%(strLumi(histo['%s_toStack'%iIndex].GetBinContent(nBinsX)*auxScaleFactor,unitAux))
200
201 if (recovBool and "%s__recov"%iIndex in list(histo.keys()) and histo["%s__recov"%iIndex].GetBinContent(nBinsX) != 0.):
202 baseEntryRecov = "%s"%(strLumi(histo["%s__recov"%iIndex].GetBinContent(nBinsX),unit))
203 entry = "#splitline{%s}{%s(recov:%s) / %s}"%(indexName[iIndexName],baseEntry,baseEntryRecov,auxEntry)
204 for iBin in range(nBinsX+1):
205 resStack["%s__recov"%name].Fill(iBin-1,histo["%s__recov"%iIndex].GetBinContent(iBin))
206 else:
207 entry = "#splitline{%s}{%s / %s}"%(indexName[iIndex],baseEntry,auxEntry)
208
209 if (compBool):
210 if histo[iIndex].GetNbinsX() >= 2 and histo[iIndex].GetNbinsX()<5:
211 if histo[iIndex].GetBinContent(1) != 0.:
212 entry = "#splitline{%s}{%s"%(indexName[iIndexName],strLumi(histo[iIndex].GetBinContent(1),unit))
213 else:
214 entry = "#splitline{%s}{ - "%(indexName[iIndexName])
215 for iTag in range(2,histo[iIndex].GetNbinsX()+1):
216 if histo[iIndex].GetBinContent(iTag) != 0.:
217 entry += " / %s "%(strLumi(histo[iIndex].GetBinContent(iTag),unit))
218 else:
219 entry += " / - "
220 entry += "}"
221 else:
222 entry = "%s"%(indexName[iIndexName])
223
224 if (histo[iIndex].GetMaximum() != 0):
225 resLegend[name].AddEntry(histo[iIndex],entry,"f")
226 entryNb = entryNb+1
227
228
229 allIndex = ""
230 if ("allIntol" in list(histo.keys())):
231 allIndex = "allIntol"
232 if ("allVeto" in list(histo.keys())):
233 allIndex = "allVeto"
234
235 if allIndex != "":
236 if compBool:
237 for iBin in range(1,nBinsX+1):
238 totalIneff_comp[iBin-1] = histo[allIndex].GetBinContent(iBin)
239 else:
240 totalIneff = histo[allIndex].GetBinContent(nBinsX)
241
242 mx = resStack[name].GetMaximum()*1.2
243 resStack[name].SetMaximum(mx)
244 resStack[name].Draw("hist")
245 resStack[name].GetXaxis().LabelsOption("v")
246 resStack[name].GetXaxis().SetLabelSize(0.04)
247 resStack[name].GetXaxis().SetTitle("%s"%xAxisTitle)
248 resStack[name].GetXaxis().SetTitleOffset(1.45)
249 resStack[name].GetYaxis().SetTitle("%s"%yAxisTitle)
250 resStack[name].GetYaxis().SetTitleOffset(0.7)
251 if resStack[name].GetMaximum()>10.:
252 resCanvas[name].SetLogy(1)
253
254 if compBool:
255 resStack[name].GetXaxis().SetLabelSize(0.065)
256 if histo[iIndex].GetNbinsX() == 2:
257 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit)))
258 elif histo[iIndex].GetNbinsX() == 3:
259 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit),strLumi(totalIneff_comp[2],unit)))
260 elif histo[iIndex].GetNbinsX() == 4:
261 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s / %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit),strLumi(totalIneff_comp[2],unit),strLumi(totalIneff_comp[3],unit)))
262 else:
263 resLegend[name].SetHeader("%s"%(legendHeader))
264 else:
265 totalIneffAux = totalIneff*auxScaleFactor
266 if (approvedPlots):
267 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIneff,unit),strLumi(totalIneffAux,unitAux)))
268 else:
269 if (totalIneff != 0.):
270 resLegend[name].SetHeader("#splitline{%s (%s)}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIntegratedLumi,"pb"),strLumi(totalIneff,unit),strLumi(totalIneffAux,unitAux)))
271 else:
272 resLegend[name].SetHeader("%s (%s)"%(legendHeader,strLumi(totalIntegratedLumi,"pb")))
273 if resStack[
"%s__recov"%name].
GetEntries() != 0.:
274 resStack["%s__recov"%name].SetMarkerStyle(20)
275 resStack["%s__recov"%name].SetMarkerColor(kAzure+8)
276 resStack["%s__recov"%name].Draw("PSAME HIST")
277 resLegend[name].AddEntry(resStack["%s__recov"%name],"#splitline{Recoverable}{total: %.2f%%}"%(resStack["%s__recov"%name].GetBinContent(nBinsX)),"p")
278 entryNb = entryNb + 1
279
280 if (entryNb<9):
281 resLegend[name].SetTextSize(0.035)
282 else:
283 resLegend[name].SetTextSize(0.028)
284
285 resLegend[name].SetY1(
max(0.83-entryNb*0.098,0.05))
286 resLegend[name].Draw()
287
288 resCanvas[name].Update()
289
290 return totalIneff
291
TGraphErrors * GetEntries(TH2F *histo)
#define IsA
Declare the TObject style functions.