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")
366 for mod
in mods[:-1]:
367 src, prevsrc =
_getModule(process, src, mod[0],
"".
join(reversed(mod[:-1])),
368 options[mod[0]][mod[1]], isCosmics = isCosmics, prevsrc = prevsrc,
370 modules.append(getattr(process, src))
372 if mods[-1][-1][
"method"] ==
"load" and \
373 not mods[-1][-1].get(
"clone",
False):
374 print(
"Name of the last module needs to be modifiable.")
378 print(
"Here we must include geopro first")
379 process.load(
'Configuration.StandardSequences.GeometryDB_cff')
380 process.load(
"TrackPropagation.Geant4e.geantRefit_cff")
381 modules.append(getattr(process,
"geopro"))
383 src =
_getModule(process, src, mods[-1][0],
"FinalTrackRefitter",
384 options[mods[-1][0]][mods[-1][1]],
385 isCosmics = isCosmics, **(mods[-1][2]))
386 modules.append(getattr(process, src))
388 moduleSum = process.offlineBeamSpot
391 moduleSum += getattr(process,
"MeasurementTrackerEvent")
393 for module
in modules:
395 if hasattr(module,
"srcConstr"):
396 strSrcConstr = module.srcConstr.getModuleLabel()
398 procsrcconstr = getattr(process,strSrcConstr)
399 if hasattr(procsrcconstr,
"src"):
400 if procsrcconstr.src != module.src:
404 moduleSum += procsrcconstr
405 elif hasattr(procsrcconstr,
"srcTrk"):
406 if procsrcconstr.srcTrk != module.src:
410 procsrcconstrsrcvtx = getattr(process,procsrcconstr.srcVtx.getModuleLabel())
411 if type(procsrcconstrsrcvtx)
is cms.EDFilter:
412 procsrcconstrsrcvtxprefilter = getattr(process,procsrcconstrsrcvtx.src.getModuleLabel())
413 moduleSum += procsrcconstrsrcvtxprefilter
414 moduleSum += procsrcconstrsrcvtx
415 moduleSum += procsrcconstr
419 return cms.Sequence(moduleSum)
430 def _getModule(process, src, modType, moduleName, options, **kwargs):
431 """General function for attaching the module of type `modType` to the 432 cms.Process `process` using `options` for customization and `moduleName` as 433 the name of the new attribute of `process`. 436 - `process`: 'cms.Process' object to which the module is attached. 437 - `src`: cms.InputTag for this module. 438 - `modType`: Type of the requested module. 439 - `options`: Dictionary with customized values for the module's options. 440 - `**kwargs`: Used to supply options at construction time of the module. 443 objTuple = globals()[
"_"+modType](kwargs)
444 method = kwargs.get(
"method")
445 if method ==
"import":
446 __import__(objTuple[0])
447 obj = getattr(sys.modules[objTuple[0]], objTuple[1]).
clone()
448 elif method ==
"load":
449 process.load(objTuple[0])
450 if kwargs.get(
"clone",
False):
451 obj = getattr(process, objTuple[1]).
clone(src=src)
453 obj = getattr(process, objTuple[1])
454 moduleName = objTuple[1]
456 print(
"Unknown method:", method)
459 if modType ==
"TrackSplitting":
467 for option
in options:
470 if moduleName
is not objTuple[1]:
471 setattr(process, moduleName, obj)
476 """Returns TrackHitFilter module name. 479 - `kwargs`: Not used in this function. 482 return (
"RecoTracker.FinalTrackSelectors.TrackerTrackHitFilter_cff",
483 "TrackerTrackHitFilter")
487 """Returns TrackSelector module name. 490 - `kwargs`: Not used in this function. 493 return (
"Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi",
494 "AlignmentTrackSelector")
498 """Returns TrackFitter module name. 501 - `kwargs`: Used to supply options at construction time of the object. 504 isCosmics = kwargs.get(
"isCosmics",
False)
506 return (
"RecoTracker.TrackProducer.CTFFinalFitWithMaterialP5_cff",
507 "ctfWithMaterialTracksCosmics")
509 return (
"RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff",
510 "ctfWithMaterialTracks")
514 """Returns TrackRefitter module name. 517 - `kwargs`: Used to supply options at construction time of the object. 520 isCosmics = kwargs.get(
"isCosmics",
False)
522 return (
"RecoTracker.TrackProducer.TrackRefitters_cff",
525 return (
"RecoTracker.TrackProducer.TrackRefitters_cff",
529 return (
"RecoTracker.FinalTrackSelectors.cosmicTrackSplitter_cfi",
530 "cosmicTrackSplitter")
533 return (
"TrackPropagation.Geant4e.geantRefit_cff",
"geopro")
537 """Sets the attribute `attr` of the object `obj` using the value `val`. 538 `attr` can be a string or a tuple of strings, if one wants to set an 539 attribute of an attribute, etc. 542 - `obj`: Object, which must have a '__dict__' attribute. 543 - `attr`: String or tuple of strings describing the attribute's name. 544 - `val`: value of the attribute. 547 if isinstance(attr, tuple)
and len(attr) > 1:
550 if isinstance(attr, tuple): attr = attr[0]
551 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)