#!/usr/bin/env python # This is the plotting script for various upgrade studies from optparse import OptionParser import logging import os,sys from ROOT import kBlack,kWhite,kGray,kRed,kPink,kMagenta,kViolet,kBlue,kAzure,kCyan,kTeal,kGreen,kSpring,kYellow,kOrange,kDashed,kSolid,kDotted import ROOT import math from ROOT import TTree, TMath, TChain, TF1, TH1I, TH1F, TH1D, TH2F, TH2D, TGraphErrors, TGraph, THStack, TLegend, TGraph2D, TLatex, TArrow from ROOT import TFile, TCanvas, TPad, TLine, TLorentzVector from ROOT import gPad,gStyle from array import array ROOT.gROOT.SetBatch(True) sys.path.append('') from AtlasStyle import AtlasStyle from variableBin import createCanvasPads #folder ="compare/" def main(): # Init the Parser for the command line options parser = OptionParser() parser.add_option("--dotj", dest='dotj', action='store_true', default=False, help="tj plots") parser.add_option("--dotW1L", dest='dotW1L', action='store_true', default=False, help="tW 1L plots") parser.add_option("--dotW2L", dest='dotW2L', action='store_true', default=False, help="tW 2L plots") parser.add_option("--doN1Plots", dest='doN1Plots', action='store_true', default=False, help="Do N-1 plots") parser.add_option("--doCRsPlots", dest='doCRsPlots', action='store_true', default=False, help="Do control region plots") parser.add_option("--doVRsPlots", dest='doVRsPlots', action='store_true', default=False, help="Do validation region plots") parser.add_option('-b','--inputdirBkg', dest='inputdirBkg', help='input file for bkg (default: %default)') parser.add_option('-s','--inputdirSig', dest='inputdirSig', help='input file for sig (default: %default)') parser.set_defaults(inputdirBkg='/afs/cern.ch/work/g/grovelli/HistFitterMatt/tw_met_1l_liverpool/HistFitter_config/results/monotop_excl_newplot_900syst/',inputdirSig='/afs/cern.ch/work/g/grovelli/HistFitterMatt/tw_met_1l_liverpool/HistFitter_config/results/monotop_excl_signals/' ) (options, args) = parser.parse_args() pathBkg = str(options.inputdirBkg) + "/" pathSig = str(options.inputdirSig) + "/" if options.dotj == True : #BkgColors = {'Top': [kOrange -2, "t#bar{t}"], 'Wjets' : [kCyan + 2 , "W+jets"], "smallbkg" : [2, "Others"]} #SigColors = {'schannel' : [6, "m_{a}=250GeV m_{H^{\pm}}=300GeV tan#beta=1"], 'tchannel' : [1, "m_{a}=100GeV m_{H^{\pm}}=1500GeV tan#beta=1"]} BkgColors = dict(val1=('Top', kOrange - 2, "t#bar{t}"), val2 = ('Wjets', kCyan +2, "W+jets"), val3 = ('smallbkg', 2, "Others")) SigColors = {'schannel' : [413, "m_{a}=250 GeV M_{H}=300 GeV tan#beta=1"],'ex' : [1, "m_{a}=250 GeV M_{H}=1750 GeV tan#beta=0.3"]} ## N-1 plots if options.doN1Plots: doPlots(pathBkg,pathSig,"SRBDT", BkgColors, SigColors, "afterFit","BDT", "tj SR","Events", "BDT output", "log", {'leg' : [0.42, 0.58, 0.85, 0.85, 0.14], 'arrow': [0.6, 0, 0.7, 800]} ) doPlots(pathBkg,pathSig,"SRMET", BkgColors, SigColors, "afterFit","MET", "tj SR","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.58, 0.85, 0.85, 0.14], 'arrow': [225, 0, 300, 5000]}) doPlots(pathBkg,pathSig,"SRDelta", BkgColors, SigColors,"afterFit","DeltaPhiBJetLep","tj SR","Events", "#Delta#phi(lep 1, b-jet 1) [rad]", "lin", {'leg' : [0.42, 0.58, 0.85, 0.85, 0.14], 'arrow': [1.2, 0, 1.0, 180], 'arrow2': [-1.2, 0, -1.0, 180]}) doPlots(pathBkg,pathSig,"SRMTW", BkgColors, SigColors, "afterFit","MTW", "tj SR","Events","m_{T}^{lep} [GeV]", "log", {'leg' : [0.42, 0.58, 0.85, 0.85, 0.14], 'arrow': [100, 0, 200, 5000]}) doPlots(pathBkg,pathSig,"SRForward", BkgColors, SigColors, "afterFit","nGoodForward", "tj SR","Events", "N_{jets}^{Forward}", "lin", {'leg' : [0.42, 0.58, 0.85, 0.85, 0.14], 'arrow': [1, 0, 1.5, 180]}) ## Control region plots if options.doCRsPlots: doPlots(pathBkg,pathSig,"TCR", BkgColors, "", "afterFit","MET", "CR(t#bar{t}_tj)","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TCR", BkgColors, "", "afterFit","BDT", "CR(t#bar{t}_tj)","Events", "BDT output", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TCR", BkgColors, "", "afterFit","DeltaPhiBJetLep", "CR(t#bar{t}_tj)","Events", "#Delta#phi(lep 1, b-jet 1) [rad]", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TCR", BkgColors, "", "afterFit","MTW", "CR(t#bar{t}_tj)","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TCR", BkgColors, "", "afterFit","nGoodForward", "CR(t#bar{t}_tj)","Events", "N_{jets}^{Forward}", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WCR", BkgColors, "", "afterFit","MET", "CR(W+jets_tj)","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WCR", BkgColors, "", "afterFit","BDT", "CR(W+jets}_tj)","Events", "BDT output", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WCR", BkgColors, "", "afterFit","DeltaPhiBJetLep", "CR(W+jets_tj)","Events", "#Delta#phi(lep 1, b-jet 1) [rad]", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WCR", BkgColors, "", "afterFit","MTW", "CR(W+jets_tj)","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WCR", BkgColors, "", "afterFit","nGoodForward", "CR(W+jets_tj)","Events", "N_{jets}^{Forward}", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) if options.doVRsPlots: doPlots(pathBkg,pathSig,"TVR", BkgColors, "", "afterFit","MET", "VR(t#bar{t}_tj)","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TVR", BkgColors, "", "afterFit","BDT", "VR(t#bar{t}_tj)","Events", "BDT output", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TVR", BkgColors, "", "afterFit","DeltaPhiBJetLep", "VR(t#bar{t}_tj)","Events", "#Delta#phi(lep 1, b-jet 1) [rad]", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TVR", BkgColors, "", "afterFit","MTW", "VR(t#bar{t}_tj)","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"TVR", BkgColors, "", "afterFit","nGoodForward", "VR(t#bar{t}_tj)","Events", "N_{jets}^{Forward}", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WVR", BkgColors, "", "afterFit","MET", "VR(W+jets_tj)","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WVR", BkgColors, "", "afterFit","BDT", "VR(W+jets_tj)","Events", "BDT output", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WVR", BkgColors, "", "afterFit","DeltaPhiBJetLep", "CR(W+jets_tj)","Events", "#Delta#phi(lep 1, b-jet 1) [rad]", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WVR", BkgColors, "", "afterFit","MTW", "CR(W+jets_tj)","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"WVR", BkgColors, "", "afterFit","nGoodForward", "CR(W+jets_tj)","Events", "N_{jets}^{Forward}", "lin", {'leg' : [0.50, 0.66, 0.85, 0.85, 0.14]}) if options.dotW1L == True : BkgColors = dict(val1=('Top1L',kOrange - 2, "t#bar{t}"), val2=('Wjets',kCyan +2, "W+jets"), val3=('SingleTop', kOrange+2, "Single top quark"), val4 =("Diboson1L",kMagenta-4, "Diboson"), val5 = ("ttV1L", kAzure-3, "t#bar{t}V"), val6 = ("Zjets", kYellow, "Z+jets"), val7 = ("tWZ", kYellow, "tWZ"), val8 = ("ttH", kYellow, "t#bar{t}h")) print( 'dotW1L' ) SigColors = {'a250_DM10_H600_tb2_st0p7_1L0L' : [413, "m_{a}=250 GeV m_{H^{#pm}}=600 GeV tan#beta=2"], 'a300_DM10_H1200_tb1_st0p7_1L0L' : [1, "m_{a}=300 GeV m_{H^{#pm}}=1200 GeV tan#beta=1"]} if options.doN1Plots: #doPlots(pathBkg,pathSig,"tW1L_mt", BkgColors, SigColors, "afterFit","mt1000", "SR_{tW_{1L}}","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14], 'arrow': [200, 0, 300, 4000]}) doPlots(pathBkg,pathSig,"tW1L_met", BkgColors, SigColors, "afterFit","met1000", "SR_{tW_{1L}}","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_mW", BkgColors, SigColors, "afterFit","ReclusteredW_Mass1000", "SR_{tW_{1L}}", "Events", "m_{W} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14], 'arrow': [60, 0, 80, 200]}) doPlots(pathBkg,pathSig,"tW1L_amt2", BkgColors, SigColors, "afterFit","amt21000", "SR_{tW_{1L}}","Events", "am_{T2} [GeV]", "log",{'leg' : [0.32, 0.46, 0.8, 0.85, 0.14], 'arrow': [220, 0, 250, 200]}) if options.doCRsPlots: doPlots(pathBkg,pathSig,"tW1L_CRtt", BkgColors, "", "afterFit","met1000", "CR_{tW1L}(t#bar{t})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.46, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_CRWp", BkgColors, "", "afterFit","met1000", "CR_{tW1L}(W^{+})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.46, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_CRWm", BkgColors, "", "afterFit","met1000", "CR_{tW1L}(W^{-})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.46, 0.85, 0.85, 0.14]}) if options.doVRsPlots: doPlots(pathBkg,pathSig,"tW1L_VRtt_VR1", BkgColors, "", "afterFit","met1000", "VR1_{tW_{1L}}(t#bar{t})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_VRtt_VR2", BkgColors, "", "afterFit","met1000", "VR2_{tW_{1L}}(t#bar{t})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_VRW_VR1p", BkgColors, "", "afterFit","met1000", "VR1_{tW_{1L}}(W^{+})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_VRW_VR1m", BkgColors, "", "afterFit","met1000", "VR1_{tW_{1L}}(W^{-})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_VRW_VR2p", BkgColors, "", "afterFit","met1000", "VR2_{tW_{1L}}(W^{+})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_VRW_VR2m", BkgColors, "", "afterFit","met1000", "VR2_{tW_{1L}}(W^{-})","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.42, 0.38, 0.85, 0.85, 0.14]}) doPreselPlots = True if doPreselPlots: doPlots(pathBkg,pathSig,"tW1L_prese", BkgColors, SigColors, "afterFit","mt1000", "Preselection","Events", "m_{T}^{lep} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_prese", BkgColors, SigColors, "afterFit","met1000", "Preselection","Events", "E_{T}^{miss} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_prese", BkgColors, SigColors, "afterFit","ReclusteredW_Mass1000", "Preselection", "Events", "m_{W} [GeV]", "log", {'leg' : [0.32, 0.46, 0.8, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW1L_prese", BkgColors, SigColors, "afterFit","amt21000", "Preselection","Events", "am_{T2} [GeV]", "log",{'leg' : [0.32, 0.46, 0.8, 0.85, 0.14]}) if options.dotW2L == True : BkgColors = dict(val1=('Top2L',kOrange - 2, "t#bar{t}"), val2=('SingleTop', kOrange+2, "Single top"), val3 = ("ttV", kAzure-3, "t#bar{t}V"), val4 =("Diboson",kMagenta-4, "Diboson"), val5 = ("ttH", kYellow, "t#bar{t}H")) #BkgColors = {'Top2L': [kOrange-2, "t#bar{t}"], 'SingleTop' : [kOrange+2, "Single top"], "ttV" : [kAzure -3, "t#bar{t}V"], "Diboson" : [kMagenta-4, "Diboson"], "ttH" : [kYellow, "t#bar{t}H"]} SigColors = {'a250_DM10_H600_tb2_st0p7_2L' : [413, 'm_{a}=250 GeV M_{H}=600 GeV tan#beta=2'], 'a300_DM10_H1200_tb1_st0p7_2L' : [1, "m_{a}=300 GeV M_{H}=1200 GeV tan#beta=1"]} if options.doN1Plots: doPlots(pathBkg,pathSig,"tW2L_minmaxmbl", BkgColors, SigColors, "afterFit","minmaxmbl1000", "tW 2L SR","Events", "m_{bl}^{t} [GeV]", "lin", {'leg' : [0.42, 0.50, 0.85, 0.85, 0.14], 'arrow': [150, 0, 175, 5]}) doPlots(pathBkg,pathSig,"SR2L", BkgColors, SigColors, "afterFit","met1000", "tW 2L SR","Events", "E_{T}^{miss} [GeV]", "lin", {'leg' : [0.42, 0.50, 0.85, 0.85, 0.14], 'arrow': [200, 0, 250, 6]}) doPlots(pathBkg,pathSig,"SR2L", BkgColors, SigColors, "afterFit","dPhimin_4", "tW 2L SR","Events", "|#Delta(#phi_{min})| rad", "lin",{'leg' : [0.42, 0.50, 0.85, 0.85, 0.14], 'arrow': [1.1, 0, 1.6, 10]}) doPlots(pathBkg,pathSig,"SR2L", BkgColors, SigColors, "afterFit","minjbl1000", "tW 2L SR","Events", "min m_{bl} [GeV]", "lin",{'leg' : [0.42, 0.50, 0.85, 0.85, 0.14], 'arrow': [170, 0, 150, 5]}) doPlots(pathBkg,pathSig,"tW2L", BkgColors, SigColors, "afterFit","mt2_mt21000", "tW 2L SR","Events", "m_{T2} [GeV]", "log",{'leg' : [0.42, 0.50, 0.85, 0.85, 0.14], 'arrow': [130, 0, 160, 50]}) if options.doCRsPlots: doPlots(pathBkg,pathSig,"tW2L_CRtt", BkgColors, "", "afterFit","minmaxmbl1000", "CR(t#bar{t}_tW2L)","Events", "m_{bl}^{t} [GeV]", "log", {'leg' : [0.50, 0.58, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW2L_CRttZ", BkgColors, "", "afterFit","met_corr1000", "CR(t#bar{t}Z_tW2L)","Events", "E_{T, corrected}^{miss} [GeV]", "lin", {'leg' : [0.50, 0.58, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW2L_CRWZ", BkgColors, "", "afterFit","met_corr1000", "CR(WZ_tW2L)","Events", "E_{T, corrected}^{miss} [GeV]", "lin", {'leg' : [0.50, 0.58, 0.85, 0.85, 0.14]}) if options.doVRsPlots: doPlots(pathBkg,pathSig,"tW2L_VRtt", BkgColors, "", "afterFit","minmaxmbl1000", "VR(t#bar{t}_tW2L)","Events", "m_{bl}^{t} [GeV]", "log", {'leg' : [0.50, 0.54, 0.85, 0.85, 0.14]}) doPlots(pathBkg,pathSig,"tW2L_VR3L", BkgColors, "", "afterFit","met_corr1000", "VR(3L_tW2L)","Events", "E_{T, corrected}^{miss} [GeV]", "lin", {'leg' : [0.50, 0.54, 0.85, 0.85, 0.14]}) def doPlots(folderBkg, folderSig ,region, bkg, signal, fit, name_vars, caption,ylabel, xlabel, scale, style_plot): #TH1F.SetDefaultSumw2() c, pad1, pad2 = createCanvasPads() style = AtlasStyle() inputFile =folderBkg+str(region)+"_"+str(name_vars)+"_"+str(fit)+".root" rootFileBkg = TFile(inputFile) if signal: inputFileSignal = folderSig+str(region)+"_"+str(name_vars)+'_beforeFit.root' rootFileSig = TFile(inputFileSignal) ############################################## ## Getting the histograms ############################################## data = rootFileBkg.Get("h_obsData") total_SM = rootFileBkg.Get("SM_total") if total_SM: total_SM.SetLineColor(kBlack) error_band = rootFileBkg.Get("h_total_error_band") ratio = rootFileBkg.Get("h_ratio") ratio_err = rootFileBkg.Get("h_rel_error_band") bkgHisto = {} for j in bkg: bkgHisto[str(bkg[j][0])]= {} bkgHisto[str(bkg[j][0])] = rootFileBkg.Get(str(bkg[j][0])) data.SetLineColor(kBlack) data.SetLineWidth(1) SM_stack = ROOT.THStack() for j in reversed(sorted(bkg)): bkgHisto[bkg[j][0]].SetFillColor(bkg[j][1]) bkgHisto[bkg[j][0]].SetLineWidth(0) SM_stack.Add(bkgHisto[bkg[j][0]]) signalHisto = {} for j in signal: signalHisto[str(j)]= {} signalHisto[str(j)] = rootFileSig.Get(str(j)) pad1.cd() maxY = SM_stack.GetMaximum() if signal: for sg in signalHisto : if signalHisto[sg].GetMaximum() > maxY: maxY = signalHisto[sg].GetMaximum() for i in range(0, data.GetN()): eyh = data.GetErrorYhigh(i) eyl = data.GetErrorYlow(i) data.SetPointError(i,0,0,eyl,eyh) if eyh > maxY : maxY = 2.7 * float(eyh) if float(eyl) == 0 : print "Your data is zero in this entry! Please check it!" print str(xlabel) + " : Entry : " + str(i) data.SetPoint(i,-1000,-1000) w = total_SM.GetBinWidth(1) if "rad" in str(xlabel): ylabel = str(ylabel) + " / " +"{0:.1f}".format(w)+" rad" elif "BDT" in str(xlabel): ylabel = str(ylabel) + " / " +"{0:.1f}".format(w) else: ylabel = str(ylabel) + " / " +str(int(w))+" GeV" #SM_stack.Draw("HIST ][") #SM_stack.GetYaxis().SetTitle(ylabel) #SM_stack.GetYaxis().SetTitleOffset(1.1) #SM_stack.SetMaximum(2. * maxY) #SM_stack.GetXaxis().SetLabelSize(0.) #SM_stack.GetYaxis().SetTitleSize(0.044) #SM_stack.GetYaxis().SetTitleOffset(0.43) #SM_stack.GetYaxis().SetLabelSize(0.044) #if scale == "log": # SM_stack.SetMaximum(10000. * maxY) # SM_stack.SetMinimum(1) # SM_stack.GetYaxis().SetTitleOffset(1.1) # ROOT.gPad.SetLogy() SM_stack.Draw("HIST ][") SM_stack.GetYaxis().SetTitle(ylabel) SM_stack.GetYaxis().SetTitleOffset(0.9) SM_stack.SetMaximum(2. * maxY) SM_stack.GetXaxis().SetLabelSize(0.) SM_stack.GetYaxis().SetTitleSize(0.055) SM_stack.GetYaxis().SetLabelSize(0.05) if scale == "log": SM_stack.SetMaximum(1000. * maxY) SM_stack.SetMinimum(1) SM_stack.GetYaxis().SetTitleOffset(0.9) ROOT.gPad.SetLogy() total_SM.SetMarkerStyle(1) total_SM.SetFillColor(kBlack) total_SM.SetFillStyle(0) total_SM.SetLineWidth(3) total_SM.SetLineColor(kRed+2) total_SM.Draw("HIST SAME ][") #data.Draw("E P SAME") #total_SM.Draw("E2 SAME") #total_SM_clone = total_SM.Clone("total_SM_clone") #total_SM_clone.SetFillStyle(3004) #total_SM_clone.Draw("HIST SAME") #total_SM.Draw("E2 SAME") style_l = 2 factor = 1 if signal: for sg in signalHisto : signalHisto[sg].SetLineColor(signal[sg][0]) signalHisto[sg].SetFillColor(0) signalHisto[sg].SetLineWidth(4) signalHisto[sg].SetMarkerStyle(0) signalHisto[sg].SetLineStyle(style_l) #signalHisto[sg].Scale(signalHisto[sg].Integral()*factor) #signalHisto[sg].GetYaxis().SetRangeUser(1, maxY) signalHisto[sg].Draw("HIST SAME") #style_l +=1 data.SetMarkerSize(1) gStyle.SetHatchesLineWidth(5) error_band.SetFillStyle(3004) error_band.SetLineWidth(3) error_band.SetLineColor(kRed+2) error_band.SetMarkerColor(kBlack) error_band.SetFillColor(kBlack) mgup = ROOT.TMultiGraph() mgup.Add(data,"P E1 same") mgup.Add(error_band,"F E2") mgup.Draw() if style_plot: if "tj" in caption: leg = TLegend(style_plot['leg'][0]+0.12,style_plot['leg'][1]+0.05,style_plot['leg'][2], style_plot['leg'][3]) if signal: leg1 = TLegend(style_plot['leg'][0],style_plot['leg'][1]-0.08,style_plot['leg'][2], style_plot['leg'][3]-0.27) elif "tW1L" in region: leg = TLegend(style_plot['leg'][0]+0.12,style_plot['leg'][1],style_plot['leg'][2], style_plot['leg'][3]) if signal: leg1 = TLegend(style_plot['leg'][0],style_plot['leg'][1]-0.12,style_plot['leg'][2], style_plot['leg'][3]-0.38) elif "2L" in region: leg = TLegend(style_plot['leg'][0],style_plot['leg'][1],style_plot['leg'][2], style_plot['leg'][3]) if signal: leg1 = TLegend(style_plot['leg'][0],style_plot['leg'][1]-0.10,style_plot['leg'][2], style_plot['leg'][3]-0.28) else: leg1 = TLegend(0.65, 0.60, 0.70, 0.70) if signal: leg1.SetTextSize(0.045) leg1.SetFillStyle(0) leg1.SetMargin(0.22) leg1.SetFillColor(0) leg1.SetBorderSize(0) leg1.SetTextFont(42) else: leg = TLegend(0.65, 0.60, 0.83, 0.87) leg.SetTextSize(0.045) leg.SetFillStyle(0) leg.SetMargin(0.22) leg.SetFillColor(0) leg.SetBorderSize(0) leg.SetTextFont(42) leg.AddEntry(data, "Data", "PX0E") leg.AddEntry(error_band, "SM Total", "fl") for e in sorted(bkg): if e == "val6": leg.AddEntry(bkgHisto[bkg[e][0]], "Others", "f") continue if e == "val7" or e == "val8": continue leg.AddEntry(bkgHisto[bkg[e][0]], bkg[e][2], "f") if signal: for sg in signalHisto : if style_plot: print signal[sg][1] leg.AddEntry(signalHisto[sg], signal[sg][1], "l") # leg1.Draw() else: leg.AddEntry(signalHisto[sg], sg, "l") #leg.AddEntry(error_band, "Standard Model", "fl") leg.Draw() #style.ATLASLabel(0.2,0.85,0.15,Preliminary="Internal", size=0.04) if style_plot and signal: #custom_text(style_plot['leg'][4], style_plot['leg'][3]-0.03, "#bf{#it{ATLAS}} %s" % "Internal", 0.065, 1) custom_text(style_plot['leg'][4], style_plot['leg'][3]-0.03, "#bf{#it{ATLAS}} %s" % "Preliminary", 0.065, 1) style.myText(style_plot['leg'][4],style_plot['leg'][3]-0.09,color=1,size=0.055,text="#sqrt{s} = 13 TeV, 139 fb^{#minus1}") style.myText(style_plot['leg'][4],style_plot['leg'][3]-0.15,color=1,size=0.055,text="{} {}".format(str(caption),"#bf{Post-fit}")) elif style_plot: #custom_text(style_plot['leg'][4], style_plot['leg'][3]-0.03, "#bf{#it{ATLAS}} %s" % "Internal", 0.065, 1) custom_text(style_plot['leg'][4], style_plot['leg'][3]-0.03, "#bf{#it{ATLAS}} %s" % "Preliminary", 0.065, 1) style.myText(style_plot['leg'][4],style_plot['leg'][3]-0.09,color=1,size=0.055,text="#sqrt{s} = 13 TeV, 139 fb^{#minus1}") style.myText(style_plot['leg'][4],style_plot['leg'][3]-0.15,color=1,size=0.055,text="{} {}".format(str(caption),"#bf{Post-fit}")) else: #custom_text(0.2, 85, "#bf{#it{ATLAS}} %s" % "Internal", 0.065, 1) custom_text(0.2, 85, "#bf{#it{ATLAS}} %s" % "Preliminary", 0.065, 1) style.myText(0.2,0.80,color=1,size=0.055,text="#sqrt{s} = 13 TeV, 139 fb^{#minus1}") style.myText(0.2,0.75,color=1,size=0.055,text="{} {}".format(str(caption),"#bf{Post-fit}")) #// Draw an arrow on the canvas //#10 #if style_plot['arrow'] : if 'arrow' in style_plot: arr = TArrow(style_plot['arrow'][0], style_plot['arrow'][3], style_plot['arrow'][2], style_plot['arrow'][3]) arr.SetLineStyle(1) arr.SetLineWidth(3) arr.SetLineColor(kGray+3) arr.SetArrowSize(0.015) arr.Draw() l = TLine(style_plot['arrow'][0], style_plot['arrow'][1], style_plot['arrow'][0],style_plot['arrow'][3]) l.SetLineStyle(1) l.SetLineWidth(3) l.SetLineColor(kGray+3) l.Draw("same") if 'arrow2' in style_plot: arr2 = TArrow(style_plot['arrow2'][0], style_plot['arrow2'][3], style_plot['arrow2'][2], style_plot['arrow2'][3]) arr2.SetLineStyle(1) arr2.SetLineWidth(3) arr2.SetLineColor(kGray+3) arr2.SetArrowSize(0.015) arr2.Draw() l2 = TLine(style_plot['arrow2'][0], style_plot['arrow2'][1], style_plot['arrow2'][0],style_plot['arrow2'][3]) l2.SetLineStyle(1) l2.SetLineWidth(3) l2.SetLineColor(kGray+3) l2.Draw("same") c.Update pad2.cd() frame = total_SM.Clone() for i in range(frame.GetNbinsX()): frame.SetBinContent(i, 0.) frame.SetMaximum(2.) frame.SetMinimum(0.) frame.Draw("HIST") ratio.Draw("EP") ratio_err.Draw("F") frame.GetXaxis().SetTitle(xlabel) frame.GetYaxis().SetTitle("Data/SM") frame.GetXaxis().SetTitleSize(0.125) frame.GetYaxis().SetTitleSize(0.125) frame.GetXaxis().SetTitleOffset(1.0) frame.GetYaxis().SetTitleOffset(0.40) frame.GetXaxis().SetLabelSize(0.125) frame.GetYaxis().SetLabelSize(0.125) frame.GetXaxis().SetLabelOffset(0.04) frame.GetXaxis().SetTitleOffset(1.1) frame.GetYaxis().SetNdivisions(504) frame.GetYaxis().CenterTitle(); pad2.SetGridy(); frame.Draw("AXIS") frame.Draw("AXIG SAME") #ratio.Draw("EP") ratio_err.SetFillStyle(3004); ratio_err.SetLineWidth(2) ratio_err.SetMarkerColor(kBlack); ratio_err.SetFillColor(kBlack) ratio.SetMarkerSize(1.) ratio.SetLineWidth(1) #ratio_err.Draw("a3 SAME"); #ratio_err.Draw("F") mg = ROOT.TMultiGraph() mg.Add(ratio,"E0P") mg.Add(ratio_err,"F") mg.Draw() ROOT.gPad.RedrawAxis() c.Update folder = "plots/" create_dir(folder) if signal: c.SaveAs(str(folder)+"Signal_"+str(region)+"_"+str(name_vars)+"_"+fit+".pdf") else: c.SaveAs(str(folder)+"Bkg_"+str(region)+"_"+str(name_vars)+"_"+fit+".pdf") return # --------------------------------------------------------------- # Create Directory if NOT exists # --------------------------------------------------------------- def create_dir(directory): if not os.path.exists(directory): try: os.makedirs(directory) except OSError: if os.path.islink(directory): os.remove(directory) os.makedirs(directory) else: errmsg = " Directory %s cannot be created!" % directory printd( bcolors.FAIL + errmsg + bcolors.ENDC) sys.exit() def custom_text(x, y, text, size, color): l = TLatex() # l.SetTextAlign(12) l.SetTextFont(42) l.SetTextSize(size) l.SetTextColor(color) l.SetNDC() l.DrawLatex(x,y,text) return if __name__ == '__main__': main()