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