def __init__(self, indir="./METSkim_v1", outdir='./output/stacker/', channel='inclusive', whichregion='SR', zpt_cut='100', met_cut= '100', lumi = 2.318278305, sepSig=True, LogY=True, doRatio=True, addSig=True, addData=True, scaleDphi=False, onlyStats=False): self.outdir=outdir self.channel=channel self.whichregion=whichregion self.zpt_cut, self.met_cut = zpt_cut, met_cut self.lumi=lumi CheckDir(self.outdir) # if not, this will create it #channel='inclusive'#raw_input("Please choose a channel (el or mu): \n") self.tag0='ZJstudy' self.plotter_dd = InitializePlotter(indir=indir, addSig=addSig, addData=addData, doRatio=doRatio, scaleDphi=scaleDphi, onlyStats=onlyStats) self.plotter = InitializePlotter(indir=indir, addSig=addSig, addData=addData, doRatio=doRatio, onlyStats=onlyStats) self.plotter.Stack.rmPlotter(self.plotter.ZJets, "ZJets","Z+Jets", "background") setcuts = SetCuts() self.cuts_eld = setcuts.abcdCuts(channel=self.channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) zjcuts = setcuts.GetZjetsCuts(whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) self.cuts = zjcuts[self.channel] # self.fabsDphi={'A': "fabs(llnunu_deltaPhi)", # 'B': "fabs(llnunu_deltaPhi)+TMath::Pi()/4", # 'C': "fabs(llnunu_deltaPhi)+TMath::Pi()/2", # 'D': "fabs(llnunu_deltaPhi)+TMath::Pi()*3/4"} self.fabsDphi="fabs(llnunu_deltaPhi)" # et1="TMath::Sqrt(llnunu_l1_pt*llnunu_l1_pt+llnunu_l1_mass*llnunu_l1_mass)" # et2="TMath::Sqrt(llnunu_l2_pt*llnunu_l2_pt+llnunu_l1_mass*llnunu_l1_mass)" # newMtB='TMath::Sqrt(2.0*(llnunu_l1_mass*llnunu_l1_mass+'+et1+'*'+et2+'-llnunu_l1_pt*llnunu_l2_pt*cos('+self.fabsDphi['B']+')))' # newMtC='TMath::Sqrt(2.0*(llnunu_l1_mass*llnunu_l1_mass+'+et1+'*'+et2+'-llnunu_l1_pt*llnunu_l2_pt*cos('+self.fabsDphi['C']+')))' # newMtD='TMath::Sqrt(2.0*(llnunu_l1_mass*llnunu_l1_mass+'+et1+'*'+et2+'-llnunu_l1_pt*llnunu_l2_pt*cos('+self.fabsDphi['D']+')))' # self.Mt={'A':'llnunu_mt', # 'B':newMtB, # 'C':newMtC, # 'D':newMtD} self.Mt='llnunu_mt' self.mtxbins=[150,200,250,300,350,400,450,550,850] self.mtnbins, self.mtxmin, self.mtxmax= len(self.mtxbins), min(self.mtxbins), max(self.mtxbins)#14, 150.0, 850.0 ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C') ROOT.gStyle.SetPadBottomMargin(0.2) ROOT.gStyle.SetPadLeftMargin(0.15)
def __init__(self, indir="./nonResSkim_v3.0", outdir='stack_test', lumi = 2.318278305, sepSig=True, LogY=True, doRatio=True, addSig=True, addData=True): if not os.path.exists(outdir): os.system('mkdir '+outdir) self.logy=LogY self.outdir = outdir self.lumi = lumi self.plotter_eu=InitializePlotter(indir, addSig=False, addData=True, doRatio=doRatio, doElMu=True, LogY=LogY) self.plotter_ll=InitializePlotter(indir, addSig=addSig, addData=True, doRatio=doRatio, LogY=LogY) self.plotter_ll.Stack.rmPlotter(self.plotter_ll.TT, "TT","TT", "background") self.plotter_ll.Stack.rmPlotter(self.plotter_ll.WW, "WW","WW, WZ non-reson.", "background") self.plotter_ll.Stack.rmPlotter(self.plotter_ll.WJets, "WJets","W+Jets", "background") self.setcuts=SetCuts() ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C') self.zpt_cut, self.met_cut= '100', '0' self.cuts=self.setcuts.GetAlphaCuts(zpt_cut=self.zpt_cut, met_cut=self.met_cut)
if whichregion == "": lswhichregion = ['SR', 'VR'] else: lswhichregion.append(whichregion) # ll in Z | ll out Z # -------------------- M_out [35,65] U [115,120] # eu in Z | eu out Z # M_in (70,110) ### ----- Initialize (samples): plotter_ll = InitializePlotter(addSig=False, addData=False, doRatio=False) plotter_eu = InitializePlotter(addSig=False, addData=False, doRatio=False, doElMu=True) setcuts = SetCuts() print "I am cuts_ll:" cuts_ll = setcuts.alphaCuts(inclusive=True) print "I am cuts_eu:" cuts_eu = setcuts.alphaCuts(isll=False, inclusive=True) exit(0) ### ----- Execute (plotting): print product(lsChannel, lswhichregion) for Channel, whichregion in product(lsChannel, lswhichregion): cuts = mycuts.abcdCuts(Channel, whichregion) print cuts ROOT.gROOT.ProcessLine('.x tdrstyle.C')
##--- Setup: inputs newvar = "dPhi_jetMet_min" indir = "/dataf/mewu/METSkim_v1.1/" outdir = "output/newcut/" CheckDir(outdir) # if not, this will create it onlyStats = False scaleDphi = False LogY = True doRatio = False # no data, please set doRatio to false sigk = 1000 lumi = 2.318278305 lepsf = 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf' triggersf = 'triggersf' setcuts = SetCuts() cuts = setcuts.abcdCuts(channel="inclusive", whichRegion="SR", isPreSelect=True, zpt_cut='100', met_cut='50') ##--- Initialize: plotter zjetsPlotters = [] zjetsSamples = ['DYJetsToLL_M50_BIG'] # M50_BIG = M50 + M50_Ext for sample in zjetsSamples: zjetsPlotters.append(TreePlotter(indir + '/' + sample + '.root', 'tree')) if not onlyStats: zjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') zjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') #zjetsPlotters[-1].addCorrectionFactor('(1921.8*3)','xsec')
def __init__(self, indir="../AnalysisRegion", outdir='plots', lumi=2.169126704526, sepSig=True, LogY=True, doRatio=True): if not os.path.exists(outdir): os.system('mkdir ' + outdir) self.mycuts = SetCuts() self.Channel = raw_input("Please choose a channel (el or mu): \n") self.outdir = outdir self.lumi = lumi self.sepSig = sepSig self.tex_dic = self.mycuts.Tex_dic self.whichregion = raw_input( "Please choose a benchmarck Region (SR or VR): \n") self.cuts = self.mycuts.abcdCuts(self.Channel, self.whichregion) self.preCuts = self.mycuts.abcdCuts(self.Channel, self.whichregion, True) if self.whichregion == "VR": self.nbins, self.xMin, self.xMax = 10, 0, float(self.mycuts.met_pt) else: self.nbins, self.xMin, self.xMax = 10, 0, 500 #######----------- Prepare samples to plot: zjetsPlotters = [] #zjetsSamples = ['DYJetsToLL_M50_HT100to200','DYJetsToLL_M50_HT200to400','DYJetsToLL_M50_HT400to600','DYJetsToLL_M50_HT600toInf'] #zjetsSamples = ['DYJetsToLL_M50','DYJetsToLL_M50_Ext'] zjetsSamples = ['DYJetsToLL_M50_BIG'] # M50_BIG = M50 + M50_Ext for sample in zjetsSamples: zjetsPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) zjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') zjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') zjetsPlotters[-1].addCorrectionFactor('genWeight', 'tree') zjetsPlotters[-1].addCorrectionFactor('puWeight', 'tree') zjetsPlotters[-1].addCorrectionFactor('triggersf', 'tree') zjetsPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.ZJets = MergedPlotter(zjetsPlotters) self.ZJets.setFillProperties(1001, ROOT.kGreen + 2) wwPlotters = [] wwSamples = ['WWTo2L2Nu', 'WWToLNuQQ', 'WZTo1L1Nu2Q'] for sample in wwSamples: wwPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) wwPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') wwPlotters[-1].addCorrectionFactor('xsec', 'tree') wwPlotters[-1].addCorrectionFactor('genWeight', 'tree') wwPlotters[-1].addCorrectionFactor('puWeight', 'tree') wwPlotters[-1].addCorrectionFactor('triggersf', 'tree') wwPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.WW = MergedPlotter(wwPlotters) self.WW.setFillProperties(1001, ROOT.kOrange) vvPlotters = [] vvSamples = ['WZTo2L2Q', 'WZTo3LNu', 'ZZTo2L2Nu', 'ZZTo2L2Q', 'ZZTo4L'] for sample in vvSamples: vvPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) vvPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') vvPlotters[-1].addCorrectionFactor('xsec', 'tree') vvPlotters[-1].addCorrectionFactor('genWeight', 'tree') vvPlotters[-1].addCorrectionFactor('puWeight', 'tree') vvPlotters[-1].addCorrectionFactor('triggersf', 'tree') vvPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.VV = MergedPlotter(vvPlotters) self.VV.setFillProperties(1001, ROOT.kMagenta) wjetsPlotters = [] wjetsSamples = ['WJetsToLNu'] for sample in wjetsSamples: wjetsPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) wjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') wjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') wjetsPlotters[-1].addCorrectionFactor('genWeight', 'tree') wjetsPlotters[-1].addCorrectionFactor('puWeight', 'tree') wjetsPlotters[-1].addCorrectionFactor('triggersf', 'tree') wjetsPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.WJets = MergedPlotter(wjetsPlotters) self.WJets.setFillProperties(1001, ROOT.kBlue - 6) ttPlotters = [] ttSamples = ['TTTo2L2Nu'] #,'TTZToLLNuNu','TTWJetsToLNu'] for sample in ttSamples: ttPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) ttPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') ttPlotters[-1].addCorrectionFactor('xsec', 'tree') ttPlotters[-1].addCorrectionFactor('genWeight', 'tree') ttPlotters[-1].addCorrectionFactor('puWeight', 'tree') ttPlotters[-1].addCorrectionFactor('triggersf', 'tree') ttPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.TT = MergedPlotter(ttPlotters) self.TT.setFillProperties(1001, ROOT.kAzure - 9) # --> define different background sets: nonZBGPlotters = [] nonZBGSamples = wwSamples + vvSamples + wjetsSamples + ttSamples for sample in nonZBGSamples: nonZBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) nonZBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') nonZBGPlotters[-1].addCorrectionFactor('xsec', 'tree') nonZBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') nonZBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') nonZBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') nonZBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.NonZBG = MergedPlotter(nonZBGPlotters) self.NonZBG.setFillProperties(1001, ROOT.kPink + 6) nonResBGPlotters = [] nonResBGSamples = wwSamples + wjetsSamples + ttSamples for sample in nonResBGSamples: nonResBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) nonResBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') nonResBGPlotters[-1].addCorrectionFactor('xsec', 'tree') nonResBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') nonResBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') nonResBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') nonResBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.NonResBG = MergedPlotter(nonResBGPlotters) self.NonResBG.setFillProperties(1001, ROOT.kYellow) resBGPlotters = [] resBGSamples = zjetsSamples + vvSamples for sample in resBGSamples: resBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) resBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') resBGPlotters[-1].addCorrectionFactor('xsec', 'tree') resBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') resBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') resBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') resBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.ResBG = MergedPlotter(resBGPlotters) self.ResBG.setFillProperties(1001, ROOT.kRed) # --> Prepare the signal plotters: sigPlotters = [] sigSamples = [ 'BulkGravToZZToZlepZinv_narrow_800', 'BulkGravToZZToZlepZinv_narrow_1000', 'BulkGravToZZToZlepZinv_narrow_1200', ] k = 1000 sigSampleNames = [ str(k) + ' x BulkG-800', str(k) + ' x BulkG-1000', str(k) + ' x BulkG-1200', ] sigXsec = { 'BulkGravToZZToZlepZinv_narrow_800': 4.42472e-04 * k, 'BulkGravToZZToZlepZinv_narrow_1000': 1.33926e-04 * k, 'BulkGravToZZToZlepZinv_narrow_1200': 4.76544e-05 * k, } for sample in sigSamples: sigPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) sigPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') sigPlotters[-1].addCorrectionFactor(str(sigXsec[sample]), 'tree') sigPlotters[-1].addCorrectionFactor('genWeight', 'tree') sigPlotters[-1].addCorrectionFactor('puWeight', 'tree') sigPlotters[-1].addCorrectionFactor('triggersf', 'tree') sigPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') sigPlotters[-1].setFillProperties(0, ROOT.kWhite) # --> Prepare data plotters: dataPlotters = [] dataSamples = [ 'SingleElectron_Run2015C_25ns_16Dec', 'SingleElectron_Run2015D_16Dec', 'SingleMuon_Run2015C_25ns_16Dec', 'SingleMuon_Run2015D_16Dec' ] for sample in dataSamples: dataPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) self.Data = MergedPlotter(dataPlotters) self.Data.setFillProperties(1001, ROOT.kGreen + 2) self.Stack = StackPlotter() self.Stack.addPlotter(self.Data, "data_obs", "Data", "data") self.Stack.addPlotter(self.WJets, "WJets", "W+Jets", "background") self.Stack.addPlotter(self.WW, "WW", "WW, WZ non-reson.", "background") self.Stack.addPlotter(self.TT, "TT", "TT", "background") self.Stack.addPlotter(self.VV, "ZZ", "ZZ, WZ reson.", "background") self.Stack.addPlotter(self.ZJets, "ZJets", "Z+Jets", "background") for i in range(len(sigSamples)): sigPlotters[i].setLineProperties(2, ROOT.kRed + i, 2) self.Stack.addPlotter(sigPlotters[i], sigSamples[i], sigSampleNames[i], 'signal') self.Stack.setLog(LogY) self.Stack.doRatio(doRatio) ROOT.gROOT.ProcessLine('.x tdrstyle.C')
# M_in (70,110) ### ----- Initialize (samples): plotter_ll = InitializePlotter(indir, addSig=False, addData=True, doRatio=True, LogY=logy) plotter_eu = InitializePlotter(indir, addSig=False, addData=True, doRatio=True, doElMu=True, scaleElMu=False, LogY=logy) setcuts = SetCuts() cuts = setcuts.GetAlphaCuts(zpt_cut=zpt_cut, met_cut=met_cut) outtxt.write('\n' + '*' * 20 + '\n') for reg in cuts: outtxt.write(reg + " inclusive : " + cuts[reg]['inclusive'] + '\n' + '-' * 20 + '\n') ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C') ### ----- Execute (plotting): #Inclusive stack plot: plotter_ll.Stack.drawStack('llnunu_l1_mass', cuts['ll']['inclusive'], str(lumi * 1000),
'nick':'udPhi', 'title':'||#Delta#Phi_{Z,MET}| - #pi/2|', 'par':(16, 0, 1.6)}, 2:{'var':'(llnunu_l2_pt*(abs(llnunu_deltaPhi)-TMath::Pi()/2)/abs(abs(llnunu_deltaPhi)-TMath::Pi()/2)/llnunu_l1_pt)', 'nick':'ptRatio_signed', 'title':'(+/-)E_{T}^{miss}/p_{T}^{Z}', 'par':(50, -5, 5)}} ### ----- Initialize (cuts and samples): Plotters = InitializePlotter(indir,addSig=True, addData=True) plotters = [(Plotters.ZJets, tags[0]), (Plotters.sigPlotters[1], tags[1])] #ZJets = plotter.ZJets #ZJets=plotter.sigPlotters[1] mycuts = SetCuts() #tex_dic = mycuts.Tex_dic cuts = mycuts.abcdCuts(Channel, Region) preSelect = mycuts.abcdCuts(Channel, Region, isPreSelect=True, zpt_cut=zpt_cut, met_cut=met_cut) preCuts = OrderedDict({'preSelect': preSelect, 'preSelect_dphiJMet2': preSelect+'&&(dPhi_jetMet_min>0.2)', 'preSelect_dphiJMet2a': preSelect+'&&(dPhi_jetMet_min_a>0.2)', 'preSelect_dphiJMet2b': preSelect+'&&(dPhi_jetMet_min_b>0.2)', 'preSelect_dphiJMet4': preSelect+'&&(dPhi_jetMet_min>0.4)', 'preSelect_dphiJMet4a': preSelect+'&&(dPhi_jetMet_min_a>0.4)', 'preSelect_dphiJMet4b': preSelect+'&&(dPhi_jetMet_min_b>0.4)', 'preSelect_dphiJMet2a_plus7': preSelect+'&&(dPhi_jetMet_min_a>0.2)&&(llnunu_l1_pt/llnunu_mtc<0.7)', 'preSelect_dphiJMet2a_plus8': preSelect+'&&(dPhi_jetMet_min_a>0.2)&&(llnunu_l1_pt/llnunu_mtc<0.8)', 'preSelect_dphiJMet4a_plus7': preSelect+'&&(dPhi_jetMet_min_a>0.4)&&(llnunu_l1_pt/llnunu_mtc<0.7)', 'preSelect_dphiJMet4a_plus8': preSelect+'&&(dPhi_jetMet_min_a>0.4)&&(llnunu_l1_pt/llnunu_mtc<0.8)', 'preSelect_dphiJMet4b_plus7': preSelect+'&&(dPhi_jetMet_min_b>0.4)&&(llnunu_l1_pt/llnunu_mtc<0.7)',
from python.SimplePlot import * tag0='sf_vs_met' tag = tag0+'_'+'test' outdir='sfvsMet1/' indir="../AnalysisRegion" lumi=2.318278305 if not os.path.exists(outdir): os.system('mkdir '+outdir) met_pt=np.arange(30,150,5).tolist() ### ----- Initialize (samples): plotter_ll=InitializePlotter(addSig=False, addData=True,doRatio=False, indir=indir) #plotter_eu=InitializePlotter(addSig=False, addData=True,doRatio=False, doElMu=True) setcuts=SetCuts() # print "I am cuts_ll:" # cuts_ll=setcuts.alphaCuts(Zmass='inclusive') # print "I am cuts_eu:" # cuts_eu=setcuts.alphaCuts(isll=False, Zmass='inclusive') # ROOT.gROOT.ProcessLine('.x tdrstyle.C') channel = raw_input("[info] 'sf_vs_met.py' -> Please choose el/mu channel (el or mu, default mu): \n") if channel=='': channel='mu' cuts_met0=setcuts.abcdCuts(channel, 'SR', met_cut='0') fout = ROOT.TFile(outdir+tag+"_"+channel+'.root','recreate') histo={} for key in cuts_met0: # MET (data):
import ROOT, os, sys from math import * from itertools import combinations, product from python.SimplePlot import * from python.SetCuts import SetCuts from python.InitializePlotter import InitializePlotter printfile = open('num_out.txt', 'a') Channel = raw_input("Please choose a channel (el or mu): \n") lsChannel = [] if Channel == "": lsChannel = ['el', 'mu'] else: lsChannel.append(Channel) mycuts = SetCuts() tag0 = 'ZJstudy' outdir = 'test' indir = "./METSkim/" lumi = 2.318278305 doprint = True if not os.path.exists(outdir): os.system('mkdir ' + outdir) tag = tag0 + '_' + 'test' outTag = outdir + '/' + tag # B | A # ------- |dphi-pi/2| # D | C
import ROOT, os, sys from math import * from itertools import combinations, product from python.SimplePlot import * from python.SetCuts import SetCuts from python.InitializePlotter import InitializePlotter printfile = open('num_out.txt', 'a') Channel=raw_input("Please choose a channel (el or mu): \n") lsChannel=[] if Channel=="": lsChannel=['el', 'mu'] else: lsChannel.append(Channel) mycuts=SetCuts() tag0='ZJstudy' outdir='test' indir="./METSkim/" lumi=2.318278305 doprint=True if not os.path.exists(outdir): os.system('mkdir '+outdir) tag = tag0+'_'+'test' outTag=outdir+'/'+tag # B | A # ------- |dphi-pi/2| # D | C
'var': 'abs(llnunu_deltaPhi-TMath::Pi()/2)', 'nick': 'udPhi', 'title': '#Delta#Phi_{Z,MET} - #pi/2', 'par': (16, 0, 1.6) }, 2: { 'var': '(llnunu_l2_pt*(llnunu_deltaPhi-TMath::Pi()/2)/abs(llnunu_deltaPhi-TMath::Pi()/2)/llnunu_l1_pt)', 'nick': 'ptRatio_signed', 'title': '(+/-)E_{T}^{miss}/p_{T}^{Z}', 'par': (50, -5, 5) } } ### ----- Initialize (cuts and samples): mycuts = SetCuts() #tex_dic = mycuts.Tex_dic srcuts = mycuts.GetSRCut() srcuts_dev = OrderedDict({'SR': srcuts, 'SR_LepVeto': srcuts + '&&(nlep<3)'}) for key in srcuts_dev: print key, srcuts_dev[key] plotter = InitializePlotter(indir) Stack = plotter.Stack ### ----- Execute (plotting): ROOT.gROOT.ProcessLine('.x tdrstyle.C') ROOT.gStyle.SetPadBottomMargin(0.2) ROOT.gStyle.SetPadLeftMargin(0.15) #ROOT.TH1.AddDirectory(ROOT.kFALSE) #in this way you could close the TFile after you registe the histograms yields = OrderedDict()
from math import * from itertools import combinations, product from python.TreePlotter import TreePlotter from python.MergedPlotter import MergedPlotter from python.StackPlotter import StackPlotter from python.SimplePlot import * from python.SetCuts import SetCuts printfile = open('num_out.txt', 'a') Channel = raw_input("Please choose a channel (el or mu): \n") lsChannel = [] if Channel == "": lsChannel = ['el', 'mu'] else: lsChannel.append(Channel) mycuts = SetCuts() tag0 = 'ZJstudy' outdir = 'test' indir = "../AnalysisRegion" lumi = 2.169126704526 LogY = False doprint = True if not os.path.exists(outdir): os.system('mkdir ' + outdir) tag = tag0 + '_' + 'test' if LogY: tag = tag + '_log' outTag = outdir + '/' + tag # A | C
var="fabs(llnunu_deltaPhi)" doSub=True whichdt='dt_sub' if doSub else 'dt' whichbcd='zjets' if doSub else 'allmc' tag = tag0+'_'+'printer' outTag=outdir+'/'+tag CheckDir(outdir) outtxt = open(outdir+'/num_out.txt', 'a') ### ----- Initialize (samples): plotter=InitializePlotter(indir=indir, addData=True) setcuts = SetCuts() cuts=setcuts.abcdCuts(channel=channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut,extra_cut='dPhi_jetMet_min_b>0.5') outtxt.write( '\n'+ '*'*20+'\n') outtxt.write( '\n'+ whichregion+'\n') for reg in cuts: outtxt.write(reg+" "+channel+" : "+cuts[reg]+'\n'+'-'*20+'\n') histo=OrderedDict() # will have histo[<reg>]=[h1, h2...] yields=OrderedDict() # will have yields[<reg>][<memeber>]=yield err=OrderedDict() # will have yields[<reg>][<memeber>]=err nbins, xmin, xmax=32, 0.0, 3.2 members={'non-zjets': plotter.NonZBG, 'zjets': plotter.ZJets, 'dt': plotter.Data } # in format: members[<reg>][<mem>]=plotter
outdir = 'test' indir = "../AnalysisRegion" lumi = 2.169126704526 LogY = False if not os.path.exists(outdir): os.system('mkdir ' + outdir) tag = tag0 + '_' + 'test' if LogY: tag = tag + '_log' outTag = outdir + '/' + tag # A | C # ------- dPhi(Z,MET) = 2.5 # B | D # dR(ll)=0.8 / 1.0 mycuts = SetCuts() tex_dic = mycuts.Tex_dic cuts = mycuts.abcdCuts(Channel) print cuts ### ----- Initialize (samples): zjetsPlotters = [] zjetsSamples = ['DYJetsToLL_M50'] # M50_BIG = M50 + M50_Ext, 150M evts for sample in zjetsSamples: zjetsPlotters.append(TreePlotter(indir + '/' + sample + '.root', 'tree')) zjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') zjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') zjetsPlotters[-1].addCorrectionFactor('genWeight', 'tree') zjetsPlotters[-1].addCorrectionFactor('puWeight', 'tree')
class StackDataDriven: def __init__(self, indir="./nonResSkim_v3.0", outdir='stack_test', lumi = 2.318278305, sepSig=True, LogY=True, doRatio=True, addSig=True, addData=True): if not os.path.exists(outdir): os.system('mkdir '+outdir) self.logy=LogY self.outdir = outdir self.lumi = lumi self.plotter_eu=InitializePlotter(indir, addSig=False, addData=True, doRatio=doRatio, doElMu=True, LogY=LogY) self.plotter_ll=InitializePlotter(indir, addSig=addSig, addData=True, doRatio=doRatio, LogY=LogY) self.plotter_ll.Stack.rmPlotter(self.plotter_ll.TT, "TT","TT", "background") self.plotter_ll.Stack.rmPlotter(self.plotter_ll.WW, "WW","WW, WZ non-reson.", "background") self.plotter_ll.Stack.rmPlotter(self.plotter_ll.WJets, "WJets","W+Jets", "background") self.setcuts=SetCuts() ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C') self.zpt_cut, self.met_cut= '100', '0' self.cuts=self.setcuts.GetAlphaCuts(zpt_cut=self.zpt_cut, met_cut=self.met_cut) def drawDataDrivenMC(self, var_ll, var_emu, nbinsx, xmin, xmax, titlex, units, xcutmin, xcutmax): h_nonRes_dd = self.plotter_eu.Data.drawTH1(var_emu, var_emu, self.cuts['emu']['in'], '1', nbinsx, xmin, xmax, titlex = titlex, units = units, drawStyle="HIST") h_nonRes_mc = self.plotter_ll.NonResBG.drawTH1(var_ll, var_ll, self.cuts['ll']['in'], str(self.lumi*1000), nbinsx, xmin, xmax, titlex = titlex, units = units, drawStyle="HIST") drawCompareSimple(h_nonRes_dd, h_nonRes_mc, "non-reson. data-driven", "non-reson. MC", xmin=xcutmin, xmax=xcutmax, outdir=self.outdir, notes="", tag='compare_dataDriven_MC'+'_'+var_ll, units=units, lumi=self.lumi, ytitle='events') return def drawDataDrivenStack(self, var_ll, var_emu, nbinsx, xmin, xmax, titlex, units, xcutmin, xcutmax): tag = 'stack_nonResDD'+'_'+'test' outTag = self.outdir+'/'+tag stackTag=tag+'_'+var_ll self.plotter_ll.Stack.drawStack(var_ll, self.cuts['ll']['in'], str(self.lumi*1000), nbinsx, xmin, xmax, titlex = titlex, units = units, output=stackTag, outDir=self.outdir, separateSignal=True, drawtex="", channel="") h_nonRes_dd = self.plotter_eu.Data.drawTH1(var_emu, var_emu, self.cuts['emu']['in'], '1', nbinsx, xmin, xmax, titlex = titlex, units = units, drawStyle="HIST") h_nonRes_dd.SetFillColor(ROOT.kAzure-9) # Draw the m_ll in z window with data-driven non-res bkg ROOT.TH1.AddDirectory(ROOT.kFALSE) fstack=ROOT.TFile(self.outdir+'/'+stackTag+'.root') hs=fstack.Get(stackTag+"_stack") hframe=fstack.Get(stackTag+'_frame') hframe.GetXaxis().SetRangeUser(xcutmin, xcutmax) if ROOT.TString(var_ll).Contains("mass"): if self.logy: hframe.SetMaximum(hframe.GetMaximum()*100) else: hframe.SetMaximum(hframe.GetMaximum()*1.2) hdata=fstack.Get(stackTag+'_data0') legend=fstack.Get(stackTag+'_legend') hsig1=fstack.Get(stackTag+'_BulkGravToZZToZlepZinv_narrow_800') hsig2=fstack.Get(stackTag+'_BulkGravToZZToZlepZinv_narrow_1000') hsig3=fstack.Get(stackTag+'_BulkGravToZZToZlepZinv_narrow_1200') fstack.Close() print '[debug] llin, datadriven nonres: ', h_nonRes_dd.Integral() print '[debug] llin, dt: ', hdata.Integral() hsnew=ROOT.THStack(stackTag+"_stack_new","") hsnew.Add(h_nonRes_dd) nonresTag=[stackTag+'_'+sample for sample in ['WJets0','TT0','WW0'] ] for ihist in hs.GetHists(): if ihist.GetName() in nonresTag: print '[Removing...] I am a nonres bkg : ',ihist.GetName() else: hsnew.Add(ihist) for ih in hsnew.GetHists(): print '[debug] ', ih.GetName() print hsnew hratio=GetRatio_TH1(hdata,hsnew,True) myentry=ROOT.TLegendEntry(h_nonRes_dd,"non-reson. (data-driven)","f") # Let's remove the signal entries in the legend for ileg in legend.GetListOfPrimitives(): if ileg.GetLabel() in ['W+Jets', 'TT', 'WW, WZ non-reson.']: legend.GetListOfPrimitives().Remove(ileg) if ileg.GetLabel()=='Data': beforeObject=ileg legend.GetListOfPrimitives().AddBefore(beforeObject,myentry) drawStack_simple(hframe, hsnew, hdata, hratio, legend, hstack_opt="A, HIST", outDir=self.outdir, output=stackTag+"_datadriven", channel=ROOT.TString("inclusive"), xmin=xcutmin, xmax=xcutmax, xtitle=titlex ,units=units, lumi=self.lumi, notes="no E_{T}^{miss}/P_{T}^{Z} cuts", drawSig=True, hsig=[hsig1, hsig2, hsig3]) return
from python.myStackPlotter import StackPlotter from python.SimplePlot import * from python.SetCuts import SetCuts ##--- Setup: inputs newvar="dPhi_jetMet_min" indir="/dataf/mewu/METSkim_v1.1/"; outdir="output/newcut/" CheckDir(outdir) # if not, this will create it onlyStats=False; scaleDphi=False; LogY=True; doRatio=False;# no data, please set doRatio to false sigk=1000; lumi=2.318278305; lepsf='llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf' triggersf='triggersf' setcuts = SetCuts() cuts = setcuts.abcdCuts(channel="inclusive", whichRegion="SR", isPreSelect=True, zpt_cut='100', met_cut='50') ##--- Initialize: plotter zjetsPlotters=[] zjetsSamples = ['DYJetsToLL_M50_BIG'] # M50_BIG = M50 + M50_Ext for sample in zjetsSamples: zjetsPlotters.append(TreePlotter(indir+'/'+sample+'.root','tree')) if not onlyStats: zjetsPlotters[-1].addCorrectionFactor('1./SumWeights','tree') zjetsPlotters[-1].addCorrectionFactor('xsec','tree') #zjetsPlotters[-1].addCorrectionFactor('(1921.8*3)','xsec') zjetsPlotters[-1].addCorrectionFactor('genWeight','tree') zjetsPlotters[-1].addCorrectionFactor('puWeight','tree') zjetsPlotters[-1].addCorrectionFactor(triggersf,'tree') zjetsPlotters[-1].addCorrectionFactor(lepsf,'tree')
# ll in Z | ll out Z # -------------------- M_out [35,65] U [115,120] # eu in Z | eu out Z # M_in (70,110) ### ----- Initialize (samples): plotter_ll = InitializePlotter(indir, addSig=False, addData=True, doRatio=False) plotter_eu = InitializePlotter(indir, addSig=False, addData=True, doRatio=False, doElMu=True) setcuts = SetCuts() cuts_ll = { 'inclusive': setcuts.alphaCuts(Zmass='inclusive', zpt_cut=zpt_cut, met_cut=met_cut), 'in': setcuts.alphaCuts(isll=True, Zmass='in', zpt_cut=zpt_cut, met_cut=met_cut), 'out': setcuts.alphaCuts(isll=True, Zmass='out', zpt_cut=zpt_cut, met_cut=met_cut) } cuts_eu = { 'inclusive': setcuts.alphaCuts(isll=False, Zmass='inclusive', zpt_cut=zpt_cut, met_cut=met_cut), 'in':
whichregion=raw_input("Please choose a benchmarck Region (SR or VR): \n") lswhichregion=[] if whichregion=="": lswhichregion=['SR', 'VR'] else: lswhichregion.append(whichregion) # ll in Z | ll out Z # -------------------- M_out [35,65] U [115,120] # eu in Z | eu out Z # M_in (70,110) ### ----- Initialize (samples): plotter_ll=InitializePlotter(addSig=False, addData=False,doRatio=False) plotter_eu=InitializePlotter(addSig=False, addData=False,doRatio=False, doElMu=True) setcuts=SetCuts() print "I am cuts_ll:" cuts_ll=setcuts.alphaCuts(inclusive=True) print "I am cuts_eu:" cuts_eu=setcuts.alphaCuts(isll=False, inclusive=True) exit(0) ### ----- Execute (plotting): print product(lsChannel, lswhichregion) for Channel, whichregion in product(lsChannel, lswhichregion): cuts=mycuts.abcdCuts(Channel, whichregion) print cuts ROOT.gROOT.ProcessLine('.x tdrstyle.C')
tag = tag0 + '_' + 'test' outdir = 'sfvsMet1/' indir = "../AnalysisRegion" lumi = 2.318278305 if not os.path.exists(outdir): os.system('mkdir ' + outdir) met_pt = np.arange(30, 150, 5).tolist() ### ----- Initialize (samples): plotter_ll = InitializePlotter(addSig=False, addData=True, doRatio=False, indir=indir) #plotter_eu=InitializePlotter(addSig=False, addData=True,doRatio=False, doElMu=True) setcuts = SetCuts() # print "I am cuts_ll:" # cuts_ll=setcuts.alphaCuts(Zmass='inclusive') # print "I am cuts_eu:" # cuts_eu=setcuts.alphaCuts(isll=False, Zmass='inclusive') # ROOT.gROOT.ProcessLine('.x tdrstyle.C') channel = raw_input( "[info] 'sf_vs_met.py' -> Please choose el/mu channel (el or mu, default mu): \n" ) if channel == '': channel = 'mu' cuts_met0 = setcuts.abcdCuts(channel, 'SR', met_cut='0') fout = ROOT.TFile(outdir + tag + "_" + channel + '.root', 'recreate') histo = {}
outdir = './output/comparison2D' CheckDir(outdir) lumi = 2.318278305 tag0 = 'ZJstudy' whichregion = 'SR' channel = 'inclusive' zpt_cut, met_cut = '100', '50' yvar, xvar = 'llnunu_l2_pt', 'llnunu_l1_pt' ymin, ymax, ytitle, xunits = 50, 300, "E_{T}^{miss}", "GeV" xmin, xmax, xtitle, yunits = 100, 600, "p_{T}^{Z}", "GeV" nbinsy, nbinsx = int((ymax - ymin) / 5.), int((xmax - xmin) / 5.) ### ----- Initialize (samples): plotter = InitializePlotter(indir=indir) setcuts = SetCuts() cuts = setcuts.abcdCuts(channel=channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) histo = OrderedDict() ### ----- Execute (plotting): for reg in cuts: nameseq = [tag0, '2D', yvar, xvar, reg] h2 = plotter.ZJets.drawTH2('_'.join(nameseq), yvar + ':' + xvar, cuts[reg], str(lumi * 1000), nbinsx, xmin,
lumi=2.318278305 zpt_cut, met_cut= '100', '100' if not os.path.exists(outdir): os.system('mkdir '+outdir) tag = tag0+'_'+'test' outTag=outdir+'/'+tag # ll in Z | ll out Z # -------------------- M_out [35,65] U [115,120] # eu in Z | eu out Z # M_in (70,110) ### ----- Initialize (samples): plotter_ll=InitializePlotter(indir, addSig=False, addData=True,doRatio=False) plotter_eu=InitializePlotter(indir, addSig=False, addData=True,doRatio=False, doElMu=True) setcuts=SetCuts() cuts_ll={'inclusive': setcuts.alphaCuts(Zmass='inclusive', zpt_cut=zpt_cut, met_cut=met_cut), 'in': setcuts.alphaCuts(isll=True, Zmass='in', zpt_cut=zpt_cut, met_cut=met_cut), 'out': setcuts.alphaCuts(isll=True, Zmass='out', zpt_cut=zpt_cut, met_cut=met_cut)} cuts_eu={'inclusive': setcuts.alphaCuts(isll=False, Zmass='inclusive', zpt_cut=zpt_cut, met_cut=met_cut), 'in' : setcuts.alphaCuts(isll=False, Zmass='in', zpt_cut=zpt_cut, met_cut=met_cut), 'out': setcuts.alphaCuts(isll=False, Zmass='out', zpt_cut=zpt_cut, met_cut=met_cut)} ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C') ### ----- Execute (plotting): plotter_ll.Stack.drawStack('llnunu_l1_mass', cuts_ll['inclusive'], str(lumi*1000), 10, 0.0, 200.0, titlex = "M_{Z}^{ll}", units = "GeV", output=tag+'_mll',outDir=outdir, separateSignal=True, drawtex="", channel="") plotter_eu.Stack.drawStack('elmununu_l1_mass', cuts_eu['inclusive'], str(lumi*1000), 10, 0.0, 200.0, titlex = "M_{Z}^{e#mu}", units = "GeV",
indir="./METSkim_v1" outdir='./output/comparison2D'; CheckDir(outdir) lumi=2.318278305 tag0='ZJstudy' whichregion='SR' channel='inclusive' zpt_cut, met_cut= '100', '50' yvar, xvar='llnunu_l2_pt','llnunu_l1_pt' ymin, ymax, ytitle, xunits = 50, 300, "E_{T}^{miss}", "GeV" xmin, xmax, xtitle, yunits = 100, 600, "p_{T}^{Z}", "GeV" nbinsy, nbinsx = int((ymax-ymin)/5.), int((xmax-xmin)/5.) ### ----- Initialize (samples): plotter=InitializePlotter(indir=indir) setcuts = SetCuts() cuts=setcuts.abcdCuts(channel=channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) histo=OrderedDict() ### ----- Execute (plotting): for reg in cuts: nameseq=[tag0, '2D', yvar, xvar, reg] h2 = plotter.ZJets.drawTH2('_'.join(nameseq), yvar+':'+xvar, cuts[reg], str(lumi*1000), nbinsx, xmin, xmax, nbinsy, ymin, ymax, titlex = xtitle, unitsx = xunits, titley = ytitle, unitsy = yunits) histo[reg]=h2 ### ----- Finalize (Save to file): ROOT.TH1.AddDirectory(ROOT.kFALSE) outseq=[tag0, '2D', yvar, xvar] fout2d=ROOT.TFile(outdir+'/'+'_'.join(outseq)+".root","recreate") fout2d.cd()
2: { 'var': '(llnunu_l2_pt*(abs(llnunu_deltaPhi)-TMath::Pi()/2)/abs(abs(llnunu_deltaPhi)-TMath::Pi()/2)/llnunu_l1_pt)', 'nick': 'ptRatio_signed', 'title': '(+/-)E_{T}^{miss}/p_{T}^{Z}', 'par': (50, -5, 5) } } ### ----- Initialize (cuts and samples): Plotters = InitializePlotter(indir, addSig=True, addData=True) plotters = [(Plotters.ZJets, tags[0]), (Plotters.sigPlotters[1], tags[1])] #ZJets = plotter.ZJets #ZJets=plotter.sigPlotters[1] mycuts = SetCuts() #tex_dic = mycuts.Tex_dic cuts = mycuts.abcdCuts(Channel, Region) preSelect = mycuts.abcdCuts(Channel, Region, isPreSelect=True, zpt_cut=zpt_cut, met_cut=met_cut) preCuts = OrderedDict({ 'preSelect': preSelect, 'preSelect_dphiJMet2': preSelect + '&&(dPhi_jetMet_min>0.2)', 'preSelect_dphiJMet2a': preSelect + '&&(dPhi_jetMet_min_a>0.2)', 'preSelect_dphiJMet2b':
outdir = 'plots/sfvsMet/' indir = "./METSkim" lumi = 2.3182783052 if not os.path.exists(outdir): os.system('mkdir ' + outdir) #met_pt=np.arange(30,150,5).tolist() ### ----- Initialize (samples): plotter_ll = InitializePlotter(addSig=False, addData=True, doRatio=False, indir=indir, doMetCorr=True) #plotter_eu=InitializePlotter(addSig=False, addData=True,doRatio=False, doElMu=True) setcuts = SetCuts() # print "I am cuts_ll:" # cuts_ll=setcuts.alphaCuts(Zmass='inclusive') # print "I am cuts_eu:" # cuts_eu=setcuts.alphaCuts(isll=False, Zmass='inclusive') # ROOT.gROOT.ProcessLine('.x tdrstyle.C') channel = raw_input( "[info] 'sf_vs_met.py' -> Please choose el/mu channel (el or mu, default mu): \n" ) if channel == '': channel = 'mu' cuts_met0 = setcuts.abcdCuts(channel, 'SR', met_cut='0') for i in cuts_met0: print i, ' : ', cuts_met0[i]
var = "fabs(llnunu_deltaPhi)" doSub = True whichdt = 'dt_sub' if doSub else 'dt' whichbcd = 'zjets' if doSub else 'allmc' tag = tag0 + '_' + 'printer' outTag = outdir + '/' + tag CheckDir(outdir) outtxt = open(outdir + '/num_out.txt', 'a') ### ----- Initialize (samples): plotter = InitializePlotter(indir=indir) setcuts = SetCuts() #cuts=setcuts.abcdCuts(channel=channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) #preselect=setcuts.abcdCuts(channel=channel, whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut,isPreSelect=True) zjcuts = setcuts.GetZjetsCuts(whichRegion=whichregion, zpt_cut=zpt_cut, met_cut=met_cut) cuts = zjcuts[channel] outtxt.write('\n' + '*' * 20 + '\n') outtxt.write('\n' + whichregion + '\n') for reg in cuts: outtxt.write(reg + " " + channel + " : " + cuts[reg] + '\n' + '-' * 20 + '\n') histo = OrderedDict() # will have histo[<reg>]=[h1, h2...] yields = OrderedDict() # will have yields[<reg>][<memeber>]=yield
class abcdAnalyzer: def __init__(self, indir="../AnalysisRegion", outdir='plots', lumi=2.169126704526, sepSig=True, LogY=True, doRatio=True): if not os.path.exists(outdir): os.system('mkdir ' + outdir) self.mycuts = SetCuts() self.Channel = raw_input("Please choose a channel (el or mu): \n") self.outdir = outdir self.lumi = lumi self.sepSig = sepSig self.tex_dic = self.mycuts.Tex_dic self.whichregion = raw_input( "Please choose a benchmarck Region (SR or VR): \n") self.cuts = self.mycuts.abcdCuts(self.Channel, self.whichregion) self.preCuts = self.mycuts.abcdCuts(self.Channel, self.whichregion, True) if self.whichregion == "VR": self.nbins, self.xMin, self.xMax = 10, 0, float(self.mycuts.met_pt) else: self.nbins, self.xMin, self.xMax = 10, 0, 500 #######----------- Prepare samples to plot: zjetsPlotters = [] #zjetsSamples = ['DYJetsToLL_M50_HT100to200','DYJetsToLL_M50_HT200to400','DYJetsToLL_M50_HT400to600','DYJetsToLL_M50_HT600toInf'] #zjetsSamples = ['DYJetsToLL_M50','DYJetsToLL_M50_Ext'] zjetsSamples = ['DYJetsToLL_M50_BIG'] # M50_BIG = M50 + M50_Ext for sample in zjetsSamples: zjetsPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) zjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') zjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') zjetsPlotters[-1].addCorrectionFactor('genWeight', 'tree') zjetsPlotters[-1].addCorrectionFactor('puWeight', 'tree') zjetsPlotters[-1].addCorrectionFactor('triggersf', 'tree') zjetsPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.ZJets = MergedPlotter(zjetsPlotters) self.ZJets.setFillProperties(1001, ROOT.kGreen + 2) wwPlotters = [] wwSamples = ['WWTo2L2Nu', 'WWToLNuQQ', 'WZTo1L1Nu2Q'] for sample in wwSamples: wwPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) wwPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') wwPlotters[-1].addCorrectionFactor('xsec', 'tree') wwPlotters[-1].addCorrectionFactor('genWeight', 'tree') wwPlotters[-1].addCorrectionFactor('puWeight', 'tree') wwPlotters[-1].addCorrectionFactor('triggersf', 'tree') wwPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.WW = MergedPlotter(wwPlotters) self.WW.setFillProperties(1001, ROOT.kOrange) vvPlotters = [] vvSamples = ['WZTo2L2Q', 'WZTo3LNu', 'ZZTo2L2Nu', 'ZZTo2L2Q', 'ZZTo4L'] for sample in vvSamples: vvPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) vvPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') vvPlotters[-1].addCorrectionFactor('xsec', 'tree') vvPlotters[-1].addCorrectionFactor('genWeight', 'tree') vvPlotters[-1].addCorrectionFactor('puWeight', 'tree') vvPlotters[-1].addCorrectionFactor('triggersf', 'tree') vvPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.VV = MergedPlotter(vvPlotters) self.VV.setFillProperties(1001, ROOT.kMagenta) wjetsPlotters = [] wjetsSamples = ['WJetsToLNu'] for sample in wjetsSamples: wjetsPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) wjetsPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') wjetsPlotters[-1].addCorrectionFactor('xsec', 'tree') wjetsPlotters[-1].addCorrectionFactor('genWeight', 'tree') wjetsPlotters[-1].addCorrectionFactor('puWeight', 'tree') wjetsPlotters[-1].addCorrectionFactor('triggersf', 'tree') wjetsPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.WJets = MergedPlotter(wjetsPlotters) self.WJets.setFillProperties(1001, ROOT.kBlue - 6) ttPlotters = [] ttSamples = ['TTTo2L2Nu'] #,'TTZToLLNuNu','TTWJetsToLNu'] for sample in ttSamples: ttPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) ttPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') ttPlotters[-1].addCorrectionFactor('xsec', 'tree') ttPlotters[-1].addCorrectionFactor('genWeight', 'tree') ttPlotters[-1].addCorrectionFactor('puWeight', 'tree') ttPlotters[-1].addCorrectionFactor('triggersf', 'tree') ttPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.TT = MergedPlotter(ttPlotters) self.TT.setFillProperties(1001, ROOT.kAzure - 9) # --> define different background sets: nonZBGPlotters = [] nonZBGSamples = wwSamples + vvSamples + wjetsSamples + ttSamples for sample in nonZBGSamples: nonZBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) nonZBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') nonZBGPlotters[-1].addCorrectionFactor('xsec', 'tree') nonZBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') nonZBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') nonZBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') nonZBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.NonZBG = MergedPlotter(nonZBGPlotters) self.NonZBG.setFillProperties(1001, ROOT.kPink + 6) nonResBGPlotters = [] nonResBGSamples = wwSamples + wjetsSamples + ttSamples for sample in nonResBGSamples: nonResBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) nonResBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') nonResBGPlotters[-1].addCorrectionFactor('xsec', 'tree') nonResBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') nonResBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') nonResBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') nonResBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.NonResBG = MergedPlotter(nonResBGPlotters) self.NonResBG.setFillProperties(1001, ROOT.kYellow) resBGPlotters = [] resBGSamples = zjetsSamples + vvSamples for sample in resBGSamples: resBGPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) resBGPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') resBGPlotters[-1].addCorrectionFactor('xsec', 'tree') resBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') resBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') resBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') resBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') self.ResBG = MergedPlotter(resBGPlotters) self.ResBG.setFillProperties(1001, ROOT.kRed) # --> Prepare the signal plotters: sigPlotters = [] sigSamples = [ 'BulkGravToZZToZlepZinv_narrow_800', 'BulkGravToZZToZlepZinv_narrow_1000', 'BulkGravToZZToZlepZinv_narrow_1200', ] k = 1000 sigSampleNames = [ str(k) + ' x BulkG-800', str(k) + ' x BulkG-1000', str(k) + ' x BulkG-1200', ] sigXsec = { 'BulkGravToZZToZlepZinv_narrow_800': 4.42472e-04 * k, 'BulkGravToZZToZlepZinv_narrow_1000': 1.33926e-04 * k, 'BulkGravToZZToZlepZinv_narrow_1200': 4.76544e-05 * k, } for sample in sigSamples: sigPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) sigPlotters[-1].addCorrectionFactor('1./SumWeights', 'tree') sigPlotters[-1].addCorrectionFactor(str(sigXsec[sample]), 'tree') sigPlotters[-1].addCorrectionFactor('genWeight', 'tree') sigPlotters[-1].addCorrectionFactor('puWeight', 'tree') sigPlotters[-1].addCorrectionFactor('triggersf', 'tree') sigPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') sigPlotters[-1].setFillProperties(0, ROOT.kWhite) # --> Prepare data plotters: dataPlotters = [] dataSamples = [ 'SingleElectron_Run2015C_25ns_16Dec', 'SingleElectron_Run2015D_16Dec', 'SingleMuon_Run2015C_25ns_16Dec', 'SingleMuon_Run2015D_16Dec' ] for sample in dataSamples: dataPlotters.append( TreePlotter(indir + '/' + sample + '.root', 'tree')) self.Data = MergedPlotter(dataPlotters) self.Data.setFillProperties(1001, ROOT.kGreen + 2) self.Stack = StackPlotter() self.Stack.addPlotter(self.Data, "data_obs", "Data", "data") self.Stack.addPlotter(self.WJets, "WJets", "W+Jets", "background") self.Stack.addPlotter(self.WW, "WW", "WW, WZ non-reson.", "background") self.Stack.addPlotter(self.TT, "TT", "TT", "background") self.Stack.addPlotter(self.VV, "ZZ", "ZZ, WZ reson.", "background") self.Stack.addPlotter(self.ZJets, "ZJets", "Z+Jets", "background") for i in range(len(sigSamples)): sigPlotters[i].setLineProperties(2, ROOT.kRed + i, 2) self.Stack.addPlotter(sigPlotters[i], sigSamples[i], sigSampleNames[i], 'signal') self.Stack.setLog(LogY) self.Stack.doRatio(doRatio) ROOT.gROOT.ProcessLine('.x tdrstyle.C') def GetStack(self): return self.Stack #######----------- Start Plotting: def draw_preselection(self): tag = 'PreSelection_' + self.Channel + '_' #print self.Stack.log if self.Stack.log: tag = tag + 'log_' self.Stack.drawStack('met_pt', self.preCuts, str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex="E_{T}^{miss}", units="GeV", output=tag + 'met_low', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) self.Stack.drawStack('llnunu_l1_deltaR', self.preCuts, str(self.lumi * 1000), 30, 0, 3, titlex="#Delta R(l,l)", units="", output=tag + 'dR_ll', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) self.Stack.drawStack('llnunu_deltaPhi', self.preCuts, str(self.lumi * 1000), 35, 0, 3.5, titlex="#Delta#Phi(Z,E_{T}^{miss})", units="", output=tag + 'dPhi_llvv', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) self.Stack.drawStack('llnunu_l1_deltaPhi', self.preCuts, str(self.lumi * 1000), 30, 0, 3, titlex="#Delta#Phi(l,l)", units="", output=tag + 'dPhi_ll', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) self.Stack.drawStack('llnunu_l1_mass', self.preCuts, str(self.lumi * 1000), 50, 50, 150, titlex="M_{ll}", units="GeV", output=tag + 'zmass', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) self.Stack.drawStack('llnunu_mt', self.preCuts, str(self.lumi * 1000), 30, 0.0, 600.0, titlex="M_{T}^{ll#nu#nu}", units="GeV", output=tag + 'mt_low', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.whichregion + " pre-selection", channel=self.Channel) #self.Stack.drawStack('llnunu_mt', self.preCuts, str(self.lumi*1000), 60, 0.0, 1200.0, titlex = "M_{T}^{ll#nu#nu}", units = "GeV", output=tag+'mt',outDir=self.outdir,separateSignal=self.sepSig,drawtex=self.whichregion+" pre-selection", channel=self.Channel) #self.Stack.drawStack('llnunu_mt', self.preCuts, str(self.lumi*1000), 150, 0.0, 3000.0, titlex = "M_{T}^{ll#nu#nu}", units = "GeV", output=tag+'mt_high',outDir=self.outdir,separateSignal=self.sepSig,drawtex=self.whichregion+" pre-selection", channel=self.Channel) # merge all output plots into one pdf file os.system('gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=' + self.outdir + '/' + tag + 'all.pdf ' + self.outdir + '/' + tag + '*.eps') print 'All plots merged in single pdf file ' + tag + '.pdf .' # merge root file os.system('hadd -f ' + self.outdir + '/' + tag + 'all.root ' + self.outdir + '/' + tag + '*.root') return def draw_BCD(self): #cuts=python.SetCuts.Cuts(self.Channel) for key in self.tex_dic: if ROOT.TString(key).Contains("SR"): continue else: tag = key + '_' + self.whichregion + '_' + self.Channel + '_' if self.Stack.log: tag = tag + 'log_' else: pass self.Stack.drawStack('llnunu_mt', self.cuts[key], str(self.lumi * 1000), 60, 0.0, 1200.0, titlex="M_{T}", units="GeV", output=tag + 'mt', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic[key], channel=self.Channel) self.Stack.drawStack('llnunu_mt', self.cuts[key], str(self.lumi * 1000), 150, 0.0, 3000.0, titlex="M_{T}", units="GeV", output=tag + 'mt_high', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic[key], channel=self.Channel) self.Stack.drawStack('llnunu_l1_pt', self.cuts[key], str(self.lumi * 1000), 100, 0, 1000, titlex="p_{T}^{ll}", units="GeV", output=tag + 'pt', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic[key], channel=self.Channel) self.Stack.drawStack('met_pt', self.cuts[key], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex="E_{T}^{miss}", units="GeV", output=tag + 'met_low', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic[key], channel=self.Channel) # merge all output plots into one pdf file os.system( 'gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=' + self.outdir + '/' + tag + 'all.pdf ' + self.outdir + '/' + tag + '*.eps') print 'All plots merged in single pdf file ' + tag + '.pdf .' # merge root file os.system('hadd -f ' + self.outdir + '/' + tag + 'all.root ' + self.outdir + '/' + tag + '*.root') return def draw_A(self, useMC=False, sf_bd=0.0): tag = 'regionA_' + self.whichregion + '_' + self.Channel + '_' if not useMC: if sf_bd == 0.0: sf_bd = ROOT.Double( raw_input( "Please give the scale factor derived from B,D regions: \n" )) else: pass self.Stack.rmPlotter(self.ZJets, "ZJets", "Z+Jets", "background") self.Stack.drawStack('met_pt', self.cuts['SR'], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex="E_{T}^{miss}", units="GeV", output=tag + 'met_low', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic['SR'], channel=self.Channel) file = ROOT.TFile(self.outdir + '/' + tag + 'met_low.root') h_met_zjets_a = self.ZJets.drawTH1('met_pt', self.cuts['SR'], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex='E_{T}^{miss}', units='GeV', drawStyle="HIST") h_met_zjets_a.Scale(1. / h_met_zjets_a.Integral()) h_met_zjets_c = self.ZJets.drawTH1('met_pt', self.cuts['CRc'], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex='E_{T}^{miss}', units='GeV', drawStyle="HIST") h_met_zjets_c.Scale(1. / h_met_zjets_c.Integral()) h_met_zjets_a.Divide(h_met_zjets_c) h_met_zjets = self.Data.drawTH1('met_pt', self.cuts['CRc'], str('1'), self.nbins, self.xMin, self.xMax, titlex='E_{T}^{miss}', units='GeV', drawStyle="HIST") h_met_nonzjets = self.NonZBG.drawTH1('met_pt', self.cuts['CRc'], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex='E_{T}^{miss}', units='GeV', drawStyle="HIST") h_met_zjets.Add(h_met_nonzjets, -1) # subtract the non-z bkg MC from data-C h_met_zjets.Multiply(h_met_zjets_a) h_met_zjets.Scale(sf_bd) hframe = file.Get(tag + 'met_low_frame') hs = file.Get(tag + 'met_low_stack') hs.Add(h_met_zjets) hdata = file.Get(tag + 'met_low_data') hratio = GetRatio_TH1(hdata, hs, True) legend = file.Get(tag + 'met_low_legend') myentry = ROOT.TLegendEntry(h_met_zjets, "Z+jets(data-driven)", "f") legend.GetListOfPrimitives().AddFirst(myentry) # Let's remove the signal entries in the legend for i in legend.GetListOfPrimitives(): if ROOT.TString(i.GetLabel()).Contains("Bulk"): legend.GetListOfPrimitives().Remove(i) drawStack_simple(hframe, hs, hdata, hratio, legend, hstack_opt="A, HIST", outDir=self.outdir, output=self.whichregion + '_regionA_' + self.Channel + '_met_low', channel=ROOT.TString(self.Channel), xmin=self.xMin, xmax=self.xMax, xtitle="E_{T}^{miss}", units="GeV", lumi=self.lumi, notes="Region A (" + self.whichregion + ")") self.Stack.addPlotter(self.ZJets, "ZJets", "Z+Jets", "background") else: self.Stack.drawStack('met_pt', self.cuts['SR'], str(self.lumi * 1000), self.nbins, self.xMin, self.xMax, titlex="E_{T}^{miss}", units="GeV", output=tag + 'met_low', outDir=self.outdir, separateSignal=self.sepSig, drawtex=self.tex_dic['SR'], channel=self.Channel) return