1 from __future__
import print_function
3 import FWCore.ParameterSet.Config
as cms
7 TTRHBuilder = "WithAngleAndTemplate",
8 usePixelQualityFlag = None,
9 openMassWindow = False,
10 cosmicsDecoMode = False,
11 cosmicsZeroTesla = True,
12 momentumConstraint = None,
13 cosmicTrackSplitting = False,
14 isPVValidation = False,
17 """This function returns a cms.Sequence containing as last element the 18 module 'FinalTrackRefitter', which can be used as cms.InputTag for 19 subsequent processing steps. 20 The modules in the sequence are already attached to the given `process` 21 object using the given track collection `collection` and the given 25 - `process`: 'cms.Process' object to which the modules of the sequence will 27 - `collection`: String indicating the input track collection. 28 - `saveCPU`: If set to 'True', some steps are merged to reduce CPU time. 29 Reduces a little the accuracy of the results. 30 This option is currently not recommended. 31 - `TTRHBuilder`: Option used for the Track(Re)Fitter modules. 32 - `usePixelQualityFlag`: Option used for the TrackHitFilter module. 33 Defaults to 'True' but is automatically set to 34 'False' if a `TTRHBuilder` without templates is 36 If this is still wanted for some reason, one can 37 explicitely specify it as 'True'. 38 - `openMassWindow`: Used to configure the TwoBodyDecaySelector for ZMuMu. 39 - `cosmicsDecoMode`: If set to 'True' a lower Signal/Noise cut is used. 40 - `cosmicsZeroTesla`: If set to 'True' a 0T-specific selection is used. 41 - `momentumConstraint`: If you want to apply a momentum constraint for the 42 track refitting, e.g. for CRUZET data, you need 43 to provide here the name of the constraint module. 44 - `cosmicTrackSplitting`: If set to 'True' cosmic tracks are split before the 45 second track refitter. 46 - `isPVValidation`: If set to 'True' most of the selection cuts are overridden 47 to allow unbiased selection of tracks for vertex refitting 48 - `use_d0cut`: If 'True' (default), apply a cut |d0| < 50. 55 print(
"g4Refitting=",g4Refitting)
57 if usePixelQualityFlag
is None:
58 if "Template" not in TTRHBuilder:
59 usePixelQualityFlag =
False 60 print(
"Using 'TTRHBuilder' without templates:", TTRHBuilder)
61 print(
" --> Turning off pixel quality flag in hit filter.")
63 usePixelQualityFlag =
True 70 options = {
"TrackHitFilter": {},
76 options[
"TrackSelector"][
"HighPurity"] = {
77 "trackQualities": [
"highPurity"],
83 options[
"TrackSelector"][
"Alignment"] = {
94 options[
"TrackRefitter"][
"First"] = {
95 "NavigationSchool":
"",
96 "TTRHBuilder": TTRHBuilder,
98 options[
"TrackRefitter"][
"Second"] = {
99 "NavigationSchool":
"",
100 "TTRHBuilder": TTRHBuilder,
102 options[
"TrackHitFilter"][
"Tracker"] = {
103 "useTrajectories":
True,
105 "commands": cms.vstring(
"keep PXB",
"keep PXE",
"keep TIB",
"keep TID",
106 "keep TOB",
"keep TEC"),
107 "replaceWithInactiveHits":
True,
108 "rejectBadStoNHits":
True,
109 "rejectLowAngleHits":
True,
110 "usePixelQualityFlag": usePixelQualityFlag,
111 "StoNcommands": cms.vstring(
"ALL 12.0"),
112 "TrackAngleCut": 0.087,
114 options[
"TrackFitter"][
"HitFilteredTracks"] = {
115 "NavigationSchool":
"",
116 "TTRHBuilder": TTRHBuilder,
118 options[
"geopro"][
""] = {
122 options[
"TrackRefitter"][
"Second"] = {
123 "AlgorithmName" : cms.string(
'undefAlgorithm'),
124 "Fitter" : cms.string(
'G4eFitterSmoother'),
125 "GeometricInnerState" : cms.bool(
False),
126 "MeasurementTracker" : cms.string(
''),
127 "MeasurementTrackerEvent" : cms.InputTag(
"MeasurementTrackerEvent"),
128 "NavigationSchool" : cms.string(
'SimpleNavigationSchool'),
129 "Propagator" : cms.string(
'Geant4ePropagator'),
130 "TTRHBuilder" : cms.string(
'WithAngleAndTemplate'),
131 "TrajectoryInEvent" : cms.bool(
True),
132 "beamSpot" : cms.InputTag(
"offlineBeamSpot"),
133 "constraint" : cms.string(
''),
134 "src" : cms.InputTag(
"AlignmentTrackSelector"),
135 "srcConstr" : cms.InputTag(
""),
136 "useHitsSplitting" : cms.bool(
False),
137 "usePropagatorForPCA" : cms.bool(
True)
145 if collection
in (
"ALCARECOTkAlMinBias",
"generalTracks",
146 "ALCARECOTkAlMinBiasHI",
"hiGeneralTracks",
147 "ALCARECOTkAlJetHT",
"ALCARECOTkAlDiMuonVertexTracks"):
148 options[
"TrackSelector"][
"Alignment"].
update({
152 options[
"TrackHitFilter"][
"Tracker"].
update({
155 elif collection
in (
"ALCARECOTkAlCosmicsCTF0T",
156 "ALCARECOTkAlCosmicsInCollisions"):
158 options[
"TrackSelector"][
"HighPurity"] = {}
159 if not cosmicsDecoMode:
160 options[
"TrackHitFilter"][
"Tracker"].
update({
161 "StoNcommands": cms.vstring(
"ALL 18.0")
164 options[
"TrackHitFilter"][
"Tracker"].
update({
168 options[
"TrackHitFilter"][
"Tracker"].
update({
171 options[
"TrackSelector"][
"Alignment"].
update({
175 "applyMultiplicityFilter":
True,
178 if cosmicTrackSplitting:
179 options[
"TrackSplitting"] = {}
180 options[
"TrackSplitting"][
"TrackSplitting"] = {}
182 options[
"TrackSelector"][
"Alignment"].
update({
186 elif collection
in (
"ALCARECOTkAlMuonIsolated",
187 "ALCARECOTkAlMuonIsolatedHI",
188 "ALCARECOTkAlMuonIsolatedPA"):
189 options[
"TrackSelector"][
"Alignment"].
update({
190 (
"minHitsPerSubDet",
"inPIXEL"): 1,
193 "applyMultiplicityFilter":
True,
194 "maxMultiplicity": 1,
196 elif collection
in (
"ALCARECOTkAlZMuMu",
197 "ALCARECOTkAlZMuMuHI",
198 "ALCARECOTkAlZMuMuPA",
199 "ALCARECOTkAlDiMuon"):
200 options[
"TrackSelector"][
"Alignment"].
update({
205 "applyMultiplicityFilter":
True,
206 "minMultiplicity": 2,
207 "maxMultiplicity": 2,
208 (
"minHitsPerSubDet",
"inPIXEL"): 1,
209 (
"TwoBodyDecaySelector",
"applyChargeFilter"):
True,
210 (
"TwoBodyDecaySelector",
"charge"): 0,
211 (
"TwoBodyDecaySelector",
212 "applyMassrangeFilter"):
not openMassWindow,
213 (
"TwoBodyDecaySelector",
"minXMass"): 85.8,
214 (
"TwoBodyDecaySelector",
"maxXMass"): 95.8,
215 (
"TwoBodyDecaySelector",
"daughterMass"): 0.105
217 options[
"TrackHitFilter"][
"Tracker"].
update({
220 elif collection ==
"ALCARECOTkAlUpsilonMuMu":
221 options[
"TrackSelector"][
"Alignment"].
update({
226 "applyMultiplicityFilter":
True,
227 "minMultiplicity": 2,
228 "maxMultiplicity": 2,
229 (
"minHitsPerSubDet",
"inPIXEL"): 1,
230 (
"TwoBodyDecaySelector",
"applyChargeFilter"):
True,
231 (
"TwoBodyDecaySelector",
"charge"): 0,
232 (
"TwoBodyDecaySelector",
233 "applyMassrangeFilter"):
not openMassWindow,
234 (
"TwoBodyDecaySelector",
"minXMass"): 9.2,
235 (
"TwoBodyDecaySelector",
"maxXMass"): 9.7,
236 (
"TwoBodyDecaySelector",
"daughterMass"): 0.105
238 options[
"TrackHitFilter"][
"Tracker"].
update({
241 elif collection ==
"ALCARECOTkAlJpsiMuMu":
242 options[
"TrackSelector"][
"Alignment"].
update({
247 "applyMultiplicityFilter":
True,
248 "minMultiplicity": 2,
249 "maxMultiplicity": 2,
250 (
"minHitsPerSubDet",
"inPIXEL"): 1,
251 (
"TwoBodyDecaySelector",
"applyChargeFilter"):
True,
252 (
"TwoBodyDecaySelector",
"charge"): 0,
253 (
"TwoBodyDecaySelector",
254 "applyMassrangeFilter"):
not openMassWindow,
255 (
"TwoBodyDecaySelector",
"minXMass"): 2.7,
256 (
"TwoBodyDecaySelector",
"maxXMass"): 3.4,
257 (
"TwoBodyDecaySelector",
"daughterMass"): 0.105
259 options[
"TrackHitFilter"][
"Tracker"].
update({
263 raise ValueError(
"Unknown input track collection: {}".
format(collection))
265 if cosmicTrackSplitting
and not isCosmics:
266 raise ValueError(
"Can only do cosmic track splitting for cosmics.")
275 if cosmicTrackSplitting:
276 raise ValueError(
"Can't turn on both saveCPU and cosmicTrackSplitting at the same time")
277 mods = [(
"TrackSelector",
"Alignment", {
"method":
"load"}),
278 (
"TrackRefitter",
"First", {
"method":
"load",
280 (
"TrackHitFilter",
"Tracker", {
"method":
"load"}),
281 (
"TrackFitter",
"HitFilteredTracks", {
"method":
"import"})]
282 options[
"TrackSelector"][
"Alignment"].
update(
283 options[
"TrackSelector"][
"HighPurity"])
284 elif cosmicTrackSplitting:
285 mods = [(
"TrackRefitter",
"First", {
"method":
"load",
287 (
"TrackSelector",
"Alignment", {
"method":
"load"}),
288 (
"TrackSplitting",
"TrackSplitting", {
"method":
"load"}),
289 (
"TrackFitter",
"HitFilteredTracks", {
"method":
"import"}),
290 (
"TrackRefitter",
"Second", {
"method":
"load",
293 mods = [(
"TrackSelector",
"HighPurity", {
"method":
"import"}),
294 (
"TrackRefitter",
"First", {
"method":
"load",
296 (
"TrackHitFilter",
"Tracker", {
"method":
"load"}),
297 (
"TrackFitter",
"HitFilteredTracks", {
"method":
"import"}),
298 (
"TrackSelector",
"Alignment", {
"method":
"load"}),
300 (
"TrackRefitter",
"Second", {
"method":
"load",
302 if isCosmics: mods = mods[1:]
304 mods = [(
"TrackSelector",
"HighPurity", {
"method":
"import"}),
305 (
"TrackRefitter",
"First", {
"method":
"load",
307 (
"TrackHitFilter",
"Tracker", {
"method":
"load"}),
308 (
"TrackFitter",
"HitFilteredTracks", {
"method":
"import"}),
309 (
"TrackSelector",
"Alignment", {
"method":
"load"}),
310 (
"TrackRefitter",
"Second", {
"method":
"load",
312 if isCosmics: mods = mods[1:]
319 options[
"TrackSelector"][
"HighPurity"].
update({
320 "trackQualities": [],
323 options[
"TrackSelector"][
"Alignment"].
update({
338 if momentumConstraint
is not None:
339 for mod
in options[
"TrackRefitter"]:
340 momconstrspecs = momentumConstraint.split(
',')
341 if len(momconstrspecs)==1:
342 options[
"TrackRefitter"][mod].
update({
343 "constraint":
"momentum",
344 "srcConstr": momconstrspecs[0]
347 options[
"TrackRefitter"][mod].
update({
348 "constraint": momconstrspecs[1],
349 "srcConstr": momconstrspecs[0]
357 process.load(
"RecoVertex.BeamSpotProducer.BeamSpot_cff")
363 if "Fast" in TTRHBuilder:
364 print(
"PixelCPEFast has been chosen, here we must include CUDAService first")
365 process.load(
'HeterogeneousCore.CUDAServices.CUDAService_cfi')
370 for mod
in mods[:-1]:
371 src, prevsrc =
_getModule(process, src, mod[0],
"".
join(reversed(mod[:-1])),
372 options[mod[0]][mod[1]], isCosmics = isCosmics, prevsrc = prevsrc,
374 modules.append(getattr(process, src))
376 if mods[-1][-1][
"method"] ==
"load" and \
377 not mods[-1][-1].get(
"clone",
False):
378 print(
"Name of the last module needs to be modifiable.")
382 print(
"Here we must include geopro first")
383 process.load(
'Configuration.StandardSequences.GeometryDB_cff')
384 process.load(
"TrackPropagation.Geant4e.geantRefit_cff")
385 modules.append(getattr(process,
"geopro"))
387 src =
_getModule(process, src, mods[-1][0],
"FinalTrackRefitter",
388 options[mods[-1][0]][mods[-1][1]],
389 isCosmics = isCosmics, **(mods[-1][2]))
390 modules.append(getattr(process, src))
392 moduleSum = process.offlineBeamSpot
395 moduleSum += getattr(process,
"MeasurementTrackerEvent")
397 for module
in modules:
399 if hasattr(module,
"srcConstr"):
400 strSrcConstr = module.srcConstr.getModuleLabel()
402 procsrcconstr = getattr(process,strSrcConstr)
403 if hasattr(procsrcconstr,
"src"):
404 if procsrcconstr.src != module.src:
408 moduleSum += procsrcconstr
409 elif hasattr(procsrcconstr,
"srcTrk"):
410 if procsrcconstr.srcTrk != module.src:
414 procsrcconstrsrcvtx = getattr(process,procsrcconstr.srcVtx.getModuleLabel())
415 if type(procsrcconstrsrcvtx)
is cms.EDFilter:
416 procsrcconstrsrcvtxprefilter = getattr(process,procsrcconstrsrcvtx.src.getModuleLabel())
417 moduleSum += procsrcconstrsrcvtxprefilter
418 moduleSum += procsrcconstrsrcvtx
419 moduleSum += procsrcconstr
423 return cms.Sequence(moduleSum)
434 def _getModule(process, src, modType, moduleName, options, **kwargs):
435 """General function for attaching the module of type `modType` to the 436 cms.Process `process` using `options` for customization and `moduleName` as 437 the name of the new attribute of `process`. 440 - `process`: 'cms.Process' object to which the module is attached. 441 - `src`: cms.InputTag for this module. 442 - `modType`: Type of the requested module. 443 - `options`: Dictionary with customized values for the module's options. 444 - `**kwargs`: Used to supply options at construction time of the module. 447 objTuple = globals()[
"_"+modType](kwargs)
448 method = kwargs.get(
"method")
449 if method ==
"import":
450 __import__(objTuple[0])
451 obj = getattr(sys.modules[objTuple[0]], objTuple[1]).
clone()
452 elif method ==
"load":
453 process.load(objTuple[0])
454 if kwargs.get(
"clone",
False):
455 obj = getattr(process, objTuple[1]).
clone(src=src)
457 obj = getattr(process, objTuple[1])
458 moduleName = objTuple[1]
460 print(
"Unknown method:", method)
463 if modType ==
"TrackSplitting":
471 for option
in options:
474 if moduleName
is not objTuple[1]:
475 setattr(process, moduleName, obj)
480 """Returns TrackHitFilter module name. 483 - `kwargs`: Not used in this function. 486 return (
"RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
487 "TrackerTrackHitFilter")
491 """Returns TrackSelector module name. 494 - `kwargs`: Not used in this function. 497 return (
"Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
498 "AlignmentTrackSelector")
502 """Returns TrackFitter module name. 505 - `kwargs`: Used to supply options at construction time of the object. 508 isCosmics = kwargs.get(
"isCosmics",
False)
510 return (
"RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
511 "ctfWithMaterialTracksCosmics")
513 return (
"RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
514 "ctfWithMaterialTracks")
518 """Returns TrackRefitter module name. 521 - `kwargs`: Used to supply options at construction time of the object. 524 isCosmics = kwargs.get(
"isCosmics",
False)
526 return (
"RecoTracker.TrackProducer.TrackRefitters_cff",
529 return (
"RecoTracker.TrackProducer.TrackRefitters_cff",
533 return (
"RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
534 "cosmicTrackSplitter")
537 return (
"TrackPropagation.Geant4e.geantRefit_cff",
"geopro")
541 """Sets the attribute `attr` of the object `obj` using the value `val`. 542 `attr` can be a string or a tuple of strings, if one wants to set an 543 attribute of an attribute, etc. 546 - `obj`: Object, which must have a '__dict__' attribute. 547 - `attr`: String or tuple of strings describing the attribute's name. 548 - `val`: value of the attribute. 551 if isinstance(attr, tuple)
and len(attr) > 1:
554 if isinstance(attr, tuple): attr = attr[0]
555 setattr(obj, attr, val)
def _customSetattr(obj, attr, val)
def _TrackSplitting(kwargs)
def getSequence(process, collection, saveCPU=False, TTRHBuilder="WithAngleAndTemplate", usePixelQualityFlag=None, openMassWindow=False, cosmicsDecoMode=False, cosmicsZeroTesla=True, momentumConstraint=None, cosmicTrackSplitting=False, isPVValidation=False, use_d0cut=True, g4Refitting=False)
def _TrackSelector(kwargs)
def _getModule(process, src, modType, moduleName, options, kwargs)
Auxiliary functions ###
def _TrackRefitter(kwargs)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def _TrackHitFilter(kwargs)
static std::string join(char **cmd)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)