CMS 3D CMS Logo

Functions
DeltaR Namespace Reference

Functions

def bestMatch (object, matchCollection)
 
def cleanObjectCollection (objects, masks, deltaRMin)
 
def cleanObjectCollection2 (objects, masks, deltaRMin)
 
def deltaPhi (p1, p2)
 
def deltaR (*args)
 
def deltaR2 (e1, p1, e2, p2)
 
def matchObjectCollection (objects, matchCollection, deltaR2Max)
 
def matchObjectCollection2 (objects, matchCollection, deltaRMax=0.3)
 
def matchObjectCollection3 (objects, matchCollection, deltaRMax=0.3, filter=lambda x, True y)
 

Function Documentation

◆ bestMatch()

def DeltaR.bestMatch (   object,
  matchCollection 
)
Return the best match to object in matchCollection, which is the closest object in delta R

Definition at line 118 of file DeltaR.py.

118 def bestMatch( object, matchCollection):
119  '''Return the best match to object in matchCollection, which is the closest object in delta R'''
120  deltaR2Min = float('+inf')
121  bm = None
122  for match in matchCollection:
123  dR2 = deltaR2( object.eta(), object.phi(),
124  match.eta(), match.phi() )
125  if dR2 < deltaR2Min:
126  deltaR2Min = dR2
127  bm = match
128  return bm, deltaR2Min
129 
130 

References deltaR2(), and dqmMemoryStats.float.

Referenced by matchObjectCollection().

◆ cleanObjectCollection()

