CMS 3D CMS Logo

Functions
trackselectionRefitting Namespace Reference

Functions

def _customSetattr (obj, attr, val)
 
def _getModule (process, src, modType, moduleName, options, kwargs)
 

Auxiliary functions ###

More...
 
def _TrackFitter (kwargs)
 
def _TrackHitFilter (kwargs)
 
def _TrackRefitter (kwargs)
 
def _TrackSelector (kwargs)
 
def _TrackSplitting (kwargs)
 
def getSequence (process, collection, saveCPU=False, TTRHBuilder="WithAngleAndTemplate", usePixelQualityFlag=None, openMassWindow=False, cosmicsDecoMode=False, cosmicsZeroTesla=True, momentumConstraint=None, cosmicTrackSplitting=False, isPVValidation=False, use_d0cut=True)
 

Function Documentation

def trackselectionRefitting._customSetattr (   obj,
  attr,
  val 
)
private
Sets the attribute `attr` of the object `obj` using the value `val`.
`attr` can be a string or a tuple of strings, if one wants to set an
attribute of an attribute, etc.

Arguments:
- `obj`: Object, which must have a '__dict__' attribute.
- `attr`: String or tuple of strings describing the attribute's name.
- `val`: value of the attribute.

Definition at line 492 of file trackselectionRefitting.py.

Referenced by _getModule().

492 def _customSetattr(obj, attr, val):
493  """Sets the attribute `attr` of the object `obj` using the value `val`.
494  `attr` can be a string or a tuple of strings, if one wants to set an
495  attribute of an attribute, etc.
496 
497  Arguments:
498  - `obj`: Object, which must have a '__dict__' attribute.
499  - `attr`: String or tuple of strings describing the attribute's name.
500  - `val`: value of the attribute.
501  """
502 
503  if isinstance(attr, tuple) and len(attr) > 1:
504  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
505  else:
506  if isinstance(attr, tuple): attr = attr[0]
507  setattr(obj, attr, val)
508 
509 
def _customSetattr(obj, attr, val)
def trackselectionRefitting._getModule (   process,
  src,
  modType,
  moduleName,
  options,
  kwargs 
)
private

Auxiliary functions ###

General function for attaching the module of type `modType` to the
cms.Process `process` using `options` for customization and `moduleName` as
the name of the new attribute of `process`.

Arguments:
- `process`: 'cms.Process' object to which the module is attached.
- `src`: cms.InputTag for this module.
- `modType`: Type of the requested module.
- `options`: Dictionary with customized values for the module's options.
- `**kwargs`: Used to supply options at construction time of the module.

Definition at line 389 of file trackselectionRefitting.py.

References _customSetattr(), and clone().

Referenced by getSequence().

389 def _getModule(process, src, modType, moduleName, options, **kwargs):
390  """General function for attaching the module of type `modType` to the
391  cms.Process `process` using `options` for customization and `moduleName` as
392  the name of the new attribute of `process`.
393 
394  Arguments:
395  - `process`: 'cms.Process' object to which the module is attached.
396  - `src`: cms.InputTag for this module.
397  - `modType`: Type of the requested module.
398  - `options`: Dictionary with customized values for the module's options.
399  - `**kwargs`: Used to supply options at construction time of the module.
400  """
401 
402  objTuple = globals()["_"+modType](kwargs)
403  method = kwargs.get("method")
404  if method == "import":
405  __import__(objTuple[0])
406  obj = getattr(sys.modules[objTuple[0]], objTuple[1]).clone()
407  elif method == "load":
408  process.load(objTuple[0])
409  if kwargs.get("clone", False):
410  obj = getattr(process, objTuple[1]).clone(src=src)
411  else:
412  obj = getattr(process, objTuple[1])
413  moduleName = objTuple[1]
414  else:
415  print "Unknown method:", method
416  sys.exit(1)
417 
418  if modType == "TrackSplitting":
419  #track splitting takes the TrackSelector as tracks
420  # and the first TrackRefitter as tjTkAssociationMapTag
421  _customSetattr(obj, "tracks", src)
422  _customSetattr(obj, "tjTkAssociationMapTag", kwargs["prevsrc"])
423  else:
424  obj.src = src
425 
426  for option in options:
427  _customSetattr(obj, option, options[option])
428 
429  if moduleName is not objTuple[1]:
430  setattr(process, moduleName, obj)
431  return moduleName
432 
433 
def _customSetattr(obj, attr, val)
def _getModule(process, src, modType, moduleName, options, kwargs)
Auxiliary functions ###
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def trackselectionRefitting._TrackFitter (   kwargs)
private
Returns TrackFitter module name.

