test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
deltar Namespace Reference

Functions

def bestMatch
 
def cleanObjectCollection
 
def cleanObjectCollection2
 
def deltaPhi
 
def deltaR
 
def deltaR2
 
def inConeCollection
 
def matchObjectCollection
 
def matchObjectCollection2
 
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 139 of file deltar.py.

References deltaR2().

Referenced by PrimaryVertexAnalyzer4PUSlimmed.fillResolutionAndPullHistograms(), RecoTauDifferenceAnalyzer.filter(), HLTMuonPlotter.findMatches(), CSCMake2DRecHit.findWireBx(), GlobalCosmicMuonTrajectoryBuilder.match(), matchObjectCollection(), and MuonIdTruthInfo.truthMatchMuon().

140 def bestMatch( object, matchCollection):
141  '''Return the best match to object in matchCollection, which is the closest object in delta R'''
142  deltaR2Min = float('+inf')
143  bm = None
144  for match in matchCollection:
145  dR2 = deltaR2( object.eta(), object.phi(),
146  match.eta(), match.phi() )
147  if dR2 < deltaR2Min:
148  deltaR2Min = dR2
149  bm = match
150  return bm, deltaR2Min
151 
def bestMatch
Definition: deltar.py:139
def deltaR2
Definition: deltar.py:7
def deltar.cleanObjectCollection (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut.

Definition at line 119 of file deltar.py.

References deltaR2().

Referenced by JetAnalyzer.JetAnalyzer.process().

120 def cleanObjectCollection( objects, masks, deltaRMin ):
121  '''Masks objects using a deltaR cut.'''
122  if len(objects)==0 or len(masks)==0:
123  return objects, []
124  deltaR2Min = deltaRMin*deltaRMin
125  cleanObjects = []
126  dirtyObjects = []
127  for object in objects:
128  ok = True
129  for mask in masks:
130  dR2 = deltaR2( object.eta(), object.phi(),
131  mask.eta(), mask.phi() )
132  if dR2 < deltaR2Min:
133  ok = False
134  if ok:
135  cleanObjects.append( object )
136  else:
137  dirtyObjects.append( object )
138  return cleanObjects, dirtyObjects
def cleanObjectCollection
Definition: deltar.py:119
def deltaR2
Definition: deltar.py:7
def deltar.cleanObjectCollection2 (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut, another algorithm (same results).

Definition at line 92 of file deltar.py.

References deltaR2().

92 
93 def cleanObjectCollection2( objects, masks, deltaRMin ):
94  '''Masks objects using a deltaR cut, another algorithm (same results).'''
95  if len(objects)==0:
96  return objects
97  deltaR2Min = deltaRMin*deltaRMin
98  cleanObjects = copy.copy( objects )
99  for mask in masks:
100  tooClose = []
101  for idx, object in enumerate(cleanObjects):
102  dR2 = deltaR2( object.eta(), object.phi(),
103  mask.eta(), mask.phi() )
104  if dR2 < deltaR2Min:
105  tooClose.append( idx )
106  nRemoved = 0
107  for idx in tooClose:
108  # yes, everytime an object is removed, the list of objects is updated
109  # so need to update the index accordingly.
110  # example: to remove : ele 1 and 2
111  # first, ele 1 is removed
112  # -> ele 2 is now at index 1
113  # one should again remove the element at index 1
114  idx -= nRemoved
115  del cleanObjects[idx]
116  nRemoved += 1
117  return cleanObjects
118 
def cleanObjectCollection2
Definition: deltar.py:92
def deltaR2
Definition: deltar.py:7
def deltar.deltaPhi (   p1,
  p2 
)
Computes delta phi, handling periodic limit conditions.

Definition at line 20 of file deltar.py.

Referenced by deltaR2().

20 
21 def deltaPhi( p1, p2):
22  '''Computes delta phi, handling periodic limit conditions.'''
23  res = p1 - p2
24  while res > math.pi:
25  res -= 2*math.pi
26  while res < -math.pi:
27  res += 2*math.pi
28  return res
29 
def deltaPhi
Definition: deltar.py:20
def deltar.deltaR (   args)

Definition at line 16 of file deltar.py.

References deltaR2().

16 
17 def deltaR( *args ):
18  return math.sqrt( deltaR2(*args) )
19 
def deltaR2
Definition: deltar.py:7
def deltaR
Definition: deltar.py:16
def deltar.deltaR2 (   e1,
  p1,
  e2 = None,
  p2 = None 
)
Take either 4 arguments (eta,phi, eta,phi) or two objects that have 'eta', 'phi' methods)

Definition at line 7 of file deltar.py.

References deltaPhi().

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

7 
8 def deltaR2( e1, p1, e2=None, p2=None):
9  """Take either 4 arguments (eta,phi, eta,phi) or two objects that have 'eta', 'phi' methods)"""
10  if (e2 == None and p2 == None):
11  return deltaR2(e1.eta(),e1.phi(), p1.eta(), p1.phi())
12  de = e1 - e2
13  dp = deltaPhi(p1, p2)
14  return de*de + dp*dp
15 
def deltaPhi
Definition: deltar.py:20
def deltaR2
Definition: deltar.py:7
def deltar.inConeCollection (   pivot,
  particles,
  deltaRMax,
  deltaRMin = 1e-5 
)
Returns the list of particles that are less than deltaRMax away from pivot.

Definition at line 30 of file deltar.py.

References deltaR2().

30 
31 def inConeCollection(pivot, particles, deltaRMax, deltaRMin=1e-5):
32  '''Returns the list of particles that are less than deltaRMax away from pivot.'''
33  dR2Max = deltaRMax ** 2
34  dR2Min = deltaRMin ** 2 if deltaRMin > 0 else -1
35  results = []
36  for ptc in particles:
37  dR2 = deltaR2(pivot.eta(), pivot.phi(), ptc.eta(), ptc.phi())
38  if dR2Min < dR2 and dR2 < dR2Max:
39  results.append(ptc)
40  return results
def inConeCollection
Definition: deltar.py:30
def deltaR2
Definition: deltar.py:7
def deltar.matchObjectCollection (   objects,
  matchCollection,
  deltaR2Max,
  filter = lambda x,
  y 
)

Definition at line 152 of file deltar.py.

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

Referenced by SimpleJetAnalyzer.SimpleJetAnalyzer.process(), core.TriggerMatchAnalyzer.TriggerMatchAnalyzer.process(), Matcher.Matcher.process(), and JetAnalyzer.JetAnalyzer.process().

153 def matchObjectCollection( objects, matchCollection, deltaR2Max, filter = lambda x,y : True):
154  pairs = {}
155  if len(objects)==0:
156  return pairs
157  if len(matchCollection)==0:
158  return dict( list(zip(objects, [None]*len(objects))) )
159  for object in objects:
160  bm, dr2 = bestMatch( object, [mob for mob in matchCollection if filter(object,mob)] )
161  if dr2<deltaR2Max:
162  pairs[object] = bm
163  else:
164  pairs[object] = None
165  return pairs
166 
def bestMatch
Definition: deltar.py:139
def matchObjectCollection
Definition: deltar.py:152
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
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 is they are re part of a matched tulpe.
By default, the matching is true only if delta R is smaller than 0.3.

Definition at line 167 of file deltar.py.

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

Referenced by objects.JetAnalyzer.JetAnalyzer.matchJets().

168 def matchObjectCollection2 ( objects, matchCollection, deltaRMax = 0.3 ):
169  '''Univoque association of an element from matchCollection to an element of objects.
170  Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
171  By default, the matching is true only if delta R is smaller than 0.3.
172  '''
173 
174  pairs = {}
175  if len(objects)==0:
176  return pairs
177  if len(matchCollection)==0:
178  return dict( list(zip(objects, [None]*len(objects))) )
179  # build all possible combinations
180  allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection]
181  allPairs.sort ()
182 
183  # to flag already matched objects
184  # FIXME this variable remains appended to the object, I do not like it
185  for object in objects:
186  object.matched = False
187  for match in matchCollection:
188  match.matched = False
189 
190  deltaR2Max = deltaRMax * deltaRMax
191  for dR2, (object, match) in allPairs:
192  if dR2 > deltaR2Max:
193  break
194  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
195  object.matched = True
196  match.matched = True
197  pairs[object] = match
198 
199  for object in objects:
200  if object.matched == False:
201  pairs[object] = None
202 
203  return pairs
204  # by now, the matched attribute remains in the objects, for future usage
205  # one could remove it with delattr (object, attrname)
206 
207 
208 
def matchObjectCollection2
Definition: deltar.py:167
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
def deltar.matchObjectCollection3 (   objects,
  matchCollection,
  deltaRMax = 0.3,
  filter = lambda x,
  y 
)

