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
 

Function Documentation

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

Definition at line 117 of file DeltaR.py.

References deltaR2(), and objects.autophobj.float.

Referenced by matchObjectCollection().

117 def bestMatch( object, matchCollection):
118  '''Return the best match to object in matchCollection, which is the closest object in delta R'''
119  deltaR2Min = float('+inf')
120  bm = None
121  for match in matchCollection:
122  dR2 = deltaR2( object.eta(), object.phi(),
123  match.eta(), match.phi() )
124  if dR2 < deltaR2Min:
125  deltaR2Min = dR2
126  bm = match
127  return bm, deltaR2Min
128 
129 
def deltaR2(e1, p1, e2, p2)
Definition: DeltaR.py:5
def bestMatch(object, matchCollection)
Definition: DeltaR.py:117
def DeltaR.cleanObjectCollection (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut.

Definition at line 95 of file DeltaR.py.

References deltaR2().

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

Definition at line 68 of file DeltaR.py.

References deltaR2().

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

Definition at line 15 of file DeltaR.py.

Referenced by deltaR2().

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

Definition at line 11 of file DeltaR.py.

References deltaR2().

11 def deltaR( *args ):
12  return math.sqrt( deltaR2(*args) )
13 
14 
def deltaR2(e1, p1, e2, p2)
Definition: DeltaR.py:5
def deltaR(args)
Definition: DeltaR.py:11
def DeltaR.deltaR2 (   e1,
  p1,
  e2,
  p2 
)

Definition at line 5 of file DeltaR.py.

References deltaPhi().

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

5 def deltaR2( e1, p1, e2, p2):
6  de = e1 - e2
7  dp = deltaPhi(p1, p2)
8  return de*de + dp*dp
9 
10 
def deltaPhi(p1, p2)
Definition: DeltaR.py:15
def deltaR2(e1, p1, e2, p2)
Definition: DeltaR.py:5
def DeltaR.matchObjectCollection (   objects,
  matchCollection,
  deltaR2Max 
)

Definition at line 130 of file DeltaR.py.

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

130 def matchObjectCollection( objects, matchCollection, deltaR2Max):
131  pairs = {}
132  if len(objects)==0:
133  return pairs
134  if len(matchCollection)==0:
135  return dict( zip(objects, [None]*len(objects)) )
136  for object in objects:
137  bm, dr2 = bestMatch( object, matchCollection )
138  if dr2<deltaR2Max:
139  pairs[object] = bm
140  else:
141  pairs[object] = None
142  return pairs
143 
144 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def matchObjectCollection(objects, matchCollection, deltaR2Max)
Definition: DeltaR.py:130
def bestMatch(object, matchCollection)
Definition: DeltaR.py:117
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 145 of file DeltaR.py.

References cmsPerfStripChart.dict, and ComparisonHelper.zip().

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

Definition at line 24 of file DeltaR.py.

References cmsPerfStripChart.dict, ALCARECOTkAlBeamHalo_cff.filter, list(), and ComparisonHelper.zip().

24 def matchObjectCollection3 ( objects, matchCollection, deltaRMax = 0.3, filter = lambda x,y : True ):
25  '''Univoque association of an element from matchCollection to an element of objects.
26  Reco and Gen objects get the "matched" attribute, true if they are part of a matched tuple.
27  By default, the matching is true only if delta R is smaller than 0.3.
28  '''
29  #
30  pairs = {}
31  if len(objects)==0:
32  return pairs
33  if len(matchCollection)==0:
34  return dict( zip(objects, [None]*len(objects)) )
35  # build all possible combinations
36 
37  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)) ])
38  #
39  # to flag already matched objects
40  # FIXME this variable remains appended to the object, I do not like it
41 
42  for object in objects:
43  object.matched = False
44  for match in matchCollection:
45  match.matched = False
46  #
47 
48  deltaR2Max = deltaRMax * deltaRMax
49  for dR2, (object, match) in allPairs:
50  if dR2 > deltaR2Max:
51  break
52  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
53  object.matched = True
54  match.matched = True
55  pairs[object] = match
56  #
57 
58  for object in objects:
59  if object.matched == False:
60  pairs[object] = None
61  #
62 
63  return pairs
64  # by now, the matched attribute remains in the objects, for future usage
65  # one could remove it with delattr (object, attrname)
66 
67 
def matchObjectCollection3
Definition: DeltaR.py:24
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run