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