7 def deltaR2( e1, p1, e2=None, p2=None):
8 """Take either 4 arguments (eta,phi, eta,phi) or two objects that have 'eta', 'phi' methods)"""
9 if (e2 ==
None and p2 ==
None):
10 return deltaR2(e1.eta(),e1.phi(), p1.eta(), p1.phi())
17 return math.sqrt(
deltaR2(*args) )
21 '''Computes delta phi, handling periodic limit conditions.'''
31 '''Returns the list of particles that are less than deltaRMax away from pivot.'''
32 dR2Max = deltaRMax ** 2
33 dR2Min = deltaRMin ** 2
36 dR2 =
deltaR2(pivot.eta(), pivot.phi(), ptc.eta(), ptc.phi())
37 if dR2Min < dR2 < dR2Max:
42 '''Univoque association of an element from matchCollection to an element of objects.
43 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
44 By default, the matching is true only if delta R is smaller than 0.3.
51 if len(matchCollection)==0:
52 return dict( zip(objects, [
None]*len(objects)) )
55 objectCoords = [ (o.eta(),o.phi(),o)
for o
in objects ]
56 matchdCoords = [ (o.eta(),o.phi(),o)
for o
in matchCollection ]
57 allPairs = [(deltaR2 (oeta, ophi, meta, mphi), (object, match))
for (oeta,ophi,object)
in objectCoords
for (meta,mphi,match)
in matchdCoords
if abs(oeta-meta)<=deltaRMax
and filter(object,match) ]
64 for object
in objects:
65 object.matched =
False
66 for match
in matchCollection:
70 deltaR2Max = deltaRMax * deltaRMax
71 for dR2, (object, match)
in allPairs:
74 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
80 for object
in objects:
81 if object.matched ==
False:
93 '''Masks objects using a deltaR cut, another algorithm (same results).'''
96 deltaR2Min = deltaRMin*deltaRMin
97 cleanObjects = copy.copy( objects )
100 for idx, object
in enumerate(cleanObjects):
101 dR2 =
deltaR2( object.eta(), object.phi(),
102 mask.eta(), mask.phi() )
104 tooClose.append( idx )
114 del cleanObjects[idx]
120 '''Masks objects using a deltaR cut.'''
121 if len(objects)==0
or len(masks)==0:
123 deltaR2Min = deltaRMin*deltaRMin
126 for object
in objects:
129 dR2 =
deltaR2( object.eta(), object.phi(),
130 mask.eta(), mask.phi() )
134 cleanObjects.append( object )
136 dirtyObjects.append( object )
137 return cleanObjects, dirtyObjects
140 '''Return the best match to object in matchCollection, which is the closest object in delta R'''
141 deltaR2Min = float(
'+inf')
143 for match
in matchCollection:
144 dR2 =
deltaR2( object.eta(), object.phi(),
145 match.eta(), match.phi() )
149 return bm, deltaR2Min
156 if len(matchCollection)==0:
157 return dict( zip(objects, [
None]*len(objects)) )
158 for object
in objects:
159 bm, dr2 =
bestMatch( object, matchCollection )
168 '''Univoque association of an element from matchCollection to an element of objects.
169 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
170 By default, the matching is true only if delta R is smaller than 0.3.
176 if len(matchCollection)==0:
177 return dict( zip(objects, [
None]*len(objects)) )
179 allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match))
for object
in objects
for match
in matchCollection]
184 for object
in objects:
185 object.matched =
False
186 for match
in matchCollection:
187 match.matched =
False
189 deltaR2Max = deltaRMax * deltaRMax
190 for dR2, (object, match)
in allPairs:
193 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
194 object.matched =
True
196 pairs[object] = match
198 for object
in objects:
199 if object.matched ==
False:
208 if __name__ ==
'__main__':
212 fargs =
map( float, args )
214 print 'dR2 = ',
deltaR2( *fargs )
215 print 'dR = ',
deltaR( *fargs )
def cleanObjectCollection
def matchObjectCollection
def cleanObjectCollection2
def matchObjectCollection2
Abs< T >::type abs(const T &t)
def matchObjectCollection3