CMS 3D CMS Logo

ResonanceBuilder.py
Go to the documentation of this file.
1 
2 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
3 from PhysicsTools.Heppy.physicsobjects.Particle import Particle
4 
5 import pprint
6 import itertools
7 
8 mass = {23: 91., 25: 125.}
9 
11  '''Resonance decaying into 2 particles.
12 
13  The interface of this class mimics the interface of the CMS Candidate class.
14  In this way Resonance objects or CMS Candidate objects can be processed
15  transparently.
16  '''
17 
18  def __init__(self, leg1, leg2, pdgid, status=3):
19  '''
20  Parameters (stored as attributes):
21  leg1,2 : first and second leg.
22  pdgid : pdg code of the resonance
23  status : status code of the resonance
24  '''
25  self.leg1 = leg1
26  self.leg2 = leg2
27  self._p4 = leg1.p4() + leg2.p4()
28  self._charge = leg1.charge() + leg2.charge()
29  self._pdgid = pdgid
30  self._status = status
31 
32  def p4(self):
33  return self._p4
34 
35  def pt(self):
36  return self._p4.pt()
37 
38  def energy(self):
39  return self._p4.energy()
40 
41  def eta(self):
42  return self._p4.eta()
43 
44  def phi(self):
45  return self._p4.phi()
46 
47  def mass(self):
48  return self._p4.mass()
49 
50  def charge(self):
51  return self._charge
52 
53  def pdgId(self):
54  return self._pdgid
55 
56 
58  '''Builds resonances from an input collection of particles.
59 
60  Example configuration:
61 
62  from PhysicsTools.Heppy.analyzers.examples.ResonanceBuilder import ResonanceBuilder
63  dimuons = cfg.Analyzer(
64  ResonanceBuilder,
65  'dimuons',
66  leg_collection = 'muons', # input collection
67  filter_func = lambda x : True, # filtering function for input objects. here, take all.
68  pdgid = 23 # pdgid for the resonances, here Z
69  )
70 
71  This analyzer puts one collection in the event:
72  event.dimuons : all resonances, sorted by their distance to the nominal mass
73  corresponding to the specified pdgid
74  '''
75  def process(self, event):
76  legs = getattr(event, self.cfg_ana.leg_collection)
77  legs = [leg for leg in legs if self.cfg_ana.filter_func(leg)]
78  resonances = []
79  for leg1, leg2 in itertools.combinations(legs,2):
80  resonances.append( Resonance(leg1, leg2, self.cfg_ana.pdgid, 3) )
81  # sorting according to distance to nominal mass
82  nominal_mass = mass[self.cfg_ana.pdgid]
83  resonances.sort(key=lambda x: abs(x.mass()-nominal_mass))
84  setattr(event, self.instance_label, resonances)
85 
86 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def __init__(self, leg1, leg2, pdgid, status=3)