Arguments:
- `kwargs`: Used to supply options at construction time of the object.

Definition at line 456 of file trackselectionRefitting.py.

456 def _TrackFitter(kwargs):
457  """Returns TrackFitter module name.
458 
459  Arguments:
460  - `kwargs`: Used to supply options at construction time of the object.
461  """
462 
463  isCosmics = kwargs.get("isCosmics", False)
464  if isCosmics:
465  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
466  "ctfWithMaterialTracksCosmics")
467  else:
468  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
469  "ctfWithMaterialTracks")
470 
471 
def trackselectionRefitting._TrackHitFilter (   kwargs)
private
Returns TrackHitFilter module name.

Arguments:
- `kwargs`: Not used in this function.

Definition at line 434 of file trackselectionRefitting.py.

434 def _TrackHitFilter(kwargs):
435  """Returns TrackHitFilter module name.
436 
437  Arguments:
438  - `kwargs`: Not used in this function.
439  """
440 
441  return ("RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
442  "TrackerTrackHitFilter")
443 
444 
def trackselectionRefitting._TrackRefitter (   kwargs)
private
Returns TrackRefitter module name.

Arguments:
- `kwargs`: Used to supply options at construction time of the object.

Definition at line 472 of file trackselectionRefitting.py.

472 def _TrackRefitter(kwargs):
473  """Returns TrackRefitter module name.
474 
475  Arguments:
476  - `kwargs`: Used to supply options at construction time of the object.
477  """
478 
479  isCosmics = kwargs.get("isCosmics", False)
480  if isCosmics:
481  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
482  "TrackRefitterP5")
483  else:
484  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
485  "TrackRefitter")
486 
def trackselectionRefitting._TrackSelector (   kwargs)
private
Returns TrackSelector module name.

Arguments:
- `kwargs`: Not used in this function.

Definition at line 445 of file trackselectionRefitting.py.

445 def _TrackSelector(kwargs):
446  """Returns TrackSelector module name.
447 
448  Arguments:
449  - `kwargs`: Not used in this function.
450  """
451 
452  return ("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
453  "AlignmentTrackSelector")
454 
455 
def trackselectionRefitting._TrackSplitting (   kwargs)
private

Definition at line 487 of file trackselectionRefitting.py.

487 def _TrackSplitting(kwargs):
488  return ("RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
489  "cosmicTrackSplitter")
490 
491 
def trackselectionRefitting.getSequence (   process,
  collection,
  saveCPU = False,
  TTRHBuilder = "WithAngleAndTemplate",
  usePixelQualityFlag = None,
  openMassWindow = False,
  cosmicsDecoMode = False,
  cosmicsZeroTesla = True,
  momentumConstraint = None,
  cosmicTrackSplitting = False,
  isPVValidation = False,
  use_d0cut = True 
)
This function returns a cms.Sequence containing as last element the
module 'FinalTrackRefitter', which can be used as cms.InputTag for
subsequent processing steps.
The modules in the sequence are already attached to the given `process`
object using the given track collection `collection` and the given
optional arguments.

Arguments:
- `process`: 'cms.Process' object to which the modules of the sequence will
             be attached.
- `collection`: String indicating the input track collection.
- `saveCPU`: If set to 'True', some steps are merged to reduce CPU time.
             Reduces a little the accuracy of the results.
             This option is currently not recommended.
- `TTRHBuilder`: Option used for the Track(Re)Fitter modules.
- `usePixelQualityFlag`: Option used for the TrackHitFilter module.
                         Defaults to 'True' but is automatically set to
                         'False' if a `TTRHBuilder` without templates is
                         used.
                         If this is still wanted for some reason, one can
                         explicitely specify it as 'True'.
