Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0002 from PhysicsTools.HeppyCore.utils.deltar import deltaR
0003 
0004 class GenHeavyFlavourAnalyzer( Analyzer ):
0005     """
0006        Makes:
0007           event.genallbquarks, event.genallcquarks:
0008                 list of all b and c quarks (without doublecounting of b->b and c->c chains).
0009                 if status2Only == True, only status 2 ones are included.
0010           event.allBPartons
0011                 all status 2 b-quarks, sorted by pt decreasingly
0012           event.bPartons:
0013                 status 2 b-quarks passing a pt cut bquarkPtCut (default: 15)
0014 
0015        Requires:
0016           event.genParticles      
0017        """
0018 
0019     def __init__(self, cfg_ana, cfg_comp, looperName ):
0020         super(GenHeavyFlavourAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
0021         self.status2Only = cfg_ana.status2Only 
0022         self.bquarkPtCut = cfg_ana.bquarkPtCut
0023  
0024     def declareHandles(self):
0025         super(GenHeavyFlavourAnalyzer, self).declareHandles()
0026 
0027     def beginLoop(self,setup):
0028         super(GenHeavyFlavourAnalyzer,self).beginLoop(setup)
0029 
0030     def makeBPartons(self,event):
0031         event.allBPartons = [ q for q in event.genParticles if abs(q.pdgId()) == 5 and abs(q.status()) == 2 and abs(q.pt()) > self.bquarkPtCut ]
0032         event.allBPartons.sort(key = lambda q : q.pt(), reverse = True)
0033         event.bPartons = []
0034         for q in event.allBPartons:
0035             duplicate = False
0036             for q2 in event.bPartons:
0037                 if deltaR(q.eta(),q.phi(),q2.eta(),q2.phi()) < 0.5:
0038                     duplicate = True
0039             continue
0040             if not duplicate: event.bPartons.append(q)
0041 
0042     def process(self, event):
0043         self.readCollections( event.input )
0044 
0045         # if not MC, nothing to do
0046         if not self.cfg_comp.isMC: 
0047             return True
0048 
0049         status2f = (lambda p : p.status() == 2) if self.status2Only else (lambda p : True)
0050         event.genallcquarks = [ p for p in event.genParticles if abs(p.pdgId()) == 5 and ( p.numberOfDaughters() == 0 or abs(p.daughter(0).pdgId()) != 5) and status2f(p) ]
0051         event.genallbquarks = [ p for p in event.genParticles if abs(p.pdgId()) == 4 and ( p.numberOfDaughters() == 0 or abs(p.daughter(0).pdgId()) != 4) and status2f(p) ]
0052 
0053         self.makeBPartons(event)
0054 
0055         return True
0056 
0057 import PhysicsTools.HeppyCore.framework.config as cfg
0058 setattr(GenHeavyFlavourAnalyzer,"defaultConfig",
0059     cfg.Analyzer(GenHeavyFlavourAnalyzer,
0060         status2Only = False,
0061         bquarkPtCut = 15.0,
0062    )
0063 )