Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-02 03:39:41

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