CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 = True,
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  optionial 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  - `openMassWindow`: Used to configure the TwoBodyDecaySelector for ZMuMu.
31  - `cosmicsDecoMode`: If set to 'True' a lower Signal/Noise cut is used.
32  - `cosmicsZeroTesla`: If set to 'True' a 0T-specific selection is used.
33  - `momentumConstraint`: If you want to apply a momentum constraint for the
34  track refitting, e.g. for CRUZET data, you need
35  to provide here the name of the constraint module.
36  """
37 
38 
39  #############################
40  ## setting general options ##
41  #############################
42 
43  options = {"TrackHitFilter": {},
44  "TrackFitter": {},
45  "TrackRefitter": {},
46  "TrackSelector": {}}
47 
48  options["TrackSelector"]["HighPurity"] = {
49  "trackQualities": ["highPurity"],
50  "filter": True,
51  "etaMin": -3.0,
52  "etaMax": 3.0,
53  "pMin": 8.0
54  }
55  options["TrackSelector"]["Alignment"] = {
56  "filter": True,
57  "pMin": 3.0,
58  "nHitMin2D": 2,
59  "d0Min": -50.0,
60  "d0Max": 50.0,
61  "etaMin": -3.0,
62  "etaMax": 3.0,
63  "nHitMin": 8,
64  "chi2nMax": 9999.0
65  }
66  options["TrackRefitter"]["First"] = {
67  "NavigationSchool": "",
68  }
69  options["TrackRefitter"]["Second"] = {
70  "NavigationSchool": "",
71  "TTRHBuilder": TTRHBuilder
72  }
73  options["TrackHitFilter"]["Tracker"] = {
74  "useTrajectories": True,
75  "minimumHits": 8,
76  "commands": cms.vstring("keep PXB", "keep PXE", "keep TIB", "keep TID",
77  "keep TOB", "keep TEC"),
78  "replaceWithInactiveHits": True,
79  "rejectBadStoNHits": True,
80  "rejectLowAngleHits": True,
81  "usePixelQualityFlag": usePixelQualityFlag,
82  "StoNcommands": cms.vstring("ALL 12.0"),
83  "TrackAngleCut": 0.087
84  }
85  options["TrackFitter"]["HitFilteredTracks"] = {
86  "NavigationSchool": "",
87  "TTRHBuilder": TTRHBuilder
88  }
89 
90 
91  #########################################
92  ## setting collection specific options ##
93  #########################################
94  isCosmics = False
95 
96  if collection == "ALCARECOTkAlMinBias" or collection == "generalTracks" or collection == "ALCARECOTkAlMinBiasHI" or collection == "hiGeneralTracks":
97  options["TrackSelector"]["Alignment"].update({
98  "ptMin": 1.0,
99  "pMin": 8.,
100  })
101  options["TrackHitFilter"]["Tracker"].update({
102  "minimumHits": 10,
103  })
104  elif collection in ("ALCARECOTkAlCosmicsCTF0T",
105  "ALCARECOTkAlCosmicsInCollisions"):
106  isCosmics = True
107  options["TrackSelector"]["HighPurity"] = {} # drop high purity cut
108  if not cosmicsDecoMode:
109  options["TrackHitFilter"]["Tracker"].update({
110  "StoNcommands": cms.vstring("ALL 18.0")
111  })
112  if cosmicsZeroTesla:
113  options["TrackHitFilter"]["Tracker"].update({
114  "TrackAngleCut": 0.1 # Run-I: 0.087 for 0T
115  })
116  else:
117  options["TrackHitFilter"]["Tracker"].update({
118  "TrackAngleCut": 0.1 # Run-I: 0.35 for 3.8T
119  })
120  options["TrackSelector"]["Alignment"].update({
121  "pMin": 4.0,
122  "etaMin": -99.0,
123  "etaMax": 99.0,
124  "applyMultiplicityFilter": True,
125  "maxMultiplicity": 1
126  })
127  elif collection == "ALCARECOTkAlMuonIsolated" or collection == "ALCARECOTkAlMuonIsolatedHI" or collection == "ALCARECOTkAlMuonIsolatedPA":
128  options["TrackSelector"]["Alignment"].update({
129  ("minHitsPerSubDet", "inPIXEL"): 1,
130  "ptMin": 5.0,
131  "nHitMin": 10,
132  "applyMultiplicityFilter": True,
133  "maxMultiplicity": 1,
134  })
135  elif collection == "ALCARECOTkAlZMuMu" or collection == "ALCARECOTkAlZMuMuHI" or collection == "ALCARECOTkAlZMuMuPA":
136  options["TrackSelector"]["Alignment"].update({
137  "ptMin": 15.0,
138  "etaMin": -3.0,
139  "etaMax": 3.0,
140  "nHitMin": 10,
141  "applyMultiplicityFilter": True,
142  "minMultiplicity": 2,
143  "maxMultiplicity": 2,
144  ("minHitsPerSubDet", "inPIXEL"): 1,
145  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
146  ("TwoBodyDecaySelector", "charge"): 0,
147  ("TwoBodyDecaySelector",
148  "applyMassrangeFilter"): not openMassWindow,
149  ("TwoBodyDecaySelector", "minXMass"): 85.8,
150  ("TwoBodyDecaySelector", "maxXMass"): 95.8,
151  ("TwoBodyDecaySelector", "daughterMass"): 0.105
152  })
153  options["TrackHitFilter"]["Tracker"].update({
154  "minimumHits": 10,
155  })
156  pass
157  else:
158  print "Unknown input track collection:", collection
159  sys.exit(1)
160 
161 
162 
163  ####################
164  ## save CPU time? ##
165  ####################
166 
167  if saveCPU:
168  mods = [("TrackSelector", "Alignment", {"method": "load"}),
169  ("TrackRefitter", "First", {"method": "load",
170  "clone": True}),
171  ("TrackHitFilter", "Tracker", {"method": "load"}),
172  ("TrackFitter", "HitFilteredTracks", {"method": "import"})]
173  options["TrackSelector"]["Alignment"].update(
174  options["TrackSelector"]["HighPurity"])
175  else:
176  mods = [("TrackSelector", "HighPurity", {"method": "import"}),
177  ("TrackRefitter", "First", {"method": "load",
178  "clone": True}),
179  ("TrackHitFilter", "Tracker", {"method": "load"}),
180  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
181  ("TrackSelector", "Alignment", {"method": "load"}),
182  ("TrackRefitter", "Second", {"method": "load",
183  "clone": True})]
184  if isCosmics: mods = mods[1:]
185 
186 
187 
188  ################################
189  ## apply momentum constraint? ##
190  ################################
191 
192  if momentumConstraint is not None:
193  for mod in options["TrackRefitter"]:
194  options["TrackRefitter"][mod].update({
195  "constraint": "momentum",
196  "srcConstr": momentumConstraint
197  })
198 
199 
200 
201  ###############################
202  ## put the sequence together ##
203  ###############################
204 
205  modules = []
206  src = collection
207  for mod in mods[:-1]:
208  src = _getModule(process, src, mod[0], "".join(reversed(mod[:-1])),
209  options[mod[0]][mod[1]], isCosmics = isCosmics,
210  **(mod[2]))
211  modules.append(getattr(process, src))
212  else:
213  if mods[-1][-1]["method"] is "load" and \
214  not mods[-1][-1].get("clone", False):
215  print "Name of the last module needs to be modifiable."
216  sys.exit(1)
217  src = _getModule(process, src, mods[-1][0], "FinalTrackRefitter",
218  options[mods[-1][0]][mods[-1][1]],
219  isCosmics = isCosmics, **(mods[-1][2]))
220  modules.append(getattr(process, src))
221 
222  moduleSum = modules[0]
223  for mod in modules[1:]:
224  moduleSum += mod
225  return cms.Sequence(moduleSum)
226 
227 
228 
229 
230 
231 ###############################
232 ###############################
233 ### ###
234 ### Auxiliary functions ###
235 ### ###
236 ###############################
237 ###############################
238 
239 
240 def _getModule(process, src, modType, moduleName, options, **kwargs):
241  """General function for attaching the module of type `modType` to the
242  cms.Process `process` using `options` for customization and `moduleName` as
243  the name of the new attribute of `process`.
244 
245  Arguments:
246  - `process`: 'cms.Process' object to which the module is attached.
247  - `src`: cms.InputTag for this module.
248  - `modType`: Type of the requested module.
249  - `options`: Dictionary with customized values for the module's options.
250  - `**kwargs`: Used to supply options at construction time of the module.
251  """
252 
253  objTuple = globals()["_"+modType](kwargs)
254  method = kwargs.get("method")
255  if method is "import":
256  __import__(objTuple[0])
257  obj = getattr(sys.modules[objTuple[0]], objTuple[1]).clone(src=src)
258  elif method is "load":
259  process.load(objTuple[0])
260  if kwargs.get("clone", False):
261  obj = getattr(process, objTuple[1]).clone(src=src)
262  else:
263  obj = getattr(process, objTuple[1])
264  obj.src = src
265  moduleName = objTuple[1]
266  else:
267  print "Unknown method:", method
268  sys.exit(1)
269 
270  for option in options:
271  _customSetattr(obj, option, options[option])
272 
273  if moduleName is not objTuple[1]:
274  setattr(process, moduleName, obj)
275  return moduleName
276 
277 
278 def _TrackHitFilter(kwargs):
279  """Returns TrackHitFilter module name.
280 
281  Arguments:
282  - `kwargs`: Not used in this function.
283  """
284 
285  return ("RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
286  "TrackerTrackHitFilter")
287 
288 
289 def _TrackSelector(kwargs):
290  """Returns TrackSelector module name.
291 
292  Arguments:
293  - `kwargs`: Not used in this function.
294  """
295 
296  return ("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
297  "AlignmentTrackSelector")
298 
299 
300 def _TrackFitter(kwargs):
301  """Returns TrackFitter module name.
302 
303  Arguments:
304  - `kwargs`: Used to supply options at construction time of the object.
305  """
306 
307  isCosmics = kwargs.get("isCosmics", False)
308  if isCosmics:
309  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
310  "ctfWithMaterialTracksCosmics")
311  else:
312  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
313  "ctfWithMaterialTracks")
314 
315 
316 def _TrackRefitter(kwargs):
317  """Returns TrackRefitter module name.
318 
319  Arguments:
320  - `kwargs`: Used to supply options at construction time of the object.
321  """
322 
323  isCosmics = kwargs.get("isCosmics", False)
324  if isCosmics:
325  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
326  "TrackRefitterP5")
327  else:
328  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
329  "TrackRefitter")
330 
331 
332 def _customSetattr(obj, attr, val):
333  """Sets the attribute `attr` of the object `obj` using the value `val`.
334  `attr` can be a string or a tuple of strings, if one wants to set an
335  attribute of an attribute, etc.
336 
337  Arguments:
338  - `obj`: Object, which must have a '__dict__' attribute.
339  - `attr`: String or tuple of strings describing the attribute's name.
340  - `val`: value of the attribute.
341  """
342 
343  if type(attr) is tuple and len(attr) > 1:
344  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
345  else:
346  if type(attr) is tuple: attr = attr[0]
347  setattr(obj, attr, val)
348 
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)
def _getModule
### Auxiliary functions ###
T get(const Candidate &c)
Definition: component.h:55