コード例 #1
0
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')
コード例 #2
0
def StackPlot(var = 'mt2', xtit = 'm_{T2} (GeV)'):
  hm = HistoManager(process, syst, path=path)
  hm.ReadHistosFromFile(var)
  hm.GetDataHisto()
  s = Stack(outpath=outpath)
  s.SetColors(colors)
  s.SetProcesses(processes)
  s.SetLumi(GetLumi(year))
  s.SetOutName('stack_'+var)
  s.SetHistosFromMH(hm)
  s.DrawStack(xtit, 'Events')
コード例 #3
0
def Save(chan, year=None, ms=None, ml=None, var='dnn'):
    if isinstance(chan, list):
        if len(chan) == 4: chan, year, ms, ml = chan
        elif len(chan) == 5: chan, year, ms, ml, var = chan
    for b in bkg:
        AddHistosFromFile(GetPath(chan, year, ms, ml), b)
    AddHistosFromFile(GetPath(chan, year, msin, mlin), 'stop_test')

    processes = bkg + ['stop_test']
    processes.pop(processes.index('data'))
    hm = HistoManager(processes,
                      path='',
                      processDic=processDic[year],
                      lumi=GetLumi(year) * 1000.,
                      indic=out)
    hm.SetHisto(var)
    os.system("mkdir -p %s" % outpath(chan, year, ms, ml))
    hm.Save(outname=outpath(chan, year, ms, ml) + '/' + var, htag='')
コード例 #4
0
def SavePlots(syst, var = 'mt2', sampName = 'tt'):
  hm = HistoManager(process, syst, path=path)
  hm.ReadHistosFromFile(var)
  hm.GetDataHisto()
  a = HistoUnc(outpath, var+sampName+s, tag=sysdic[s], xtit = titdic[var] if var in titdic.keys() else '')
  a.SetLumi(GetLumi(year))
  a.AddHistoNom(hm.GetHisto(sampName, sampName))
  a.AddHistoUp(hm.GetHisto(sampName, sampName, s+'Up'))
  a.AddHistoDown(hm.GetHisto(sampName, sampName, s+'Down'))
  a.Draw()
コード例 #5
0
def GetTableOfUnc(syst, sampName='tt', var='dnn', dic = {}):
  if isinstance(sampName, str) and ',' in sampName: sampName = sampName.replace(' ', '').split(',')
  if isinstance(syst,     str) and ',' in syst    : syst     = syst    .replace(' ', '').split(',')
  if isinstance(sampName, list):
    for s in sampName: GetTableOfUnc(syst, s, var, dic)
    return
  if isinstance(syst, list):
    for s in syst: GetTableOfUnc(s, sampName, var, dic)
    return
  if not sampName in dic: dic[sampName] = {}
  if not syst in dic[sampName]: dic[sampName][syst] = {}
  hm = HistoManager(process, syst, path=path)
  hm.ReadHistosFromFile(var)
  hm.GetDataHisto()
  n = hm.GetHisto(sampName, sampName             ).Integral()
  u = hm.GetHisto(sampName, sampName, syst+'Up'  ).Integral()
  d = hm.GetHisto(sampName, sampName, syst+'Down').Integral()
  meanval = (abs(n-d) + abs(n-u))/(2*n)*100
  dic[sampName][syst] = meanval
  return dic
コード例 #6
0
from ROOT.TMath import Sqrt as sqrt
from ROOT import kRed, kOrange, kBlue, kTeal, kGreen, kGray, kAzure, kPink, kCyan, kBlack, kSpring, kViolet, kYellow
from ROOT import TCanvas, gROOT
gROOT.SetBatch(1)

