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 '''Masks objects using a deltaR cut, another algorithm (same results).'''
42 deltaR2Min = deltaRMin*deltaRMin
43 cleanObjects = copy.copy( objects )
46 for idx, object
in enumerate(cleanObjects):
47 dR2 =
deltaR2( object.eta(), object.phi(),
48 mask.eta(), mask.phi() )
50 tooClose.append( idx )
66 '''Masks objects using a deltaR cut.'''
67 if len(objects)==0
or len(masks)==0:
69 deltaR2Min = deltaRMin*deltaRMin
72 for object
in objects:
75 dR2 =
deltaR2( object.eta(), object.phi(),
76 mask.eta(), mask.phi() )
80 cleanObjects.append( object )
82 dirtyObjects.append( object )
83 return cleanObjects, dirtyObjects
86 '''Return the best match to object in matchCollection, which is the closest object in delta R'''
87 deltaR2Min = float(
'+inf')
89 for match
in matchCollection:
90 dR2 =
deltaR2( object.eta(), object.phi(),
91 match.eta(), match.phi() )
102 if len(matchCollection)==0:
103 return dict(
zip(objects, [
None]*len(objects)) )
104 for object
in objects:
105 bm, dr2 =
bestMatch( object, matchCollection )
114 '''Univoque association of an element from matchCollection to an element of objects.
115 Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
116 By default, the matching is true only if delta R is smaller than 0.3.
122 if len(matchCollection)==0:
123 return dict(
zip(objects, [
None]*len(objects)) )
125 allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match))
for object
in objects
for match
in matchCollection]
130 for object
in objects:
131 object.matched =
False
132 for match
in matchCollection:
133 match.matched =
False
135 deltaR2Max = deltaRMax * deltaRMax
136 for dR2, (object, match)
in allPairs:
139 if dR2 < deltaR2Max
and object.matched ==
False and match.matched ==
False:
140 object.matched =
True
142 pairs[object] = match
144 for object
in objects:
145 if object.matched ==
False:
154 if __name__ ==
'__main__':
158 fargs =
map( float, args )
160 print 'dR2 = ',
deltaR2( *fargs )
161 print 'dR = ',
deltaR( *fargs )
def cleanObjectCollection
def matchObjectCollection
def cleanObjectCollection2
def matchObjectCollection2