Definition at line 41 of file deltar.py.

References funct.abs(), cmsPerfStripChart.dict, alcazmumu_cfi.filter, list(), and ComparisonHelper.zip().

Referenced by objects.LeptonAnalyzer.LeptonAnalyzer.matchAnyLeptons(), objects.IsoTrackAnalyzer.matchIsoTrack(), objects.LeptonAnalyzer.LeptonAnalyzer.matchLeptons(), objects.PhotonAnalyzer.PhotonAnalyzer.matchPhotons(), objects.TauAnalyzer.TauAnalyzer.matchTaus(), objects.LeptonAnalyzer.LeptonAnalyzer.matchToPhotons(), and core.TriggerMatchAnalyzer.TriggerMatchAnalyzer.process().

41 
42 def matchObjectCollection3 ( objects, matchCollection, deltaRMax = 0.3, filter = lambda x,y : True ):
43  '''Univoque association of an element from matchCollection to an element of objects.
44  Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
45  By default, the matching is true only if delta R is smaller than 0.3.
46  '''
47  #
48 
49  pairs = {}
50  if len(objects)==0:
51  return pairs
52  if len(matchCollection)==0:
53  return dict( list(zip(objects, [None]*len(objects))) )
54  # build all possible combinations
55 
56  objectCoords = [ (o.eta(),o.phi(),o) for o in objects ]
57  matchdCoords = [ (o.eta(),o.phi(),o) for o in matchCollection ]
58  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) ]
59  #allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection if filter(object,match) ]
60  allPairs.sort ()
61  #
62  # to flag already matched objects
63  # FIXME this variable remains appended to the object, I do not like it
64 
65  for object in objects:
66  object.matched = False
67  for match in matchCollection:
68  match.matched = False
69  #
70 
71  deltaR2Max = deltaRMax * deltaRMax
72  for dR2, (object, match) in allPairs:
73  if dR2 > deltaR2Max:
74  break
75  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
76  object.matched = True
77  match.matched = True
78  pairs[object] = match
79  #
80 
81  for object in objects:
82  if object.matched == False:
83  pairs[object] = None
84  #
85 
86  return pairs
87  # by now, the matched attribute remains in the objects, for future usage
88  # one could remove it with delattr (object, attrname)
89 
90 
91 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def matchObjectCollection3
Definition: deltar.py:41
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