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 allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match))
for object
in objects
for match
in matchCollection
if filter(object,match) ]
58 for object
in objects:
59 object.matched =
False
60 for match
in matchCollection:
64 deltaR2Max = deltaRMax * deltaRMax
65 for dR2, (object, match)
in allPairs:
68 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
74 for object
in objects:
75 if object.matched ==
False:
87 '''Masks objects using a deltaR cut, another algorithm (same results).'''
90 deltaR2Min = deltaRMin*deltaRMin
91 cleanObjects = copy.copy( objects )
94 for idx, object
in enumerate(cleanObjects):
95 dR2 =
deltaR2( object.eta(), object.phi(),
96 mask.eta(), mask.phi() )
98 tooClose.append( idx )
108 del cleanObjects[idx]
114 '''Masks objects using a deltaR cut.'''
115 if len(objects)==0
or len(masks)==0:
117 deltaR2Min = deltaRMin*deltaRMin
120 for object
in objects:
123 dR2 =
deltaR2( object.eta(), object.phi(),
124 mask.eta(), mask.phi() )
128 cleanObjects.append( object )
130 dirtyObjects.append( object )
131 return cleanObjects, dirtyObjects
134 '''Return the best match to object in matchCollection, which is the closest object in delta R'''
135 deltaR2Min = float(
'+inf')
137 for match
in matchCollection:
138 dR2 =
deltaR2( object.eta(), object.phi(),
139 match.eta(), match.phi() )
143 return bm, deltaR2Min
150 if len(matchCollection)==0:
151 return dict(
zip(objects, [
None]*len(objects)) )
152 for object
in objects:
153 bm, dr2 =
bestMatch( object, matchCollection )
162 '''Univoque association of an element from matchCollection to an element of objects.
163 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
164 By default, the matching is true only if delta R is smaller than 0.3.
170 if len(matchCollection)==0:
171 return dict(
zip(objects, [
None]*len(objects)) )
173 allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match))
for object
in objects
for match
in matchCollection]
178 for object
in objects:
179 object.matched =
False
180 for match
in matchCollection:
181 match.matched =
False
183 deltaR2Max = deltaRMax * deltaRMax
184 for dR2, (object, match)
in allPairs:
187 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
188 object.matched =
True
190 pairs[object] = match
192 for object
in objects:
193 if object.matched ==
False:
202 if __name__ ==
'__main__':
206 fargs =
map( float, args )
208 print 'dR2 = ',
deltaR2( *fargs )
209 print 'dR = ',
deltaR( *fargs )
def cleanObjectCollection
def matchObjectCollection
def cleanObjectCollection2
def matchObjectCollection2
def matchObjectCollection3