def DeltaR.cleanObjectCollection (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut.

Definition at line 96 of file DeltaR.py.

96 def cleanObjectCollection( objects, masks, deltaRMin ):
97  '''Masks objects using a deltaR cut.'''
98  if len(objects)==0 or len(masks)==0:
99  return objects, []
100  deltaR2Min = deltaRMin*deltaRMin
101  cleanObjects = []
102  dirtyObjects = []
103  for object in objects:
104  ok = True
105  for mask in masks:
106  dR2 = deltaR2( object.eta(), object.phi(),
107  mask.eta(), mask.phi() )
108  if dR2 < deltaR2Min:
109  ok = False
110  if ok:
111  cleanObjects.append( object )
112  else:
113  dirtyObjects.append( object )
114  return cleanObjects, dirtyObjects
115 
116 
117 

References deltaR2().

◆ cleanObjectCollection2()

def DeltaR.cleanObjectCollection2 (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut, another algorithm (same results).

Definition at line 69 of file DeltaR.py.

69 def cleanObjectCollection2( objects, masks, deltaRMin ):
70  '''Masks objects using a deltaR cut, another algorithm (same results).'''
71  if len(objects)==0:
72  return objects
73  deltaR2Min = deltaRMin*deltaRMin
74  cleanObjects = copy.copy( objects )
75  for mask in masks:
76  tooClose = []
77  for idx, object in enumerate(cleanObjects):
78  dR2 = deltaR2( object.eta(), object.phi(),
79  mask.eta(), mask.phi() )
80  if dR2 < deltaR2Min:
81  tooClose.append( idx )
82  nRemoved = 0
83  for idx in tooClose:
84  # yes, everytime an object is removed, the list of objects is updated
85  # so need to update the index accordingly.
86  # example: to remove : ele 1 and 2
87  # first, ele 1 is removed
88  # -> ele 2 is now at index 1
89  # one should again remove the element at index 1
90  idx -= nRemoved
91  del cleanObjects[idx]
92  nRemoved += 1
93  return cleanObjects
94 
95 

References deltaR2().

◆ deltaPhi()

def DeltaR.deltaPhi (   p1,
  p2 
)
Computes delta phi, handling periodic limit conditions.

Definition at line 16 of file DeltaR.py.

16 def deltaPhi( p1, p2):
17  '''Computes delta phi, handling periodic limit conditions.'''
18  res = p1 - p2
19  while res > math.pi:
20  res -= 2*math.pi
21  while res < -math.pi:
22  res += 2*math.pi
23  return res
24 

Referenced by deltaR2().

◆ deltaR()

def DeltaR.deltaR ( args)

Definition at line 12 of file DeltaR.py.

12 def deltaR( *args ):
13  return math.sqrt( deltaR2(*args) )
14 
15 

References deltaR2().

◆ deltaR2()

def DeltaR.deltaR2 (   e1,
  p1,
  e2,
  p2 
)

Definition at line 6 of file DeltaR.py.

6 def deltaR2( e1, p1, e2, p2):
7  de = e1 - e2
8  dp = deltaPhi(p1, p2)
9  return de*de + dp*dp
10 
11 

References deltaPhi().

Referenced by bestMatch(), cleanObjectCollection(), cleanObjectCollection2(), and deltaR().

◆ matchObjectCollection()

def DeltaR.matchObjectCollection (   objects,
  matchCollection,
  deltaR2Max 
)

Definition at line 131 of file DeltaR.py.

131 def matchObjectCollection( objects, matchCollection, deltaR2Max):
132  pairs = {}
133  if len(objects)==0:
134  return pairs
135  if len(matchCollection)==0:
136  return dict( zip(objects, [None]*len(objects)) )
137  for object in objects:
138  bm, dr2 = bestMatch( object, matchCollection )
139  if dr2<deltaR2Max:
140  pairs[object] = bm
141  else:
142  pairs[object] = None
143  return pairs
144 
145 

References bestMatch(), and ComparisonHelper.zip().

◆ matchObjectCollection2()

def DeltaR.matchObjectCollection2 (   objects,
  matchCollection,
  deltaRMax = 0.3 
)
Univoque association of an element from matchCollection to an element of objects.
Reco and Gen objects get the "matched" attribute, true if they are part of a matched tuple.
By default, the matching is true only if delta R is smaller than 0.3.

Definition at line 146 of file DeltaR.py.

146 def matchObjectCollection2 ( objects, matchCollection, deltaRMax = 0.3 ):
147  '''Univoque association of an element from matchCollection to an element of objects.
148  Reco and Gen objects get the "matched" attribute, true if they are part of a matched tuple.
149  By default, the matching is true only if delta R is smaller than 0.3.
150  '''
151 
152  pairs = {}
153  if len(objects)==0:
154  return pairs
155  if len(matchCollection)==0:
156  return dict( zip(objects, [None]*len(objects)) )
157  # build all possible combinations
158  allPairs = sorted([(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection])
159 
160  # to flag already matched objects
161  # FIXME this variable remains appended to the object, I do not like it
162  for object in objects:
163  object.matched = False
164  for match in matchCollection:
165  match.matched = False
166 
167  deltaR2Max = deltaRMax * deltaRMax
168  for dR2, (object, match) in allPairs:
169  if dR2 > deltaR2Max:
170  break
171  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
172  object.matched = True
173  match.matched = True
174  pairs[object] = match
175 
176  for object in objects:
177  if object.matched == False:
178  pairs[object] = None
179 
180  return pairs
181  # by now, the matched attribute remains in the objects, for future usage
182  # one could remove it with delattr (object, attrname)
183 
184 
185 

References ComparisonHelper.zip().

◆ matchObjectCollection3()

def DeltaR.matchObjectCollection3 (   objects,
  matchCollection,
  deltaRMax = 0.3,
  filter = lambda x,
True   y 
)
Univoque association of an element from matchCollection to an element of objects. 
Reco and Gen objects get the "matched" attribute, true if they are part of a matched tuple. 
By default, the matching is true only if delta R is smaller than 0.3.

Definition at line 25 of file DeltaR.py.

25 def matchObjectCollection3 ( objects, matchCollection, deltaRMax = 0.3, filter = lambda x,y : True ):
26  '''Univoque association of an element from matchCollection to an element of objects.
27  Reco and Gen objects get the "matched" attribute, true if they are part of a matched tuple.
28  By default, the matching is true only if delta R is smaller than 0.3.
29  '''
30  #
31  pairs = {}
32  if len(objects)==0:
33  return pairs
34  if len(matchCollection)==0:
35  return dict( zip(objects, [None]*len(objects)) )
36  # build all possible combinations
37 
38  allPairs = sorted([(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection if list(filter(object,match)) ])
39  #
40  # to flag already matched objects
41  # FIXME this variable remains appended to the object, I do not like it
42 
43  for object in objects:
44  object.matched = False
45  for match in matchCollection:
46  match.matched = False
47  #
48 
49  deltaR2Max = deltaRMax * deltaRMax
50  for dR2, (object, match) in allPairs:
51  if dR2 > deltaR2Max:
52  break
53  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
54  object.matched = True
55  match.matched = True
56  pairs[object] = match
57  #
58 
59  for object in objects:
60  if object.matched == False:
61  pairs[object] = None
62  #
63 
64  return pairs
65  # by now, the matched attribute remains in the objects, for future usage
66  # one could remove it with delattr (object, attrname)
67 
68 

References ALCARECOTkAlBeamHalo_cff.filter, and ComparisonHelper.zip().

dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
DeltaR.matchObjectCollection
def matchObjectCollection(objects, matchCollection, deltaR2Max)
Definition: DeltaR.py:131
DeltaR.matchObjectCollection3
def matchObjectCollection3(objects, matchCollection, deltaRMax=0.3, filter=lambda x, True y)
Definition: DeltaR.py:25
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
DeltaR.cleanObjectCollection2
def cleanObjectCollection2(objects, masks, deltaRMin)
Definition: DeltaR.py:69
DeltaR.bestMatch
def bestMatch(object, matchCollection)
Definition: DeltaR.py:118
DeltaR.deltaR
def deltaR(*args)
Definition: DeltaR.py:12
DeltaR.deltaPhi
def deltaPhi(p1, p2)
Definition: DeltaR.py:16
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:41
DeltaR.cleanObjectCollection
def cleanObjectCollection(objects, masks, deltaRMin)
Definition: DeltaR.py:96
DeltaR.deltaR2
def deltaR2(e1, p1, e2, p2)
Definition: DeltaR.py:6
DeltaR.matchObjectCollection2
def matchObjectCollection2(objects, matchCollection, deltaRMax=0.3)
Definition: DeltaR.py:146