CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
Matcher.Matcher Class Reference
Inheritance diagram for Matcher.Matcher:

Public Member Functions

def beginLoop
 
def process
 

Public Attributes

 match_collections
 

Detailed Description

Particle matcher. 

Works with any kind of object with a p4 function. 

Simple example configuration: 

from heppy_fcc.analyzers.Matcher import Matcher
papas_jet_match = cfg.Analyzer(
  Matcher,
  instance_label = 'papas', 
  match_particles = 'gen_jets',
  particles = 'papas_jets'
)

particles: Name of the collection containing the particles to be matched. 
match_particles: Name of the collection containing the particles where a match 
           is to be found. 

In this particular case, each jet in "papas_jets" will end up with a new 
attribute called "match". This attribute can be either the closest gen jet in the 
"gen_jets" collection in case a gen_jet is found within delta R = 0.3, 
or None in case a match cannot be found in this cone.

More complex example configuration: 

papas_particle_match_g2r = cfg.Analyzer(
  Matcher,
  instance_label = 'papas_g2r', 
  particles = 'gen_particles_stable',
  match_particles = [
    ('papas_rec_particles', None),
    ('papas_rec_particles', 211),
    ('papas_rec_particles', 130),
    ('papas_rec_particles', 22)
  ] 
  )

In this case, each gen particle in gen_particles_stable will end up with the following 
new attributes: 
  - "match"    : closest reconstructed particle in "papas_rec_particles", if any. 
  - "match_211": closest reconstructed particle of pdgId 211 in "papas_rec_particles", 
                 if any. 
  - etc. 

Definition at line 6 of file Matcher.py.

Member Function Documentation

def Matcher.Matcher.beginLoop (   self,
  setup 
)

Definition at line 54 of file Matcher.py.

54 
55  def beginLoop(self, setup):
56  super(Matcher, self).beginLoop(setup)
57  self.match_collections = []
58  if isinstance( self.cfg_ana.match_particles, str):
59  self.match_collections.append( (self.cfg_ana.match_particles, None) )
60  else:
61  self.match_collections = self.cfg_ana.match_particles
def Matcher.Matcher.process (   self,
  event 
)

Definition at line 62 of file Matcher.py.

References HLT_FULL_cff.deltaR, Matcher.Matcher.match_collections, and deltar.matchObjectCollection().

62 
63  def process(self, event):
64  particles = getattr(event, self.cfg_ana.particles)
65  # match_particles = getattr(event, self.cfg_ana.match_particles)
66  for collname, pdgid in self.match_collections:
67  match_ptcs = getattr(event, collname)
68  match_ptcs_filtered = match_ptcs
69  if pdgid is not None:
70  match_ptcs_filtered = [ptc for ptc in match_ptcs
71  if ptc.pdgid()==pdgid]
72  pairs = matchObjectCollection(particles, match_ptcs_filtered,
73  0.3**2)
74  for ptc in particles:
75  matchname = 'match'
76  if pdgid:
77  matchname = 'match_{pdgid}'.format(pdgid=pdgid)
78  match = pairs[ptc]
79  setattr(ptc, matchname, match)
80  if match:
81  drname = 'dr'
82  if pdgid:
83  drname = 'dr_{pdgid}'.format(pdgid=pdgid)
84  dr = deltaR(ptc.theta(), ptc.phi(),
85  match.theta(), match.phi())
86  setattr(ptc, drname, dr)
87  # print dr, ptc, match
def matchObjectCollection
Definition: deltar.py:151

Member Data Documentation

Matcher.Matcher.match_collections

Definition at line 56 of file Matcher.py.

Referenced by Matcher.Matcher.process().