systdic = {
 't#bar{t}': {
   'hdampUp'   : 'TTTo2L2Nu_hdampUp',
   'hdampDown' : 'TTTo2L2Nu_hdampDown',
   'TuneUp'    : 'TTTo2L2Nu_TuneCP5Up',
   'TuneDown'  : 'TTTo2L2Nu_TuneCP5Down'
   }
}
path = '/nfs/fanae/user/andreatf/PAFnanoAOD/temp2018_new/'
systematics = 'MuonEff, ElecEff, PU, Btag, Mistag, hdamp, Tune'
hm = HistoManager(['t#bar{t}'], systematics, '', path = path, processDic=processDic[2018], lumi = GetLumi(2018)*1000, systdic = systdic)

def DrawHisto(hname = 'H_NJets_ElMu_1btag', syst = 'ElecEff', systname = 'Electron Efficiency', out = 'temp', xtit = 'Jet Multiplicity'):
  hm.SetHisto(hname, rebin = 100)
  histo    = hm.GetUncHist(syst, includeStat = True).Clone("nom")
  histoUnc = histo.Clone("syst")
  histo.SetFillStyle(0)
  histoUnc.SetFillStyle(1000)
  histoUnc.SetFillColorAlpha(kAzure+2, 0.5)
  histoUnc.SetLineWidth(0)
  hratio = hm.GetRatioHistoUnc(syst, includeStat = True)

  s = HistoComp(outpath = './temp/', doNorm = False, doRatio = True)
  s.SetLumi(GetLumi(2018))
  s.AddHisto(     histo,  'hist', '', 't#bar{t}')
  s.AddHisto(  histoUnc,  '', 'e2', systname)
コード例 #7
0
l.AddHisto('THT', 'ht', 40, 0, 800, weight=weight, cut='')
l.AddHisto('TNJets', 'njets', 6, 1.5, 7.5, weight=weight, cut='')
l.AddHisto('TNBtags', 'nbtags', 3, 0.5, 3.5, weight=weight, cut='')
histos = [
    'mt2', 'met', 'mll', 'dnn', 'dileppt', 'deltaphi', 'deltaeta', 'ht',
    'lep0pt', 'lep1pt', 'lep0eta', 'lep1eta', 'njets', 'nbtags', 'jet0pt',
    'jet1pt', 'jet0eta', 'jet1eta'
]
histos += ['dnn_5bins', 'dnn_10bins', 'dnn_30bins', 'dnn_40bins']

out = l.Run()

if sendJobs: exit()
# Create HistoManager with the out dictionary from the looper
hm = HistoManager(processes,
                  path=path[year] if region == 'SR' else pathBS[year],
                  processDic=processDic[year],
                  lumi=GetLumi(year) * 1000,
                  indic=out)


# Function to save the histograms into combine rootfiles
def save(name):
    hm.SetHisto(name)
    hm.Save(outname=outpath + '/' + name, htag='')


# Save the histograms
for v in histos:
    save(v)
コード例 #8
0
ファイル: SS.py プロジェクト: joanrs95/xuAnalysis
for k in nonpromptSS.keys(): ss[k] = nonpromptSS[k]

hDDOSdic = {}
for v in vardic.keys(): save(v)
  hDDOS = ss['data'][var].Clone()
  nb = hDDOS.GetNbinsX()
  for ib in range(0, nb+1):
    dataSS   = ss['data'][var].GetBinContent(ib)
    promptSS = ss['Prompt SS'][var].GetBinContent(ib) + ss['Charge flips'][var].GetBinContent(ib)
    mcOS     = nonpromptOS['Semileptonic tt'][var].GetBinContent(ib) + nonpromptOS['Other nonprompt'][var].GetBinContent(ib)
    mcSS     = ss['Semileptonic tt'][var].GetBinContent(ib) + ss['Other nonprompt'][var].GetBinContent(ib)
    ddbin    = (dataSS - promptSS)*(mcOS/mcSS)
    hDDOS.SetBinContent(ib, ddbin)
  hDDOSdic[var] = hDDOS

