def beginJob(self,histFile=None,histDirName=None): self.vars = ["eta","phi","mass"] self.vars_leptons = ["pdgId",'jetIdx','pt'] self.vars_taus = ["pt"] self.vars_taus_int = ['jetIdx'] self.vars_taus_uchar = ['idMVAoldDMdR032017v2','idDeepTau2017v2p1VSjet'] self.vars_jets = [("pt","pt_nom") if self.isMC else 'pt',"btagDeepB","qgl",'btagDeepFlavB'] + [ 'pt_%s%s'%(x,y) for x in self.variations for y in ["Up","Down"]] #"btagCSVV2",,"btagDeepC"]#"btagCSV","btagDeepCSV",,"btagDeepCSVCvsL","btagDeepCSVCvsB","ptd","axis1"] # FIXME recover self.vars_jets_int = (["hadronFlavour"] if self.isMC else []) self.vars_jets_nooutput = [] self.systsJEC = {0:""} if self.isMC: for sys in range(len(self.variations)): self.systsJEC[sys+1] = '_' + self.variations[sys] + 'Up' self.systsJEC[-(sys+1)] = '_' + self.variations[sys] + 'Down' self.outmasses=['mZ1','minMllAFAS','minMllAFOS','minMllAFSS','minMllSFOS','mZ2','m4l'] self._outjetvars = [x%self.jc for x in ['ht%s%%dj','mht%s%%d','nB%sLoose%%d','nB%sMedium%%d','n%s%%d']] self.outjetvars=[] for jetPt in self.jetPts: self.outjetvars.extend([(x%jetPt+y,'I' if ('nB%s'%self.jc in x or 'n%s'%self.jc in x) else 'F') for x in self._outjetvars for y in self.systsJEC.values()]) self.outjetvars.extend([('nFwdJet'+self.systsJEC[y],'I') for y in self.systsJEC ]) self.outjetvars.extend([(x+self.systsJEC[y],'F') for y in self.systsJEC for x in ['FwdJet1_pt','FwdJet1_eta'] ]) self.branches = [var+self.label for var in self.outmasses] self.branches.extend([(var+self.label,_type) for var,_type in self.outjetvars]) self.branches += [("LepGood_conePt","F",100,"nLepGood")] self._helper_lepsF = CollectionSkimmer("LepFO"+self.label, "LepGood", floats=[], maxSize=10, saveTagForAll=True, saveSelectedIndices=True,padSelectedIndicesWith=0) self._helper_lepsT = CollectionSkimmer("LepTight"+self.label, "LepGood", floats=[], maxSize=10, saveTagForAll=True) self._helper_taus = CollectionSkimmer("TauSel"+self.label, self.tauc, floats=self.vars+self.vars_taus, ints=self.vars_taus_int, uchars=self.vars_taus_uchar, maxSize=10) self._helper_jets = CollectionSkimmer("%sSel"%self.jc+self.label, self.jc, floats=self.vars+self.vars_jets, ints=self.vars_jets_int, maxSize=20, saveSelectedIndices=True,padSelectedIndicesWith=0) self._helpers = [self._helper_lepsF,self._helper_lepsT,self._helper_taus,self._helper_jets]
def __init__(self, label=""): JetReCleaner_TreeReaders.__init__(self, label) self._helper = CollectionSkimmer("JetGood" + self.label, "Jet", floats=self.vars, maxSize=20) self.branches = [] # output is done in C++
def __init__(self,label,inlabel,cleanTausWithLooseLeptons,cleanJetsWithFOTaus,doVetoZ,doVetoLMf,doVetoLMt,jetPts,btagL_thr,btagM_thr,jetCollection='Jet',isMC=True): self.label = "" if (label in ["",None]) else ("_"+label) self.inlabel = inlabel self.vars = ["pt","eta","phi","mass"] self.vars_leptons = ["pdgId"] self.vars_taus = ["mvaId2017"] self.vars_taus_int = ["idMVAdR03"] self.vars_jets = ["btagCSV","btagDeepCSV","qgl","btagDeepCSVCvsL","btagDeepCSVCvsB","ptd","axis1","corr","corr_JECUp","corr_JECDown"] self.vars_jets_int = ["mult"]+(["hadronFlavour"] if isMC else []) self.vars_jets_nooutput = [] self.jc = jetCollection self.cleanTausWithLooseLeptons = cleanTausWithLooseLeptons self.cleanJetsWithFOTaus = cleanJetsWithFOTaus self.jetPts = jetPts self.systsJEC = {0:"", 1:"_jecUp", -1:"_jecDown"} self.outmasses=['mZ1','minMllAFAS','minMllAFOS','minMllAFSS','minMllSFOS','mZ2','m4l'] self._outjetvars = [x%self.jc for x in ['ht%s%%dj','mht%s%%d','nB%sLoose%%d','nB%sMedium%%d','n%s%%d']] self.outjetvars=[] for jetPt in self.jetPts: self.outjetvars.extend([(x%jetPt+y,'I' if ('nB%s'%self.jc in x or 'n%s'%self.jc in x) else 'F') for x in self._outjetvars for y in self.systsJEC.values()]) self.branches = [var+self.label for var in self.outmasses] self.branches.extend([(var+self.label,_type) for var,_type in self.outjetvars]) self.branches += [("LepGood_conePt","F",20,"nLepGood")] self._helper_lepsF = CollectionSkimmer("LepFO"+self.label, "LepGood", floats=[], maxSize=20, saveSelectedIndices=True,padSelectedIndicesWith=0) self._helper_lepsT = CollectionSkimmer("LepTight"+self.label, "LepGood", floats=[], maxSize=20, saveTagForAll=True) self._helper_taus = CollectionSkimmer("TauSel"+self.label, "TauGood", floats=self.vars+self.vars_taus, ints=self.vars_taus_int, maxSize=20) self._helper_jets = CollectionSkimmer("%sSel"%self.jc+self.label, self.jc, floats=self.vars+self.vars_jets, ints=self.vars_jets_int, maxSize=20) self._helpers = [self._helper_lepsF,self._helper_lepsT,self._helper_taus,self._helper_jets] if "/fastCombinedObjectRecleanerHelper_cxx.so" not in ROOT.gSystem.GetLibraries(): print "Load C++ recleaner worker module" ROOT.gROOT.ProcessLine(".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerHelper.cxx+O" % os.environ['CMSSW_BASE']) self._worker = ROOT.fastCombinedObjectRecleanerHelper(self._helper_taus.cppImpl(),self._helper_jets.cppImpl(),self.cleanJetsWithFOTaus,btagL_thr,btagM_thr) for x in self.jetPts: self._worker.addJetPt(x) if "/fastCombinedObjectRecleanerMassVetoCalculator_cxx.so" not in ROOT.gSystem.GetLibraries(): print "Load C++ recleaner mass and veto calculator module" ROOT.gROOT.ProcessLine(".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerMassVetoCalculator.cxx+O" % os.environ['CMSSW_BASE']) self._workerMV = ROOT.fastCombinedObjectRecleanerMassVetoCalculator(self._helper_lepsF.cppImpl(),self._helper_lepsT.cppImpl(),doVetoZ,doVetoLMf,doVetoLMt)
def init(self, tree): for v in self.floats + self.ints: if not tree.GetBranch("Jet_" + v): print "Missing branch Jet_" + v self.floats = [v for v in self.floats if tree.GetBranch("Jet_" + v)] self.ints = [v for v in self.ints if tree.GetBranch("Jet_" + v)] self._helper = CollectionSkimmer("JetGood" + self.label, "Jet", floats=self.floats, ints=self.ints, saveSelectedIndices=True, maxSize=20) self._worker = ROOT.JetReCleanerExampleHelper(self._helper.cppImpl()) self._helper.initInputTree(tree) self.initReaders(tree) self._helper.initOutputTree(self._out)
def init(self, tree): for v in self.floats + self.ints: if not tree.GetBranch("LepOther_" + v): print "Missing branch LepOther_" + v self.floats = [ v for v in self.floats if tree.GetBranch("LepOther_" + v) ] self.ints = [v for v in self.ints if tree.GetBranch("LepOther_" + v)] self._helper = CollectionSkimmer("LepOtherGood" + self.label, "LepOther", floats=self.floats, ints=self.ints, saveSelectedIndices=True, maxSize=20) self._helper.initInputTree(tree) self.initReaders(tree) self._helper.initOutputTree(self._out)
def init(self,tree): for v in self.floats+self.ints: if not tree.GetBranch("GenPart_"+v): print "Missing branch GenPart_"+v self.floats = [v for v in self.floats if tree.GetBranch("GenPart_"+v)] self.ints = [v for v in self.ints if tree.GetBranch("GenPart_"+v)] self.collections = ['Higgs','Top','ATop','bFromTop','WFromTop','bFromATop','WFromATop', 'dFromWFromTop','dFromWFromATop','dDirectFromHiggs','dAllFromHiggs', 'dFromOnShellVFromHiggs','dFromOffShellVFromHiggs','allFinalParton'] for x in self.collections: cs = CollectionSkimmer(x+self.label, "GenPart", floats=self.floats, ints=self.ints, saveSelectedIndices=True, saveTagForAll=True, maxSize=50) setattr(self,'_h_%s'%x,cs) self._helpers.append(cs) for x in self._helpers: x.initInputTree(tree) x.initOutputTree(self._out) self.initReaders(tree)
def __init__(self, label, inlabel, cleanTausWithLooseLeptons, cleanJetsWithFOTaus, doVetoZ, doVetoLMf, doVetoLMt, jetPts, btagL_thr, btagM_thr): self.label = "" if (label in ["", None]) else ("_" + label) self.inlabel = inlabel self.vars = ["pt", "eta", "phi", "mass"] self.vars_leptons = ["pdgId"] self.vars_jets = ["btagCSV"] self.cleanTausWithLooseLeptons = cleanTausWithLooseLeptons self.cleanJetsWithFOTaus = cleanJetsWithFOTaus self.jetPts = jetPts self.outmasses = [ 'mZ1', 'minMllAFAS', 'minMllAFOS', 'minMllAFSS', 'minMllSFOS' ] self._outjetvars = [ 'htJet%dj', 'mhtJet%d', 'nBJetLoose%d', 'nBJetMedium%d' ] self.outjetvars = [] for jetPt in self.jetPts: self.outjetvars.extend([(x % jetPt, 'I' if 'nBJet' in x else 'F') for x in self._outjetvars]) self.branches = [var + self.label for var in self.outmasses] self.branches.extend([(var + self.label, _type) for var, _type in self.outjetvars]) self.branches += [("LepGood_conePt", "F", 20, "nLepGood")] self._helper_lepsF = CollectionSkimmer("LepFO" + self.label, "LepGood", floats=[], maxSize=20, saveSelectedIndices=True, padSelectedIndicesWith=0) self._helper_lepsT = CollectionSkimmer("LepTight" + self.label, "LepGood", floats=[], maxSize=20, saveTagForAll=True) self._helper_taus = CollectionSkimmer("TauSel" + self.label, "TauGood", floats=self.vars, maxSize=20) self._helper_jets = CollectionSkimmer("JetSel" + self.label, "Jet", floats=self.vars + self.vars_jets, maxSize=20) self._helpers = [ self._helper_lepsF, self._helper_lepsT, self._helper_taus, self._helper_jets ] if "/fastCombinedObjectRecleanerHelper_cxx.so" not in ROOT.gSystem.GetLibraries( ): print "Load C++ recleaner worker module" ROOT.gROOT.ProcessLine( ".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerHelper.cxx+O" % os.environ['CMSSW_BASE']) self._worker = ROOT.fastCombinedObjectRecleanerHelper( self._helper_taus.cppImpl(), self._helper_jets.cppImpl(), self.cleanJetsWithFOTaus, btagL_thr, btagM_thr) for x in self.jetPts: self._worker.addJetPt(x) if "/fastCombinedObjectRecleanerMassVetoCalculator_cxx.so" not in ROOT.gSystem.GetLibraries( ): print "Load C++ recleaner mass and veto calculator module" ROOT.gROOT.ProcessLine( ".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerMassVetoCalculator.cxx+O" % os.environ['CMSSW_BASE']) self._workerMV = ROOT.fastCombinedObjectRecleanerMassVetoCalculator( self._helper_lepsF.cppImpl(), self._helper_lepsT.cppImpl(), doVetoZ, doVetoLMf, doVetoLMt)
def beginJob(self, histFile=None, histDirName=None): self.vars = ["eta", "phi", "mass"] self.vars_leptons = ["pdgId", 'jetIdx', 'pt'] self.vars_taus = ["pt"] self.vars_taus_int = ['jetIdx'] self.vars_taus_uchar = [ 'idMVAoldDMdR032017v2', 'idDeepTau2017v2p1VSjet' ] self.vars_jets = [ ("pt", "pt_nom") if self.isMC and len(self.variations) else 'pt', "btagDeepB", "qgl", 'btagDeepFlavB' ] + [ 'pt_%s%s' % (x, y) for x in self.variations for y in ["Up", "Down"] ] #"btagCSVV2",,"btagDeepC"]#"btagCSV","btagDeepCSV",,"btagDeepCSVCvsL","btagDeepCSVCvsB","ptd","axis1"] # FIXME recover self.vars_jets_int = (["hadronFlavour"] if self.isMC else []) self.vars_jets_nooutput = [] self.systsJEC = {0: ""} if self.isMC: for sys in range(len(self.variations)): self.systsJEC[sys + 1] = '_' + self.variations[sys] + 'Up' self.systsJEC[-(sys + 1)] = '_' + self.variations[sys] + 'Down' self.outmasses = [ 'mZ1', 'minMllAFAS', 'minMllAFOS', 'minMllAFSS', 'minMllSFOS', 'mZ2', 'm4l' ] self._outjetvars = [ x % self.jc for x in [ 'ht%s%%dj', 'mht%s%%d', 'nB%sLoose%%d', 'nB%sMedium%%d', 'n%s%%d' ] ] self.outjetvars = [] for jetPt in self.jetPts: self.outjetvars.extend([ (x % jetPt + y, 'I' if ('nB%s' % self.jc in x or 'n%s' % self.jc in x) else 'F') for x in self._outjetvars for y in self.systsJEC.values() ]) self.outjetvars.extend([('nFwdJet' + self.systsJEC[y], 'I') for y in self.systsJEC]) self.outjetvars.extend([(x + self.systsJEC[y], 'F') for y in self.systsJEC for x in ['FwdJet1_pt', 'FwdJet1_eta']]) self.branches = [var + self.label for var in self.outmasses] self.branches.extend([(var + self.label, _type) for var, _type in self.outjetvars]) self.branches += [("LepGood_conePt", "F", 100, "nLepGood")] self._helper_lepsF = CollectionSkimmer("LepFO" + self.label, "LepGood", floats=[], maxSize=10, saveSelectedIndices=True, padSelectedIndicesWith=0) self._helper_lepsT = CollectionSkimmer("LepTight" + self.label, "LepGood", floats=[], maxSize=10, saveTagForAll=True) self._helper_taus = CollectionSkimmer("TauSel" + self.label, self.tauc, floats=self.vars + self.vars_taus, ints=self.vars_taus_int, uchars=self.vars_taus_uchar, maxSize=10) self._helper_jets = CollectionSkimmer("%sSel" % self.jc + self.label, self.jc, floats=self.vars + self.vars_jets, ints=self.vars_jets_int, maxSize=20) self._helpers = [ self._helper_lepsF, self._helper_lepsT, self._helper_taus, self._helper_jets ] if "/fastCombinedObjectRecleanerHelper_cxx.so" not in ROOT.gSystem.GetLibraries( ): print "Load C++ recleaner worker module" ROOT.gROOT.ProcessLine( ".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerHelper.cxx+O" % os.environ['CMSSW_BASE']) self._worker = ROOT.fastCombinedObjectRecleanerHelper( self._helper_taus.cppImpl(), self._helper_jets.cppImpl(), self.cleanJetsWithFOTaus, self.btagL_thr, self.btagM_thr, True) for x in self.jetPts: self._worker.addJetPt(x) self._worker.setFwdPt(self.jetPtsFwd[0], self.jetPtsFwd[1]) if "/fastCombinedObjectRecleanerMassVetoCalculator_cxx.so" not in ROOT.gSystem.GetLibraries( ): print "Load C++ recleaner mass and veto calculator module" ROOT.gROOT.ProcessLine( ".L %s/src/CMGTools/TTHAnalysis/python/tools/fastCombinedObjectRecleanerMassVetoCalculator.cxx+O" % os.environ['CMSSW_BASE']) self._workerMV = ROOT.fastCombinedObjectRecleanerMassVetoCalculator( self._helper_lepsF.cppImpl(), self._helper_lepsT.cppImpl(), self.doVetoZ, self.doVetoLMf, self.doVetoLMt)