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)
'(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':
'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)', 'preSelect_dphiJMet4b_plus8': preSelect+'&&(dPhi_jetMet_min_b>0.4)&&(llnunu_l1_pt/llnunu_mtc<0.8)', })
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): h_met_dt=plotter_ll.Data.drawTH1('h_met_dt','llnunu_l2_pt',cuts_met0[key],"1",100,0,500,titlex='E_T^{miss}',units='GeV',drawStyle="HIST") #h_met_dt.Write() # MET (non-zjets): h_met_nonZ=plotter_ll.NonZBG.drawTH1('h_met_nonZ','llnunu_l2_pt',cuts_met0[key],str(lumi*1000),100,0,500,titlex='E_T^{miss}',units='GeV',drawStyle="HIST") #h_met_nonZ.Write() # MET (zjets): h_met=plotter_ll.ZJets.drawTH1('h_met','llnunu_l2_pt',cuts_met0[key],str(lumi*1000),100,0,500,titlex='E_T^{miss}',units='GeV',drawStyle="HIST") #h_met.Write() histo[key]={'h_met_dt':h_met_dt, 'h_met_nonZ':h_met_nonZ,
if whichregion == "": lswhichregion = ['SR', 'VR'] else: lswhichregion.append(whichregion) ### ----- Initialize (samples): plotter = InitializePlotter(indir=indir, addData=True, doMetCorr=True) ZJets = plotter.ZJets Data = plotter.Data otherBG = plotter.NonZBG ### ----- Execute (plotting): comb = [lsChannel, lswhichregion] print list(product(*comb)) for Channel, whichregion in list(product(*comb)): cuts = mycuts.abcdCuts(Channel, whichregion, zpt_cut='100', met_cut='50') #cuts_loose=mycuts.abcdCuts(Channel, whichregion, met_cut='50') print cuts ROOT.gROOT.ProcessLine('.x ../src/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 = {} err = {} err['data'] = {} yields['data'] = {} err['Zjets'] = {} yields['Zjets'] = {} err['non-Zjets'] = {}
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')
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') if scaleDphi:
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() for ih in histo:
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] fout = ROOT.TFile(outdir + tag + "_" + channel + '.root', 'recreate') histo = {} for key in cuts_met0: # MET (data): h_met_dt = plotter_ll.Data.drawTH1('h_met_dt' + key, 'llnunu_l2_pt', cuts_met0[key], "1", 24, 30, 150, titlex='E_T^{miss}',
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): h_met_dt = plotter_ll.Data.drawTH1('h_met_dt', 'llnunu_l2_pt', cuts_met0[key], "1", 100, 0, 500, titlex='E_T^{miss}', units='GeV', drawStyle="HIST")
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,
if whichregion=="": lswhichregion=['SR', 'VR'] else: lswhichregion.append(whichregion) ### ----- Initialize (samples): plotter = InitializePlotter(indir=indir, addData=True, doMetCorr=True) ZJets = plotter.ZJets Data = plotter.Data otherBG = plotter.NonZBG ### ----- Execute (plotting): comb=[lsChannel, lswhichregion] print list(product(*comb)) for Channel, whichregion in list(product(*comb)): cuts=mycuts.abcdCuts(Channel, whichregion, zpt_cut='100', met_cut='50') #cuts_loose=mycuts.abcdCuts(Channel, whichregion, met_cut='50') print cuts ROOT.gROOT.ProcessLine('.x ../src/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={} err={} err['data']={} yields['data']={} err['Zjets']={} yields['Zjets']={} err['non-Zjets']={}
otherBGPlotters[-1].addCorrectionFactor('genWeight', 'tree') otherBGPlotters[-1].addCorrectionFactor('puWeight', 'tree') otherBGPlotters[-1].addCorrectionFactor('triggersf', 'tree') otherBGPlotters[-1].addCorrectionFactor( 'llnunu_l1_l1_lepsf*llnunu_l1_l2_lepsf', 'tree') otherBG = MergedPlotter(otherBGPlotters) otherBG.setFillProperties(1001, ROOT.kMagenta) ### ----- Execute (plotting): comb = [lsChannel, lswhichregion] print list(product(*comb)) for Channel, whichregion in list(product(*comb)): cuts = mycuts.abcdCuts(Channel, whichregion) print cuts 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 = {} err = {} err['data'] = {} yields['data'] = {} err['Zjets'] = {} yields['Zjets'] = {} err['non-Zjets'] = {} yields['non-Zjets'] = {}
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 ROOT.gROOT.ProcessLine('.x ../src/tdrstyle.C')
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') ZJets = MergedPlotter(zjetsPlotters)
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