CMS 3D CMS Logo

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

Functions

def _customSetattr
 
def _getModule
 
                  ###

Auxiliary functions ###

More...
 
def _TrackFitter
 
def _TrackHitFilter
 
def _TrackRefitter
 
def _TrackSelector
 
def _TrackSplitting
 
def getSequence
 

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 494 of file trackselectionRefitting.py.

Referenced by _getModule().

495 def _customSetattr(obj, attr, val):
496  """Sets the attribute `attr` of the object `obj` using the value `val`.
497  `attr` can be a string or a tuple of strings, if one wants to set an
498  attribute of an attribute, etc.
499 
500  Arguments:
501  - `obj`: Object, which must have a '__dict__' attribute.
502  - `attr`: String or tuple of strings describing the attribute's name.
503  - `val`: value of the attribute.
504  """
505 
506  if isinstance(attr, tuple) and len(attr) > 1:
507  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
508  else:
509  if isinstance(attr, tuple): attr = attr[0]
510  setattr(obj, attr, val)
511 
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 391 of file trackselectionRefitting.py.

References _customSetattr(), clone(), and print().

Referenced by getSequence().

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

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

Definition at line 458 of file trackselectionRefitting.py.

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

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

Definition at line 436 of file trackselectionRefitting.py.

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

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

Definition at line 474 of file trackselectionRefitting.py.

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

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

Definition at line 447 of file trackselectionRefitting.py.

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

Definition at line 489 of file trackselectionRefitting.py.

490 def _TrackSplitting(kwargs):
491  return ("RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
492  "cosmicTrackSplitter")
493 
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 17 of file trackselectionRefitting.py.

References _getModule(), join(), print(), and update.

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