Beispiel #1
0
def StackPlot(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, syst, 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)
  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')
  s.SetRatioMin(0.5); s.SetRatioMax(1.5)
  s.SetYratioTitle('Ratio')
  s.DrawStack(xtit, 'Events')
  s.SetLogY()
  s.SetOutName('stack_'+var+'_log')
  s.SetPlotMinimum(1.)
  s.SetPlotMaxScale(1200)
  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')
Beispiel #3
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')