hm = HistoManager(['Prompt SS', 'Charge flips', 'Other nonprompt', 'Semileptonic tt'], path = path[year], processDic = processDic[year], lumi = GetLumi(year)*1000, indic=ss)

hm = HistoManager(['Prompt SS', 'Charge flips', 'Other nonprompt', 'Semileptonic tt'], path = path[year], processDic = processDic[year], lumi = GetLumi(year)*1000, indic=ss)
def save(name):
  hm.SetHisto(name)
  hm.Save(outname = outpath+'/'+name, htag = '')
  s = Stack(outpath = outpath+'/plots/')
  s.SetColors(colors)
  s.SetProcesses(processes)
  s.SetLumi(GetLumi(year))
  s.SetOutName(name)
  s.SetHistosFromMH(hm)
  s.DrawStack(vardic[name] if name in vardic.keys() else '', 'Events')

for v in vardic.keys(): save(v)
コード例 #9
0
def StackPlotFancyRatios(var = 'mt2', xtit = 'm_{T2} (GeV)'):
  pr = [ 'ttZ', 'tW', 'Othernonprompt', 'tWnonprompt', 'Semileptonictt', 'ttDilepNonprompt', 'ttnongaus', 'ttgaus', 'tt']
  if isinstance(year, str):
    if chan=='all':
        hm     = HistoManager(pr, syst, path=GetOutPath(2016, region, 'emu'  , ms, ml), signalList = 'stop'); hm    .ReadHistosFromFile(var)
        hm17   = HistoManager(pr, syst, path=GetOutPath(2017, region, 'emu'  , ms, ml), signalList = 'stop'); hm17  .ReadHistosFromFile(var)
        hm18   = HistoManager(pr, syst, path=GetOutPath(2018, region, 'emu'  , ms, ml), signalList = 'stop'); hm18  .ReadHistosFromFile(var)
        hmee   = HistoManager(pr, syst, path=GetOutPath(2016, region, 'ee'   , ms, ml), signalList = 'stop'); hmee  .ReadHistosFromFile(var)
        hm17ee = HistoManager(pr, syst, path=GetOutPath(2017, region, 'ee'   , ms, ml), signalList = 'stop'); hm17ee.ReadHistosFromFile(var)
        hm18ee = HistoManager(pr, syst, path=GetOutPath(2018, region, 'ee'   , ms, ml), signalList = 'stop'); hm18ee.ReadHistosFromFile(var)
        hmmm   = HistoManager(pr, syst, path=GetOutPath(2016, region, 'mumu' , ms, ml), signalList = 'stop'); hmmm  .ReadHistosFromFile(var)
        hm17mm = HistoManager(pr, syst, path=GetOutPath(2017, region, 'mumu' , ms, ml), signalList = 'stop'); hm17mm.ReadHistosFromFile(var)
        hm18mm = HistoManager(pr, syst, path=GetOutPath(2018, region, 'mumu' , ms, ml), signalList = 'stop'); hm18mm.ReadHistosFromFile(var)
        hm.Add(hm17).Add(hm18).Add(hmee).Add(hm17ee).Add(hm18ee).Add(hmmm).Add(hm17mm).Add(hm18mm)
    else:
      hm   = HistoManager(pr, syst, path=GetOutPath(2016, region, chan, ms, ml), signalList = 'stop')
      hm.ReadHistosFromFile(var)
      hm17 = HistoManager(pr, syst, path=GetOutPath(2017, region, chan, ms, ml), signalList = 'stop')
      hm17.ReadHistosFromFile(var)
      hm18 = HistoManager(pr, syst, path=GetOutPath(2018, region, chan, ms, ml), signalList = 'stop')
      hm18.ReadHistosFromFile(var)
      hm.Add(hm17).Add(hm18)
  else: 
    hm = HistoManager(pr, '', path=path, signalList = 'stop')
    hm.ReadHistosFromFile(var)
  #hm.AddNormUnc({'tt':0.06, 'ttgaus':0.06, 'ttnongaus':0.3, 'ttDilepNonprompt':30, 'Semileptonictt':0.3, 'tWnonprompt':0.3, 'Nonprompt':0.3, 'ttZ':0.3,'tW':0.15})
  outdir = GetWebpath(year, region, chan, ms, ml)
  s = Stack(outpath=outdir+'/stackplots/')
  s.SetLegendName(legendNames)
  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.SetLegendPos(x0 = 0.45, y0 = 0.65, x1 = 0.93, y1 = 0.91, size = 0.035, ncol = 2)
  s.hRatioStatUnc.SetFillColorAlpha(0, 0)
  s.hRatioUnc.SetFillColorAlpha(0, 0)
  if (not var in ['mt2', 'met', 'dnn']) or (region != 'SR'): 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 == 'ttmt2': s.SetTextChan('BS + met < 50')
  elif region == 'ttmet': s.SetTextChan('BS + m_{T2} < 80')
  hbkg=s.TotMC.Clone("Asimov")
  h1=hm.indic['ttgaus']['ttgaus'].Clone('ttgaus')
  h1.SetLineColor(colors['ttgaus']);h1.SetLineWidth(3); h1.SetFillColor(0) 
  h1.Divide(hbkg)
  s.SetRatio(h1)
  h2=hm.indic['ttnongaus']['ttnongaus'].Clone('ttnongaus')
  h2.SetLineColor(colors['ttnongaus']);h2.SetLineWidth(3); h2.SetFillColor(0)
  h2.Divide(hbkg)
  h3=hm.indic['tt']['tt'].Clone('tt')
  h3.SetLineColor(colors['tt']);h3.SetLineWidth(3); h3.SetFillColor(0)  
  h3.Divide(hbkg)
  s.extraRatio.append(h3)
  s.extraRatio.append(h2)
  s.extraRatio.append(h1)
  
  s.SetRatioMin(0); s.SetRatioMax(1)
  s.SetYratioTitle('Ratio')
  s.DrawStack(xtit, 'Events')
  s.SetLogY()
  s.SetOutName('stackFancy_'+var+'_log')
  s.SetPlotMinimum(1.)
  s.SetPlotMaxScale(1200)
  s.SetLegendRatioPos(0,0,0,0,0)
  s.DrawStack(xtit, 'Events')
