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 
ResonanceBuilder.Resonance._charge
_charge
Definition: ResonanceBuilder.py:28
ResonanceBuilder.Resonance.p4
def p4(self)
Definition: ResonanceBuilder.py:32
ResonanceBuilder.Resonance
Definition: ResonanceBuilder.py:10
ResonanceBuilder.Resonance.mass
def mass(self)
Definition: ResonanceBuilder.py:47
ResonanceBuilder.ResonanceBuilder
Definition: ResonanceBuilder.py:57
remoteMonitoring_LED_IterMethod_cfg.Analyzer
Analyzer
Definition: remoteMonitoring_LED_IterMethod_cfg.py:32
ResonanceBuilder.Resonance.pdgId
def pdgId(self)
Definition: ResonanceBuilder.py:53
ResonanceBuilder.Resonance._pdgid
_pdgid
Definition: ResonanceBuilder.py:29
ResonanceBuilder.Resonance.eta
def eta(self)
Definition: ResonanceBuilder.py:41
ResonanceBuilder.Resonance.charge
def charge(self)
Definition: ResonanceBuilder.py:50
ResonanceBuilder.Resonance.__init__
def __init__(self, leg1, leg2, pdgid, status=3)
Definition: ResonanceBuilder.py:18
ResonanceBuilder.Resonance.phi
def phi(self)
Definition: ResonanceBuilder.py:44
ResonanceBuilder.Resonance.energy
def energy(self)
Definition: ResonanceBuilder.py:38
ResonanceBuilder.Resonance._status
_status
Definition: ResonanceBuilder.py:30
ResonanceBuilder.Resonance.leg1
leg1
Definition: ResonanceBuilder.py:25
Particle
Definition: Particle.py:1
ResonanceBuilder.Resonance.pt
def pt(self)
Definition: ResonanceBuilder.py:35
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ResonanceBuilder.ResonanceBuilder.process
def process(self, event)
Definition: ResonanceBuilder.py:75
ResonanceBuilder.Resonance.leg2
leg2
Definition: ResonanceBuilder.py:26
ResonanceBuilder.Resonance._p4
_p4
Definition: ResonanceBuilder.py:27