def StackPlot(var='NJets', ch='ElMu', lev='2jets', blind=False, ratiolims=[0.4, 1.6], binlabels='', rangeX=[0, 0]): hm = HistoManager(processes, syst, path=path) fname = '%s%s%s' % (var, ('_' + ch) if ch != '' else '', ('_' + lev) if lev != '' else '') hm.ReadHistosFromFile(fname, rebin=(rebin[var] if var in rebin.keys() else 1)) hm.AddNormUnc(normunc) hm.GetDataHisto() s = Stack(outpath=outpath + '/stackplots/') s.SetRangeX(rangeX) s.SetColors(colors) s.SetProcesses(processes) s.SetLumi(Lumi) s.SetRangeX(ran[var][lev] if var in ran and ( isinstance(ran[var], dict) and lev in ran[var].keys()) else ( ran[var] if var in ran.keys() else [0, 0])) s.SetHistoPadMargins(top=0.08, bottom=0.10, right=0.06, left=0.10) s.SetRatioPadMargins(top=0.03, bottom=0.40, right=0.06, left=0.10) s.SetTextLumi(texlumi='%2.1f pb^{-1} (5.02 TeV)', texlumiX=0.62, texlumiY=0.97, texlumiS=0.05) if binlabels != '': s.SetBinLabels(binlabels) s.SetOutName('stack_' + fname) s.SetHistosFromMH(hm) s.SetTextChan(pltlabel[ch][lev] if (ch in pltlabel and lev in pltlabel[ch]) else '', x=0.18, s=0.036) xtit = titdic[var] if var in titdic else '' if ('%s') in xtit: xtit = xtit % pltlabel[ch]['dilepton'] rmin, rmax = ratiolims s.SetRatioMin(rmin) s.SetRatioMax(rmax) s.SetYratioTitle('Data/Pred.') s.SetPlotMaxScale(1.8) # blind if blind: hData = s.TotMC.Clone("Asimov") hData.SetLineWidth(0) hData.SetMarkerStyle(20) hData.SetMarkerColor(kGray) hData2 = hData.Clone("Asimov2") hData2.Divide(hData) s.SetDataHisto(hData) s.SetRatio(hData2) s.DrawStack(xtit, 'Events') if var == 'NJets' and lev == 'dilepton': s.SetLogY() s.SetPlotMaxScale(100) s.SetPlotMinimum(0.5) s.SetOutName('stack_log_' + fname) s.DrawStack(xtit, 'Events')
def StackPlot(var = 'mt2', xtit = 'm_{T2} (GeV)', rebin=1): pr = process.replace(' ', '').split(',')#['VV', 'ttW', 'DY', 'Nonprompt', 'ttZ', 'tW', 'tt'] #pr = ['Others', 'Nonprompt', 'ttZ', 'tW', 'tt'] if year == 'comb': hm = HistoManager(pr, syst, path=GetPath(region, 2016, ms, ml, ch), signalList = 'stop'); hm.SetStackOverflow() hm.ReadHistosFromFile(var,rebin=rebin) hm17 = HistoManager(pr, syst, path=GetPath(region, 2017, ms, ml, ch), signalList = 'stop'); hm17.SetStackOverflow() hm17.ReadHistosFromFile(var,rebin=rebin) hm18 = HistoManager(pr, syst, path=GetPath(region, 2018, ms, ml, ch), signalList = 'stop'); hm18.SetStackOverflow() hm18.ReadHistosFromFile(var,rebin=rebin) hm.Add(hm17).Add(hm18) else: hm = HistoManager(pr, syst, path=path, signalList = 'stop'); hm.SetStackOverflow() hm.ReadHistosFromFile(var, rebin=rebin) hm.AddNormUnc({'tt':0.06, 'Nonprompt':0.3, 'DY':0.3,'ttZ':0.3,'tW':0.15}) hm.GetDataHisto() #if ('mt2' in var or 'met' in var or 'dnn' in var or 'lblb' in var) and region != 'CR': # #del hm.indic['data_obs'] # blind # hm.indic['data_obs']['data_obs'] = hm.GetSumBkg() outdir = GetOutpath(region, year, ms, ml, ch) s = Stack(outpath=outdir+'/stackplots/') s.SetColors(colors) s.SetProcesses(pr) s.SetLumi(GetLumi(year) if isinstance(year, int) else (GetLumi(2016) + GetLumi(2017) + GetLumi(2018)) ) s.SetOutName('stack_'+var) s.SetHistosFromMH(hm) s.SetDataHisto(hm.indic['data_obs']['data_obs']) #if not ('mt2' in var or 'met' in var or 'dnn' in var or 'lblb' in var) or (region == 'CR'): s.SetDataHisto(hm.indic['data_obs']['data_obs']) #else : # #hData = hm.GetSumBkg().Clone("Asimov") # hData = s.TotMC.Clone("Asimov") # hData.SetLineWidth(0); hData.SetMarkerStyle(20); hData.SetMarkerColor(kGray) # hData2 = hData.Clone("Asimov2") # hData2.Divide(hData) # s.SetDataHisto(hData) # s.SetRatio(hData2) s.AddSignalHisto(hm.indic['stop']['stop'], color = kTeal+2, mode = 'ontop', ratioBkg = True) if region == 'SR': s.SetTextChan('SR: BS + p_{T}^{miss} #geq 50, m_{T2} #geq 80') elif region == 'BS': s.SetTextChan('BS: e#mu, #geq 2 jets, #geq 1 btag') elif region == 'CR': s.SetTextChan('BS + met < 50, m_{T2} < 80 ') elif region == 'ttmt2': s.SetTextChan('BS + met < 50') elif region == 'ttmet': s.SetTextChan('BS + m_{T2} < 80') s.SetRatioMin(0.0); s.SetRatioMax(2.5) #s.SetYratioTitle('S/(S+B)') s.SetYratioTitle('Ratio') s.SetPlotMaxScale(2.5) s.DrawStack(xtit, 'Events') s.SetLogY() s.SetOutName('stack_log_'+var) s.SetPlotMinimum(0.1) s.SetPlotMaxScale(1200) s.DrawStack(xtit, 'Events')
indic=ss[2018]) hmSS.ScaleByLumi() hmSS16.ScaleByLumi() hmSS17.ScaleByLumi() hmSS.SetHistoName("mt2") hmSS.Add(hmSS17).Add(hmSS16) else: hmSS = HistoManager( prSS, syst, path=path[year] if not region == 'BS' else pathBS[year], processDic=processDic[year], lumi=GetLumi(year) * 1000, indic=ss) hmSS.SetDataName('data') hmSS.AddNormUnc(normUncSS) #hmOS = HistoManager(prOS, path = path[year] if not region=='BS' else pathBS[year], processDic = processDic[year], lumi = GetLumi(year)*1000, indic=ss) if isinstance(year, str): hmOS16 = HistoManager( prOS, syst, path=path[2016] if not region == 'BS' else pathBS[2016], processDic=processDic[2016], lumi=GetLumi(2016) * 1000, indic=nonpromptOS[2016]) hmOS17 = HistoManager( prOS, syst, path=path[2017] if not region == 'BS' else pathBS[2017], processDic=processDic[2017],