Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:40

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