#!/bin/env python import sys import optparse import ROOT grootargs = [] def callback_rootargs(option, opt, value, parser): grootargs.append(opt) def parseOptions(): usage = ('usage: %prog [options]\n' + '%prog -h for help') parser = optparse.OptionParser(usage) parser.add_option("--level", dest="level", default="LHE",help="level of physics : LHE, Delphes") parser.add_option("--plotRatio",action="store_true", dest="plotRatio", default=False,help="whether plot ratio plot") parser.add_option("-l",action="callback",callback=callback_rootargs) parser.add_option("-q",action="callback",callback=callback_rootargs) parser.add_option("-b",action="callback",callback=callback_rootargs) return parser if __name__ == "__main__" : parser=parseOptions() (options,args) = parser.parse_args() sys.argv = grootargs level = options.level if level != 'LHE' and level != 'Delphes' : print ("level has to be either LHE or Delphes!") sys.exit(0) plotRatio = options.plotRatio inputFile = ROOT.TFile("out"+level+".root","READ") sampleTypes = ['offshell','onshell',"inclusive"] hist = {} for sampleType in sampleTypes : hist[sampleType] = inputFile.Get(sampleType+'/mass_eplus_eminus') hsum = ROOT.TH1F() hsum.Add(hist['offshell'],hist['onshell']) hsum.SetName("offshell+onshell") c1 = ROOT.TCanvas("c1","distribution",200, 10, 700, 500) c1.SetLeftMargin(0.25) c1.SetBottomMargin(0.17) hist["inclusive"].SetTitle("") hist["inclusive"].SetLineColor(1) hist["inclusive"].SetLineWidth(2) hist["inclusive"].SetStats(0) hist["inclusive"].Draw("hist") hist["onshell"].SetTitle("") hist["onshell"].Draw("histsame") hist["onshell"].SetLineColor(862) hist["onshell"].SetLineWidth(2) hist["onshell"].SetStats(0) hist["offshell"].SetTitle("") hist["offshell"].Draw("histsame") hist["offshell"].SetLineColor(814) hist["offshell"].SetLineWidth(2) hist["offshell"].SetStats(0) hsum.SetTitle("13TeV pp collisions") hsum.GetYaxis().SetTitleSize(0.03) hsum.GetXaxis().SetLabelSize(0.03) hsum.GetYaxis().SetLabelSize(0.03) hsum.GetYaxis().SetTitle("Cross Section (pb)") hsum.GetXaxis().SetTitle("M_{e^{+}e^{-}} GeV") hsum.SetLineColor(880) hsum.SetLineWidth(2) hsum.SetStats(0) hsum.Draw("histsame") leg1 = ROOT.TLegend(0.70, 0.70, 0.85, 0.88) leg1.AddEntry(hist["inclusive"], "p p > e^{+} e^{-}", "l") leg1.AddEntry(hist["onshell"], "p p > Z, Z > e^{+} e^{-}", "l") leg1.AddEntry(hist["offshell"], "p p > e^{+} e^{-} $ Z", "l") leg1.AddEntry(hsum, "onShellZ + offShellZ ", "l") leg1.SetBorderSize(0) leg1.Draw("same") c1.SaveAs(level+"_comparison.png") c1.SetLogy() c1.SaveAs(level+"_comparison_log.png") if plotRatio : c2 = ROOT.TCanvas("c2", "Ratio plot") hist["inclusive"].SetTitle("") hist["inclusive"].SetLineColor(1) hist["inclusive"].SetLineWidth(2) hsum.SetTitle("13TeV pp collisions") hsum.GetYaxis().SetTitleSize(0.03) hsum.GetXaxis().SetLabelSize(0.03) hsum.GetYaxis().SetLabelSize(0.03) hsum.GetYaxis().SetTitle("Cross Section (pb)") hsum.GetXaxis().SetTitle("M_{2l} GeV") hsum.SetLineColor(880) hsum.SetLineWidth(2) rp = ROOT.TRatioPlot(hsum, hist["inclusive"],"divsym") #c2.SetTicks(0, 1) rp.Draw() rp.GetLowYaxis().SetNdivisions(505) rp.GetLowerRefYaxis().SetRangeUser(0,3) rp.GetLowerRefYaxis().SetTitle("sum/inclusive") pad1=rp.GetUpperPad() pad1.cd() pad1.SetLogy() leg2 = ROOT.TLegend(0.1,0.7,0.5,0.85) leg2.AddEntry(hsum,"onshell + offshell","l") leg2.AddEntry(hist["inclusive"],"p p > e^{+} e^{-}","le") leg2.Draw() c2.SaveAs(level+"_ratio.png") inputFile.Close()