def GetHistosFromLooper(year, ecut = '(t.TStatus == 1 or t.TStatus == 22)', processes = ['Charge flips','Prompt SS']): #l = looper(path=path[year], nSlots = 6, treeName = 'MiniTree', options = 'merge', nEvents = 1000, outpath=outpath+'tempfiles/') l = looper(path=path[year], nSlots = 20, treeName = 'MiniTree', options = 'merge', outpath = outpath+'tempfiles/') l.AddHeader('from framework.mva import ModelPredict\n') l.AddInit(' self.pd1 = ModelPredict("%s")\n'%model) for p in processes: l.AddSample(p, processDic[year][p]) syst = 'MuonEff, ElecEff, Trig, JES, JER, MuonES, Uncl, Btag, MisTag, PU, TopPt' if year != 2018: syst += ', Pref' systlist = [x+y for x in syst.replace(' ','').split(',') for y in ['Up','Down']] l.AddSyst(systlist) l.AddLoopCode(loopcode) l.AddExpr('deltaphi', 'TDeltaPhi', 'abs(TDeltaPhi)/3.141592') l.AddExpr('deltaeta', 'TDeltaEta', 'abs(TDeltaEta)') l.AddExpr('weight1', [], '1') l.AddExpr('vpd', '', 'prob1', True) # True because prob1 has to be defined before l.AddExpr('vmet', ['TMET'], 'TMET') l.AddExpr('vmt2', ['TMT2'], 'TMT2') l.AddExpr('vht', ['THT' ], 'THT') l.AddExpr('vmll', ['TMll'], 'TMll') l.AddExpr('exprW', ['TWeight'], 'TWeight') l.AddSelection(selection) weight = 'exprW' cut = 'TMET > 50 and TMT2 > 80 and TNJets >= 2 and TNBtags >= 1 and TPassDilep and %s'%ecut l.AddCut(cut, ['TMET', 'TMT2', 'TNJets', 'TNBtags', 'TPassDilep']) cut = '' l.AddHisto('vpd', 'dnn', 20, 0, 1, weight = weight, cut = '') l.AddHisto('TMll', 'mll', 30, 0, 300, weight = weight, cut = '') l.AddHisto('TMET', 'met', 25, 50, 300, weight = weight, cut = '') l.AddHisto('TMT2', 'mt2', 8, 80, 160, weight = weight, cut = '') l.AddHisto('TDilep_Pt', 'dileppt', 30, 0, 300, weight = weight, cut = '') l.AddHisto('TLep0Pt', 'lep0pt', 15, 0, 150, weight = weight, cut = '') l.AddHisto('TLep1Pt', 'lep1pt', 30, 0, 300, weight = weight, cut = '') l.AddHisto('TLep0Eta', 'lep0eta', 30, -2.4, 2.4, weight = weight, cut = '') l.AddHisto('TLep1Eta', 'lep1eta', 30, -2.4, 2.4, weight = weight, cut = '') l.AddHisto('deltaphi', 'deltaphi', 30, 0, 1, weight = weight, cut = '') l.AddHisto('deltaeta', 'deltaeta', 30, 0, 5, weight = weight, cut = '') l.AddHisto('TJet0Pt', 'jet0pt', 30, 0, 450, weight = weight, cut = '') l.AddHisto('TJet1Pt', 'jet1pt', 30, 0, 300, weight = weight, cut = '') l.AddHisto('TJet0Eta', 'jet0eta', 30, -2.4, 2.4, weight = weight, cut = '') l.AddHisto('TJet1Eta', 'jet1eta', 30, -2.4, 2.4, weight = weight, cut = '') 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 = '') out = l.Run() return out
region = args.region if args.BS: region = 'BS' if args.SR: region = 'SR' # Set constants outpath = baseoutpath + '/Unc_FSR/%s/%s/%i/mass%i_%i/' % (region, ch, year, ms, ml) if not os.path.isdir(outpath): os.system("mkdir -p %s" % outpath) # Create the looper, set readOutput to true to read previous temporary rootfiles created for each sample path = {} path[year] = pathToTrees(year, ch, region) pathToFiles = path[year] l = looper(path=path[year] if region == 'SR' else pathBS[year], nSlots=nSlots, treeName='MiniTree', options='merge', outpath=outpath + 'tempfiles/', readOutput=True) #, sendJobs=sendJobs) # Add processes processDic = {2016: {'tt': 'TT_PSWeights'}} processes = ['tt'] if argprocess != '': processes = argprocess for p in processes: l.AddSample(p, processDic[year][p]) # Systematic uncertainties syst = 'FSR, ISR' systlist = [ x + y for x in syst.replace(' ', '').split(',') for y in ['Up', 'Down'] ]
def GetHistosFromLooper(year, ecut='(t.TStatus == 1 or t.TStatus == 22)', processes=['Chargeflips', 'PromptSS'], outfolder='/'): #l = looper(path=path[year], nSlots = 6, treeName = 'MiniTree', options = 'merge', nEvents = 1000, outpath=outpath+'tempfiles/') l = looper(path=path[year] if not region == 'BS' else pathBS[year], nSlots=4, treeName='MiniTree', options='merge', outpath=GetOutPath(year, region) + '/' + outfolder + '/tempfiles/', readOutput=True) l.AddHeader('from framework.mva import ModelPredict\n') l.AddInit(' self.pd1 = ModelPredict("%s")\n' % model) for p in processes: l.AddSample(p, processDic[year][p]) l.AddSyst(systlist) l.AddLoopCode(loopcode) l.AddExpr('deltaphi', 'TDeltaPhi', 'abs(TDeltaPhi)/3.141592') l.AddExpr('deltaeta', 'TDeltaEta', 'abs(TDeltaEta)') l.AddExpr('weight1', [], '1') l.AddExpr('vpd', '', 'prob1', True) # True because prob1 has to be defined before l.AddExpr('vmet', ['TMET'], 'TMET') l.AddExpr('vmt2', ['TMT2'], 'TMT2') l.AddExpr('vht', ['THT'], 'THT') l.AddExpr('vmll', ['TMll'], 'TMll') l.AddExpr('exprW', ['TWeight'], 'TWeight') l.AddSelection(selection) weight = 'exprW' #cut = 'TMET > 50 and TMT2 > 80 and TNJets >= 2 and TNBtags >= 1 and TPassDilep and %s'%ecut #l.AddCut(cut, ['TMET', 'TMT2', 'TNJets', 'TNBtags', 'TPassDilep']) l.AddCut('TPassDilep == 1', 'TPassDilep') if region != 'BS': l.AddCut('TMET >= 50', 'TMET') l.AddCut('TMT2 >= 80', 'TMT2') l.AddCut('TNJets >= 2', 'TNJets') l.AddCut('TNBtags >= 1', 'TNBtags') l.AddCut(ecut, []) cut = '' l.AddHisto('vpd', 'dnn_5', 5, 0, 1, weight=weight, cut='') l.AddHisto('vpd', 'dnn_10', 10, 0, 1, weight=weight, cut='') l.AddHisto('vpd', 'dnn', 20, 0, 1, weight=weight, cut='') l.AddHisto('vpd', 'count', 1, 0, 2, weight=weight, cut='') l.AddHisto('TMll', 'mll', 10, 0, 300, weight=weight, cut='') l.AddHisto('TMET', 'met', 10, 50, 300, weight=weight, cut='') l.AddHisto('TMT2', 'mt2', 8, 80, 160, weight=weight, cut='') l.AddHisto('TMT2', 'mt2_4bins', 4, 80, 160, weight=weight, cut='') l.AddHisto('TDilep_Pt', 'dileppt', 10, 0, 300, weight=weight, cut='') l.AddHisto('TLep0Pt', 'lep0pt', 5, 0, 150, weight=weight, cut='') l.AddHisto('TLep1Pt', 'lep1pt', 10, 0, 300, weight=weight, cut='') l.AddHisto('TLep0Eta', 'lep0eta', 8, -2.4, 2.4, weight=weight, cut='') l.AddHisto('TLep1Eta', 'lep1eta', 8, -2.4, 2.4, weight=weight, cut='') l.AddHisto('deltaphi', 'deltaphi', 8, 0, 1, weight=weight, cut='') l.AddHisto('deltaeta', 'deltaeta', 8, 0, 5, weight=weight, cut='') l.AddHisto('TJet0Pt', 'jet0pt', 10, 0, 450, weight=weight, cut='') l.AddHisto('TJet1Pt', 'jet1pt', 6, 0, 300, weight=weight, cut='') l.AddHisto('TJet0Eta', 'jet0eta', 8, -2.4, 2.4, weight=weight, cut='') l.AddHisto('TJet1Eta', 'jet1eta', 8, -2.4, 2.4, weight=weight, cut='') l.AddHisto('THT', 'ht', 8, 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='') out = l.Run() return out
if self.outname == 'tt': if t.TJERindex != 0: return elif self.outname == 'ttgaus': if t.TJERindex != 1: return elif self.outname == 'ttnongaus': if t.TJERindex != 2: return '''%('\n'+stopcuts+'\n') loopcode = ''' values = [%i, %i, t.TDilep_Pt, t.TDeltaPhi, t.TDeltaEta, t.TLep0Pt, t.TLep0Eta, t.TLep1Pt, vmet, t.TLep1Eta, vmll, vmt2, vht] prob1 = self.pd1.GetProb(values) '''%(ms, ml) if doSaveHistos: l = looper(path=path[year] if not region=='BS' else pathBS[year], nSlots = 4, treeName = 'MiniTree', options = 'merge', outpath = GetOutPath(year, region, chan, ms, ml)+'/tempfiles/', readOutput=True) l.AddHeader('from framework.mva import ModelPredict\n') l.AddInit(' self.pd1 = ModelPredict("%s")\n'%model) processes = processDic[year].keys() #['tt'] for p in processes: l.AddSample(p, processDic[year][p]) l.AddSyst(systlist) l.AddLoopCode(loopcode) l.AddExpr('deltaphi', 'TDeltaPhi', 'abs(TDeltaPhi)/3.141592') l.AddExpr('deltaeta', 'TDeltaEta', 'abs(TDeltaEta)') l.AddExpr('weight1', [], '1') l.AddExpr('vpd', '', 'prob1', True) # True because prob1 has to be defined before l.AddExpr('vmet', ['TMET'], 'TMET') l.AddExpr('vmt2', ['TMT2'], 'TMT2')
ms = 275 ml = 100 # Set constants outpath = './Unc/SR/mass%i_%i/' % (ms, ml) os.system("mkdir -p %s" % outpath) model = '/nfs/fanae/user/juanr/CMSSW_10_2_5/src/xuAnalysis/TopPlots/DrawMiniTrees/NNtotal_model2.h5' # Set year year = 2018 # Create the looper, set readOutput to true to read previous temporary rootfiles created for each sample #l = looper(path=path[year], nSlots = 6, treeName = 'MiniTree', options = 'merge', nEvents = 1000, outpath='tempfiles/') l = looper(path=path[year], nSlots=5, treeName='MiniTree', options='merge', outpath=outpath + 'tempfiles/', readOutput=True) # Add processes processes = processDic[year].keys() #['tt'] for p in processes: l.AddSample(p, processDic[year][p]) # Systematic uncertainties syst = 'MuonEff, ElecEff, Trig, JES, JER, MuonES, Uncl, Btag, MisTag, PU, TopPt' if year != 2018: syst += ', Pref' systlist = [ x + y for x in syst.replace(' ', '').split(',') for y in ['Up', 'Down'] ]