- `openMassWindow`: Used to configure the TwoBodyDecaySelector for ZMuMu.
- `cosmicsDecoMode`: If set to 'True' a lower Signal/Noise cut is used.
- `cosmicsZeroTesla`: If set to 'True' a 0T-specific selection is used.
- `momentumConstraint`: If you want to apply a momentum constraint for the
                        track refitting, e.g. for CRUZET data, you need
                        to provide here the name of the constraint module.
- `cosmicTrackSplitting`: If set to 'True' cosmic tracks are split before the
                          second track refitter.
- `isPVValidation`: If set to 'True' most of the selection cuts are overridden
                    to allow unbiased selection of tracks for vertex refitting 
- `use_d0cut`: If 'True' (default), apply a cut |d0| < 50.

Definition at line 16 of file trackselectionRefitting.py.

References _getModule(), reco.get(), join(), and update.

16  use_d0cut = True):
17  """This function returns a cms.Sequence containing as last element the
18  module 'FinalTrackRefitter', which can be used as cms.InputTag for
19  subsequent processing steps.
20  The modules in the sequence are already attached to the given `process`
21  object using the given track collection `collection` and the given
22  optional arguments.
23 
24  Arguments:
25  - `process`: 'cms.Process' object to which the modules of the sequence will
26  be attached.
27  - `collection`: String indicating the input track collection.
28  - `saveCPU`: If set to 'True', some steps are merged to reduce CPU time.
29  Reduces a little the accuracy of the results.
30  This option is currently not recommended.
31  - `TTRHBuilder`: Option used for the Track(Re)Fitter modules.
32  - `usePixelQualityFlag`: Option used for the TrackHitFilter module.
33  Defaults to 'True' but is automatically set to
34  'False' if a `TTRHBuilder` without templates is
35  used.
36  If this is still wanted for some reason, one can
37  explicitely specify it as 'True'.
38  - `openMassWindow`: Used to configure the TwoBodyDecaySelector for ZMuMu.
39  - `cosmicsDecoMode`: If set to 'True' a lower Signal/Noise cut is used.
40  - `cosmicsZeroTesla`: If set to 'True' a 0T-specific selection is used.
41  - `momentumConstraint`: If you want to apply a momentum constraint for the
42  track refitting, e.g. for CRUZET data, you need
43  to provide here the name of the constraint module.
44  - `cosmicTrackSplitting`: If set to 'True' cosmic tracks are split before the
45  second track refitter.
46  - `isPVValidation`: If set to 'True' most of the selection cuts are overridden
47  to allow unbiased selection of tracks for vertex refitting
48  - `use_d0cut`: If 'True' (default), apply a cut |d0| < 50.
49  """
50 
51  ###################################################
52  # resolve default values incl. consistency checks #
53  ###################################################
54 
55  if usePixelQualityFlag is None:
56  if "Template" not in TTRHBuilder:
57  usePixelQualityFlag = False # not defined without templates
58  print "Using 'TTRHBuilder' without templates:", TTRHBuilder
59  print " --> Turning off pixel quality flag in hit filter."
60  else:
61  usePixelQualityFlag = True # default for usage with templates
62 
63 
64  #############################
65  ## setting general options ##
66  #############################
67 
68  options = {"TrackHitFilter": {},
69  "TrackFitter": {},
70  "TrackRefitter": {},
71  "TrackSelector": {}}
72 
73  options["TrackSelector"]["HighPurity"] = {
74  "trackQualities": ["highPurity"],
75  "filter": True,
76  "etaMin": -3.0,
77  "etaMax": 3.0,
78  "pMin": 8.0
79  }
80  options["TrackSelector"]["Alignment"] = {
81  "filter": True,
82  "pMin": 3.0,
83  "nHitMin2D": 2,
84  "d0Min": -50.0,
85  "d0Max": 50.0,
86  "etaMin": -3.0,
87  "etaMax": 3.0,
88  "nHitMin": 8,
89  "chi2nMax": 9999.0
90  }
91  options["TrackRefitter"]["First"] = {
92  "NavigationSchool": "",
93  "TTRHBuilder": TTRHBuilder,
94  }
95  options["TrackRefitter"]["Second"] = {
96  "NavigationSchool": "",
97  "TTRHBuilder": TTRHBuilder,
98  }
99  options["TrackHitFilter"]["Tracker"] = {
100  "useTrajectories": True,
101  "minimumHits": 8,
102  "commands": cms.vstring("keep PXB", "keep PXE", "keep TIB", "keep TID",
103  "keep TOB", "keep TEC"),
104  "replaceWithInactiveHits": True,
105  "rejectBadStoNHits": True,
106  "rejectLowAngleHits": True,
107  "usePixelQualityFlag": usePixelQualityFlag,
108  "StoNcommands": cms.vstring("ALL 12.0"),
109  "TrackAngleCut": 0.087,
110  }
111  options["TrackFitter"]["HitFilteredTracks"] = {
112  "NavigationSchool": "",
113  "TTRHBuilder": TTRHBuilder,
114  }
115 
116 
117  #########################################
118  ## setting collection specific options ##
119  #########################################
120  isCosmics = False
121 
122  if collection in ("ALCARECOTkAlMinBias", "generalTracks",
123  "ALCARECOTkAlMinBiasHI", "hiGeneralTracks"):
124  options["TrackSelector"]["Alignment"].update({
125  "ptMin": 1.0,
126  "pMin": 8.,
127  })
128  options["TrackHitFilter"]["Tracker"].update({
129  "minimumHits": 10,
130  })
131  elif collection in ("ALCARECOTkAlCosmicsCTF0T",
132  "ALCARECOTkAlCosmicsInCollisions"):
133  isCosmics = True
134  options["TrackSelector"]["HighPurity"] = {} # drop high purity cut
135  if not cosmicsDecoMode:
136  options["TrackHitFilter"]["Tracker"].update({
137  "StoNcommands": cms.vstring("ALL 18.0")
138  })
139  if cosmicsZeroTesla:
140  options["TrackHitFilter"]["Tracker"].update({
141  "TrackAngleCut": 0.1 # Run-I: 0.087 for 0T
142  })
143  else:
144  options["TrackHitFilter"]["Tracker"].update({
145  "TrackAngleCut": 0.1 # Run-I: 0.35 for 3.8T
146  })
147  options["TrackSelector"]["Alignment"].update({
148  "pMin": 4.0,
149  "etaMin": -99.0,
150  "etaMax": 99.0,
151  "applyMultiplicityFilter": True,
152  "maxMultiplicity": 1
153  })
154  if cosmicTrackSplitting:
155  options["TrackSplitting"] = {}
156  options["TrackSplitting"]["TrackSplitting"] = {}
157  if not use_d0cut:
158  options["TrackSelector"]["Alignment"].update({
159  "d0Min": -99999.0,
160  "d0Max": 99999.0,
161  })
162  elif collection in ("ALCARECOTkAlMuonIsolated",
163  "ALCARECOTkAlMuonIsolatedHI",
164  "ALCARECOTkAlMuonIsolatedPA"):
165  options["TrackSelector"]["Alignment"].update({
166  ("minHitsPerSubDet", "inPIXEL"): 1,
167  "ptMin": 5.0,
168  "nHitMin": 10,
169  "applyMultiplicityFilter": True,
170  "maxMultiplicity": 1,
171  })
172  elif collection in ("ALCARECOTkAlZMuMu",
173  "ALCARECOTkAlZMuMuHI",
174  "ALCARECOTkAlZMuMuPA"):
175  options["TrackSelector"]["Alignment"].update({
176  "ptMin": 15.0,
177  "etaMin": -3.0,
178  "etaMax": 3.0,
179  "nHitMin": 10,
180  "applyMultiplicityFilter": True,
181  "minMultiplicity": 2,
182  "maxMultiplicity": 2,
183  ("minHitsPerSubDet", "inPIXEL"): 1,
184  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
185  ("TwoBodyDecaySelector", "charge"): 0,
186  ("TwoBodyDecaySelector",
187  "applyMassrangeFilter"): not openMassWindow,
188  ("TwoBodyDecaySelector", "minXMass"): 85.8,
189  ("TwoBodyDecaySelector", "maxXMass"): 95.8,
190  ("TwoBodyDecaySelector", "daughterMass"): 0.105
191  })
192  options["TrackHitFilter"]["Tracker"].update({
193  "minimumHits": 10,
194  })
195  elif collection == "ALCARECOTkAlUpsilonMuMu":
196  options["TrackSelector"]["Alignment"].update({
197  "ptMin": 3.0,
198  "etaMin": -2.4,
199  "etaMax": 2.4,
200  "nHitMin": 10,
201  "applyMultiplicityFilter": True,
202  "minMultiplicity": 2,
203  "maxMultiplicity": 2,
204  ("minHitsPerSubDet", "inPIXEL"): 1,
205  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
206  ("TwoBodyDecaySelector", "charge"): 0,
207  ("TwoBodyDecaySelector",
208  "applyMassrangeFilter"): not openMassWindow,
209  ("TwoBodyDecaySelector", "minXMass"): 9.2,
210  ("TwoBodyDecaySelector", "maxXMass"): 9.7,
211  ("TwoBodyDecaySelector", "daughterMass"): 0.105
212  })
213  options["TrackHitFilter"]["Tracker"].update({
214  "minimumHits": 10,
215  })
216  elif collection == "ALCARECOTkAlJpsiMuMu":
217  options["TrackSelector"]["Alignment"].update({
218  "ptMin": 1.0,
219  "etaMin": -2.4,
220  "etaMax": 2.4,
221  "nHitMin": 10,
222  "applyMultiplicityFilter": True,
223  "minMultiplicity": 2,
224  "maxMultiplicity": 2,
225  ("minHitsPerSubDet", "inPIXEL"): 1,
226  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
227  ("TwoBodyDecaySelector", "charge"): 0,
228  ("TwoBodyDecaySelector",
229  "applyMassrangeFilter"): not openMassWindow,
230  ("TwoBodyDecaySelector", "minXMass"): 2.7,
231  ("TwoBodyDecaySelector", "maxXMass"): 3.4,
232  ("TwoBodyDecaySelector", "daughterMass"): 0.105
233  })
234  options["TrackHitFilter"]["Tracker"].update({
235  "minimumHits": 10,
236  })
237  else:
238  raise ValueError("Unknown input track collection: {}".format(collection))
239 
240  if cosmicTrackSplitting and not isCosmics:
241  raise ValueError("Can only do cosmic track splitting for cosmics.")
242 
243 
244 
245  ####################
246  ## save CPU time? ##
247  ####################
248 
249  if saveCPU:
250  if cosmicTrackSplitting:
251  raise ValueError("Can't turn on both saveCPU and cosmicTrackSplitting at the same time")
252  mods = [("TrackSelector", "Alignment", {"method": "load"}),
253  ("TrackRefitter", "First", {"method": "load",
254  "clone": True}),
255  ("TrackHitFilter", "Tracker", {"method": "load"}),
256  ("TrackFitter", "HitFilteredTracks", {"method": "import"})]
257  options["TrackSelector"]["Alignment"].update(
258  options["TrackSelector"]["HighPurity"])
259  elif cosmicTrackSplitting:
260  mods = [("TrackRefitter", "First", {"method": "load",
261  "clone": True}),
262  ("TrackSelector", "Alignment", {"method": "load"}),
263  ("TrackSplitting", "TrackSplitting", {"method": "load"}),
264  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
265  ("TrackRefitter", "Second", {"method": "load",
266  "clone": True})]
267  else:
268  mods = [("TrackSelector", "HighPurity", {"method": "import"}),
269  ("TrackRefitter", "First", {"method": "load",
270  "clone": True}),
271  ("TrackHitFilter", "Tracker", {"method": "load"}),
272  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
273  ("TrackSelector", "Alignment", {"method": "load"}),
274  ("TrackRefitter", "Second", {"method": "load",
275  "clone": True})]
276  if isCosmics: mods = mods[1:] # skip high purity selector for cosmics
277 
278  #############################
279  ## PV Validation cuts tune ##
280  #############################
281 
282  if isPVValidation:
283  options["TrackSelector"]["HighPurity"].update({
284  "trackQualities": [],
285  "pMin": 0.
286  })
287  options["TrackSelector"]["Alignment"].update({
288  "pMin" : 0.,
289  "ptMin" : 0.,
290  "nHitMin2D" : 0,
291  "nHitMin" : 0,
292  "d0Min" : -999999.0,
293  "d0Max" : 999999.0,
294  "dzMin" : -999999.0,
295  "dzMax" : 999999.0
296  })
297 
298  ################################
299  ## apply momentum constraint? ##
300  ################################
301 
302  if momentumConstraint is not None:
303  for mod in options["TrackRefitter"]:
304  momconstrspecs = momentumConstraint.split(',')
305  if len(momconstrspecs)==1:
306  options["TrackRefitter"][mod].update({
307  "constraint": "momentum",
308  "srcConstr": momconstrspecs[0]
309  })
310  else:
311  options["TrackRefitter"][mod].update({
312  "constraint": momconstrspecs[1],
313  "srcConstr": momconstrspecs[0]
314  })
315 
316 
317 
318  #######################################################
319  # load offline beam spot module required by the refit #
320  #######################################################
321  process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
322 
323 
324 
325  ###############################
326  ## put the sequence together ##
327  ###############################
328 
329  modules = []
330  src = collection
331  prevsrc = None
332  for mod in mods[:-1]:
333  src, prevsrc = _getModule(process, src, mod[0], "".join(reversed(mod[:-1])),
334  options[mod[0]][mod[1]], isCosmics = isCosmics, prevsrc = prevsrc,
335  **(mod[2])), src
336  modules.append(getattr(process, src))
337  else:
338  if mods[-1][-1]["method"] is "load" and \
339  not mods[-1][-1].get("clone", False):
340  print "Name of the last module needs to be modifiable."
341  sys.exit(1)
342  src = _getModule(process, src, mods[-1][0], "FinalTrackRefitter",
343  options[mods[-1][0]][mods[-1][1]],
344  isCosmics = isCosmics, **(mods[-1][2]))
345  modules.append(getattr(process, src))
346 
347  moduleSum = process.offlineBeamSpot # first element of the sequence
348  for module in modules:
349  # Spply srcConstr fix here
350  if hasattr(module,"srcConstr"):
351  strSrcConstr = module.srcConstr.getModuleLabel()
352  if strSrcConstr:
353  procsrcconstr = getattr(process,strSrcConstr)
354  if hasattr(procsrcconstr,"src"): # Momentum or track parameter constraints
355  if procsrcconstr.src != module.src:
356  module.srcConstr=''
357  module.constraint=''
358  else:
359  moduleSum += procsrcconstr # Add constraint
360  elif hasattr(procsrcconstr,"srcTrk"): # Vertex constraint
361  if procsrcconstr.srcTrk != module.src:
362  module.srcConstr=''
363  module.constraint=''
364  else:
365  procsrcconstrsrcvtx = getattr(process,procsrcconstr.srcVtx.getModuleLabel())
366  if type(procsrcconstrsrcvtx) is cms.EDFilter: # If source of vertices is itself a filter (e.g. good PVs)
367  procsrcconstrsrcvtxprefilter = getattr(process,procsrcconstrsrcvtx.src.getModuleLabel())
368  moduleSum += procsrcconstrsrcvtxprefilter # Add vertex source to constraint before filter
369  moduleSum += procsrcconstrsrcvtx # Add vertex source to constraint
370  moduleSum += procsrcconstr # Add constraint
371 
372  moduleSum += module # append the other modules
373 
374  return cms.Sequence(moduleSum)
375 
376 
377 
378 
379 
def _getModule(process, src, modType, moduleName, options, kwargs)
Auxiliary functions ###
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
#define update(a, b)
T get(const Candidate &c)
Definition: component.h:55