CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
Matcher.Matcher Class Reference
Inheritance diagram for Matcher.Matcher:

Public Member Functions

def beginLoop (self, setup)
 
def process (self, event)
 

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  def beginLoop(self, setup):
55  super(Matcher, self).beginLoop(setup)
57  if isinstance( self.cfg_ana.match_particles, str):
58  self.match_collections.append( (self.cfg_ana.match_particles, None) )
59  else:
60  self.match_collections = self.cfg_ana.match_particles
61 
def beginLoop(self, setup)
Definition: Matcher.py:54
def Matcher.Matcher.process (   self,
  event 
)

Definition at line 62 of file Matcher.py.

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

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

Member Data Documentation

Matcher.Matcher.match_collections

Definition at line 56 of file Matcher.py.

Referenced by Matcher.Matcher.process().