From bf4ca2256d6557e157994b240ce1e527dca4c890 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 19 Dec 2014 14:10:05 +0100 Subject: [PATCH 1/6] Heppy: remove starts when storing all bits --- .../Heppy/python/analyzers/core/TriggerBitAnalyzer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py index 5e9195fc5bdc3..f878f0fb61841 100644 --- a/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py @@ -36,6 +36,8 @@ def beginLoop(self, setup): outname="%s_BIT_%s"%(self.outprefix,TP) if not hasattr(setup ,"globalVariables") : setup.globalVariables = [] + if outname[-1] == '*' : + outname=outname[0:-1] setup.globalVariables.append( NTupleVariable(outname, eval("lambda ev: ev.%s" % outname), help="Trigger bit %s"%TP) ) self.triggerBitCheckersSingleBits.append( (TP, ROOT.heppy.TriggerBitChecker(trigVecBit)) ) @@ -55,6 +57,8 @@ def process(self, event): if self.unrollbits : for TP,TC in self.triggerBitCheckersSingleBits: outname="%s_BIT_%s"%(self.outprefix,TP) + if outname[-1] == '*' : + outname=outname[0:-1] setattr(event,outname, TC.check(event.input.object(), triggerResults)) From 3a170b19194c489804e16153b3ddfb90627a39ec Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 19 Dec 2014 14:18:12 +0100 Subject: [PATCH 2/6] Heppy: code to compute the leading track and its pt in a Jet --- .../Heppy/python/physicsobjects/Jet.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/Heppy/python/physicsobjects/Jet.py b/PhysicsTools/Heppy/python/physicsobjects/Jet.py index 910b97e96d1ea..f80b2925ee58f 100644 --- a/PhysicsTools/Heppy/python/physicsobjects/Jet.py +++ b/PhysicsTools/Heppy/python/physicsobjects/Jet.py @@ -41,6 +41,8 @@ def __init__(self, *args, **kwargs): def _physObjInit(self): self._rawFactorMultiplier = 1.0 + self._leadingTrack = None + self._leadingTrackSearched = False def jetID(self,name=""): if not self.isPFJet(): @@ -100,7 +102,22 @@ def btagWP(self,name): global _btagWPs (disc,val) = _btagWPs[name] return self.bDiscriminator(disc) > val - + + def leadingTrack(self): + if self._leadingTrackSearched : + return self._leadingTrack + self._leadingTrackSearched = True + self._leadingTrack = max( self.daughterPtrVector() , key = lambda x : x.pt() if x.charge()!=0 else 0. ) + if self._leadingTrack.charge()==0: #in case of "all neutral" + self._leadingTrack = None + return self._leadingTrack + + def leadTrackPt(self): + lt=self.leadingTrack() + if lt : + return lt.pt() + else : + return 0. class GenJet( PhysicsObject): pass From ee83fe48ecc0321ba47d93814deed5552ed7925d Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 19 Dec 2014 14:22:11 +0100 Subject: [PATCH 3/6] Heppy: make service looked for by the treeanalyzer configurable, default to 'outputfile' --- .../Heppy/python/analyzers/core/TreeAnalyzerNumpy.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/PhysicsTools/Heppy/python/analyzers/core/TreeAnalyzerNumpy.py b/PhysicsTools/Heppy/python/analyzers/core/TreeAnalyzerNumpy.py index 427c0f735e5c1..da103bec9dd1b 100644 --- a/PhysicsTools/Heppy/python/analyzers/core/TreeAnalyzerNumpy.py +++ b/PhysicsTools/Heppy/python/analyzers/core/TreeAnalyzerNumpy.py @@ -11,15 +11,17 @@ class TreeAnalyzerNumpy( Analyzer ): def __init__(self, cfg_ana, cfg_comp, looperName): super(TreeAnalyzerNumpy,self).__init__(cfg_ana, cfg_comp, looperName) - + self.outservicename = "outputfile" + if hasattr(cfg_ana,"outservicename") : + self.outservicename = cfg_ana.outservicename def beginLoop(self, setup) : super(TreeAnalyzerNumpy, self).beginLoop(setup) print setup.services - if "outputfile" in setup.services: - print "Using outputfile given in setup.outputfile" - self.file = setup.services["outputfile"].file + if self.outservicename in setup.services: + print "Using outputfile given in", self.outservicename + self.file = setup.services[self.outservicename].file else : fileName = '/'.join([self.dirName, 'tree.root']) @@ -35,6 +37,6 @@ def declareVariables(self,setup): def write(self, setup): super(TreeAnalyzerNumpy, self).write(setup) - if "outputfile" not in setup.services: + if self.outservicename not in setup.services: self.file.Write() From 04985109964aa619fe613ab560290ff9b470d919 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 19 Dec 2014 15:03:25 +0100 Subject: [PATCH 4/6] adding minimal lepton information to jets, more coming --- PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py | 4 ++++ PhysicsTools/Heppy/python/analyzers/objects/autophobj.py | 1 + 2 files changed, 5 insertions(+) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py index e9e8ce8e5d042..9c93d3b6d0c65 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py @@ -122,6 +122,10 @@ def process(self, event): ## Associate jets to leptons leptons = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons jlpairs = matchObjectCollection( leptons, allJets, self.jetLepDR**2) + + for jet in allJets: + jet.leptons = [l for l in jlpairs if jlpairs[l] == jet ] + for lep in leptons: jet = jlpairs[lep] if jet is None: diff --git a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py index e1d3b43f7c8cc..3f4f88f327da7 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/autophobj.py @@ -162,6 +162,7 @@ NTupleVariable("mult", lambda x : getattr(x,'mult', 0) , int, mcOnly=False,help="QG input variable: total multiplicity"), NTupleVariable("partonId", lambda x : getattr(x,'partonId', 0), int, mcOnly=True, help="parton flavour (manually matching to status 23 particles)"), NTupleVariable("partonMotherId", lambda x : getattr(x,'partonMotherId', 0), int, mcOnly=True, help="parton flavour (manually matching to status 23 particles)"), + NTupleVariable("nLeptons", lambda x : len(x.leptons) if hasattr(x,'leptons') else 0 , float, mcOnly=False,help="Number of associated leptons"), ]) From 32425274ef28b0bf6603a2d19918fb96ae9df61c Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 7 Jan 2015 16:21:35 +0100 Subject: [PATCH 5/6] Heppy: add LHE analyzer --- .../Heppy/python/analyzers/gen/LHEAnalyzer.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py diff --git a/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py new file mode 100644 index 0000000000000..4fe85ece8e002 --- /dev/null +++ b/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py @@ -0,0 +1,73 @@ +from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer +from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle +import PhysicsTools.HeppyCore.framework.config as cfg +from math import * +from DataFormats.FWLite import Events, Handle + +class LHEAnalyzer( Analyzer ): + """ """ + def __init__(self, cfg_ana, cfg_comp, looperName ): + super(LHEAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName) + + def declareHandles(self): + super(LHEAnalyzer, self).declareHandles() +# self.mchandles['lhestuff'] = AutoHandle( 'externalLHEProducer','LHEEventProduct') + + def beginLoop(self, setup): + super(LHEAnalyzer,self).beginLoop(setup) + + def process(self, event): + + # if not MC, nothing to do + if not self.cfg_comp.isMC: + return True + event.lheHT=0 + event.lheNj=0 + event.lheV_pt = 0 + h=Handle('LHEEventProduct') + event.input.getByLabel( 'externalLHEProducer',h) + if not h.isValid() : + return True + self.readCollections( event.input ) + hepeup=h.product().hepeup() + pup=hepeup.PUP + l=None + lBar=None + nu=None + nuBar=None + for i in xrange(0,len(pup)): + id=hepeup.IDUP[i] + status = hepeup.ISTUP[i] + idabs=abs(id) + + if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks + event.lheHT += sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py + event.lheNj +=1 + if idabs in [12,14,16] : + if id > 0 : + nu = i + else : + nuBar = i + if idabs in [11,13,15] : + if id > 0 : + l = i + else : + lBar = i + v=None + if l and lBar : #Z to LL + v=(l,lBar) + elif l and nuBar : #W + v=(l,nuBar) + elif lBar and nu : #W + v=(nu,lBar) + elif nu and nuBar : #Z to nn + v=(nu,nuBar) + if v : + event.lheV_pt = sqrt( (pup[v(0)][0]+pup[v(1)][0])**2 + (pup[v(0)][1]+pup[v(1)][1])**2 ) + + return True + +setattr(LHEAnalyzer,"defaultConfig", + cfg.Analyzer(LHEAnalyzer, + ) +) From c1d69f86e272ab8c5e611c28ee302d87c14056a1 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 8 Jan 2015 09:48:35 +0100 Subject: [PATCH 6/6] Heppy: fix LHE analyzer V_pt --- .../Heppy/python/analyzers/gen/LHEAnalyzer.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py index 4fe85ece8e002..1b8c03905df18 100644 --- a/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py @@ -43,16 +43,16 @@ def process(self, event): if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks event.lheHT += sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py event.lheNj +=1 - if idabs in [12,14,16] : - if id > 0 : - nu = i - else : - nuBar = i - if idabs in [11,13,15] : - if id > 0 : - l = i - else : - lBar = i + if idabs in [12,14,16] : + if id > 0 : + nu = i + else : + nuBar = i + if idabs in [11,13,15] : + if id > 0 : + l = i + else : + lBar = i v=None if l and lBar : #Z to LL v=(l,lBar) @@ -63,7 +63,7 @@ def process(self, event): elif nu and nuBar : #Z to nn v=(nu,nuBar) if v : - event.lheV_pt = sqrt( (pup[v(0)][0]+pup[v(1)][0])**2 + (pup[v(0)][1]+pup[v(1)][1])**2 ) + event.lheV_pt = sqrt( (pup[v[0]][0]+pup[v[1]][0])**2 + (pup[v[0]][1]+pup[v[1]][1])**2 ) return True