14 return math.sqrt(
deltaR2(*args) )
18 '''Computes delta phi, handling periodic limit conditions.'''
28 '''Returns the list of particles that are less than deltaRMax away from pivot.'''
29 dR2Max = deltaRMax ** 2
30 dR2Min = deltaRMin ** 2
33 dR2 =
deltaR2(pivot.eta(), pivot.phi(), ptc.eta(), ptc.phi())
34 if dR2Min < dR2 < dR2Max:
39 '''Univoque association of an element from matchCollection to an element of objects.
40 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
41 By default, the matching is true only if delta R is smaller than 0.3.
48 if len(matchCollection)==0:
49 return dict(
zip(objects, [
None]*len(objects)) )
52 objectCoords = [ (o.eta(),o.phi(),o)
for o
in objects ]
53 matchdCoords = [ (o.eta(),o.phi(),o)
for o
in matchCollection ]
54 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) ]
61 for object
in objects:
62 object.matched =
False
63 for match
in matchCollection:
67 deltaR2Max = deltaRMax * deltaRMax
68 for dR2, (object, match)
in allPairs:
71 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
77 for object
in objects:
78 if object.matched ==
False:
90 '''Masks objects using a deltaR cut, another algorithm (same results).'''
93 deltaR2Min = deltaRMin*deltaRMin
94 cleanObjects = copy.copy( objects )
97 for idx, object
in enumerate(cleanObjects):
98 dR2 =
deltaR2( object.eta(), object.phi(),
99 mask.eta(), mask.phi() )
101 tooClose.append( idx )
111 del cleanObjects[idx]
117 '''Masks objects using a deltaR cut.'''
118 if len(objects)==0
or len(masks)==0:
120 deltaR2Min = deltaRMin*deltaRMin
123 for object
in objects:
126 dR2 =
deltaR2( object.eta(), object.phi(),
127 mask.eta(), mask.phi() )
131 cleanObjects.append( object )
133 dirtyObjects.append( object )
134 return cleanObjects, dirtyObjects
137 '''Return the best match to object in matchCollection, which is the closest object in delta R'''
138 deltaR2Min = float(
'+inf')
140 for match
in matchCollection:
141 dR2 =
deltaR2( object.eta(), object.phi(),
142 match.eta(), match.phi() )
146 return bm, deltaR2Min
153 if len(matchCollection)==0:
154 return dict(
zip(objects, [
None]*len(objects)) )
155 for object
in objects:
156 bm, dr2 =
bestMatch( object, matchCollection )
165 '''Univoque association of an element from matchCollection to an element of objects.
166 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
167 By default, the matching is true only if delta R is smaller than 0.3.
173 if len(matchCollection)==0:
174 return dict(
zip(objects, [
None]*len(objects)) )
176 allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match))
for object
in objects
for match
in matchCollection]
181 for object
in objects:
182 object.matched =
False
183 for match
in matchCollection:
184 match.matched =
False
186 deltaR2Max = deltaRMax * deltaRMax
187 for dR2, (object, match)
in allPairs:
190 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
191 object.matched =
True
193 pairs[object] = match
195 for object
in objects:
196 if object.matched ==
False:
205 if __name__ ==
'__main__':
209 fargs =
map( float, args )
211 print 'dR2 = ',
deltaR2( *fargs )
212 print 'dR = ',
deltaR( *fargs )
def cleanObjectCollection
def matchObjectCollection
def cleanObjectCollection2
def matchObjectCollection2
Abs< T >::type abs(const T &t)
def matchObjectCollection3