コード例 #10
0
def DrawPostFit(ms=235, ml=60, htype='fit_s', var='dnn', ch='', year=''):
    getdir = lambda dirtype, ch: 'shapes_%s/%s/' % (dirtype, ch)
    getfname = lambda ms, ml: 'postfit_%s_%s_%s' % (var, str(ms), str(ml))

    # Get channels
    if not isinstance(ch, list):
        if ch == '': ch = ['ee', 'mumu', 'emu']
        elif ',' in ch: ch = ch.replace(' ', '').split(',')
        else: ch = [ch]
    if not isinstance(year, list):
        if year == '': year = [2016, 2017, 2018]
        elif isinstance(year, str) and ',' in year:
            year = year.replace(' ', '').split(',')
        else:
            year = [year]
    pch = []
    for y in year:
        for c in ch:
            pch.append(chdic[y][c])

    if len(year) == 3: yearname = 'comb'
    else: yearname = str(year[0])
    if len(ch) == 3: chname = 'all'
    else: chname = ch[0]

    # test or not depending on var
    ttname = 'tt' if not 'dnn' in var else 'tt_test'
    pr = bkg + [ttname]
    sig = ('stop'
           if not 'dnn' in var else 'stop_test') if htype != 'fit_b' else []

    hm = HistoManager(pr, '', path=pathToPostFit, signalList=sig)
    pathInTree = [getdir(htype, x) for x in pch]
    hm.SetPathInTree(pathInTree)
    hm.ReadHistosFromFile(getfname(ms, ml), dataname='data', rebin=1)
    hm.ReArrangeDic({
        'Others': ['ttW', 'ttZ', 'Nonprompt', 'VV'],
        't#bar{t}+tW': ['tW', ttname],
        'Drell-Yan': ['DY']
    })
    hm.GetDataHisto()
    #hm.indic['data_obs']['data_obs'] = hm.GetSumBkg()
    outdir = GetOutpath(region, year, ms, ml, ch)
    fprocess = ['Others', 'Drell-Yan', 't#bar{t}+tW']
    s = Stack(outpath=outdir + '/postfit/')
    colors['Others'] = kTeal + 2
    colors['t#bar{t}+tW'] = colors['tt']
    colors['Drell-Yan'] = colors['DY']
    s.SetColors(colors)
    s.SetProcesses(fprocess)
    s.SetLumi(
        GetLumi(year[0]) if len(year) == 1 else (GetLumi(2016) +
                                                 GetLumi(2017) +
                                                 GetLumi(2018)))
    outname = htype + '_' + var + '%s_%s_%i_%i' % (yearname, chname, ms, ml)
    s.SetOutName(outname)
    s.SetHistosFromMH(hm)
    #s.Set
    t = TopHistoReader(pathToPostFit)
    t.ReComputeStatUnc = False
    t.SetPathInTree(pathInTree)
    hbkg = t.GetNamedHisto('total_background', getfname(ms, ml))
    hbkg.SetLineStyle(0)
    hbkg.SetLineWidth(0)
    hbkg.SetMarkerSize(0)

    s.SetTotMC(hbkg)
    s.SetMCunc(hbkg)
    s.SetMCstatUnc(None)
    s.SetMCnormUnc(None)

    s.SetRatioStatUnc(None)
    s.SetRatioNormUnc(None)
    s.SetRatioUnc(GetRatioHistoUncFromHisto(hbkg))

    s.SetRatioUncStyle()
    s.SetUncStyle()

    if sig != []:
        s.AddSignalHisto(hm.indic[sig][sig],
                         color=kViolet + 2,
                         mode='ontop',
                         ratioBkg=True,
                         name='stop')
    s.SetTextChan('SR: BS + p_{T}^{miss} #geq 50, m_{T2} #geq 80')
    s.SetRatioMin(0.5)
    s.SetRatioMax(1.5)
    s.SetPlotMaxScale(1.8)
    xtit = 'DNN score (%i, %i)' % (ms, ml)
    chlab = ''
    if chname == 'ee': chlab = 'ee'
    elif chname == 'mumu': chlab = '#mu#mu'
    elif chname == 'emu': chlab = 'e#mu'
    flab = 'Prefit'
    if htype == 'fit_b': flab = 'Fit background only'
    elif htype == 'fit_s': flab = 'Fit S+B'
    mlab = '#splitline{m_{#tilde{t}_{1}} = %1.0f GeV}{m_{#tilde{#chi}_{1}^{0}} = %1.0f GeV}' % (
        ms, ml)
    s.AddTex(flab, x=0.15, y=0.77, s=0.05)
    s.AddTex(mlab, x=0.15, y=0.62, s=0.04)
    s.AddTex(chlab, x=0.15, y=0.84, s=0.04)
    s.DrawStack(xtit, 'Events')
    s.SetLogY()
    s.SetZoom(False)
    if var == 'dnn' and region == 'SR':
        s.SetZoom(True)
    s.SetOutName('log_' + outname)
    s.SetPlotMinimum(1)
    s.SetPlotMaxScale(1200)
    s.SetYratioTitle('Ratio')
