Exemple #1
0
def DrawDYDD(lev = '2jets', doSF = False):
  if not doSF and lev == 'MET': return 
  d = DYDD(path,outpath,'ElMu',lev, DYsamples=DYsamples, DataSamples=datasamples, lumi=Lumi, histonameprefix='')  #, hname = 'DYHistoElMu' if not doSF else 'DYHisto')
  d.SetHistoNameOF('DYHistoElMu')
  d.SetHistoNameSF('DYHisto')
  lab = 'SF' if doSF else 'OF'
  d.PrintDYestimate(doSF,  'DYDD_'+lev+'_'+lab)
Exemple #2
0
def xsec(chan='ElMu', lev='2jets', doDD=False):
    x = CrossSection(outpath, chan, lev)
    x.SetTextFormat("tex")
    bkg = []
    bkg.append(['tW', process['tW'], 0.30])
    if not doDD:
        bkg.append(['DY', process['DY'], 0.15])
        bkg.append(['Nonprompt lep', process['Nonprompt'], 0.50])
    bkg.append(['VV', process['VV'], 0.30])
    signal = ['tt', process['tt']]
    data = process['data']
    expunc = "MuonEff, ElecEff, JES, JER, TrigEff, Prefire"  # JER
    modunc = "pdf, scale, isr, fsr"

    x.ReadHistos(path,
                 chan,
                 lev,
                 bkg=bkg,
                 signal=signal,
                 data=data,
                 expUnc=expunc,
                 modUnc=modunc)
    x.SetLumi(296.1)
    x.SetLumiUnc(0.035)
    x.AddModUnc('Underlying Event', 'TT_TuneCP5up', 'TT_TuneCP5down')
    x.AddModUnc('hdamp', 'TT_hdampUP', 'TT_hdampDOWN')

    if doDD:
        d = DYDD(path,
                 outpath,
                 chan,
                 lev,
                 DYsamples=DYsamples,
                 DataSamples=datasamples,
                 lumi=Lumi,
                 histonameprefix='',
                 hname='DYHistoElMu')
        DYy, DYerr = d.GetDYDD()
        x.AddBkg('DYDD', DYy, 0, 0.15, DYerr)

        f = NonpromptDD(path,
                        chan=chan,
                        level=lev,
                        process=processDic,
                        lumi=Lumi,
                        histonameprefix='',
                        yieldsSSname='YieldsSS')
        fy, fe = f.GetNonpromptDD(chan)
        x.AddBkg('Nonprompt lep', fy, 0, 0.30, fe)

    suf = '_' + chan + '_' + lev + '_' + ('DD' if doDD else 'MC')
    x.PrintYields('Yields' + suf)
    x.PrintSystTable('Systematics' + suf)
    x.PrintXsec('CrossSection' + suf)
Exemple #3
0
def SaveHisto(name, chan, level, outname='', rebin=1):
  hname = '%s_%s_%s'%(name, chan, level)
  if outname == '': outname = hname
  honame = hname if level != '2jetsnomet' else '%s_%s_%s'%(name, chan, '2jets')

  thr = TopHistoReader(path)
  thr.SetLumi(296.1)
  systematics = 'MuonEff, ElecEff, TrigEff, JES, JER, PU, Prefire, hdamp, UE'

  processes = processDic.keys()
  hm = HistoManager(processes, systematics, '', path=path, processDic=processDic, lumi=Lumi)
  hm.SetHisto(hname, rebin)

  if level == '2jetsnomet': level = '2jets'
  d = DYDD(path,outpath,chan,level, DYsamples=processDic['DY'], DataSamples=processDic['data'], lumi=Lumi, histonameprefix='', hname = 'DYHistoElMu')# if chan == 'ElMu' else 'DYHisto')
  DYy, DYerr = d.GetDYDD()
  DYMC = hm.indic['DY'][hname].Integral()
  #hm.indic['DY'][hname].Scale(DYy/DYMC if DYMC!=0 else 1)

  # Add ISR, FSR
  nom   = hm.indic['tt'][hname].Clone('nom')
  ynom  = thr.GetNamedHisto(honame, 'TTPS').Integral()
  isrup = thr.GetNamedHisto(honame+'_ISRUp', 'TTPS').Integral()
  isrdo = thr.GetNamedHisto(honame+'_ISRDown', 'TTPS').Integral()
  fsrup = thr.GetNamedHisto(honame+'_FSRUp', 'TTPS').Integral()
  fsrdo = thr.GetNamedHisto(honame+'_FSRDown', 'TTPS').Integral()

  hisrup = nom.Clone('isrup'); hisrup.Scale(1+(isrup-ynom)/ynom)
  hisrdo = nom.Clone('isrdo'); hisrdo.Scale(1+(isrdo-ynom)/ynom)
  hfsrup = nom.Clone('fsrup'); hfsrup.Scale(1+(fsrup-ynom)/ynom)
  hfsrdo = nom.Clone('fsrdo'); hfsrdo.Scale(1+(fsrdo-ynom)/ynom)
  hm.indic['tt'][hname+'_'+'ISRUp'  ] = hisrup
  hm.indic['tt'][hname+'_'+'ISRDown'] = hisrdo
  hm.indic['tt'][hname+'_'+'FSRUp'  ] = hfsrup
  hm.indic['tt'][hname+'_'+'FSRDown'] = hfsrdo

  # Add PDF, Scale ME
  pathToTrees = '/pool/phedexrw/userstorage/juanr/5TeV5apr2020/'
  motherfname = 'TT_TuneCP5_5p02TeV'
  w = WeightReader(path, '',chan, level, sampleName='TT', pathToTrees=pathToTrees, motherfname=motherfname, PDFname='PDFweights', ScaleName='ScaleWeights', lumi=296.1, histoprefix='')
  pdfunc   = w.GetPDFandAlphaSunc()
  scaleunc = w.GetMaxRelUncScale()

  hpdfup = nom.Clone('pdfup'); hpdfup.Scale(1+pdfunc)
  hpdfdo = nom.Clone('pdfdo'); hpdfdo.Scale(1-pdfunc)
  hmeup  = nom.Clone('meup' ); hmeup .Scale(1+scaleunc)
  hmedo  = nom.Clone('medo' ); hmedo .Scale(1-scaleunc)
  hm.indic['tt'][hname+'_'+'PDFUp'    ] = hpdfup
  hm.indic['tt'][hname+'_'+'PDFDown'  ] = hpdfdo
  hm.indic['tt'][hname+'_'+'ScaleUp'  ] = hmeup
  hm.indic['tt'][hname+'_'+'ScaleDown'] = hmedo

  hm.Save(outpath+'%s'%(outname))
