CMS 3D CMS Logo

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

Functions

def bestMatch
 
def cleanObjectCollection
 
def cleanObjectCollection2
 
def deltaPhi
 
def deltaR
 
def deltaR2
 
def inConeCollection
 
def matchObjectCollection
 
def matchObjectCollection2
 
def matchObjectCollection3
 

Variables

list args = sys.argv[1:]
 
tuple fargs = map( float, args )
 

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 136 of file deltar.py.

References deltaR2().

Referenced by RecoTauDifferenceAnalyzer.filter(), findGenParticleForMCEmbedding(), HLTMuonPlotter.findMatches(), CSCMake2DRecHit.findWireBx(), objects.JetAnalyzer.JetAnalyzer.jetFlavour(), GlobalCosmicMuonTrajectoryBuilder.match(), matchObjectCollection(), and MuonIdTruthInfo.truthMatchMuon().

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

Definition at line 116 of file deltar.py.

References deltaR2().

Referenced by JetAnalyzer.JetAnalyzer.process().

117 def cleanObjectCollection( objects, masks, deltaRMin ):
118  '''Masks objects using a deltaR cut.'''
119  if len(objects)==0 or len(masks)==0:
120  return objects, []
121  deltaR2Min = deltaRMin*deltaRMin
122  cleanObjects = []
123  dirtyObjects = []
124  for object in objects:
125  ok = True
126  for mask in masks:
127  dR2 = deltaR2( object.eta(), object.phi(),
128  mask.eta(), mask.phi() )
129  if dR2 < deltaR2Min:
130  ok = False
131  if ok:
132  cleanObjects.append( object )
133  else:
134  dirtyObjects.append( object )
135  return cleanObjects, dirtyObjects
def cleanObjectCollection
Definition: deltar.py:116
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 89 of file deltar.py.

References deltaR2().

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

Definition at line 17 of file deltar.py.

Referenced by deltaR2().

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

Definition at line 13 of file deltar.py.

References deltaR2().

13 
14 def deltaR( *args ):
15  return math.sqrt( deltaR2(*args) )
16 
def deltaR2
Definition: deltar.py:7
def deltaR
Definition: deltar.py:13
def deltar.deltaR2 (   e1,
  p1,
  e2,
  p2 
)

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, p2):
9  de = e1 - e2
10  dp = deltaPhi(p1, p2)
11  return de*de + dp*dp
12 
def deltaPhi
Definition: deltar.py:17
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 27 of file deltar.py.

References deltaR2().

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

Definition at line 149 of file deltar.py.

References bestMatch(), python.multivaluedict.dict, and archive.zip.

Referenced by SimpleJetAnalyzer.SimpleJetAnalyzer.process(), and JetAnalyzer.JetAnalyzer.process().

150 def matchObjectCollection( objects, matchCollection, deltaR2Max):
151  pairs = {}
152  if len(objects)==0:
153  return pairs
154  if len(matchCollection)==0:
155  return dict( zip(objects, [None]*len(objects)) )
156  for object in objects:
157  bm, dr2 = bestMatch( object, matchCollection )
158  if dr2<deltaR2Max:
159  pairs[object] = bm
160  else:
161  pairs[object] = None
162  return pairs
163 
def bestMatch
Definition: deltar.py:136
tuple zip
Definition: archive.py:476
def matchObjectCollection
Definition: deltar.py:149
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 164 of file deltar.py.

References python.multivaluedict.dict, and archive.zip.

Referenced by objects.JetAnalyzer.JetAnalyzer.jetFlavour(), and objects.JetAnalyzer.JetAnalyzer.matchJets().

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

Definition at line 38 of file deltar.py.

References funct.abs(), python.multivaluedict.dict, alcazmumu_cfi.filter, and archive.zip.

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

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

Variable Documentation

list deltar.args = sys.argv[1:]

Definition at line 208 of file deltar.py.

tuple deltar.fargs = map( float, args )

Definition at line 209 of file deltar.py.