Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-17 03:15:34

0001 from __future__ import absolute_import
0002 import FWCore.ParameterSet.Config as cms
0003 
0004 from SimTracker.TrackAssociatorProducers.trackAssociatorByChi2_cfi import *
0005 from SimTracker.TrackAssociatorProducers.quickTrackAssociatorByHits_cfi import *
0006 from SimTracker.TrackAssociation.trackingParticleRecoTrackAsssociation_cfi import *
0007 import Validation.RecoTrack.MultiTrackValidator_cfi
0008 from Validation.RecoTrack.trajectorySeedTracks_cfi import trajectorySeedTracks as _trajectorySeedTracks
0009 from Validation.RecoTrack.PostProcessorTracker_cfi import *
0010 import Validation.RecoTrack.cutsRecoTracks_cfi as cutsRecoTracks_cfi
0011 #from . import cutsRecoTracks_cfi
0012 
0013 from SimTracker.TrackerHitAssociation.tpClusterProducer_cfi import *
0014 from SimTracker.VertexAssociation.VertexAssociatorByPositionAndTracks_cfi import *
0015 from CommonTools.RecoAlgos.trackingParticleRefSelector_cfi import trackingParticleRefSelector as _trackingParticleRefSelector
0016 from CommonTools.RecoAlgos.trackingParticleConversionRefSelector_cfi import trackingParticleConversionRefSelector as _trackingParticleConversionRefSelector
0017 from SimTracker.TrackHistory.trackingParticleBHadronRefSelector_cfi import trackingParticleBHadronRefSelector as _trackingParticleBHadronRefSelector
0018 from SimGeneral.TrackingAnalysis.trackingParticleNumberOfLayersProducer_cff import *
0019 from CommonTools.RecoAlgos.recoChargedRefCandidateToTrackRefProducer_cfi import recoChargedRefCandidateToTrackRefProducer as _recoChargedRefCandidateToTrackRefProducer
0020 
0021 import RecoTracker.IterativeTracking.iterativeTkConfig as _cfg
0022 import RecoTracker.IterativeTracking.iterativeTkUtils as _utils
0023 from Configuration.Eras.Modifier_fastSim_cff import fastSim
0024 
0025 ### First define the stuff for the standard validation sequence
0026 ## Track selectors
0027 for _eraName, _postfix, _era in _cfg.allEras():
0028     _seedProd = ["initialStepSeedsPreSplitting"]
0029     _trackProd = ["initialStepTracksPreSplitting"]
0030     if _eraName in ["trackingLowPU", "trackingPhase2PU140"]: # these don't have preSplitting
0031         _seedProd = []
0032         _trackProd = []
0033 
0034     locals()["_algos"+_postfix] = ["generalTracks"] + _cfg.iterationAlgos(_postfix) + ["duplicateMerge"]
0035     locals()["_seedProducersPreSplitting"+_postfix] = _seedProd
0036     locals()["_trackProducersPreSplitting"+_postfix] = _trackProd
0037     locals()["_seedProducers"+_postfix] = _cfg.seedProducers(_postfix)
0038     locals()["_trackProducers"+_postfix] = _cfg.trackProducers(_postfix)
0039 
0040     if _eraName != "trackingPhase2PU140":
0041         locals()["_electronSeedProducers"+_postfix] = ["tripletElectronSeeds", "pixelPairElectronSeeds", "stripPairElectronSeeds"]
0042     else:
0043         locals()["_electronSeedProducers"+_postfix] = ["tripletElectronSeeds"]
0044 
0045 _removeForFastSimSeedProducers =["initialStepSeedsPreSplitting",
0046                                  "jetCoreRegionalStepSeeds",
0047                                  "jetCoreRegionalStepSeedsBarrel","jetCoreRegionalStepSeedsEndcap",
0048                                  "displacedRegionalStepSeeds",
0049                                  "muonSeededSeedsInOut",
0050                                  "muonSeededSeedsOutIn"]
0051 
0052 _seedProducers_fastSim = [ x for x in _seedProducers if x not in _removeForFastSimSeedProducers]
0053 
0054 _removeForFastTrackProducers = ["initialStepTracksPreSplitting",
0055                                 "jetCoreRegionalStepTracks",
0056                                 "displacedRegionalStepTracks",
0057                                 "muonSeededTracksInOut",
0058                                 "muonSeededTracksOutIn"]
0059 _trackProducers_fastSim = [ x for x in _trackProducers if x not in _removeForFastTrackProducers]
0060 
0061 def _algoToSelector(algo):
0062     sel = ""
0063     if algo != "generalTracks":
0064         sel = algo[0].upper()+algo[1:]
0065     return "cutsRecoTracks"+sel
0066 
0067 def _addSelectorsByAlgo(algos, modDict):
0068     names = []
0069     task = cms.Task()
0070     for algo in algos:
0071         if algo == "generalTracks":
0072             continue
0073         modName = _algoToSelector(algo)
0074         if modName not in modDict:
0075             mod = cutsRecoTracks_cfi.cutsRecoTracks.clone(
0076 #                src = [src],
0077                 algorithm=[algo]
0078             )
0079             modDict[modName] = mod
0080         else:
0081             mod = modDict[modName]
0082         names.append(modName)
0083         task.add(mod)
0084     return (names, task)
0085 def _addSelectorsByHp(algos, modDict):
0086     task = cms.Task()
0087     names = []
0088     for algo in algos:
0089         modName = _algoToSelector(algo)
0090         modNameHp = modName+"Hp"
0091         if modNameHp not in modDict:
0092             if algo == "generalTracks":
0093                 mod = cutsRecoTracks_cfi.cutsRecoTracks.clone(quality=["highPurity"])
0094             else:
0095                 mod = modDict[modName].clone(quality=["highPurity"])
0096             modDict[modNameHp] = mod
0097         else:
0098             mod = modDict[modNameHp]
0099         names.append(modNameHp)
0100         task.add(mod)
0101     return (names, task)
0102 def _addSelectorsBySrc(modules, midfix, src, modDict):
0103     task = cms.Task()
0104     names = []
0105     for modName in modules:
0106         modNameNew = modName.replace("cutsRecoTracks", "cutsRecoTracks"+midfix)
0107         if modNameNew not in modDict:
0108             mod = modDict[modName].clone(src=src)
0109             modDict[modNameNew] = mod
0110         else:
0111             mod = modDict[modNameNew]
0112         names.append(modNameNew)
0113         task.add(mod)
0114     return (names, task)
0115 def _addSelectorsByOriginalAlgoMask(modules, midfix, algoParam,modDict):
0116     task = cms.Task()
0117     names = []
0118     for modName in modules:
0119         if modName[-2:] == "Hp":
0120             modNameNew = modName[:-2] + midfix + "Hp"
0121         else:
0122             modNameNew = modName + midfix
0123         if modNameNew not in modDict:
0124             mod = modDict[modName].clone()
0125             setattr(mod, algoParam, mod.algorithm.value())
0126             mod.algorithm = []
0127             modDict[modNameNew] = mod
0128         else:
0129             mod = modDict[modNameNew]
0130         names.append(modNameNew)
0131         task.add(mod)
0132     return (names, task)
0133 def _addSeedToTrackProducers(seedProducers,modDict):
0134     names = []
0135     task = cms.Task()
0136     for seed in seedProducers:
0137         modName = "seedTracks"+seed
0138         if modName not in modDict:
0139             mod = _trajectorySeedTracks.clone(src=seed)
0140             modDict[modName] = mod
0141         else:
0142             mod = modDict[modName]
0143         names.append(modName)
0144         task.add(mod)
0145     return (names, task)
0146 
0147 _relevantEras = _cfg.allEras()
0148 _relevantErasAndFastSim = _relevantEras + [("fastSim", "_fastSim", fastSim)]
0149 def _translateArgs(args, postfix, modDict):
0150     ret = []
0151     for arg in args:
0152         if isinstance(arg, list):
0153             ret.append(_translateArgs(arg, postfix, modDict))
0154         else:
0155             ret.append(modDict[arg+postfix])
0156     return ret
0157 def _taskForEachEra(function, args, names, task, modDict, plainArgs=[], modifyTask=None, includeFastSim=False):
0158     if task[0] != "_":
0159         raise Exception("Task name is expected to begin with _")
0160 
0161     _eras = _relevantErasAndFastSim if includeFastSim else _relevantEras
0162     for eraName, postfix, _era in _eras:
0163         _args = _translateArgs(args, postfix, modDict)
0164         _args.extend(plainArgs)
0165         ret = function(*_args, modDict=modDict)
0166         if len(ret) != 2:
0167             raise Exception("_taskForEachEra is expected to return 2 values, but function returned %d" % len(ret))
0168         modDict[names+postfix] = ret[0]
0169         modDict[task+postfix] = ret[1]
0170 
0171     # The task of the first era will be the default one
0172     defaultTaskName = task+_eras[0][0]
0173     defaultTask = modDict[defaultTaskName]
0174     modDict[defaultTaskName[1:]] = defaultTask # remove leading underscore
0175 
0176     # Optionally modify task before applying the era
0177     if modifyTask is not None:
0178         for eraName, postfix, _era in _eras:
0179             modifyTask(modDict[task+postfix])
0180 
0181     # Apply eras
0182     for _eraName, _postfix, _era in _eras[1:]:
0183         _era.toReplaceWith(defaultTask, modDict[task+_postfix])
0184 def _setForEra(module, eraName, era, **kwargs):
0185     if eraName == "":
0186         for key, value in kwargs.items():
0187             setattr(module, key, value)
0188     else:
0189         era.toModify(module, **kwargs)
0190 
0191 # Seeding layer sets
0192 def _getSeedingLayers(seedProducers, config):
0193     def _findSeedingLayers(name):
0194         prod = getattr(config, name)
0195         if hasattr(prod, "triplets"):
0196             if hasattr(prod, "layerList"): # merger
0197                 return prod.layerList.refToPSet_.value()
0198             return _findSeedingLayers(prod.triplets.getModuleLabel())
0199         elif hasattr(prod, "doublets"):
0200             return _findSeedingLayers(prod.doublets.getModuleLabel())
0201         label = prod.trackingRegionsSeedingLayers.getModuleLabel()
0202         if label != "":
0203             return label
0204         return prod.seedingLayers.getModuleLabel()
0205 
0206     seedingLayersMerged = []
0207     for seedName in seedProducers:
0208         seedProd = getattr(config, seedName)
0209         seedingLayersName = None
0210         seedingLayers = None
0211         if hasattr(seedProd, "OrderedHitsFactoryPSet"): # old seeding framework
0212             seedingLayersName = seedProd.OrderedHitsFactoryPSet.SeedingLayers.getModuleLabel()
0213         elif hasattr(seedProd, "seedingHitSets"): # new seeding framework
0214             seedingLayersName = _findSeedingLayers(seedProd.seedingHitSets.getModuleLabel())
0215         elif hasattr(seedProd, "layerList"): # FastSim:
0216             seedingLayers = seedProd.layerList.value()
0217         else:
0218             continue
0219 
0220         if seedingLayersName is not None:
0221             seedingLayers = getattr(config, seedingLayersName).layerList.value()
0222         for layerSet in seedingLayers:
0223             if layerSet not in seedingLayersMerged:
0224                 seedingLayersMerged.append(layerSet)
0225 
0226     return seedingLayersMerged
0227 import RecoTracker.IterativeTracking.iterativeTk_cff as _iterativeTk_cff
0228 import RecoTracker.IterativeTracking.ElectronSeeds_cff as _ElectronSeeds_cff
0229 for _eraName, _postfix, _era in _relevantErasAndFastSim:
0230     _stdLayers = _getSeedingLayers(locals()["_seedProducers"+_postfix], _iterativeTk_cff)
0231     _eleLayers = []
0232     if "_electronSeedProducers"+_postfix in locals(): # doesn't exist for FastSim
0233         for _layer in _getSeedingLayers(locals()["_electronSeedProducers"+_postfix], _ElectronSeeds_cff):
0234             if _layer not in _stdLayers:
0235                 _eleLayers.append(_layer)
0236 
0237     locals()["_seedingLayerSets"+_postfix] = _stdLayers
0238     locals()["_seedingLayerSetsForElectrons"+_postfix] = _eleLayers
0239 
0240 
0241 # MVA selectors
0242 def _getMVASelectors(postfix):
0243     mvaSel = _utils.getMVASelectors(postfix)
0244 
0245     pset = cms.untracked.PSet()
0246     for iteration, (trackProducer, classifiers) in mvaSel.items():
0247         setattr(pset, trackProducer, cms.untracked.vstring(classifiers))
0248     return pset
0249 for _eraName, _postfix, _era in _relevantEras:
0250     locals()["_mvaSelectors"+_postfix] = _getMVASelectors(_postfix)
0251 
0252 # Validation iterative steps
0253 _taskForEachEra(_addSelectorsByAlgo, args=["_algos"], names="_selectorsByAlgo", task="_tracksValidationSelectorsByAlgo", modDict=globals())
0254 
0255 # high purity
0256 _taskForEachEra(_addSelectorsByHp, args=["_algos"], names="_selectorsByAlgoHp", task="_tracksValidationSelectorsByAlgoHp", modDict=globals())
0257 
0258 # by originalAlgo
0259 for _eraName, _postfix, _era in _relevantEras:
0260     locals()["_selectorsByAlgoAndHp"+_postfix] = locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix]
0261     # For ByAlgoMask
0262     locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix] = [n for n in locals()["_selectorsByAlgoAndHp"+_postfix] if n not in ["generalTracks", "cutsRecoTracksHp"]]
0263     # For ByOriginalAlgo
0264     locals()["_selectorsByAlgoAndHpNoGenTkDupMerge"+_postfix] = [n for n in locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix] if n not in ["cutsRecoTracksDuplicateMerge", "cutsRecoTracksDuplicateMergeHp"]]
0265 _taskForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
0266                     args = ["_selectorsByAlgoAndHpNoGenTkDupMerge"], plainArgs = ["ByOriginalAlgo", "originalAlgorithm"],
0267                     names = "_selectorsByOriginalAlgo", task = "_tracksValidationSelectorsByOriginalAlgo")
0268 
0269 
0270 for _eraName, _postfix, _era in _relevantEras:
0271     selectors = locals()["_selectorsByAlgoHp"+_postfix]
0272     locals()["_generalTracksHp"+_postfix] = selectors[0]
0273     locals()["_selectorsByAlgoHp"+_postfix] = selectors[1:]
0274 
0275 # BTV-like selection
0276 import PhysicsTools.RecoAlgos.btvTracks_cfi as btvTracks_cfi
0277 cutsRecoTracksBtvLike = btvTracks_cfi.btvTrackRefs.clone()
0278 
0279 # Select tracks associated to AK4 jets
0280 import RecoJets.JetAssociationProducers.ak4JTA_cff as ak4JTA_cff
0281 ak4JetTracksAssociatorExplicitAll = ak4JTA_cff.ak4JetTracksAssociatorExplicit.clone(
0282     jets = "ak4PFJets"
0283 )
0284 from JetMETCorrections.Configuration.JetCorrectors_cff import *
0285 import JetMETCorrections.JetCorrector.jetTracksAssociationToTrackRefs_cfi as jetTracksAssociationToTrackRefs_cfi
0286 cutsRecoTracksAK4PFJets = jetTracksAssociationToTrackRefs_cfi.jetTracksAssociationToTrackRefs.clone(
0287     association = "ak4JetTracksAssociatorExplicitAll",
0288     jets = "ak4PFJets",
0289     correctedPtMin = 10,
0290 )
0291 
0292 
0293 ## Select signal TrackingParticles, and do the corresponding associations
0294 trackingParticlesSignal = _trackingParticleRefSelector.clone(
0295     signalOnly = True,
0296     chargedOnly = False,
0297     tip = 1e5,
0298     lip = 1e5,
0299     minRapidity = -10,
0300     maxRapidity = 10,
0301     ptMin = 0,
0302 )
0303 ## Select in-time TrackingParticles, and do the corresponding associations
0304 trackingParticlesInTime = trackingParticlesSignal.clone(
0305     signalOnly = False,
0306     intimeOnly = True,
0307 )
0308 
0309 # select tracks with pT > 0.9 GeV (for upgrade fake rates)
0310 generalTracksPt09 = cutsRecoTracks_cfi.cutsRecoTracks.clone(ptMin=0.9)
0311 # and then the selectors
0312 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
0313                 args=[["_generalTracksHp"]],
0314                 plainArgs=["Pt09", "generalTracksPt09"],
0315                 names="_selectorsPt09", task="_tracksValidationSelectorsPt09",
0316                 modifyTask=lambda task:task.add(generalTracksPt09))
0317 
0318 # select tracks from the PV
0319 from CommonTools.RecoAlgos.TrackWithVertexRefSelector_cfi import trackWithVertexRefSelector as _trackWithVertexRefSelector
0320 generalTracksFromPV = _trackWithVertexRefSelector.clone(
0321     src = "generalTracks",
0322     ptMin = 0,
0323     ptMax = 1e10,
0324     ptErrorCut = 1e10,
0325     quality = "loose",
0326     vertexTag = "offlinePrimaryVertices",
0327     nVertices = 1,
0328     vtxFallback = False,
0329     zetaVtx = 0.1, # 1 mm
0330     rhoVtx = 1e10, # intentionally no dxy cut
0331 )
0332 # and then the selectors
0333 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
0334                     args=[["_generalTracksHp"]],
0335                     plainArgs=["FromPV", "generalTracksFromPV"],
0336                     names="_selectorsFromPV", task="_tracksValidationSelectorsFromPV",
0337                     modifyTask=lambda task: task.add(generalTracksFromPV))
0338 
0339 # select tracks with pT > 0.9 GeV from the PV
0340 generalTracksFromPVPt09 = generalTracksPt09.clone(src="generalTracksFromPV")
0341 # and then the selectors
0342 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
0343                 args=[["_generalTracksHp"]],
0344                 plainArgs=["FromPVPt09", "generalTracksFromPVPt09"],
0345                 names="_selectorsFromPVPt09", task="_tracksValidationSelectorsFromPVPt09",
0346                 modifyTask=lambda task: task.add(generalTracksFromPVPt09))
0347 
0348 ## Select conversion TrackingParticles, and define the corresponding associator
0349 trackingParticlesConversion = _trackingParticleConversionRefSelector.clone()
0350 
0351 ## Select electron TPs
0352 trackingParticlesElectron = _trackingParticleRefSelector.clone(
0353     pdgId = [-11, 11],
0354     signalOnly = False,
0355     tip = 1e5,
0356     lip = 1e5,
0357     minRapidity = -10,
0358     maxRapidity = 10,
0359     ptMin = 0,
0360 )
0361 
0362 # Select jets for JetCore tracking
0363 highPtJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("ak4CaloJets"), cut = cms.string("pt()>1000")) 
0364 highPtJetsForTrk = highPtJets.clone(src = "ak4CaloJetsForTrk")
0365 
0366 # Select B-hadron TPs
0367 trackingParticlesBHadron = _trackingParticleBHadronRefSelector.clone()
0368 
0369 ## MTV instances
0370 trackValidator = Validation.RecoTrack.MultiTrackValidator_cfi.multiTrackValidator.clone(
0371     useLogPt = cms.untracked.bool(True),
0372     dodEdxPlots = True,
0373     doPVAssociationPlots = True
0374     #,minpT = cms.double(-1)
0375     #,maxpT = cms.double(3)
0376     #,nintpT = cms.int32(40)
0377 )
0378 fastSim.toModify(trackValidator,
0379                       dodEdxPlots = False)
0380 
0381 for _eraName, _postfix, _era in _relevantEras:
0382     _setForEra(trackValidator, _eraName, _era,
0383                label = ["generalTracks", locals()["_generalTracksHp"+_postfix]] +
0384                        locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix] +
0385                        locals()["_selectorsByOriginalAlgo"+_postfix] +
0386                        ["generalTracksPt09"] + locals()["_selectorsPt09"+_postfix] +
0387                [
0388                    "cutsRecoTracksBtvLike",
0389                    "cutsRecoTracksAK4PFJets"
0390                ],
0391                doResolutionPlotsForLabels = [
0392                    "generalTracks",
0393                    locals()["_generalTracksHp"+_postfix],
0394                    "generalTracksPt09",
0395                    "cutsRecoTracksBtvLike",
0396                    "cutsRecoTracksJetCoreRegionalStepByOriginalAlgo",
0397                ]
0398     )
0399     _setForEra(trackValidator.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=locals()["_seedingLayerSets"+_postfix])
0400 
0401 # for low-pT
0402 trackValidatorTPPtLess09 = trackValidator.clone(
0403     dirName = "Tracking/TrackTPPtLess09/",
0404     label = [x for x in trackValidator.label.value() if ("Pt09" not in x) and ("BtvLike" not in x) and ("AK4PFJets" not in x)],
0405     ptMaxTP = 0.9, # set maximum pT globally
0406     histoProducerAlgoBlock = dict(
0407         TpSelectorForEfficiencyVsEta  = dict(ptMin=0.05), # enough to set min pT here
0408         TpSelectorForEfficiencyVsPhi  = dict(ptMin=0.05),
0409         TpSelectorForEfficiencyVsVTXR = dict(ptMin=0.05),
0410         TpSelectorForEfficiencyVsVTXZ = dict(ptMin=0.05),
0411     ),
0412     doSimPlots = False,       # same as in trackValidator, no need to repeat here
0413     doRecoTrackPlots = False, # fake rates are same as in trackValidator, no need to repeat here
0414     doResolutionPlotsForLabels = ["disabled"], # resolutions are same as in trackValidator, no need to repeat here
0415 )
0416 
0417 ## Select signal TrackingParticles, and do the corresponding associations
0418 trackingParticlesEtaGreater2p7 = _trackingParticleRefSelector.clone(
0419     signalOnly = cms.bool(False),
0420     tip = 1e5,
0421     lip = 1e5,
0422     minRapidity = -2.7,
0423     maxRapidity =  2.7,
0424     invertRapidityCut = cms.bool(True),
0425     ptMin = 0,
0426 )
0427 
0428 
0429 # select tracks with |eta| > 2.7
0430 generalTracksEtaGreater2p7 = cutsRecoTracks_cfi.cutsRecoTracks.clone(
0431     minRapidity = cms.double(-2.7),
0432     maxRapidity = cms.double( 2.7),
0433     invertRapidityCut = cms.bool(True)
0434 )
0435 
0436 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
0437                     args=[["_generalTracksHp"]],
0438                     plainArgs=["EtaGreater2p7", "generalTracksEtaGreater2p7"],
0439                     names="_selectorsEtaGreater2p7", task="_tracksValidationSelectorsEtaGreater2p7",
0440                     modifyTask=lambda task: task.add(generalTracksEtaGreater2p7))
0441 
0442 # for high-eta (phase2 : |eta| > 2.7)
0443 trackValidatorTPEtaGreater2p7 = trackValidator.clone(
0444     dirName = "Tracking/TrackTPEtaGreater2p7/",
0445     label_tp_effic = "trackingParticlesEtaGreater2p7",
0446     label_tp_fake  = "trackingParticlesEtaGreater2p7",
0447     label_tp_effic_refvector = True,
0448     label_tp_fake_refvector  = True,
0449     dodEdxPlots = False,
0450 #    doPVAssociationPlots = False,
0451     minRapidityTP = -2.7,
0452     maxRapidityTP = 2.7,
0453     invertRapidityCutTP = True,
0454 #    ptMaxTP = 0.9, # set maximum pT globally
0455     histoProducerAlgoBlock = dict(
0456         TpSelectorForEfficiencyVsPt   = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True), # enough to set min pT here
0457         TpSelectorForEfficiencyVsEta  = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True), # enough to set min pT here
0458         TpSelectorForEfficiencyVsPhi  = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True),
0459         TpSelectorForEfficiencyVsVTXR = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True),
0460         TpSelectorForEfficiencyVsVTXZ = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True),
0461         generalTpSelector             = dict(ptMin=0.005,minRapidity=-2.7,maxRapidity=2.7,invertRapidityCut=True),
0462 #        minEta  = -4.5,
0463 #        maxEta  =  4.5,
0464 #        nintEta = 90,
0465         #    minPt  = 0.01,
0466     ),
0467     doSimPlots = True,       # ####same as in trackValidator, no need to repeat here
0468     doRecoTrackPlots = True, # ####fake rates are same as in trackValidator, no need to repeat here
0469     doResolutionPlotsForLabels = ["disabled"] # resolutions are same as in trackValidator, no need to repeat here
0470 )
0471 for _eraName, _postfix, _era in _relevantEras:
0472     _setForEra(trackValidatorTPEtaGreater2p7, _eraName, _era,
0473                label = ["generalTracksEtaGreater2p7"] + locals()["_selectorsEtaGreater2p7"+_postfix] +
0474                        locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix],
0475                doResolutionPlotsForLabels = ["generalTracksEtaGreater2p7"] + locals()["_selectorsEtaGreater2p7"+_postfix]
0476     )
0477 
0478 # For efficiency of signal TPs vs. signal tracks, and fake rate of
0479 # signal tracks vs. signal TPs
0480 trackValidatorFromPV = trackValidator.clone(
0481     dirName = "Tracking/TrackFromPV/",
0482     label_tp_effic = "trackingParticlesSignal",
0483     label_tp_fake = "trackingParticlesSignal",
0484     label_tp_effic_refvector = True,
0485     label_tp_fake_refvector = True,
0486     trackCollectionForDrCalculation = "generalTracksFromPV",
0487     doPlotsOnlyForTruePV = True,
0488     doPVAssociationPlots = False,
0489     doResolutionPlotsForLabels = ["disabled"],
0490 )
0491 for _eraName, _postfix, _era in _relevantEras:
0492     _setForEra(trackValidatorFromPV, _eraName, _era,
0493                label = ["generalTracksFromPV"] + locals()["_selectorsFromPV"+_postfix] + ["generalTracksFromPVPt09"] + locals()["_selectorsFromPVPt09"+_postfix],
0494                doResolutionPlotsForLabels = [] # for standard "FromPV" do resolution plots for all input collections as they are already limited
0495     )
0496 
0497 # For fake rate of signal tracks vs. all TPs, and pileup rate of
0498 # signal tracks vs. non-signal TPs
0499 trackValidatorFromPVAllTP = trackValidatorFromPV.clone(
0500     dirName = "Tracking/TrackFromPVAllTP/",
0501     label_tp_effic = trackValidator.label_tp_effic.value(),
0502     label_tp_fake = trackValidator.label_tp_fake.value(),
0503     label_tp_effic_refvector = False,
0504     label_tp_fake_refvector = False,
0505     doSimPlots = False,
0506     doSimTrackPlots = False,
0507     doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidatorFromPV"
0508 )
0509 
0510 # For efficiency of all TPs vs. all tracks
0511 trackValidatorAllTPEffic = trackValidator.clone(
0512     dirName = "Tracking/TrackAllTPEffic/",
0513     label = [x for x in trackValidator.label.value() if "Pt09" not in x],
0514     doSimPlots = False,
0515     doRecoTrackPlots = True, # Fake rate of all tracks vs. all TPs is already included in trackValidator, but we want the reco plots for other reasons
0516     doPVAssociationPlots = False,
0517     doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidator"
0518 )
0519 trackValidatorAllTPEffic.histoProducerAlgoBlock.generalTpSelector.signalOnly = False
0520 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsEta.signalOnly = False
0521 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPhi.signalOnly = False
0522 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPt.signalOnly = False
0523 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXR.signalOnly = False
0524 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXZ.signalOnly = False
0525 for _eraName, _postfix, _era in _relevantEras:
0526     _setForEra(trackValidatorAllTPEffic, _eraName, _era, label = ["generalTracks", locals()["_generalTracksHp"+_postfix]])
0527 
0528 # Built tracks, in the standard sequence mainly for monitoring the track selection MVA
0529 tpClusterProducerPreSplitting = tpClusterProducer.clone(pixelClusterSrc = "siPixelClustersPreSplitting")
0530 quickTrackAssociatorByHitsPreSplitting = quickTrackAssociatorByHits.clone(cluster2TPSrc = "tpClusterProducerPreSplitting")
0531 _trackValidatorSeedingBuilding = trackValidator.clone( # common for built tracks and seeds (in trackingOnly)
0532     associators = ["quickTrackAssociatorByHits"],
0533     UseAssociators = True,
0534     dodEdxPlots = False,
0535     doPVAssociationPlots = False,
0536     doSimPlots = False,
0537     doResolutionPlotsForLabels = ["disabled"],
0538 )
0539 trackValidatorBuilding = _trackValidatorSeedingBuilding.clone(
0540     dirName = "Tracking/TrackBuilding/",
0541     doMVAPlots = True,
0542     doResolutionPlotsForLabels = ['jetCoreRegionalStepTracks'],
0543 )
0544 trackValidatorBuildingPreSplitting = trackValidatorBuilding.clone(
0545     associators = ["quickTrackAssociatorByHitsPreSplitting"],
0546     doMVAPlots = False,
0547     doSummaryPlots = False,
0548 )
0549 for _eraName, _postfix, _era in _relevantErasAndFastSim:
0550     _setForEra(trackValidatorBuilding, _eraName, _era, label = locals()["_trackProducers"+_postfix])
0551 fastSim.toModify(trackValidatorBuilding, doMVAPlots=False)
0552 for _eraName, _postfix, _era in _relevantEras:
0553     _setForEra(trackValidatorBuilding, _eraName, _era, mvaLabels = locals()["_mvaSelectors"+_postfix])
0554     _setForEra(trackValidatorBuildingPreSplitting, _eraName, _era, label = locals()["_trackProducersPreSplitting"+_postfix])
0555 
0556 
0557 # For conversions
0558 trackValidatorConversion = trackValidator.clone(
0559     dirName = "Tracking/TrackConversion/",
0560     label = [
0561         "convStepTracks",
0562         "conversionStepTracks",
0563         "ckfInOutTracksFromConversions",
0564         "ckfOutInTracksFromConversions",
0565     ],
0566     label_tp_effic = "trackingParticlesConversion",
0567     label_tp_effic_refvector = True,
0568     associators = ["quickTrackAssociatorByHits"],
0569     UseAssociators = True,
0570     doSimPlots = True,
0571     dodEdxPlots = False,
0572     doPVAssociationPlots = False,
0573     calculateDrSingleCollection = False,
0574 )
0575 from RecoTracker.ConversionSeedGenerators.ConversionStep_cff import convLayerPairs as _convLayerPairs
0576 def _uniqueFirstLayers(layerList):
0577     firstLayers = [layerSet.split("+")[0] for layerSet in layerList]
0578     ret = []
0579     for l in firstLayers:
0580         if not l in ret:
0581             ret.append(l)
0582             # For conversions add also the mono-TEC to the list as 'TEC'
0583             # is used for both matched and unmatched rphi/stereo hits
0584             if l.startswith("TEC"):
0585                 ret.append("M"+l)
0586     return ret
0587 # PhotonConversionTrajectorySeedProducerFromSingleLeg keeps only the
0588 # first hit of the pairs in the seed, bookkeeping those is the best we
0589 # can do without major further development
0590 trackValidatorConversion.histoProducerAlgoBlock.seedingLayerSets = _uniqueFirstLayers(_convLayerPairs.layerList.value())
0591 # relax lip and tip
0592 for n in ["Eta", "Phi", "Pt", "VTXR", "VTXZ"]:
0593     pset = getattr(trackValidatorConversion.histoProducerAlgoBlock, "TpSelectorForEfficiencyVs"+n)
0594     pset.lip = trackValidatorConversion.lipTP.value()
0595     pset.tip = trackValidatorConversion.tipTP.value()
0596 
0597 # For electrons
0598 trackValidatorGsfTracks = trackValidatorConversion.clone(
0599     dirName = "Tracking/TrackGsf/",
0600     label = ["electronGsfTracks"],
0601     label_tp_effic = "trackingParticlesElectron",
0602 )
0603 # add the additional seeding layers from ElectronSeeds
0604 for _eraName, _postfix, _era in _relevantEras:
0605     _setForEra(trackValidatorGsfTracks.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=trackValidator.histoProducerAlgoBlock.seedingLayerSets.value()+locals()["_seedingLayerSetsForElectrons"+_postfix])
0606 
0607 # For jetCore tracks
0608 trackValidatorJetCore = trackValidator.clone(#equivalent to trackBuilding case
0609     dirName = "Tracking/JetCore/",
0610     useLogPt = cms.untracked.bool(True),
0611     dodEdxPlots = False,
0612     associators= ["trackAssociatorByChi2"],#cms.untracked.VInputTag('MTVTrackAssociationByChi2'),
0613     UseAssociators = True,
0614     doPVAssociationPlots = True,
0615     label_tp_effic = "trackingParticlesInTime",
0616     label_tp_fake = "trackingParticlesInTime",
0617     label_tp_effic_refvector = True,
0618     label_tp_fake_refvector = True,
0619 )
0620 for _eraName, _postfix, _era in _relevantEras:
0621     if 'jetCoreRegionalStep' in _cfg.iterationAlgos(_postfix) :
0622         _setForEra(trackValidatorJetCore, _eraName, _era,
0623             label = ["generalTracks", "jetCoreRegionalStepTracks", 
0624                     "cutsRecoTracksJetCoreRegionalStepByOriginalAlgo","cutsRecoTracksJetCoreRegionalStepByOriginalAlgoHp",
0625                     "cutsRecoTracksJetCoreRegionalStep", "cutsRecoTracksJetCoreRegionalStepHp"],
0626             doResolutionPlotsForLabels =["generalTracks", "jetCoreRegionalStepTracks", 
0627                     "cutsRecoTracksJetCoreRegionalStepByOriginalAlgo","cutsRecoTracksJetCoreRegionalStepByOriginalAlgoHp",
0628                     "cutsRecoTracksJetCoreRegionalStep", "cutsRecoTracksJetCoreRegionalStepHp"], 
0629         )
0630 
0631 # for B-hadrons
0632 trackValidatorBHadron = trackValidator.clone(
0633     dirName = "Tracking/TrackBHadron/",
0634     label_tp_effic = "trackingParticlesBHadron",
0635     label_tp_effic_refvector = True,
0636     doSimPlots = True,
0637     doRecoTrackPlots = False, # Fake rate is defined wrt. all TPs, and that is already included in trackValidator
0638     dodEdxPlots = False,
0639 )
0640 for _eraName, _postfix, _era in _relevantEras:
0641     _setForEra(trackValidatorBHadron, _eraName, _era,
0642                label = ["generalTracks", locals()["_generalTracksHp"+_postfix], "cutsRecoTracksBtvLike"]
0643     )
0644 
0645 
0646 # for displaced tracks
0647 trackValidatorDisplaced = trackValidator.clone(
0648     dirName = "Tracking/TrackDisplaced/",
0649     label = [x for x in trackValidator.label.value() if ("Pt09" not in x) and ("BtvLike" not in x) and ("AK4PFJets" not in x)],
0650     ptMaxTP = 1e5,
0651     dodEdxPlots = False,
0652     invertRapidityCutTP = False,
0653     histoProducerAlgoBlock = dict(
0654         TpSelectorForEfficiencyVsPt   = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5), # enough to set min pT here
0655         TpSelectorForEfficiencyVsEta  = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5), # enough to set min pT here
0656         TpSelectorForEfficiencyVsPhi  = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5),
0657         TpSelectorForEfficiencyVsVTXR = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5),
0658         TpSelectorForEfficiencyVsVTXZ = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5),
0659         generalTpSelector             = dict(ptMin=0.005, signalOnly=True, tip=1e5, lip=1e5),
0660         minDxy = -60,
0661         maxDxy =  60,
0662         nintDxy = 120,
0663         minDz  = -30,
0664         maxDz  =  30,
0665         nintDz =  60,
0666     ),
0667     signalOnlyTP = True,
0668     lipTP = 1e5,
0669     tipTP = 1e5,
0670 )
0671 
0672 # the track selectors
0673 tracksValidationSelectors = cms.Task(
0674     tracksValidationSelectorsByAlgo,
0675     tracksValidationSelectorsByAlgoHp,
0676     tracksValidationSelectorsByOriginalAlgo,
0677     cutsRecoTracksBtvLike,
0678     ak4JetTracksAssociatorExplicitAll,
0679     cutsRecoTracksAK4PFJets
0680 )
0681 phase2_tracker.toModify(tracksValidationSelectors, lambda x: x.add(generalTracksEtaGreater2p7))
0682 phase2_tracker.toModify(tracksValidationSelectors, lambda x: x.add(cutsRecoTracksEtaGreater2p7Hp))
0683 
0684 # Validation iterative steps
0685 _taskForEachEra(_addSelectorsByAlgo, modDict=globals(),
0686                 args=["_algos"], 
0687                 names="_selectorsByAlgo", task="_tracksEtaGreater2p7ValidationSelectorsByAlgo"                
0688                )
0689 
0690 # high purity
0691 _taskForEachEra(_addSelectorsByHp, modDict=globals(),
0692                 args=["_algos"], 
0693                 names="_selectorsByAlgoHp", task="_tracksEtaGreater2p7ValidationSelectorsByAlgoHp"
0694                )
0695 
0696 for _eraName, _postfix, _era in _relevantEras:
0697     selectors = locals()["_selectorsByAlgoHp"+_postfix]
0698     locals()["_generalTracksHp"+_postfix] = selectors[0]
0699     locals()["_selectorsByAlgoHp"+_postfix] = selectors[1:]
0700 
0701 phase2_tracker.toModify(tracksValidationSelectors, lambda x: x.add(tracksEtaGreater2p7ValidationSelectorsByAlgo))
0702 phase2_tracker.toModify(tracksValidationSelectors, lambda x: x.add(tracksEtaGreater2p7ValidationSelectorsByAlgoHp))
0703 
0704 tracksValidationTruth = cms.Task(
0705     tpClusterProducer,
0706     tpClusterProducerPreSplitting,
0707     trackAssociatorByChi2, 
0708     quickTrackAssociatorByHits,
0709     quickTrackAssociatorByHitsPreSplitting,
0710     trackingParticleRecoTrackAsssociation,
0711     VertexAssociatorByPositionAndTracks,
0712     trackingParticleNumberOfLayersProducer
0713 )
0714 
0715 # HIon modifiers
0716 from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
0717 
0718 trackingParticleHIPixelTrackAssociation = trackingParticleRecoTrackAsssociation.clone(
0719     label_tr = "hiConformalPixelTracks",
0720     associator = "quickTrackAssociatorByHits",
0721 )
0722 
0723 from Configuration.ProcessModifiers.pixelNtupletFit_cff import pixelNtupletFit
0724 
0725 pixelNtupletFit.toModify(trackingParticleHIPixelTrackAssociation,
0726         associator = "quickTrackAssociatorByHitsPreSplitting")
0727 
0728 HIPixelVertexAssociatorByPositionAndTracks = VertexAssociatorByPositionAndTracks.clone(
0729     trackAssociation = "trackingParticleHIPixelTrackAssociation"
0730 )
0731 
0732 pp_on_AA.toReplaceWith(tracksValidationTruth, cms.Task(
0733     tracksValidationTruth.copy(),
0734     trackingParticleHIPixelTrackAssociation,
0735     HIPixelVertexAssociatorByPositionAndTracks
0736 ))
0737 fastSim.toModify(tracksValidationTruth, lambda x: x.remove(tpClusterProducer))
0738 
0739 tracksPreValidation = cms.Task(
0740     highPtJetsForTrk,
0741     tracksValidationSelectors,
0742     tracksValidationSelectorsPt09,
0743     tracksValidationSelectorsFromPV,
0744     tracksValidationSelectorsFromPVPt09,
0745     tracksValidationTruth,
0746     trackingParticlesSignal,
0747     trackingParticlesInTime,
0748     trackingParticlesElectron,
0749     trackingParticlesConversion
0750 )
0751 fastSim.toReplaceWith(tracksPreValidation, tracksPreValidation.copyAndExclude([
0752     trackingParticlesElectron,
0753     trackingParticlesConversion,
0754 ]))
0755 
0756 
0757 
0758 tracksValidation = cms.Sequence(
0759     trackValidator +
0760     trackValidatorTPPtLess09 +
0761     trackValidatorFromPV +
0762     trackValidatorFromPVAllTP +
0763     trackValidatorAllTPEffic +
0764     trackValidatorBuilding +
0765     trackValidatorBuildingPreSplitting +
0766     trackValidatorConversion +
0767     trackValidatorGsfTracks,
0768     tracksPreValidation
0769 )
0770 
0771 trackValidatorHILowPtConformalValidator = trackValidator.clone(
0772     dirName = "Tracking/HIPixelTrack/",
0773     label = [
0774         "hiConformalPixelTracks",
0775     ],
0776     doResolutionPlotsForLabels = ["hiConformalPixelTracks"],
0777     trackCollectionForDrCalculation = "hiConformalPixelTracks",
0778     associators = ["trackingParticleHIPixelTrackAssociation"],
0779     vertexAssociator = "HIPixelVertexAssociatorByPositionAndTracks",
0780     dodEdxPlots = False,
0781     cores = "" 
0782 )
0783 
0784 tracksValidationHIonTask = cms.Task(trackValidatorHILowPtConformalValidator) 
0785 
0786 tracksValidationHIon = cms.Sequence(
0787     tracksValidation.copy(),
0788     tracksValidationHIonTask    
0789 )
0790 
0791 pp_on_AA.toReplaceWith(tracksValidation,tracksValidationHIon)
0792 
0793 
0794 from Configuration.ProcessModifiers.seedingDeepCore_cff import seedingDeepCore
0795 seedingDeepCore.toReplaceWith(tracksValidation, cms.Sequence(tracksValidation.copy()+trackValidatorJetCore))
0796 
0797 from Configuration.ProcessModifiers.displacedTrackValidation_cff import displacedTrackValidation
0798 displacedTrackValidation.toReplaceWith(tracksValidation, cms.Sequence(tracksValidation.copy()+trackValidatorDisplaced))
0799 
0800 from Configuration.Eras.Modifier_phase2_tracker_cff import phase2_tracker
0801 tracksPreValidationPhase2 = tracksPreValidation.copy()
0802 tracksPreValidationPhase2.add(trackingParticlesEtaGreater2p7)
0803 phase2_tracker.toReplaceWith(tracksPreValidation, tracksPreValidationPhase2)
0804 
0805 tracksValidationPhase2 = tracksValidation.copyAndExclude([
0806     trackValidatorJetCore
0807 ])
0808 tracksValidationPhase2+=trackValidatorTPEtaGreater2p7
0809 phase2_tracker.toReplaceWith(tracksValidation, tracksValidationPhase2)
0810 
0811 fastSim.toReplaceWith(tracksValidation, tracksValidation.copyAndExclude([
0812     trackValidatorBuildingPreSplitting,
0813     trackValidatorConversion,
0814     trackValidatorGsfTracks,
0815 ]))
0816 
0817 ### Then define stuff for standalone mode (i.e. MTV with RECO+DIGI input)
0818 
0819 # Select by originalAlgo and algoMask
0820 _taskForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
0821                 args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["ByAlgoMask", "algorithmMaskContains"],
0822                 names = "_selectorsByAlgoMask", task = "_tracksValidationSelectorsByAlgoMaskStandalone")
0823 
0824 # Select pT>0.9 by iteration
0825 # Need to avoid generalTracks+HP because those are already included in the standard validator
0826 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
0827                 args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["Pt09", "generalTracksPt09"],
0828                 names = "_selectorsPt09Standalone", task = "_tracksValidationSelectorsPt09Standalone")
0829 
0830 # Select fromPV by iteration
0831 # Need to avoid generalTracks+HP because those are already included in the standard validator
0832 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
0833                 args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPV", "generalTracksFromPV"],
0834                 names = "_selectorsFromPVStandalone", task = "_tracksValidationSelectorsFromPVStandalone")
0835 
0836 # Select pt>0.9 and fromPV by iteration
0837 # Need to avoid generalTracks+HP because those are already included in the standard validator
0838 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
0839                 args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPVPt09", "generalTracksFromPVPt09"],
0840                 names = "_selectorsFromPVPt09Standalone", task = "_tracksValidationSelectorsFromPVPt09Standalone")
0841 
0842 # MTV instances
0843 trackValidatorStandalone = trackValidator.clone(
0844     cores = "highPtJets"
0845 )
0846 trackValidatorTPPtLess09Standalone = trackValidatorTPPtLess09.clone(
0847     cores = "highPtJets"
0848 )
0849 for _eraName, _postfix, _era in _relevantEras:
0850     _setForEra(trackValidatorStandalone, _eraName, _era, label = trackValidator.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
0851     _setForEra(trackValidatorTPPtLess09Standalone, _eraName, _era, label = trackValidatorTPPtLess09.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
0852 
0853 trackValidatorFromPVStandalone = trackValidatorFromPV.clone(
0854     cores = "highPtJets"
0855 )
0856 for _eraName, _postfix, _era in _relevantEras:
0857     _setForEra(trackValidatorFromPVStandalone, _eraName, _era, label = trackValidatorFromPV.label + locals()["_selectorsFromPVStandalone"+_postfix] + locals()["_selectorsFromPVPt09Standalone"+_postfix])
0858 # do resolutions as in the standard version
0859 
0860 trackValidatorFromPVAllTPStandalone = trackValidatorFromPVAllTP.clone(
0861     label = trackValidatorFromPVStandalone.label.value(),
0862     cores = "highPtJets"
0863 
0864 )
0865 trackValidatorAllTPEfficStandalone = trackValidatorAllTPEffic.clone(
0866     label = [ x for x in trackValidator.label.value() if x not in ["cutsRecoTracksBtvLike", "cutsRecoTracksAK4PFJets"] and "Pt09" not in x],
0867     cores = "highPtJets"
0868 )
0869 
0870 trackValidatorConversionStandalone = trackValidatorConversion.clone(
0871     label = [x for x in trackValidatorConversion.label if x != "convStepTracks"],
0872     cores = "highPtJets"
0873 )
0874 
0875 trackValidatorBHadronStandalone = trackValidatorBHadron.clone(
0876     label = [x for x in trackValidatorStandalone.label if "Pt09" not in x],
0877     cores = "highPtJets"
0878 )
0879 
0880 trackValidatorGsfTracksStandalone = trackValidatorGsfTracks.clone(
0881     cores = "highPtJets"
0882 )
0883 
0884 # sequences
0885 tracksPreValidationStandalone = tracksPreValidation.copy()
0886 tracksPreValidationStandalone.add(trackingParticlesBHadron)
0887 tracksPreValidationStandalone.replace(highPtJetsForTrk,highPtJets)
0888 fastSim.toReplaceWith(tracksPreValidationStandalone, tracksPreValidation)
0889 
0890 tracksValidationSelectorsStandalone = cms.Task(
0891     tracksValidationSelectorsByAlgoMaskStandalone,
0892     tracksValidationSelectorsPt09Standalone,
0893     tracksValidationSelectorsFromPVStandalone,
0894     tracksValidationSelectorsFromPVPt09Standalone
0895 )
0896 
0897 # we copy this for both Standalone and TrackingOnly
0898 #  and later make modifications from it which change based on era
0899 _trackValidatorsBase = cms.Sequence(
0900     trackValidatorStandalone +
0901     trackValidatorTPPtLess09Standalone +
0902     trackValidatorFromPVStandalone +
0903     trackValidatorFromPVAllTPStandalone +
0904     trackValidatorAllTPEfficStandalone +
0905     trackValidatorConversionStandalone +
0906     trackValidatorGsfTracksStandalone +
0907     trackValidatorBHadronStandalone
0908 )
0909 
0910 _trackValidatorsBasePhase2 = _trackValidatorsBase.copy()
0911 _trackValidatorsBasePhase2+=trackValidatorTPEtaGreater2p7
0912 phase2_tracker.toReplaceWith(_trackValidatorsBase, _trackValidatorsBasePhase2)
0913 
0914 trackValidatorsStandalone = _trackValidatorsBase.copy()
0915 fastSim.toModify(trackValidatorsStandalone, lambda x: x.remove(trackValidatorConversionStandalone) )
0916 
0917 tracksValidationStandalone = cms.Sequence(
0918     ak4PFL1FastL2L3CorrectorChain +
0919     trackValidatorsStandalone,
0920     tracksPreValidationStandalone,
0921     tracksValidationSelectorsStandalone
0922 )
0923 
0924 ### TrackingOnly mode (i.e. MTV with DIGI input + tracking-only reconstruction)
0925 
0926 # selectors
0927 tracksValidationSelectorsTrackingOnly = tracksValidationSelectors.copyAndExclude([ak4JetTracksAssociatorExplicitAll,cutsRecoTracksAK4PFJets]) # selectors using track information only (i.e. no PF)
0928 _taskForEachEra(_addSeedToTrackProducers, args=["_seedProducers"], names="_seedSelectors", task="_tracksValidationSeedSelectorsTrackingOnly", includeFastSim=True, modDict=globals())
0929 _taskForEachEra(_addSeedToTrackProducers, args=["_seedProducersPreSplitting"], names="_seedSelectorsPreSplitting", task="_tracksValidationSeedSelectorsPreSplittingTrackingOnly", modDict=globals())
0930 tracksValidationSeedSelectorsTrackingOnly.add(tracksValidationSeedSelectorsPreSplittingTrackingOnly)
0931 
0932 # MTV instances
0933 trackValidatorTrackingOnly = trackValidatorStandalone.clone(
0934     label = [ x for x in trackValidatorStandalone.label if x != "cutsRecoTracksAK4PFJets"],
0935     cores = "highPtJetsForTrk"
0936  )
0937 
0938 trackValidatorSeedingTrackingOnly = _trackValidatorSeedingBuilding.clone(
0939     dirName = "Tracking/TrackSeeding/",
0940     label = _seedSelectors,
0941     doSeedPlots = True,
0942     doResolutionPlotsForLabels = [ "seedTracksjetCoreRegionalStepSeeds" ]
0943 )
0944 seedingDeepCore.toModify(trackValidatorSeedingTrackingOnly, doResolutionPlotsForLabels = ["seedTracksjetCoreRegionalStepSeedsBarrel","seedTracksjetCoreRegionalStepSeedsEndcap"] )
0945 
0946 trackValidatorSeedingPreSplittingTrackingOnly = trackValidatorSeedingTrackingOnly.clone(
0947     associators = ["quickTrackAssociatorByHitsPreSplitting"],
0948     label = _seedSelectorsPreSplitting,
0949     doSummaryPlots = False,
0950 
0951 )
0952 
0953 trackValidatorJetCoreSeedingTrackingOnly = trackValidatorSeedingTrackingOnly.clone(
0954     dirName = "Tracking/JetCore/TrackSeeding/",
0955     associators = ["trackAssociatorByChi2"],
0956     UseAssociators = True,
0957     doSeedPlots = True,
0958 )
0959 
0960 for _eraName, _postfix, _era in _relevantEras:
0961     if 'jetCoreRegionalStep' in _cfg.iterationAlgos(_postfix) :
0962       _setForEra(trackValidatorJetCoreSeedingTrackingOnly, _eraName, _era,
0963                  label = [ "seedTracksjetCoreRegionalStepSeedsBarrel","seedTracksjetCoreRegionalStepSeedsEndcap" ],
0964                  doResolutionPlotsForLabels = [ "seedTracksjetCoreRegionalStepSeedsBarrel","seedTracksjetCoreRegionalStepSeedsEndcap" ]
0965       )
0966     
0967 for _eraName, _postfix, _era in _relevantErasAndFastSim:
0968     _setForEra(trackValidatorSeedingTrackingOnly, _eraName, _era, label = locals()["_seedSelectors"+_postfix])
0969 for _eraName, _postfix, _era in _relevantEras:
0970     _setForEra(trackValidatorSeedingPreSplittingTrackingOnly, _eraName, _era, label = locals()["_seedSelectorsPreSplitting"+_postfix])
0971 
0972 
0973 trackValidatorConversionTrackingOnly = trackValidatorConversion.clone(label = [x for x in trackValidatorConversion.label if x not in ["ckfInOutTracksFromConversions", "ckfOutInTracksFromConversions"]])
0974 
0975 trackValidatorBHadronTrackingOnly = trackValidatorBHadron.clone(label = [x for x in trackValidatorTrackingOnly.label if "Pt09" not in x])
0976 
0977 trackValidatorTPPtLess09TrackingOnly = trackValidatorTPPtLess09Standalone.clone(cores = "highPtJetsForTrk")
0978 trackValidatorFromPVTrackingOnly = trackValidatorFromPVStandalone.clone(cores = "highPtJetsForTrk")
0979 trackValidatorFromPVAllTPTrackingOnly = trackValidatorFromPVAllTPStandalone.clone(cores = "highPtJetsForTrk")
0980 trackValidatorAllTPEfficTrackingOnly = trackValidatorAllTPEfficStandalone.clone(cores = "highPtJetsForTrk")
0981 # sequences
0982 tracksPreValidationTrackingOnly = tracksPreValidationStandalone.copy()
0983 tracksPreValidationTrackingOnly.replace(tracksValidationSelectors, tracksValidationSelectorsTrackingOnly)
0984 tracksPreValidationTrackingOnly.replace(highPtJets,highPtJetsForTrk)
0985 
0986 trackValidatorsTrackingOnly = _trackValidatorsBase.copy()
0987 trackValidatorsTrackingOnly.replace(trackValidatorStandalone, trackValidatorTrackingOnly)
0988 trackValidatorsTrackingOnly.replace(trackValidatorTPPtLess09Standalone,trackValidatorTPPtLess09TrackingOnly)
0989 trackValidatorsTrackingOnly.replace(trackValidatorFromPVStandalone,trackValidatorFromPVTrackingOnly)
0990 trackValidatorsTrackingOnly.replace(trackValidatorFromPVAllTPStandalone,trackValidatorFromPVAllTPTrackingOnly)
0991 trackValidatorsTrackingOnly.replace(trackValidatorAllTPEfficStandalone,trackValidatorAllTPEfficTrackingOnly)
0992 trackValidatorsTrackingOnly += trackValidatorSeedingTrackingOnly
0993 trackValidatorsTrackingOnly += trackValidatorSeedingPreSplittingTrackingOnly
0994 trackValidatorsTrackingOnly += trackValidatorBuilding
0995 trackValidatorsTrackingOnly += trackValidatorBuildingPreSplitting
0996 trackValidatorsTrackingOnly.replace(trackValidatorConversionStandalone, trackValidatorConversionTrackingOnly)
0997 trackValidatorsTrackingOnly.remove(trackValidatorGsfTracksStandalone)
0998 trackValidatorsTrackingOnly.replace(trackValidatorBHadronStandalone, trackValidatorBHadronTrackingOnly)
0999 
1000 (seedingDeepCore & ~fastSim).toReplaceWith(trackValidatorsTrackingOnly, cms.Sequence(
1001             trackValidatorsTrackingOnly.copy()+
1002             trackValidatorJetCore+
1003             trackValidatorJetCoreSeedingTrackingOnly
1004             ) 
1005         )
1006 phase2_tracker.toReplaceWith(trackValidatorsTrackingOnly, trackValidatorsTrackingOnly.copyAndExclude([ #must be done for each era which does not have jetcore in the iteration
1007     trackValidatorJetCore,
1008     trackValidatorJetCoreSeedingTrackingOnly
1009 ])) 
1010 
1011 displacedTrackValidation.toReplaceWith(trackValidatorsTrackingOnly, cms.Sequence(trackValidatorsTrackingOnly.copy()+trackValidatorDisplaced))
1012 
1013 fastSim.toReplaceWith(trackValidatorsTrackingOnly, trackValidatorsTrackingOnly.copyAndExclude([
1014     trackValidatorBuildingPreSplitting,
1015     trackValidatorSeedingPreSplittingTrackingOnly,
1016     trackValidatorConversionTrackingOnly,
1017     trackValidatorBHadronTrackingOnly
1018 ]))
1019 tracksValidationTrackingOnly = cms.Sequence(
1020     trackValidatorsTrackingOnly,
1021     tracksPreValidationTrackingOnly,
1022     tracksValidationSelectorsStandalone,
1023     tracksValidationSeedSelectorsTrackingOnly
1024 )
1025 
1026 
1027 tracksValidationHIonTrackingOnly = cms.Sequence(
1028     tracksValidation.copy(),
1029     tracksValidationHIonTask    
1030 )
1031 
1032 pp_on_AA.toReplaceWith(tracksValidationTrackingOnly,tracksValidationHIonTrackingOnly)
1033 
1034 
1035 ####################################################################################################
1036 ### Pixel tracking only mode (placeholder for now)
1037 trackingParticlePixelTrackAsssociation = trackingParticleRecoTrackAsssociation.clone(
1038     label_tr = "pixelTracks",
1039     associator = "quickTrackAssociatorByHitsPreSplitting",
1040 )
1041 PixelVertexAssociatorByPositionAndTracks = VertexAssociatorByPositionAndTracks.clone(
1042     trackAssociation = "trackingParticlePixelTrackAsssociation"
1043 )
1044 
1045 _pixelTracksCustom = dict(
1046     src = "pixelTracks",
1047     vertexTag = "pixelVertices",
1048 )
1049 
1050 trackRefSelector = cms.EDFilter('TrackRefSelector',
1051                                 src = cms.InputTag('pixelTracks'),
1052                                 cut = cms.string("")
1053 )
1054 
1055 trackSelector = cms.EDFilter('TrackSelector',
1056                              src = cms.InputTag('pixelTracks'),
1057                              cut = cms.string("")
1058 )
1059 
1060 cutstring = "hitPattern.trackerLayersWithMeasurement == 3"
1061 pixelTracks3hits = trackRefSelector.clone( cut = cutstring )
1062 
1063 cutstring = "hitPattern.trackerLayersWithMeasurement >= 4"
1064 pixelTracks4hits = trackRefSelector.clone( cut = cutstring )
1065 
1066 cutstring = "pt > 0.9"
1067 pixelTracksPt09 = trackRefSelector.clone( cut = cutstring )
1068 #pixelTracksPt09 = generalTracksPt09.clone(quality = ["undefQuality"], **_pixelTracksCustom)
1069 
1070 pixelTracksFromPV = generalTracksFromPV.clone(quality = "highPurity", ptMin = 0.0, ptMax = 99999., ptErrorCut = 99999., copyExtras = True, **_pixelTracksCustom)
1071 #pixelTracksFromPVPt09 = generalTracksPt09.clone(quality = ["loose","tight","highPurity"], vertexTag = "pixelVertices", src = "pixelTracksFromPV")
1072 pixelTracksFromPVPt09 = pixelTracksFromPV.clone(ptMin = 0.9)
1073 
1074 cutstring = "hitPattern.trackerLayersWithMeasurement >= 4"
1075 #pixelTracksFromPV4hits = trackRefSelector.clone( cut = cutstring, src = "pixelTracksFromPV" )
1076 pixelTracksFromPV4hits = pixelTracksFromPV.clone( numberOfValidPixelHits = 4 )
1077 
1078 
1079 trackValidatorPixelTrackingOnly = trackValidator.clone(
1080     dirName = "Tracking/PixelTrack/",
1081     label = [
1082         "pixelTracks", "pixelTracksPt09", "pixelTracks3hits", "pixelTracks4hits",
1083         "pixelTracksL", "pixelTracksPt09L", "pixelTracks3hitsL", "pixelTracks4hitsL",
1084         "pixelTracksT", "pixelTracksPt09T", "pixelTracks3hitsT", "pixelTracks4hitsT",
1085         "pixelTracksHP", "pixelTracksPt09HP", "pixelTracks3hitsHP", "pixelTracks4hitsHP",
1086     ],
1087     doResolutionPlotsForLabels = [],
1088     trackCollectionForDrCalculation = "pixelTracks",
1089     associators = ["trackingParticlePixelTrackAsssociation"],
1090     label_vertex = "pixelVertices",
1091     vertexAssociator = "PixelVertexAssociatorByPositionAndTracks",
1092     dodEdxPlots = False,
1093     cores = "" 
1094 )
1095 
1096 trackValidatorFromPVPixelTrackingOnly = trackValidatorPixelTrackingOnly.clone(
1097     dirName = "Tracking/PixelTrackFromPV/",
1098     label = [
1099         "pixelTracksFromPV", "pixelTracksFromPVPt09", "pixelTracksFromPV4hits",
1100         "pixelTracksFromPVL", "pixelTracksFromPVT", "pixelTracksFromPVHP",
1101         "pixelTracksFromPVPt09L", "pixelTracksFromPVPt09T", "pixelTracksFromPVPt09HP",
1102         "pixelTracksFromPV4hitsL", "pixelTracksFromPV4hitsT", "pixelTracksFromPV4hitsHP",
1103     ],
1104     label_tp_effic = "trackingParticlesSignal",
1105     label_tp_fake = "trackingParticlesSignal",
1106     label_tp_effic_refvector = True,
1107     label_tp_fake_refvector = True,
1108     trackCollectionForDrCalculation = "pixelTracksFromPV",
1109     doPlotsOnlyForTruePV = True,
1110     doPVAssociationPlots = False,
1111     doResolutionPlotsForLabels = ["disabled"],
1112 )
1113 trackValidatorFromPVAllTPPixelTrackingOnly = trackValidatorFromPVPixelTrackingOnly.clone(
1114     dirName = "Tracking/PixelTrackFromPVAllTP/",
1115     label_tp_effic = trackValidatorPixelTrackingOnly.label_tp_effic.value(),
1116     label_tp_fake = trackValidatorPixelTrackingOnly.label_tp_fake.value(),
1117     label_tp_effic_refvector = False,
1118     label_tp_fake_refvector = False,
1119     doSimPlots = False,
1120     doSimTrackPlots = False,
1121 )
1122 trackValidatorBHadronPixelTrackingOnly = trackValidatorPixelTrackingOnly.clone(
1123     dirName = "Tracking/PixelTrackBHadron/",
1124     label = [
1125         "pixelTracks", "pixelTracksPt09",
1126         "pixelTracksL", "pixelTracks3hitsL", "pixelTracks4hitsL",
1127         "pixelTracksT", "pixelTracks3hitsT", "pixelTracks4hitsT",
1128         "pixelTracksHP", "pixelTracks3hitsHP", "pixelTracks4hitsHP",
1129          ],
1130     label_tp_effic = "trackingParticlesBHadron",
1131     label_tp_effic_refvector = True,
1132     doSimPlots = True,
1133     doRecoTrackPlots = False, # Fake rate is defined wrt. all TPs, and that is already included in trackValidator
1134     dodEdxPlots = False,
1135 )
1136 
1137 tracksValidationTruthPixelTrackingOnly = tracksValidationTruth.copy()
1138 tracksValidationTruthPixelTrackingOnly.replace(trackingParticleRecoTrackAsssociation, trackingParticlePixelTrackAsssociation)
1139 tracksValidationTruthPixelTrackingOnly.replace(VertexAssociatorByPositionAndTracks, PixelVertexAssociatorByPositionAndTracks)
1140 tracksValidationTruthPixelTrackingOnly.add(trackingParticlesBHadron)
1141 tracksValidationTruthPixelTrackingOnly.add( pixelTracks3hits )
1142 tracksValidationTruthPixelTrackingOnly.add( pixelTracks4hits )
1143 tracksValidationTruthPixelTrackingOnly.add( pixelTracksPt09 )
1144 tracksValidationTruthPixelTrackingOnly.add( pixelTracksFromPV )
1145 tracksValidationTruthPixelTrackingOnly.add( pixelTracksFromPVPt09 )
1146 tracksValidationTruthPixelTrackingOnly.add( pixelTracksFromPV4hits )
1147 
1148 tracksPreValidationPixelTrackingOnly = cms.Task(
1149     tracksValidationTruthPixelTrackingOnly,
1150     trackingParticlesSignal)
1151 
1152 ##https://cmssdt.cern.ch/lxr/source/DataFormats/TrackReco/interface/TrackBase.h#0150
1153 quality = {
1154     "L"  : (1,"loose",     ["loose","tight","highPurity"]),
1155     "T"  : (2,"tight",     ["tight","highPurity"]),
1156     "HP" : (4,"highPurity",["highPurity"]),
1157 }
1158 
1159 for key,value in quality.items():
1160     qualityName = value[1]
1161     qualityBit  = value[0]
1162     qualityList = value[2]
1163 
1164     label = "pixelTracks"+str(key)
1165     cutstring = "qualityMask <= 7 & qualityMask >= " + str(qualityBit)
1166     locals()[label] = trackRefSelector.clone( cut = cutstring )
1167     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1168 
1169     label = "pixelTracksFromPV"+key
1170 #    locals()[label] = generalTracksPt09.clone( ptMin = 0.0, vertexTag = "pixelVertices", src = "pixelTracksFromPV", quality = qualityList )
1171     locals()[label] = pixelTracksFromPV.clone( quality = qualityName )
1172     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1173 #-----------    
1174     cutstring = "pt > 0.9 & qualityMask <= 7 & qualityMask >= " + str(qualityBit) 
1175     label = "pixelTracksPt09"+key
1176     locals()[label] = trackRefSelector.clone( cut = cutstring )
1177     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1178 
1179     label = "pixelTracksFromPVPt09"+key
1180  #   locals()[label] = generalTracksPt09.clone( ptMin = 0.9, vertexTag = "pixelVertices", src = "pixelTracksFromPV", quality = qualityList )
1181     locals()[label] = pixelTracksFromPVPt09.clone( quality = qualityName )
1182     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1183 #-----------         
1184     label = "pixelTracks4hits"+key
1185     cutstring = "hitPattern.trackerLayersWithMeasurement >= 4 & qualityMask <= 7 & qualityMask >= " + str(qualityBit)
1186     locals()[label] = trackRefSelector.clone( cut = cutstring )
1187     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1188     
1189     label = "pixelTracksFromPV4hits"+key
1190 #    locals()[label] = generalTracksPt09.clone( ptMin = 0.0, minHit = 4, vertexTag = "pixelVertices", src = "pixelTracksFromPV", quality = qualityList )
1191     locals()[label] = pixelTracksFromPV4hits.clone( quality = qualityName )
1192     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1193 #--------    
1194     label = "pixelTracks3hits"+key
1195     cutstring = "hitPattern.trackerLayersWithMeasurement == 3 & qualityMask <= 7 & qualityMask >= " + str(qualityBit)
1196     locals()[label] = trackRefSelector.clone( cut = cutstring )
1197     tracksPreValidationPixelTrackingOnly.add(locals()[label])
1198      
1199 tracksValidationPixelTrackingOnly = cms.Sequence(
1200     trackValidatorPixelTrackingOnly +
1201     trackValidatorFromPVPixelTrackingOnly +
1202     trackValidatorFromPVAllTPPixelTrackingOnly +
1203     trackValidatorBHadronPixelTrackingOnly,
1204     tracksPreValidationPixelTrackingOnly
1205 )
1206 ####################################################################################################
1207 
1208 ### Lite mode (only generalTracks and HP)
1209 trackValidatorLite = trackValidator.clone(
1210     label = ["generalTracks", "cutsRecoTracksHp"]
1211 )
1212 tracksValidationLite = cms.Sequence(
1213     cutsRecoTracksHp +
1214     trackValidatorLite,
1215     tracksValidationTruth
1216 )
1217 
1218 ## customization for timing
1219 from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
1220 phase2_timing_layer.toModify( generalTracksFromPV, 
1221                               timesTag  = cms.InputTag('tofPID:t0'), 
1222                               timeResosTag = cms.InputTag('tofPID:sigmat0'),
1223                               nSigmaDtVertex = cms.double(3) )
1224 phase2_timing_layer.toModify( trackValidatorStandalone,
1225                               label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
1226 phase2_timing_layer.toModify( trackValidatorFromPVStandalone,
1227                               label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
1228 phase2_timing_layer.toModify( trackValidatorFromPVAllTPStandalone,
1229                               label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
1230 phase2_timing_layer.toModify( trackValidatorConversionStandalone,
1231                               label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
1232 phase2_timing_layer.toModify( trackValidatorGsfTracks,
1233                               label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )