15 print "\nCannot load PYROOT, make sure you have setup ROOT in the path"
16 print "and pyroot library is also defined in the variable PYTHONPATH, try:\n"
17 if (os.getenv(
"PYTHONPATH")):
18 print " setenv PYTHONPATH ${PYTHONPATH}:$ROOTSYS/lib\n"
20 print " setenv PYTHONPATH $ROOTSYS/lib\n"
23 from ROOT
import TFile
24 from ROOT
import TCanvas
26 from ROOT
import TLegend
27 from ROOT
import TLatex
30 from ROOT
import TVectorD
31 from ROOT
import TGraphErrors
32 from ROOT
import Double
35 from listHistos
import *
40 fileNameVal =
"BTagRelVal_TTbar_Startup_14_612SLHC2.root"
41 fileNameRef =
"BTagRelVal_TTbar_Startup_612SLHC1_14.root"
43 ValRel =
"612SLHC2_14"
44 RefRel =
"612SLHC1_14"
46 ValSample =
"TTbar_FullSim"
47 RefSample =
"TTbar_FullSim"
53 Banner =
"CMS Preliminary"
57 pathInFile =
"/DQMData/Run 1/Btag/Run summary/"
130 unity = TF1(
"unity",
"1",-1000,1000)
131 unity.SetLineColor(8)
132 unity.SetLineWidth(1)
133 unity.SetLineStyle(1)
184 if histos
is None :
return
185 if isVal : sample =
"Val"
186 else : sample =
"Ref"
192 if plot.binning
and len(plot.binning)==3 :
193 histos[k].SetBins(plot.binning[0],plot.binning[1],plot.binning[2])
194 elif plot.binning
and len(plot.binning)==2 :
195 nbins=plot.binning[1]+1-plot.binning[0]
196 xmin=histos[k].GetBinLowEdge(plot.binning[0])
197 xmax=histos[k].GetBinLowEdge(plot.binning[1]+1)
198 valtmp=TH1F(histos[k].GetName(),histos[k].GetTitle(),nbins,xmin,xmax)
200 for bin
in range(plot.binning[0],plot.binning[1]+1) :
201 valtmp.SetBinContent(i,histos[k].GetBinContent(bin))
204 if plot.Rebin
and plot.Rebin > 0 :
205 histos[k].
Rebin(plot.Rebin)
207 histos[k].SetLineColor(mapColor[k])
208 histos[k].SetMarkerColor(mapColor[k])
209 histos[k].SetMarkerStyle(mapMarker[sample])
210 if drawOption ==
"HIST" :
211 histos[k].SetLineWidth(mapLineWidth[sample])
212 histos[k].SetLineStyle(mapLineStyle[sample])
216 if plot.doNormalization :
217 histos[k].Scale(1./histos[k].Integral())
219 histos[k].Scale(weight)
221 if histos[k].GetMinimum(0.) < minY :
222 minY = histos[k].GetMinimum(0.)
224 if histos[k].GetBinContent(histos[k].GetMaximumBin()) > maxY :
225 maxY = histos[k].GetBinContent(histos[k].GetMaximumBin())+histos[k].GetBinError(histos[k].GetMaximumBin())
228 histos[k].SetXTitle(plot.Xlabel)
230 histos[k].SetYTitle(plot.Ylabel)
231 outhistos.append(histos[k])
233 if not plot.logY : outhistos[0].GetYaxis().SetRangeUser(0,1.1*maxY)
235 else : outhistos[0].GetYaxis().SetRangeUser(
max(0.0001,0.5*minY),1.1*maxY)
239 def graphProducer(plot,histos,tagFlav="B",mistagFlav=["C","DUSG"],isVal=True):
240 if histos
is None :
return
241 if isVal : sample =
"Val"
242 else : sample =
"Ref"
246 if tagFlav
not in listFlavors :
248 if plot.tagFlavor
and plot.mistagFlavor :
249 tagFlav = plot.tagFlavor
250 mistagFlav = plot.mistagFlavor
251 for f
in listFlavors :
257 for f
in listFlavors :
261 maxnpoints = histos[tagFlav].GetNbinsX()
262 for f
in listFlavors :
263 Eff[f].
append(histos[f].GetBinContent(1))
264 EffErr[f].
append(histos[f].GetBinError(1))
265 for bin
in range(2,maxnpoints+1) :
267 if len(Eff[tagFlav])>0 :
268 delta = Eff[tagFlav][-1]-histos[tagFlav].GetBinContent(bin)
269 if delta>
max(0.005,EffErr[tagFlav][-1]) :
271 for f
in listFlavors :
272 Eff[f].
append(histos[f].GetBinContent(bin))
273 EffErr[f].
append(histos[f].GetBinError(bin))
275 len_ = len(Eff[tagFlav])
278 for f
in listFlavors :
279 TVec_Eff[f] = TVectorD(len_)
280 TVec_EffErr[f] = TVectorD(len_)
282 for j
in range(0,len_) :
283 for f
in listFlavors :
284 TVec_Eff[f][j] = Eff[f][j]
285 TVec_EffErr[f][j] = EffErr[f][j]
287 for mis
in mistagFlav :
288 g[tagFlav+mis]=TGraphErrors(TVec_Eff[tagFlav],TVec_Eff[mis],TVec_EffErr[tagFlav],TVec_EffErr[mis])
290 for f
in listFlavors :
291 if f
not in mistagFlav :
continue
292 g[tagFlav+f].SetLineColor(mapColor[f])
293 g[tagFlav+f].SetMarkerStyle(mapMarker[sample])
294 g[tagFlav+f].SetMarkerColor(mapColor[f])
295 g_out.append(g[tagFlav+f])
299 if g_i
is not None :
break
301 g_out[index].GetXaxis().SetRangeUser(0,1)
302 g_out[index].GetYaxis().SetRangeUser(0.0001,1)
304 g_out[index].GetXaxis().SetTitle(plot.Xlabel)
306 g_out[index].GetYaxis().SetTitle(plot.Ylabel)
308 for index,f
in enumerate(listFlavors) :
309 if f
not in mistagFlav : g_out.insert(index,
None)
313 def savePlots(title,saveName,listFromats,plot,Histos,keyHisto,listLegend,options,ratios=None,legendName="") :
318 c[keyHisto] = TCanvas(saveName,keyHisto+plot.title,700,700+24*len(listFlavors))
319 pads[
"hist"] = TPad(
"hist", saveName+plot.title,0,0.11*len(listFlavors),1.0,1.0)
321 c[keyHisto] = TCanvas(keyHisto,saveName+plot.title,700,700)
322 pads[
"hist"] = TPad(
"hist", saveName+plot.title,0,0.,1.0,1.0)
325 for r
in range(0,len(ratios)) :
326 pads[
"ratio_"+str(r)] = TPad(
"ratio_"+str(r), saveName+plot.title+str(r),0,0.11*r,1.0,0.11*(r+1))
327 pads[
"ratio_"+str(r)].Draw()
330 if plot.logY : pads[
"hist"].SetLogy()
331 if plot.grid : pads[
"hist"].SetGrid()
333 leg = TLegend(0.6,0.4,0.8,0.6)
335 leg.SetTextSize(0.035)
341 optionSame = drawOption+
"same"
342 if plot.doPerformance :
345 for i
in range(0,len(Histos)) :
346 if Histos[i]
is None :
continue
348 if not plot.doPerformance : Histos[i].GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0)
349 Histos[i].SetTitle(title)
350 Histos[i].Draw(option)
352 else : Histos[i].Draw(optionSame)
354 if plot.legend
and len(Histos)%len(listLegend)==0:
355 r=len(Histos)/len(listLegend)
356 index=i-r*len(listLegend)
358 index+=len(listLegend)
359 legName = legendName.replace(
"KEY",listLegend[index])
360 if i<len(listLegend) : legName = legName.replace(
"isVAL",options.ValRel)
361 else : legName = legName.replace(
"isVAL",options.RefRel)
362 if drawOption==
"HIST" :
363 leg.AddEntry(Histos[i],legName,
"L")
365 leg.AddEntry(Histos[i],legName,
"P")
367 if plot.legend
and options.drawLegend : leg.Draw(
"same")
369 if options.printBanner :
370 print type(options.printBanner)
371 tex = TLatex(0.55,0.75,options.Banner)
373 tex.SetTextSize(0.05)
377 for r
in range(0,len(ratios)) :
378 pads[
"ratio_"+str(r)].cd()
379 if ratios[r]
is None :
continue
380 pads[
"ratio_"+str(r)].SetGrid()
381 ratios[r].GetYaxis().SetTitle(listLegend[r]+
"-jets")
382 ratios[r].GetYaxis().SetTitleSize(0.15)
383 ratios[r].GetYaxis().SetTitleOffset(0.2)
384 ratios[r].GetYaxis().SetNdivisions(3,3,2)
387 for format
in listFromats :
388 save = saveName+
"."+format
389 c[keyHisto].
Print(save)
390 return [c,leg,tex,pads]
394 for h_i
in range(0,len(hVal)):
395 if hVal[h_i]
is None :
continue
396 r = TH1F(hVal[h_i].GetName()+
"ratio",
"ratio "+hVal[h_i].GetTitle(),hVal[h_i].GetNbinsX(),hVal[h_i].GetXaxis().GetXmin(),hVal[h_i].GetXaxis().GetXmax())
399 r.GetYaxis().SetRangeUser(0.25,1.75)
400 r.SetMarkerColor(hVal[h_i].GetMarkerColor())
401 r.SetLineColor(hVal[h_i].GetLineColor())
402 r.GetYaxis().SetLabelSize(0.15)
403 r.GetXaxis().SetLabelSize(0.15)
409 for g_i
in range(0,len(hVal)):
410 if hVal[g_i]
is None :
413 tmp = hVal[g_i].GetHistogram()
414 histVal = TH1F(hVal[g_i].GetName()+
"_ratio",hVal[g_i].GetTitle()+
"_ratio",tmp.GetNbinsX(),tmp.GetXaxis().GetXmin(),tmp.GetXaxis().GetXmax())
415 histRef = TH1F(hRef[g_i].GetName()+
"_ratio",hRef[g_i].GetTitle()+
"_ratio",histVal.GetNbinsX(),histVal.GetXaxis().GetXmin(),histVal.GetXaxis().GetXmax())
417 for p
in range(0,hVal[g_i].GetN()-1):
421 hVal[g_i].GetPoint(p,x,y)
422 xerr = hVal[g_i].GetErrorX(p)
423 yerr = hVal[g_i].GetErrorY(p)
424 bin_p = histVal.FindBin(x)
425 xHist = histVal.GetBinCenter(bin_p)
432 xbiserr = hVal[g_i].GetErrorX(p-1)
433 ybiserr = hVal[g_i].GetErrorY(p-1)
434 hVal[g_i].GetPoint(p-1,xbis,ybis)
436 xbiserr = hVal[g_i].GetErrorX(p+1)
437 ybiserr = hVal[g_i].GetErrorY(p+1)
438 hVal[g_i].GetPoint(p+1,xbis,ybis)
442 bin_p_valContent_errP = y+yerr
443 bin_p_valContent_errM = y-yerr
448 bin_p_valContent = a*xHist+b
450 aerrP = ( (ybis+ybiserr)-(y+yerr) ) / (xbis-x)
451 berrP = (y+yerr)-aerrP*x
452 bin_p_valContent_errP = aerrP*xHist+berrP
453 aerrM = ( (ybis-ybiserr)-(y-yerr) ) / (xbis-x)
454 berrM = (y-yerr)-aerrM*x
455 bin_p_valContent_errM = aerrM*xHist+berrM
457 histVal.SetBinContent(bin_p,bin_p_valContent)
458 histVal.SetBinError(bin_p,(bin_p_valContent_errP-bin_p_valContent_errM)/2)
460 for pRef
in range(0,hRef[g_i].GetN()):
464 hRef[g_i].GetPoint(pRef,xRef,yRef)
466 if xRef > xHist :
continue
467 xReferr = hRef[g_i].GetErrorX(pRef)
468 yReferr = hRef[g_i].GetErrorY(pRef)
472 xRefbiserr = hRef[g_i].GetErrorX(pRef+1)
473 yRefbiserr = hRef[g_i].GetErrorY(pRef+1)
474 hRef[g_i].GetPoint(pRef+1,xRefbis,yRefbis)
477 bin_p_refContent = yRef
478 bin_p_refContent_errP = yRef+yReferr
479 bin_p_refContent_errM = yRef-yReferr
482 aRef=(ybis-y)/(xbis-x)
484 bin_p_refContent = aRef*xHist+bRef
486 aReferrP = ((yRefbis+yRefbiserr)-(yRef+yReferr))/((xRefbis)-(xRef))
487 bReferrP = (yRef+yReferr)-aReferrP*(xRef-xReferr)
488 bin_p_refContent_errP = aReferrP*xHist+bReferrP
489 aReferrM = ((yRefbis-yRefbiserr)-(yRef-yReferr))/((xRefbis)-(xRef))
490 bReferrM = (yRef-yReferr)-aReferrM*(xRef+xReferr)
491 bin_p_refContent_errM = aReferrM*xHist+bReferrM
494 histRef.SetBinContent(bin_p,bin_p_refContent)
495 histRef.SetBinError(bin_p,(bin_p_refContent_errP-bin_p_refContent_errM)/2)
499 histVal.Divide(histRef)
501 histVal.GetXaxis().SetRangeUser(0.,1.)
503 histVal.GetYaxis().SetRangeUser(0.25,1.75)
504 histVal.SetMarkerColor(hVal[g_i].GetMarkerColor())
505 histVal.SetLineColor(hVal[g_i].GetLineColor())
506 histVal.GetYaxis().SetLabelSize(0.15)
507 histVal.GetXaxis().SetLabelSize(0.15)
508 ratio.append(histVal)
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...