118def plotStack(name,histo,index,indexName,histoIntLumi,lumiBool,resStack,resCanvas,resLegend,recovBool = True,compBool = False,approvedPlots = False):
137 nameSplitted = name.split(
"--")
138 xAxisTitle = nameSplitted[1]
140 yAxisTitle =
"Lost luminosity due to %s [%%]"%(nameSplitted[0])
142 yAxisTitle =
"Lost luminosity due to %s [%s]"%(nameSplitted[0],unit)
143 legendHeader =
"%s - %s"%(nameSplitted[2],time.strftime(
"%d %b", time.localtime()))
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,
"",
"")
155 nBinsX = histoIntLumi.GetNbinsX()
158 totalIneff_comp = nBinsX * [0.]
160 totalIntegratedLumi = histoIntLumi.GetBinContent(nBinsX)
162 auxScaleFactor = 100./totalIntegratedLumi
164 auxScaleFactor = totalIntegratedLumi/100.
166 tmpColor = [kBlue-4,kOrange-7,kTeal+1,kMagenta-4,kPink-3,kGreen+3,kSpring-3,kViolet+4,kAzure-8,kCyan+1]
169 for iIndex
in sorted(index,reverse=
True):
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)
174 iIndexName = iIndex.split(
"_")[0]
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
185 if (histo[iIndex]).
IsA().InheritsFrom(
"TProfile"):
186 histo[
'%s_toStack'%iIndex] = histo[iIndex].ProjectionX()
187 histo[
'%s_toStack'%iIndex].SetFillColor(histo[iIndex].GetFillColor())
189 histo[
'%s_toStack'%iIndex] = histo[iIndex]
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])
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))
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))
207 entry =
"#splitline{%s}{%s / %s}"%(indexName[iIndex],baseEntry,auxEntry)
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))
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))
222 entry =
"%s"%(indexName[iIndexName])
224 if (histo[iIndex].GetMaximum() != 0):
225 resLegend[name].AddEntry(histo[iIndex],entry,
"f")
230 if (
"allIntol" in list(histo.keys())):
231 allIndex =
"allIntol"
232 if (
"allVeto" in list(histo.keys())):
237 for iBin
in range(1,nBinsX+1):
238 totalIneff_comp[iBin-1] = histo[allIndex].GetBinContent(iBin)
240 totalIneff = histo[allIndex].GetBinContent(nBinsX)
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)
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)))
263 resLegend[name].SetHeader(
"%s"%(legendHeader))
265 totalIneffAux = totalIneff*auxScaleFactor
267 resLegend[name].SetHeader(
"#splitline{%s}{Total loss: %s / %s}"%(legendHeader,
strLumi(totalIneff,unit),
strLumi(totalIneffAux,unitAux)))
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)))
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
281 resLegend[name].SetTextSize(0.035)
283 resLegend[name].SetTextSize(0.028)
285 resLegend[name].SetY1(
max(0.83-entryNb*0.098,0.05))
286 resLegend[name].Draw()
288 resCanvas[name].Update()