Skip to content

Commit

Permalink
Merge pull request #13 from arizzi/heppy_7_2_2_patch2
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
cbernet committed Jan 8, 2015
2 parents ba3b2eb + c1d69f8 commit c493196
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 6 deletions.
12 changes: 7 additions & 5 deletions PhysicsTools/Heppy/python/analyzers/core/TreeAnalyzerNumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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()

Original file line number Diff line number Diff line change
Expand Up @@ -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)) )

Expand All @@ -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))


Expand Down
73 changes: 73 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/gen/LHEAnalyzer.py
Original file line number Diff line number Diff line change
@@ -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,
)
)
4 changes: 4 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions PhysicsTools/Heppy/python/analyzers/objects/autophobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
])


Expand Down
19 changes: 18 additions & 1 deletion PhysicsTools/Heppy/python/physicsobjects/Jet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c493196

Please sign in to comment.