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
 

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

References deltaR2().

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

85 
86 def bestMatch( object, matchCollection):
87  '''Return the best match to object in matchCollection, which is the closest object in delta R'''
88  deltaR2Min = float('+inf')
89  bm = None
90  for match in matchCollection:
91  dR2 = deltaR2( object.eta(), object.phi(),
92  match.eta(), match.phi() )
93  if dR2 < deltaR2Min:
94  deltaR2Min = dR2
95  bm = match
96  return bm, deltaR2Min
97 
def bestMatch
Definition: deltar.py:85
def deltaR2
Definition: deltar.py:7
def deltar.cleanObjectCollection (   objects,
  masks,
  deltaRMin 
)
Masks objects using a deltaR cut.

Definition at line 65 of file deltar.py.

References deltaR2().

Referenced by JetAnalyzer.JetAnalyzer.process().

65 
66 def cleanObjectCollection( objects, masks, deltaRMin ):
67  '''Masks objects using a deltaR cut.'''
68  if len(objects)==0 or len(masks)==0:
69  return objects, []
70  deltaR2Min = deltaRMin*deltaRMin
71  cleanObjects = []
72  dirtyObjects = []
73  for object in objects:
74  ok = True
75  for mask in masks:
76  dR2 = deltaR2( object.eta(), object.phi(),
77  mask.eta(), mask.phi() )
78  if dR2 < deltaR2Min:
79  ok = False
80  if ok:
81  cleanObjects.append( object )
82  else:
83  dirtyObjects.append( object )
84  return cleanObjects, dirtyObjects
def cleanObjectCollection
Definition: deltar.py:65
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 38 of file deltar.py.

References deltaR2().

38 
39 def cleanObjectCollection2( objects, masks, deltaRMin ):
40  '''Masks objects using a deltaR cut, another algorithm (same results).'''
41  if len(objects)==0:
42  return objects
43  deltaR2Min = deltaRMin*deltaRMin
44  cleanObjects = copy.copy( objects )
45  for mask in masks:
46  tooClose = []
47  for idx, object in enumerate(cleanObjects):
48  dR2 = deltaR2( object.eta(), object.phi(),
49  mask.eta(), mask.phi() )
50  if dR2 < deltaR2Min:
51  tooClose.append( idx )
52  nRemoved = 0
53  for idx in tooClose:
54  # yes, everytime an object is removed, the list of objects is updated
55  # so need to update the index accordingly.
56  # example: to remove : ele 1 and 2
57  # first, ele 1 is removed
58  # -> ele 2 is now at index 1
59  # one should again remove the element at index 1
60  idx -= nRemoved
61  del cleanObjects[idx]
62  nRemoved += 1
63  return cleanObjects
64 
def cleanObjectCollection2
Definition: deltar.py:38
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 98 of file deltar.py.

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

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

98 
99 def matchObjectCollection( objects, matchCollection, deltaR2Max):
100  pairs = {}
101  if len(objects)==0:
102  return pairs
103  if len(matchCollection)==0:
104  return dict( zip(objects, [None]*len(objects)) )
105  for object in objects:
106  bm, dr2 = bestMatch( object, matchCollection )
107  if dr2<deltaR2Max:
108  pairs[object] = bm
109  else:
110  pairs[object] = None
111  return pairs
112 
def bestMatch
Definition: deltar.py:85
tuple zip
Definition: archive.py:476
def matchObjectCollection
Definition: deltar.py:98
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 113 of file deltar.py.

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

114 def matchObjectCollection2 ( objects, matchCollection, deltaRMax = 0.3 ):
115  '''Univoque association of an element from matchCollection to an element of objects.
116  Reco and Gen objects get the "matched" attribute, true is they are re part of a matched tulpe.
117  By default, the matching is true only if delta R is smaller than 0.3.
118  '''
119 
120  pairs = {}
121  if len(objects)==0:
122  return pairs
123  if len(matchCollection)==0:
124  return dict( zip(objects, [None]*len(objects)) )
125  # build all possible combinations
126  allPairs = [(deltaR2 (object.eta(), object.phi(), match.eta(), match.phi()), (object, match)) for object in objects for match in matchCollection]
127  allPairs.sort ()
128 
129  # to flag already matched objects
130  # FIXME this variable remains appended to the object, I do not like it
131  for object in objects:
132  object.matched = False
133  for match in matchCollection:
134  match.matched = False
135 
136  deltaR2Max = deltaRMax * deltaRMax
137  for dR2, (object, match) in allPairs:
138  if dR2 > deltaR2Max:
139  break
140  if dR2 < deltaR2Max and object.matched == False and match.matched == False:
141  object.matched = True
142  match.matched = True
143  pairs[object] = match
144 
145  for object in objects:
146  if object.matched == False:
147  pairs[object] = None
148 
149  return pairs
150  # by now, the matched attribute remains in the objects, for future usage
151  # one could remove it with delattr (object, attrname)
152 
153 
tuple zip
Definition: archive.py:476
def matchObjectCollection2
Definition: deltar.py:113

Variable Documentation

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

Definition at line 157 of file deltar.py.

tuple deltar.fargs = map( float, args )

Definition at line 158 of file deltar.py.