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  use_d0cut = True):
16  """This function returns a cms.Sequence containing as last element the
17  module 'FinalTrackRefitter', which can be used as cms.InputTag for
18  subsequent processing steps.
19  The modules in the sequence are already attached to the given `process`
20  object using the given track collection `collection` and the given
21  optional arguments.
22 
23  Arguments:
24  - `process`: 'cms.Process' object to which the modules of the sequence will
25  be attached.
26  - `collection`: String indicating the input track collection.
27  - `saveCPU`: If set to 'True', some steps are merged to reduce CPU time.
28  Reduces a little the accuracy of the results.
29  This option is currently not recommended.
30  - `TTRHBuilder`: Option used for the Track(Re)Fitter modules.
31  - `usePixelQualityFlag`: Option used for the TrackHitFilter module.
32  Defaults to 'True' but is automatically set to
33  'False' if a `TTRHBuilder` without templates is
34  used.
35  If this is still wanted for some reason, one can
36  explicitely specify it as 'True'.
37  - `openMassWindow`: Used to configure the TwoBodyDecaySelector for ZMuMu.
38  - `cosmicsDecoMode`: If set to 'True' a lower Signal/Noise cut is used.
39  - `cosmicsZeroTesla`: If set to 'True' a 0T-specific selection is used.
40  - `momentumConstraint`: If you want to apply a momentum constraint for the
41  track refitting, e.g. for CRUZET data, you need
42  to provide here the name of the constraint module.
43  - `cosmicTrackSplitting`: If set to 'True' cosmic tracks are split before the
44  second track refitter.
45  - `use_d0cut`: If 'True' (default), apply a cut |d0| < 50.
46  """
47 
48  ###################################################
49  # resolve default values incl. consistency checks #
50  ###################################################
51 
52  if usePixelQualityFlag is None:
53  if "Template" not in TTRHBuilder:
54  usePixelQualityFlag = False # not defined without templates
55  print "Using 'TTRHBuilder' without templates:", TTRHBuilder
56  print " --> Turning off pixel quality flag in hit filter."
57  else:
58  usePixelQualityFlag = True # default for usage with templates
59 
60 
61  #############################
62  ## setting general options ##
63  #############################
64 
65  options = {"TrackHitFilter": {},
66  "TrackFitter": {},
67  "TrackRefitter": {},
68  "TrackSelector": {}}
69 
70  options["TrackSelector"]["HighPurity"] = {
71  "trackQualities": ["highPurity"],
72  "filter": True,
73  "etaMin": -3.0,
74  "etaMax": 3.0,
75  "pMin": 8.0
76  }
77  options["TrackSelector"]["Alignment"] = {
78  "filter": True,
79  "pMin": 3.0,
80  "nHitMin2D": 2,
81  "d0Min": -50.0,
82  "d0Max": 50.0,
83  "etaMin": -3.0,
84  "etaMax": 3.0,
85  "nHitMin": 8,
86  "chi2nMax": 9999.0
87  }
88  options["TrackRefitter"]["First"] = {
89  "NavigationSchool": "",
90  "TTRHBuilder": TTRHBuilder,
91  }
92  options["TrackRefitter"]["Second"] = {
93  "NavigationSchool": "",
94  "TTRHBuilder": TTRHBuilder,
95  }
96  options["TrackHitFilter"]["Tracker"] = {
97  "useTrajectories": True,
98  "minimumHits": 8,
99  "commands": cms.vstring("keep PXB", "keep PXE", "keep TIB", "keep TID",
100  "keep TOB", "keep TEC"),
101  "replaceWithInactiveHits": True,
102  "rejectBadStoNHits": True,
103  "rejectLowAngleHits": True,
104  "usePixelQualityFlag": usePixelQualityFlag,
105  "StoNcommands": cms.vstring("ALL 12.0"),
106  "TrackAngleCut": 0.087,
107  }
108  options["TrackFitter"]["HitFilteredTracks"] = {
109  "NavigationSchool": "",
110  "TTRHBuilder": TTRHBuilder,
111  }
112 
113 
114  #########################################
115  ## setting collection specific options ##
116  #########################################
117  isCosmics = False
118 
119  if collection in ("ALCARECOTkAlMinBias", "generalTracks",
120  "ALCARECOTkAlMinBiasHI", "hiGeneralTracks"):
121  options["TrackSelector"]["Alignment"].update({
122  "ptMin": 1.0,
123  "pMin": 8.,
124  })
125  options["TrackHitFilter"]["Tracker"].update({
126  "minimumHits": 10,
127  })
128  elif collection in ("ALCARECOTkAlCosmicsCTF0T",
129  "ALCARECOTkAlCosmicsInCollisions"):
130  isCosmics = True
131  options["TrackSelector"]["HighPurity"] = {} # drop high purity cut
132  if not cosmicsDecoMode:
133  options["TrackHitFilter"]["Tracker"].update({
134  "StoNcommands": cms.vstring("ALL 18.0")
135  })
136  if cosmicsZeroTesla:
137  options["TrackHitFilter"]["Tracker"].update({
138  "TrackAngleCut": 0.1 # Run-I: 0.087 for 0T
139  })
140  else:
141  options["TrackHitFilter"]["Tracker"].update({
142  "TrackAngleCut": 0.1 # Run-I: 0.35 for 3.8T
143  })
144  options["TrackSelector"]["Alignment"].update({
145  "pMin": 4.0,
146  "etaMin": -99.0,
147  "etaMax": 99.0,
148  "applyMultiplicityFilter": True,
149  "maxMultiplicity": 1
150  })
151  if cosmicTrackSplitting:
152  options["TrackSplitting"] = {}
153  options["TrackSplitting"]["TrackSplitting"] = {}
154  if not use_d0cut:
155  options["TrackSelector"]["Alignment"].update({
156  "d0Min": -99999.0,
157  "d0Max": 99999.0,
158  })
159  elif collection in ("ALCARECOTkAlMuonIsolated",
160  "ALCARECOTkAlMuonIsolatedHI",
161  "ALCARECOTkAlMuonIsolatedPA"):
162  options["TrackSelector"]["Alignment"].update({
163  ("minHitsPerSubDet", "inPIXEL"): 1,
164  "ptMin": 5.0,
165  "nHitMin": 10,
166  "applyMultiplicityFilter": True,
167  "maxMultiplicity": 1,
168  })
169  elif collection in ("ALCARECOTkAlZMuMu",
170  "ALCARECOTkAlZMuMuHI",
171  "ALCARECOTkAlZMuMuPA"):
172  options["TrackSelector"]["Alignment"].update({
173  "ptMin": 15.0,
174  "etaMin": -3.0,
175  "etaMax": 3.0,
176  "nHitMin": 10,
177  "applyMultiplicityFilter": True,
178  "minMultiplicity": 2,
179  "maxMultiplicity": 2,
180  ("minHitsPerSubDet", "inPIXEL"): 1,
181  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
182  ("TwoBodyDecaySelector", "charge"): 0,
183  ("TwoBodyDecaySelector",
184  "applyMassrangeFilter"): not openMassWindow,
185  ("TwoBodyDecaySelector", "minXMass"): 85.8,
186  ("TwoBodyDecaySelector", "maxXMass"): 95.8,
187  ("TwoBodyDecaySelector", "daughterMass"): 0.105
188  })
189  options["TrackHitFilter"]["Tracker"].update({
190  "minimumHits": 10,
191  })
192  elif collection == "ALCARECOTkAlUpsilonMuMu":
193  options["TrackSelector"]["Alignment"].update({
194  "ptMin": 3.0,
195  "etaMin": -2.4,
196  "etaMax": 2.4,
197  "nHitMin": 10,
198  "applyMultiplicityFilter": True,
199  "minMultiplicity": 2,
200  "maxMultiplicity": 2,
201  ("minHitsPerSubDet", "inPIXEL"): 1,
202  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
203  ("TwoBodyDecaySelector", "charge"): 0,
204  ("TwoBodyDecaySelector",
205  "applyMassrangeFilter"): not openMassWindow,
206  ("TwoBodyDecaySelector", "minXMass"): 9.2,
207  ("TwoBodyDecaySelector", "maxXMass"): 9.7,
208  ("TwoBodyDecaySelector", "daughterMass"): 0.105
209  })
210  options["TrackHitFilter"]["Tracker"].update({
211  "minimumHits": 10,
212  })
213  elif collection == "ALCARECOTkAlJpsiMuMu":
214  options["TrackSelector"]["Alignment"].update({
215  "ptMin": 1.0,
216  "etaMin": -2.4,
217  "etaMax": 2.4,
218  "nHitMin": 10,
219  "applyMultiplicityFilter": True,
220  "minMultiplicity": 2,
221  "maxMultiplicity": 2,
222  ("minHitsPerSubDet", "inPIXEL"): 1,
223  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
224  ("TwoBodyDecaySelector", "charge"): 0,
225  ("TwoBodyDecaySelector",
226  "applyMassrangeFilter"): not openMassWindow,
227  ("TwoBodyDecaySelector", "minXMass"): 2.7,
228  ("TwoBodyDecaySelector", "maxXMass"): 3.4,
229  ("TwoBodyDecaySelector", "daughterMass"): 0.105
230  })
231  options["TrackHitFilter"]["Tracker"].update({
232  "minimumHits": 10,
233  })
234  else:
235  raise ValueError("Unknown input track collection: {}".format(collection))
236 
237  if cosmicTrackSplitting and not isCosmics:
238  raise ValueError("Can only do cosmic track splitting for cosmics.")
239 
240 
241 
242  ####################
243  ## save CPU time? ##
244  ####################
245 
246  if saveCPU:
247  if cosmicTrackSplitting:
248  raise ValueError("Can't turn on both saveCPU and cosmicTrackSplitting at the same time")
249  mods = [("TrackSelector", "Alignment", {"method": "load"}),
250  ("TrackRefitter", "First", {"method": "load",
251  "clone": True}),
252  ("TrackHitFilter", "Tracker", {"method": "load"}),
253  ("TrackFitter", "HitFilteredTracks", {"method": "import"})]
254  options["TrackSelector"]["Alignment"].update(
255  options["TrackSelector"]["HighPurity"])
256  elif cosmicTrackSplitting:
257  mods = [("TrackRefitter", "First", {"method": "load",
258  "clone": True}),
259  ("TrackSelector", "Alignment", {"method": "load"}),
260  ("TrackSplitting", "TrackSplitting", {"method": "load"}),
261  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
262  ("TrackRefitter", "Second", {"method": "load",
263  "clone": True})]
264  else:
265  mods = [("TrackSelector", "HighPurity", {"method": "import"}),
266  ("TrackRefitter", "First", {"method": "load",
267  "clone": True}),
268  ("TrackHitFilter", "Tracker", {"method": "load"}),
269  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
270  ("TrackSelector", "Alignment", {"method": "load"}),
271  ("TrackRefitter", "Second", {"method": "load",
272  "clone": True})]
273  if isCosmics: mods = mods[1:] # skip high purity selector for cosmics
274 
275 
276  ################################
277  ## apply momentum constraint? ##
278  ################################
279 
280  if momentumConstraint is not None:
281  for mod in options["TrackRefitter"]:
282  momconstrspecs = momentumConstraint.split(',')
283  if len(momconstrspecs)==1:
284  options["TrackRefitter"][mod].update({
285  "constraint": "momentum",
286  "srcConstr": momconstrspecs[0]
287  })
288  else:
289  options["TrackRefitter"][mod].update({
290  "constraint": momconstrspecs[1],
291  "srcConstr": momconstrspecs[0]
292  })
293 
294 
295 
296  #######################################################
297  # load offline beam spot module required by the refit #
298  #######################################################
299  process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
300 
301 
302 
303  ###############################
304  ## put the sequence together ##
305  ###############################
306 
307  modules = []
308  src = collection
309  prevsrc = None
310  for mod in mods[:-1]:
311  src, prevsrc = _getModule(process, src, mod[0], "".join(reversed(mod[:-1])),
312  options[mod[0]][mod[1]], isCosmics = isCosmics, prevsrc = prevsrc,
313  **(mod[2])), src
314  modules.append(getattr(process, src))
315  else:
316  if mods[-1][-1]["method"] is "load" and \
317  not mods[-1][-1].get("clone", False):
318  print "Name of the last module needs to be modifiable."
319  sys.exit(1)
320  src = _getModule(process, src, mods[-1][0], "FinalTrackRefitter",
321  options[mods[-1][0]][mods[-1][1]],
322  isCosmics = isCosmics, **(mods[-1][2]))
323  modules.append(getattr(process, src))
324 
325  moduleSum = process.offlineBeamSpot # first element of the sequence
326  for module in modules:
327  # Spply srcConstr fix here
328  if hasattr(module,"srcConstr"):
329  strSrcConstr = module.srcConstr.getModuleLabel()
330  if strSrcConstr:
331  procsrcconstr = getattr(process,strSrcConstr)
332  if procsrcconstr.src != module.src:
333  module.srcConstr=''
334  module.constraint=''
335  else:
336  moduleSum += procsrcconstr
337 
338  moduleSum += module # append the other modules
339 
340  return cms.Sequence(moduleSum)
341 
342 
343 
344 
345 
346 ###############################
347 ###############################
348 ### ###
349 ### Auxiliary functions ###
350 ### ###
351 ###############################
352 ###############################
353 
354 
355 def _getModule(process, src, modType, moduleName, options, **kwargs):
356  """General function for attaching the module of type `modType` to the
357  cms.Process `process` using `options` for customization and `moduleName` as
358  the name of the new attribute of `process`.
359 
360  Arguments:
361  - `process`: 'cms.Process' object to which the module is attached.
362  - `src`: cms.InputTag for this module.
363  - `modType`: Type of the requested module.
364  - `options`: Dictionary with customized values for the module's options.
365  - `**kwargs`: Used to supply options at construction time of the module.
366  """
367 
368  objTuple = globals()["_"+modType](kwargs)
369  method = kwargs.get("method")
370  if method == "import":
371  __import__(objTuple[0])
372  obj = getattr(sys.modules[objTuple[0]], objTuple[1]).clone()
373  elif method == "load":
374  process.load(objTuple[0])
375  if kwargs.get("clone", False):
376  obj = getattr(process, objTuple[1]).clone(src=src)
377  else:
378  obj = getattr(process, objTuple[1])
379  moduleName = objTuple[1]
380  else:
381  print "Unknown method:", method
382  sys.exit(1)
383 
384  if modType == "TrackSplitting":
385  #track splitting takes the TrackSelector as tracks
386  # and the first TrackRefitter as tjTkAssociationMapTag
387  _customSetattr(obj, "tracks", src)
388  _customSetattr(obj, "tjTkAssociationMapTag", kwargs["prevsrc"])
389  else:
390  obj.src = src
391 
392  for option in options:
393  _customSetattr(obj, option, options[option])
394 
395  if moduleName is not objTuple[1]:
396  setattr(process, moduleName, obj)
397  return moduleName
398 
399 
400 def _TrackHitFilter(kwargs):
401  """Returns TrackHitFilter module name.
402 
403  Arguments:
404  - `kwargs`: Not used in this function.
405  """
406 
407  return ("RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
408  "TrackerTrackHitFilter")
409 
410 
411 def _TrackSelector(kwargs):
412  """Returns TrackSelector module name.
413 
414  Arguments:
415  - `kwargs`: Not used in this function.
416  """
417 
418  return ("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
419  "AlignmentTrackSelector")
420 
421 
422 def _TrackFitter(kwargs):
423  """Returns TrackFitter module name.
424 
425  Arguments:
426  - `kwargs`: Used to supply options at construction time of the object.
427  """
428 
429  isCosmics = kwargs.get("isCosmics", False)
430  if isCosmics:
431  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
432  "ctfWithMaterialTracksCosmics")
433  else:
434  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
435  "ctfWithMaterialTracks")
436 
437 
438 def _TrackRefitter(kwargs):
439  """Returns TrackRefitter module name.
440 
441  Arguments:
442  - `kwargs`: Used to supply options at construction time of the object.
443  """
444 
445  isCosmics = kwargs.get("isCosmics", False)
446  if isCosmics:
447  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
448  "TrackRefitterP5")
449  else:
450  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
451  "TrackRefitter")
452 
453 def _TrackSplitting(kwargs):
454  return ("RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
455  "cosmicTrackSplitter")
456 
457 
458 def _customSetattr(obj, attr, val):
459  """Sets the attribute `attr` of the object `obj` using the value `val`.
460  `attr` can be a string or a tuple of strings, if one wants to set an
461  attribute of an attribute, etc.
462 
463  Arguments:
464  - `obj`: Object, which must have a '__dict__' attribute.
465  - `attr`: String or tuple of strings describing the attribute's name.
466  - `val`: value of the attribute.
467  """
468 
469  if type(attr) is tuple and len(attr) > 1:
470  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
471  else:
472  if type(attr) is tuple: attr = attr[0]
473  setattr(obj, attr, val)
474 
def _customSetattr(obj, attr, val)
def getSequence(process, collection, saveCPU=False, TTRHBuilder="WithAngleAndTemplate", usePixelQualityFlag=None, openMassWindow=False, cosmicsDecoMode=False, cosmicsZeroTesla=True, momentumConstraint=None, cosmicTrackSplitting=False, use_d0cut=True)
def _getModule(process, src, modType, moduleName, options, kwargs)
Auxiliary functions ###
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