コード例 #11
0
ファイル: SS.py プロジェクト: masar-almuttairi/xuAnalysis

if isinstance(year, str):
    for y in [2016, 2017, 2018]:
        hDDOSdic = GetDDOS(y, ss[y], nonpromptOS[y])
        nonpromptOS[y]['DDOS'] = hDDOSdic
        #ss[y]['MCOS'] = nonpromptOS[y]['Semileptonictt']
else:
    hDDOSdic = GetDDOS(year, ss, nonpromptOS)
    nonpromptOS['DDOS'] = hDDOSdic

if isinstance(year, str):
    hmSS16 = HistoManager(
        prSS,
        syst,
        path=path[2016] if not region == 'BS' else pathBS[2016],
        processDic=processDic[2016],
        lumi=GetLumi(2016) * 1000,
        indic=ss[2016])
    hmSS17 = HistoManager(
        prSS,
        syst,
        path=path[2017] if not region == 'BS' else pathBS[2017],
        processDic=processDic[2017],
        lumi=GetLumi(2017) * 1000,
        indic=ss[2017])
    hmSS = HistoManager(
        prSS,
        syst,
        path=path[2018] if not region == 'BS' else pathBS[2018],
        processDic=processDic[2018],
コード例 #12
0
ファイル: stack.py プロジェクト: masar-almuttairi/xuAnalysis
from conf import *
basepath = os.path.abspath(__file__).rsplit('/xuAnalysis/',1)[0]+'/xuAnalysis/'
sys.path.append(basepath)
from plotter.TopHistoReader import TopHistoReader, HistoManager
from plotter.Plotter import Stack
from ROOT.TMath import Sqrt as sqrt
from ROOT import kRed, kOrange, kBlue, kTeal, kGreen, kGray, kAzure, kPink, kCyan, kBlack, kSpring, kViolet, kYellow
from ROOT import TCanvas, gROOT
gROOT.SetBatch(1)

year = 2018

#hm.SetHisto(hname, 1)
#hm16 = HistoManager(processes, systematics, '', path = path[2016], processDic = processDic[2016], lumi = GetLumi(2016)*1000)
#hm17 = HistoManager(processes, systematics, '', path = path[2017], processDic = processDic[2017], lumi = GetLumi(2017)*1000)
hm18 = HistoManager(processes, systematics, '', path = path[2018], processDic = processDic[2018], lumi = GetLumi(2018)*1000)

s = Stack(outpath = '/nfs/fanae/user/juanr/www/temp/%s/'%year)
s.SetColors(colors)
s.SetProcesses(processes)
s.SetLumi(GetLumi(year))# if not isinstance(year, str) else GetLumi(2016)+GetLumi(2017)+GetLumi(2018))

def Draw(var = 'H_Lep0Pt_ElMu_2jets', ch = 'ElMu', lev = 'dilepton', rebin = 1, xtit = '', ytit = 'Events', doStackOverflow = False, binlabels = '', setLogY = False, maxscale = 1.15):
  name = 'H_%s_%s_%s'%(var, ch, lev)
  #hm16.SetStackOverflow(doStackOverflow)
  #hm17.SetStackOverflow(doStackOverflow)
  hm18.SetStackOverflow(doStackOverflow)
  hm18.SetHisto(name, rebin)
  hm = hm18#hm16.Add(hm17).Add(hm18)
  s.SetHistosFromMH(hm)
  s.SetOutName(name)
コード例 #13
0
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')
コード例 #14
0
    hname = 'dnnScanstop%i_%i_%1.0f' % (ms, ml, val * 100)
    histos.append(hname)
    l.AddHisto('weight1',
               hname,
               1,
               -1,
               20,
               weight=weight,
               cut='vpd > %1.2f' % val)

# Let's rock
out = l.Run()

# Create HistoManager with the out dictionary from the looper
hm = HistoManager(processes,
                  path=path[year],
                  processDic=processDic[year],
                  lumi=GetLumi(year) * 1000,
                  indic=out)


# Function to save the histograms into combine rootfiles
def save(name):
    hm.SetHisto(name)
    hm.Save(outname=outpath + '/' + name, htag='')


# Save the histograms
for v in histos:
    save(v)