Exemple #4
0
def DrawClosure(lev='2jets', ratio=[0.8, 1.2]):
    d = DYDD(path,
             outpath + '/DYDD/',
             'ElMu',
             lev,
             DYsamples=DYsamples,
             DataSamples=datasamples,
             lumi=Lumi,
             histonameprefix=''
             )  #, hname = 'DYHistoElMu' if not doSF else 'DYHisto')
    d.SetHistoNameOF('DYHistoElMu')
    d.SetHistoNameSF('DYHisto')
    d.DrawClosureMCeff(lev)
Exemple #5
0
def DrawDYDDnjets(lev='2jets'):
    d = DYDD(path, outpath, lev)
    d.PrintDYSFnjets()
Exemple #6
0
def xsec(chan='ElMu', lev='2jets', doDD=False):
    x = CrossSection(outpath, chan, lev)
    x.SetTextFormat("tex")
    x.SetPathToTrees('/pool/ciencias/nanoAODv4/5TeV/5TeV_21nov2019/')
    bkg = []
    bkg.append(['tW', process['tW'], 0.20])
    bkg.append(['Nonprompt lep', process['Nonprompt'], 0.50])
    if not doDD:  # or chan == 'MuMu' or chan == 'ElEl':
        bkg.append(['DY', process['DY'], 0.00])
    bkg.append(['VV', process['VV'], 0.30])
    signal = ['tt', process['tt']]
    data = process['data']
    expunc = "MuonEff, ElecEff, TrigEff, Prefire, JES, JER, Prefire, PU"  #, JES, JER, TrigEff, Prefire" # JER
    modunc = "pdf, scale"  #, isr, fsr"

    x.ReadHistos(path,
                 chan,
                 lev,
                 bkg=bkg,
                 signal=signal,
                 data=data,
                 expUnc=expunc,
                 modUnc=modunc)
    x.SetLumi(Lumi)
    x.SetLumiUnc(0.015)
    #x.AddModUnc('Underlying Event','TT_TuneCP5up','TT_TuneCP5down')
    #x.AddModUnc('hdamp','TT_hdampUP','TT_hdampDOWN')

    thr = TopHistoReader(path)
    thr.SetLumi(Lumi)
    hname = 'Lep0Eta_%s_%s' % (chan, lev)
    if os.path.isfile(path + '/TTPS.root'):
        nom = thr.GetNamedHisto(hname, 'TTPS').Integral()
        isrup = thr.GetNamedHisto(hname + '_ISRUp', 'TTPS').Integral()
        isrdo = thr.GetNamedHisto(hname + '_ISRDown', 'TTPS').Integral()
        fsrup = thr.GetNamedHisto(hname + '_FSRUp', 'TTPS').Integral()
        fsrdo = thr.GetNamedHisto(hname + '_FSRDown', 'TTPS').Integral()
        isr = (abs(isrdo - nom) / nom + abs(isrup - nom) / nom) / 2
        fsr = (abs(fsrdo - nom) / nom + abs(fsrup - nom) / nom) / 2
        x.AddModUnc('FSR', fsr)
        x.AddModUnc('ISR', isr)

    if doDD:
        d = DYDD(path,
                 outpath,
                 chan,
                 lev,
                 DYsamples=DYsamples,
                 DataSamples=datasamples,
                 lumi=Lumi,
                 histonameprefix='',
                 hname='DYHistoElMu' if chan == 'ElMu' else 'DYHisto')
        DYy, DYerr = d.GetDYDD()
        x.AddBkg('DYDD', DYy, 0, 0.30, DYerr)
        '''
    d = DYDD(path,outpath,chan,lev, DYsamples=DYsamples, DataSamples=datasamples, lumi=Lumi, histonameprefix='', hname = 'DYHistoElMu')
    if chan == 'ElMu': 
      DYy, DYerr = d.GetDYDD()
      x.AddBkg('DYDD', DYy, 0, 0.15, DYerr)
    else:
      SF, SFerr = d.GetScaleFactor()
      dy = x.GetBkg('DY').GetYield()
      print 'dy = ', dy
      print 'dy = ', dy*SFerr
      x.GetBkg('DY').SetYield(dy*SF)
      x.GetBkg('DY').SetStatUnc(dy*SFerr)
    '''

        #f = NonpromptDD(path, chan=chan, level=lev, process=processDic , lumi=Lumi, histonameprefix='',yieldsSSname='YieldsSS')
        #fy, fe = f.GetNonpromptDD(chan)
        #x.AddBkg('Nonprompt lep', fy, 0, 0.30, fe)

    suf = '_' + chan + '_' + lev + '_' + ('DD' if doDD else 'MC')
    x.PrintYields('Yields' + suf)
    x.PrintSystTable('Systematics' + suf)
    x.PrintXsec('CrossSection' + suf)
    x.AddToTxt('ttxsec', labdic[chan])