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