test
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":
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 == "ALCARECOTkAlCosmicsCTF0T":
105  isCosmics = True
106  options["TrackSelector"]["HighPurity"] = {} # drop high purity cut
107  if not cosmicsDecoMode:
108  options["TrackHitFilter"]["Tracker"].update({
109  "StoNcommands": cms.vstring("ALL 18.0")
110  })
111  if cosmicsZeroTesla:
112  options["TrackHitFilter"]["Tracker"].update({
113  "TrackAngleCut": 0.1 # Run-I: 0.087 for 0T
114  })
115  else:
116  options["TrackHitFilter"]["Tracker"].update({
117  "TrackAngleCut": 0.1 # Run-I: 0.35 for 3.8T
118  })
119  options["TrackSelector"]["Alignment"].update({
120  "pMin": 4.0,
121  "etaMin": -99.0,
122  "etaMax": 99.0,
123  "applyMultiplicityFilter": True,
124  "maxMultiplicity": 1
125  })
126  elif collection == "ALCARECOTkAlMuonIsolated":
127  options["TrackSelector"]["Alignment"].update({
128  ("minHitsPerSubDet", "inPIXEL"): 1,
129  "ptMin": 5.0,
130  "nHitMin": 10,
131  "applyMultiplicityFilter": True,
132  "maxMultiplicity": 1,
133  })
134  elif collection == "ALCARECOTkAlZMuMu":
135  options["TrackSelector"]["Alignment"].update({
136  "ptMin": 15.0,
137  "etaMin": -3.0,
138  "etaMax": 3.0,
139  "nHitMin": 10,
140  "applyMultiplicityFilter": True,
141  "minMultiplicity": 2,
142  "maxMultiplicity": 2,
143  ("minHitsPerSubDet", "inPIXEL"): 1,
144  ("TwoBodyDecaySelector", "applyChargeFilter"): True,
145  ("TwoBodyDecaySelector", "charge"): 0,
146  ("TwoBodyDecaySelector",
147  "applyMassrangeFilter"): not openMassWindow,
148  ("TwoBodyDecaySelector", "minXMass"): 85.8,
149  ("TwoBodyDecaySelector", "maxXMass"): 95.8,
150  ("TwoBodyDecaySelector", "daughterMass"): 0.105
151  })
152  options["TrackHitFilter"]["Tracker"].update({
153  "minimumHits": 10,
154  })
155  pass
156  else:
157  print "Unknown input track collection:", collection
158  sys.exit(1)
159 
160 
161 
162  ####################
163  ## save CPU time? ##
164  ####################
165 
166  if saveCPU:
167  mods = [("TrackSelector", "Alignment", {"method": "load"}),
168  ("TrackRefitter", "First", {"method": "load",
169  "clone": True}),
170  ("TrackHitFilter", "Tracker", {"method": "load"}),
171  ("TrackFitter", "HitFilteredTracks", {"method": "import"})]
172  options["TrackSelector"]["Alignment"].update(
173  options["TrackSelector"]["HighPurity"])
174  else:
175  mods = [("TrackSelector", "HighPurity", {"method": "import"}),
176  ("TrackRefitter", "First", {"method": "load",
177  "clone": True}),
178  ("TrackHitFilter", "Tracker", {"method": "load"}),
179  ("TrackFitter", "HitFilteredTracks", {"method": "import"}),
180  ("TrackSelector", "Alignment", {"method": "load"}),
181  ("TrackRefitter", "Second", {"method": "load",
182  "clone": True})]
183  if isCosmics: mods = mods[1:]
184 
185 
186 
187  ################################
188  ## apply momentum constraint? ##
189  ################################
190 
191  if momentumConstraint is not None:
192  for mod in options["TrackRefitter"]:
193  options["TrackRefitter"][mod].update({
194  "constraint": "momentum",
195  "srcConstr": momentumConstraint
196  })
197 
198 
199 
200  ###############################
201  ## put the sequence together ##
202  ###############################
203 
204  modules = []
205  src = collection
206  for mod in mods[:-1]:
207  src = _getModule(process, src, mod[0], "".join(reversed(mod[:-1])),
208  options[mod[0]][mod[1]], isCosmics = isCosmics,
209  **(mod[2]))
210  modules.append(getattr(process, src))
211  else:
212  if mods[-1][-1]["method"] is "load" and \
213  not mods[-1][-1].get("clone", False):
214  print "Name of the last module needs to be modifiable."
215  sys.exit(1)
216  src = _getModule(process, src, mods[-1][0], "FinalTrackRefitter",
217  options[mods[-1][0]][mods[-1][1]],
218  isCosmics = isCosmics, **(mods[-1][2]))
219  modules.append(getattr(process, src))
220 
221  moduleSum = modules[0]
222  for mod in modules[1:]:
223  moduleSum += mod
224  return cms.Sequence(moduleSum)
225 
226 
227 
228 
229 
230 ###############################
231 ###############################
232 ### ###
233 ### Auxiliary functions ###
234 ### ###
235 ###############################
236 ###############################
237 
238 
239 def _getModule(process, src, modType, moduleName, options, **kwargs):
240  """General function for attaching the module of type `modType` to the
241  cms.Process `process` using `options` for customization and `moduleName` as
242  the name of the new attribute of `process`.
243 
244  Arguments:
245  - `process`: 'cms.Process' object to which the module is attached.
246  - `src`: cms.InputTag for this module.
247  - `modType`: Type of the requested module.
248  - `options`: Dictionary with customized values for the module's options.
249  - `**kwargs`: Used to supply options at construction time of the module.
250  """
251 
252  objTuple = globals()["_"+modType](kwargs)
253  method = kwargs.get("method")
254  if method is "import":
255  __import__(objTuple[0])
256  obj = getattr(sys.modules[objTuple[0]], objTuple[1]).clone(src=src)
257  elif method is "load":
258  process.load(objTuple[0])
259  if kwargs.get("clone", False):
260  obj = getattr(process, objTuple[1]).clone(src=src)
261  else:
262  obj = getattr(process, objTuple[1])
263  obj.src = src
264  moduleName = objTuple[1]
265  else:
266  print "Unknown method:", method
267  sys.exit(1)
268 
269  for option in options:
270  _customSetattr(obj, option, options[option])
271 
272  if moduleName is not objTuple[1]:
273  setattr(process, moduleName, obj)
274  return moduleName
275 
276 
277 def _TrackHitFilter(kwargs):
278  """Returns TrackHitFilter module name.
279 
280  Arguments:
281  - `kwargs`: Not used in this function.
282  """
283 
284  return ("RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
285  "TrackerTrackHitFilter")
286 
287 
288 def _TrackSelector(kwargs):
289  """Returns TrackSelector module name.
290 
291  Arguments:
292  - `kwargs`: Not used in this function.
293  """
294 
295  return ("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
296  "AlignmentTrackSelector")
297 
298 
299 def _TrackFitter(kwargs):
300  """Returns TrackFitter module name.
301 
302  Arguments:
303  - `kwargs`: Used to supply options at construction time of the object.
304  """
305 
306  isCosmics = kwargs.get("isCosmics", False)
307  if isCosmics:
308  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
309  "ctfWithMaterialTracksCosmics")
310  else:
311  return ("RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
312  "ctfWithMaterialTracks")
313 
314 
315 def _TrackRefitter(kwargs):
316  """Returns TrackRefitter module name.
317 
318  Arguments:
319  - `kwargs`: Used to supply options at construction time of the object.
320  """
321 
322  isCosmics = kwargs.get("isCosmics", False)
323  if isCosmics:
324  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
325  "TrackRefitterP5")
326  else:
327  return ("RecoTracker.TrackProducer.TrackRefitters_cff",
328  "TrackRefitter")
329 
330 
331 def _customSetattr(obj, attr, val):
332  """Sets the attribute `attr` of the object `obj` using the value `val`.
333  `attr` can be a string or a tuple of strings, if one wants to set an
334  attribute of an attribute, etc.
335 
336  Arguments:
337  - `obj`: Object, which must have a '__dict__' attribute.
338  - `attr`: String or tuple of strings describing the attribute's name.
339  - `val`: value of the attribute.
340  """
341 
342  if type(attr) is tuple and len(attr) > 1:
343  _customSetattr(getattr(obj, attr[0]), attr[1:], val)
344  else:
345  if type(attr) is tuple: attr = attr[0]
346  setattr(obj, attr, val)
347 
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