Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 from builtins import range
0002 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0003 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0004 import PhysicsTools.HeppyCore.framework.config as cfg
0005 from math import *
0006 from DataFormats.FWLite import Events, Handle
0007 
0008 class LHEAnalyzer( Analyzer ):
0009     """    """
0010     def __init__(self, cfg_ana, cfg_comp, looperName ):
0011         super(LHEAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
0012         self.lheh=Handle('LHEEventProduct')
0013 
0014     def declareHandles(self):
0015         super(LHEAnalyzer, self).declareHandles()
0016 #        self.mchandles['lhestuff'] = AutoHandle( 'externalLHEProducer','LHEEventProduct')
0017 
0018     def beginLoop(self, setup):
0019         super(LHEAnalyzer,self).beginLoop(setup)
0020 
0021     def process(self, event):
0022 
0023         # if not MC, nothing to do
0024         if not self.cfg_comp.isMC: 
0025             return True
0026         event.lheHT=0
0027         event.lheHTIncoming=0 #restrict HT computation to particles that have status<0 mothers
0028         event.lheNj=0
0029         event.lheNb=0
0030         event.lheNc=0
0031         event.lheNl=0
0032         event.lheNg=0
0033         event.lheV_pt = 0
0034         try:
0035           event.input.getByLabel( 'externalLHEProducer',self.lheh)
0036         except :
0037           return True
0038         if not  self.lheh.isValid() :
0039             return True
0040         self.readCollections( event.input )
0041         hepeup=self.lheh.product().hepeup()
0042         pup=hepeup.PUP
0043         l=None
0044         lBar=None
0045         nu=None
0046         nuBar=None 
0047         for i in range(0,len(pup)):
0048           id=hepeup.IDUP[i]
0049           status = hepeup.ISTUP[i]
0050           idabs=abs(id)
0051 
0052           mothIdx = max(hepeup.MOTHUP[i][0]-1,0) #first and last mother as pair; first entry has index 1 in LHE; incoming particles return motherindex 0
0053           mothIdxTwo = max(hepeup.MOTHUP[i][1]-1,0) 
0054           
0055           mothStatus  = hepeup.ISTUP[mothIdx] 
0056           mothStatusTwo  = hepeup.ISTUP[mothIdxTwo] 
0057 
0058           hasIncomingAsMother = mothStatus<0 or mothStatusTwo<0
0059           
0060           if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks
0061               pt = sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py
0062               event.lheHT += pt
0063               if hasIncomingAsMother: event.lheHTIncoming += pt
0064               event.lheNj +=1
0065               if idabs==5:
0066                 event.lheNb += 1
0067               if idabs==4:
0068                 event.lheNc += 1
0069               if idabs in [1,2,3]:
0070                 event.lheNl += 1
0071               if idabs==21:
0072                 event.lheNg += 1
0073           if idabs in [12,14,16] :  
0074               if id > 0 :
0075                 nu = i
0076               else :
0077                 nuBar = i
0078           if idabs in [11,13,15] :  
0079               if id > 0 :
0080                 l = i
0081               else :
0082                 lBar = i
0083           v=None
0084           if l and lBar : #Z to LL
0085               v=(l,lBar)
0086           elif l and nuBar : #W 
0087               v=(l,nuBar)
0088           elif lBar and nu : #W 
0089               v=(nu,lBar)
0090           elif nu and nuBar : #Z to nn 
0091               v=(nu,nuBar)
0092           if v :
0093             event.lheV_pt = sqrt( (pup[v[0]][0]+pup[v[1]][0])**2 +  (pup[v[0]][1]+pup[v[1]][1])**2 )
0094 
0095         return True
0096 
0097 setattr(LHEAnalyzer,"defaultConfig",
0098     cfg.Analyzer(LHEAnalyzer,
0099     )
0100 )