CMS 3D CMS Logo

trackselectionRefitting.py
Go to the documentation of this file.
1 import sys
2 import FWCore.ParameterSet.Config as cms
3 
4 
5 
6 def getSequence(process, collection,
7  saveCPU = False,
8  TTRHBuilder = "WithAngleAndTemplate",
9  usePixelQualityFlag = None,
10  openMassWindow = False,
11  cosmicsDecoMode = False,
12  cosmicsZeroTesla = True,
13  momentumConstraint = None,
14  cosmicTrackSplitting = False,
15  isPVValidation = False,
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 procsrcconstr.src != module.src:
355  module.srcConstr=''
356  module.constraint=''
357  else:
358  moduleSum += procsrcconstr
359 
360  moduleSum += module # append the other modules
361 
362  return cms.Sequence(moduleSum)
363 
364 
365 
366 
367 
368 ###############################
369 ###############################
370 ### ###
371 ### Auxiliary functions ###
372 ### ###
373 ###############################
374 ###############################
375 
376 
377 def _getModule(process, src, modType, moduleName, options, **kwargs):
378  """General function for attaching the module of type `modType` to the
379  cms.Process `process` using `options` for customization and `moduleName` as
380  the name of the new attribute of `process`.
381 
382  Arguments:
383  - `process`: 'cms.Process' object to which the module is attached.
384  - `src`: cms.InputTag for this module.
385  - `modType`: Type of the requested module.
386  - `options`: Dictionary with customized values for the module's options.
387  - `**kwargs`: Used to supply options at construction time of the module.
388  """
389 
390  objTuple = globals()["_"+modType](kwargs)
391  method = kwargs.get("method")
392  if method == "import":
393  __import__(objTuple[0])
394  obj = getattr(sys.modules[objTuple[0]], objTuple[1]).clone()
395  elif method == "load":
396  process.load(objTuple[0])
397  if kwargs.get("clone", False):
398  obj = getattr(process, objTuple[1]).clone(src=src)
399  else:
400  obj = getattr(process, objTuple[1])
401  moduleName = objTuple[1]
402  else:
403  print "Unknown method:", method
404  sys.exit(1)
405 
406  if modType == "TrackSplitting":
407  #track splitting takes the TrackSelector as tracks
408  # and the first TrackRefitter as tjTkAssociationMapTag
409  _customSetattr(obj, "tracks", src)
410  _customSetattr(obj, "tjTkAssociationMapTag", kwargs["prevsrc"])
411  else:
412  obj.src = src
413 
414  for option in options:
415  _customSetattr(obj, option, options[option])
416 
417  if moduleName is not objTuple[1]:
418  setattr(process, moduleName, obj)
419  return moduleName
420 
421 
422 def _TrackHitFilter(kwargs):
423  """Returns TrackHitFilter module name.
424 
425  Arguments:
426  - `kwargs`: Not used in this function.
427  """
428 
429  return ("RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
430  "TrackerTrackHitFilter")
431 
432 
433 def _TrackSelector(kwargs):
434  """Returns TrackSelector module name.
435 
436  Arguments:
437  - `kwargs`: Not used in this function.
438  """
439 
440  return ("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
441  "AlignmentTrackSelector")
442 
443 
444 def _TrackFitter(kwargs):
445  """Returns TrackFitter module name.
446 
447  Arguments:
448  - `kwargs`: Used to supply options at construction time of the object.
449  """
450 
451  isCosmics = kwargs.get("isCosmics", False)
452  if isCosmics:
453  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
454  "ctfWithMaterialTracksCosmics")
455  else:
456  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
457  "ctfWithMaterialTracks")
458 
459 
460 def _TrackRefitter(kwargs):
461  """Returns TrackRefitter module name.
462 
463  Arguments:
464  - `kwargs`: Used to supply options at construction time of the object.
465  """
466 
467  isCosmics = kwargs.get("isCosmics", False)
468  if isCosmics:
469  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
470  "TrackRefitterP5")
471  else:
472  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
473  "TrackRefitter")
474 
475 def _TrackSplitting(kwargs):
476  return ("RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
477  "cosmicTrackSplitter")
478 
479 
480 def _customSetattr(obj, attr, val):
481  """Sets the attribute `attr` of the object `obj` using the value `val`.
482  `attr` can be a string or a tuple of strings, if one wants to set an
483  attribute of an attribute, etc.
484 
485  Arguments:
486  - `obj`: Object, which must have a '__dict__' attribute.
487  - `attr`: String or tuple of strings describing the attribute's name.
488  - `val`: value of the attribute.
489  """
490 
491  if type(attr) is tuple and len(attr) > 1:
492  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
493  else:
494  if type(attr) is tuple: attr = attr[0]
495  setattr(obj, attr, val)
496 
def _customSetattr(obj, attr, val)
def _getModule(process, src, modType, moduleName, options, kwargs)
Auxiliary functions ###
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)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
#define update(a, b)
T get(const Candidate &c)
Definition: component.h:55