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

References deltaR2().

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

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

Definition at line 113 of file deltar.py.

References deltaR2().

Referenced by JetAnalyzer.JetAnalyzer.process().

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

References deltaR2().

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

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

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

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

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

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

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

Definition at line 38 of file deltar.py.

References 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  allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection if filter(object,match) ]
54  allPairs.sort ()
55  #
56  # to flag already matched objects
57  # FIXME this variable remains appended to the object, I do not like it
58 
59  for object in objects:
60  object.matched = False
61  for match in matchCollection:
62  match.matched = False
63  #
64 
65  deltaR2Max = deltaRMax * deltaRMax
66  for dR2, (object, match) in allPairs:
67  if dR2 > deltaR2Max:
68  break
69  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
70  object.matched = True
71  match.matched = True
72  pairs[object] = match
73  #
74 
75  for object in objects:
76  if object.matched == False:
77  pairs[object] = None
78  #
79 
80  return pairs
81  # by now, the matched attribute remains in the objects, for future usage
82  # one could remove it with delattr (object, attrname)
83 
84 
85 
tuple zip
Definition: archive.py:476
def matchObjectCollection3
Definition: deltar.py:38

Variable Documentation

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

Definition at line 205 of file deltar.py.

tuple deltar.fargs = map( float, args )

Definition at line 206 of file deltar.py.