CMS 3D CMS Logo

TrackValidation_cff.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 import FWCore.ParameterSet.Config as cms
3 
8 from Validation.RecoTrack.trajectorySeedTracks_cfi import trajectorySeedTracks as _trajectorySeedTracks
12 from . import cutsRecoTracks_cfi
13 
16 from CommonTools.RecoAlgos.trackingParticleRefSelector_cfi import trackingParticleRefSelector as _trackingParticleRefSelector
17 from CommonTools.RecoAlgos.trackingParticleConversionRefSelector_cfi import trackingParticleConversionRefSelector as _trackingParticleConversionRefSelector
18 from SimTracker.TrackHistory.trackingParticleBHadronRefSelector_cfi import trackingParticleBHadronRefSelector as _trackingParticleBHadronRefSelector
20 from CommonTools.RecoAlgos.recoChargedRefCandidateToTrackRefProducer_cfi import recoChargedRefCandidateToTrackRefProducer as _recoChargedRefCandidateToTrackRefProducer
21 
22 import RecoTracker.IterativeTracking.iterativeTkConfig as _cfg
23 import RecoTracker.IterativeTracking.iterativeTkUtils as _utils
24 from Configuration.Eras.Modifier_fastSim_cff import fastSim
25 import six
26 
27 ### First define the stuff for the standard validation sequence
28 ## Track selectors
29 for _eraName, _postfix, _era in _cfg.allEras():
30  _seedProd = ["initialStepSeedsPreSplitting"]
31  _trackProd = ["initialStepTracksPreSplitting"]
32  if _eraName in ["trackingLowPU", "trackingPhase2PU140"]: # these don't have preSplitting
33  _seedProd = []
34  _trackProd = []
35 
36  locals()["_algos"+_postfix] = ["generalTracks"] + _cfg.iterationAlgos(_postfix) + ["duplicateMerge"]
37  locals()["_seedProducersPreSplitting"+_postfix] = _seedProd
38  locals()["_trackProducersPreSplitting"+_postfix] = _trackProd
39  locals()["_seedProducers"+_postfix] = _cfg.seedProducers(_postfix)
40  locals()["_trackProducers"+_postfix] = _cfg.trackProducers(_postfix)
41 
42  if _eraName != "trackingPhase2PU140":
43  locals()["_electronSeedProducers"+_postfix] = ["tripletElectronSeeds", "pixelPairElectronSeeds", "stripPairElectronSeeds"]
44  else:
45  locals()["_electronSeedProducers"+_postfix] = ["tripletElectronSeeds"]
46 
47 _removeForFastSimSeedProducers =["initialStepSeedsPreSplitting",
48  "jetCoreRegionalStepSeeds",
49  "muonSeededSeedsInOut",
50  "muonSeededSeedsOutIn"]
51 _seedProducers_fastSim = [ x for x in _seedProducers if x not in _removeForFastSimSeedProducers]
52 
53 _removeForFastTrackProducers = ["initialStepTracksPreSplitting",
54  "jetCoreRegionalStepTracks",
55  "muonSeededTracksInOut",
56  "muonSeededTracksOutIn"]
57 _trackProducers_fastSim = [ x for x in _trackProducers if x not in _removeForFastTrackProducers]
58 
59 def _algoToSelector(algo):
60  sel = ""
61  if algo != "generalTracks":
62  sel = algo[0].upper()+algo[1:]
63  return "cutsRecoTracks"+sel
64 
65 def _addSelectorsByAlgo(algos, modDict):
66  names = []
67  task = cms.Task()
68  for algo in algos:
69  if algo == "generalTracks":
70  continue
71  modName = _algoToSelector(algo)
72  if modName not in modDict:
73  mod = cutsRecoTracks_cfi.cutsRecoTracks.clone(algorithm=[algo])
74  modDict[modName] = mod
75  else:
76  mod = modDict[modName]
77  names.append(modName)
78  task.add(mod)
79  return (names, task)
80 def _addSelectorsByHp(algos, modDict):
81  task = cms.Task()
82  names = []
83  for algo in algos:
84  modName = _algoToSelector(algo)
85  modNameHp = modName+"Hp"
86  if modNameHp not in modDict:
87  if algo == "generalTracks":
88  mod = cutsRecoTracks_cfi.cutsRecoTracks.clone(quality=["highPurity"])
89  else:
90  mod = modDict[modName].clone(quality=["highPurity"])
91  modDict[modNameHp] = mod
92  else:
93  mod = modDict[modNameHp]
94  names.append(modNameHp)
95  task.add(mod)
96  return (names, task)
97 def _addSelectorsBySrc(modules, midfix, src, modDict):
98  task = cms.Task()
99  names = []
100  for modName in modules:
101  modNameNew = modName.replace("cutsRecoTracks", "cutsRecoTracks"+midfix)
102  if modNameNew not in modDict:
103  mod = modDict[modName].clone(src=src)
104  modDict[modNameNew] = mod
105  else:
106  mod = modDict[modNameNew]
107  names.append(modNameNew)
108  task.add(mod)
109  return (names, task)
110 def _addSelectorsByOriginalAlgoMask(modules, midfix, algoParam,modDict):
111  task = cms.Task()
112  names = []
113  for modName in modules:
114  if modName[-2:] == "Hp":
115  modNameNew = modName[:-2] + midfix + "Hp"
116  else:
117  modNameNew = modName + midfix
118  if modNameNew not in modDict:
119  mod = modDict[modName].clone()
120  setattr(mod, algoParam, mod.algorithm.value())
121  mod.algorithm = []
122  modDict[modNameNew] = mod
123  else:
124  mod = modDict[modNameNew]
125  names.append(modNameNew)
126  task.add(mod)
127  return (names, task)
128 def _addSeedToTrackProducers(seedProducers,modDict):
129  names = []
130  task = cms.Task()
131  for seed in seedProducers:
132  modName = "seedTracks"+seed
133  if modName not in modDict:
134  mod = _trajectorySeedTracks.clone(src=seed)
135  modDict[modName] = mod
136  else:
137  mod = modDict[modName]
138  names.append(modName)
139  task.add(mod)
140  return (names, task)
141 
142 _relevantEras = _cfg.allEras()
143 _relevantErasAndFastSim = _relevantEras + [("fastSim", "_fastSim", fastSim)]
144 def _translateArgs(args, postfix, modDict):
145  ret = []
146  for arg in args:
147  if isinstance(arg, list):
148  ret.append(_translateArgs(arg, postfix, modDict))
149  else:
150  ret.append(modDict[arg+postfix])
151  return ret
152 def _taskForEachEra(function, args, names, task, modDict, plainArgs=[], modifyTask=None, includeFastSim=False):
153  if task[0] != "_":
154  raise Exception("Task name is expected to begin with _")
155 
156  _eras = _relevantErasAndFastSim if includeFastSim else _relevantEras
157  for eraName, postfix, _era in _eras:
158  _args = _translateArgs(args, postfix, modDict)
159  _args.extend(plainArgs)
160  ret = function(*_args, modDict=modDict)
161  if len(ret) != 2:
162  raise Exception("_taskForEachEra is expected to return 2 values, but function returned %d" % len(ret))
163  modDict[names+postfix] = ret[0]
164  modDict[task+postfix] = ret[1]
165 
166  # The task of the first era will be the default one
167  defaultTaskName = task+_eras[0][0]
168  defaultTask = modDict[defaultTaskName]
169  modDict[defaultTaskName[1:]] = defaultTask # remove leading underscore
170 
171  # Optionally modify task before applying the era
172  if modifyTask is not None:
173  for eraName, postfix, _era in _eras:
174  modifyTask(modDict[task+postfix])
175 
176  # Apply eras
177  for _eraName, _postfix, _era in _eras[1:]:
178  _era.toReplaceWith(defaultTask, modDict[task+_postfix])
179 def _setForEra(module, eraName, era, **kwargs):
180  if eraName == "":
181  for key, value in six.iteritems(kwargs):
182  setattr(module, key, value)
183  else:
184  era.toModify(module, **kwargs)
185 
186 # Seeding layer sets
187 def _getSeedingLayers(seedProducers, config):
188  def _findSeedingLayers(name):
189  prod = getattr(config, name)
190  if hasattr(prod, "triplets"):
191  if hasattr(prod, "layerList"): # merger
192  return prod.layerList.refToPSet_.value()
193  return _findSeedingLayers(prod.triplets.getModuleLabel())
194  elif hasattr(prod, "doublets"):
195  return _findSeedingLayers(prod.doublets.getModuleLabel())
196  label = prod.trackingRegionsSeedingLayers.getModuleLabel()
197  if label != "":
198  return label
199  return prod.seedingLayers.getModuleLabel()
200 
201  seedingLayersMerged = []
202  for seedName in seedProducers:
203  seedProd = getattr(config, seedName)
204  seedingLayersName = None
205  seedingLayers = None
206  if hasattr(seedProd, "OrderedHitsFactoryPSet"): # old seeding framework
207  seedingLayersName = seedProd.OrderedHitsFactoryPSet.SeedingLayers.getModuleLabel()
208  elif hasattr(seedProd, "seedingHitSets"): # new seeding framework
209  seedingLayersName = _findSeedingLayers(seedProd.seedingHitSets.getModuleLabel())
210  elif hasattr(seedProd, "layerList"): # FastSim:
211  seedingLayers = seedProd.layerList.value()
212  else:
213  continue
214 
215  if seedingLayersName is not None:
216  seedingLayers = getattr(config, seedingLayersName).layerList.value()
217  for layerSet in seedingLayers:
218  if layerSet not in seedingLayersMerged:
219  seedingLayersMerged.append(layerSet)
220 
221  return seedingLayersMerged
222 import RecoTracker.IterativeTracking.iterativeTk_cff as _iterativeTk_cff
223 import RecoTracker.IterativeTracking.ElectronSeeds_cff as _ElectronSeeds_cff
224 for _eraName, _postfix, _era in _relevantErasAndFastSim:
225  _stdLayers = _getSeedingLayers(locals()["_seedProducers"+_postfix], _iterativeTk_cff)
226  _eleLayers = []
227  if "_electronSeedProducers"+_postfix in locals(): # doesn't exist for FastSim
228  for _layer in _getSeedingLayers(locals()["_electronSeedProducers"+_postfix], _ElectronSeeds_cff):
229  if _layer not in _stdLayers:
230  _eleLayers.append(_layer)
231 
232  locals()["_seedingLayerSets"+_postfix] = _stdLayers
233  locals()["_seedingLayerSetsForElectrons"+_postfix] = _eleLayers
234 
235 
236 # MVA selectors
237 def _getMVASelectors(postfix):
238  mvaSel = _utils.getMVASelectors(postfix)
239 
240  pset = cms.untracked.PSet()
241  for iteration, (trackProducer, classifiers) in six.iteritems(mvaSel):
242  setattr(pset, trackProducer, cms.untracked.vstring(classifiers))
243  return pset
244 for _eraName, _postfix, _era in _relevantEras:
245  locals()["_mvaSelectors"+_postfix] = _getMVASelectors(_postfix)
246 
247 # Validation iterative steps
248 _taskForEachEra(_addSelectorsByAlgo, args=["_algos"], names="_selectorsByAlgo", task="_tracksValidationSelectorsByAlgo", modDict=globals())
249 
250 # high purity
251 _taskForEachEra(_addSelectorsByHp, args=["_algos"], names="_selectorsByAlgoHp", task="_tracksValidationSelectorsByAlgoHp", modDict=globals())
252 
253 # by originalAlgo
254 for _eraName, _postfix, _era in _relevantEras:
255  locals()["_selectorsByAlgoAndHp"+_postfix] = locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix]
256  # For ByAlgoMask
257  locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix] = [n for n in locals()["_selectorsByAlgoAndHp"+_postfix] if n not in ["generalTracks", "cutsRecoTracksHp"]]
258  # For ByOriginalAlgo
259  locals()["_selectorsByAlgoAndHpNoGenTkDupMerge"+_postfix] = [n for n in locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix] if n not in ["cutsRecoTracksDuplicateMerge", "cutsRecoTracksDuplicateMergeHp"]]
260 _taskForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
261  args = ["_selectorsByAlgoAndHpNoGenTkDupMerge"], plainArgs = ["ByOriginalAlgo", "originalAlgorithm"],
262  names = "_selectorsByOriginalAlgo", task = "_tracksValidationSelectorsByOriginalAlgo")
263 
264 
265 for _eraName, _postfix, _era in _relevantEras:
266  selectors = locals()["_selectorsByAlgoHp"+_postfix]
267  locals()["_generalTracksHp"+_postfix] = selectors[0]
268  locals()["_selectorsByAlgoHp"+_postfix] = selectors[1:]
269 
270 # BTV-like selection
271 import PhysicsTools.RecoAlgos.btvTracks_cfi as btvTracks_cfi
272 cutsRecoTracksBtvLike = btvTracks_cfi.btvTrackRefs.clone()
273 
274 # Select tracks associated to AK4 jets
276 ak4JetTracksAssociatorExplicitAll = ak4JTA_cff.ak4JetTracksAssociatorExplicit.clone(
277  jets = "ak4PFJets"
278 )
280 import CommonTools.RecoAlgos.jetTracksAssociationToTrackRefs_cfi as jetTracksAssociationToTrackRefs_cfi
281 cutsRecoTracksAK4PFJets = jetTracksAssociationToTrackRefs_cfi.jetTracksAssociationToTrackRefs.clone(
282  association = "ak4JetTracksAssociatorExplicitAll",
283  jets = "ak4PFJets",
284  correctedPtMin = 10,
285 )
286 
287 
288 ## Select signal TrackingParticles, and do the corresponding associations
289 trackingParticlesSignal = _trackingParticleRefSelector.clone(
290  signalOnly = True,
291  chargedOnly = False,
292  tip = 1e5,
293  lip = 1e5,
294  minRapidity = -10,
295  maxRapidity = 10,
296  ptMin = 0,
297 )
298 
299 # select tracks with pT > 0.9 GeV (for upgrade fake rates)
300 generalTracksPt09 = cutsRecoTracks_cfi.cutsRecoTracks.clone(ptMin=0.9)
301 # and then the selectors
302 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
303  args=[["_generalTracksHp"]],
304  plainArgs=["Pt09", "generalTracksPt09"],
305  names="_selectorsPt09", task="_tracksValidationSelectorsPt09",
306  modifyTask=lambda task:task.add(generalTracksPt09))
307 
308 # select tracks from the PV
309 from CommonTools.RecoAlgos.TrackWithVertexRefSelector_cfi import trackWithVertexRefSelector as _trackWithVertexRefSelector
310 generalTracksFromPV = _trackWithVertexRefSelector.clone(
311  src = "generalTracks",
312  ptMin = 0,
313  ptMax = 1e10,
314  ptErrorCut = 1e10,
315  quality = "loose",
316  vertexTag = "offlinePrimaryVertices",
317  nVertices = 1,
318  vtxFallback = False,
319  zetaVtx = 0.1, # 1 mm
320  rhoVtx = 1e10, # intentionally no dxy cut
321 )
322 # and then the selectors
323 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
324  args=[["_generalTracksHp"]],
325  plainArgs=["FromPV", "generalTracksFromPV"],
326  names="_selectorsFromPV", task="_tracksValidationSelectorsFromPV",
327  modifyTask=lambda task: task.add(generalTracksFromPV))
328 
329 # select tracks with pT > 0.9 GeV from the PV
330 generalTracksFromPVPt09 = generalTracksPt09.clone(src="generalTracksFromPV")
331 # and then the selectors
332 _taskForEachEra(_addSelectorsBySrc, modDict=globals(),
333  args=[["_generalTracksHp"]],
334  plainArgs=["FromPVPt09", "generalTracksFromPVPt09"],
335  names="_selectorsFromPVPt09", task="_tracksValidationSelectorsFromPVPt09",
336  modifyTask=lambda task: task.add(generalTracksFromPVPt09))
337 
338 ## Select conversion TrackingParticles, and define the corresponding associator
339 trackingParticlesConversion = _trackingParticleConversionRefSelector.clone()
340 
341 ## Select electron TPs
342 trackingParticlesElectron = _trackingParticleRefSelector.clone(
343  pdgId = [-11, 11],
344  signalOnly = False,
345  tip = 1e5,
346  lip = 1e5,
347  minRapidity = -10,
348  maxRapidity = 10,
349  ptMin = 0,
350 )
351 
352 # Select jets for JetCore tracking
353 highPtJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("ak4CaloJets"), cut = cms.string("pt()>1000"))
354 highPtJetsForTrk = highPtJetsForTrk = highPtJets.clone(src = "ak4CaloJetsForTrk")
355 
356 # Select B-hadron TPs
357 trackingParticlesBHadron = _trackingParticleBHadronRefSelector.clone()
358 
359 ## MTV instances
360 trackValidator = Validation.RecoTrack.MultiTrackValidator_cfi.multiTrackValidator.clone(
361  useLogPt = cms.untracked.bool(True),
362  dodEdxPlots = True,
363  doPVAssociationPlots = True
364  #,minpT = cms.double(-1)
365  #,maxpT = cms.double(3)
366  #,nintpT = cms.int32(40)
367 )
368 fastSim.toModify(trackValidator,
369  dodEdxPlots = False)
370 
371 for _eraName, _postfix, _era in _relevantEras:
372  _setForEra(trackValidator, _eraName, _era,
373  label = ["generalTracks", locals()["_generalTracksHp"+_postfix]] +
374  locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix] +
375  locals()["_selectorsByOriginalAlgo"+_postfix] +
376  ["generalTracksPt09"] + locals()["_selectorsPt09"+_postfix] +
377  [
378  "cutsRecoTracksBtvLike",
379  "cutsRecoTracksAK4PFJets"
380  ],
381  doResolutionPlotsForLabels = [
382  "generalTracks",
383  locals()["_generalTracksHp"+_postfix],
384  "generalTracksPt09",
385  "cutsRecoTracksBtvLike",
386  ]
387  )
388  _setForEra(trackValidator.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=locals()["_seedingLayerSets"+_postfix])
389 
390 # for low-pT
391 trackValidatorTPPtLess09 = trackValidator.clone(
392  dirName = "Tracking/TrackTPPtLess09/",
393  label = [x for x in trackValidator.label.value() if ("Pt09" not in x) and ("BtvLike" not in x) and ("AK4PFJets" not in x)],
394  ptMaxTP = 0.9, # set maximum pT globally
395  histoProducerAlgoBlock = dict(
396  TpSelectorForEfficiencyVsEta = dict(ptMin=0.05), # enough to set min pT here
397  TpSelectorForEfficiencyVsPhi = dict(ptMin=0.05),
398  TpSelectorForEfficiencyVsVTXR = dict(ptMin=0.05),
399  TpSelectorForEfficiencyVsVTXZ = dict(ptMin=0.05),
400  ),
401  doSimPlots = False, # same as in trackValidator, no need to repeat here
402  doRecoTrackPlots = False, # fake rates are same as in trackValidator, no need to repeat here
403  doResolutionPlotsForLabels = ["disabled"], # resolutions are same as in trackValidator, no need to repeat here
404 )
405 
406 # For efficiency of signal TPs vs. signal tracks, and fake rate of
407 # signal tracks vs. signal TPs
408 trackValidatorFromPV = trackValidator.clone(
409  dirName = "Tracking/TrackFromPV/",
410  label_tp_effic = "trackingParticlesSignal",
411  label_tp_fake = "trackingParticlesSignal",
412  label_tp_effic_refvector = True,
413  label_tp_fake_refvector = True,
414  trackCollectionForDrCalculation = "generalTracksFromPV",
415  doPlotsOnlyForTruePV = True,
416  doPVAssociationPlots = False,
417  doResolutionPlotsForLabels = ["disabled"],
418 )
419 for _eraName, _postfix, _era in _relevantEras:
420  _setForEra(trackValidatorFromPV, _eraName, _era,
421  label = ["generalTracksFromPV"] + locals()["_selectorsFromPV"+_postfix] + ["generalTracksFromPVPt09"] + locals()["_selectorsFromPVPt09"+_postfix],
422  doResolutionPlotsForLabels = [] # for standard "FromPV" do resolution plots for all input collections as they are already limited
423  )
424 
425 # For fake rate of signal tracks vs. all TPs, and pileup rate of
426 # signal tracks vs. non-signal TPs
427 trackValidatorFromPVAllTP = trackValidatorFromPV.clone(
428  dirName = "Tracking/TrackFromPVAllTP/",
429  label_tp_effic = trackValidator.label_tp_effic.value(),
430  label_tp_fake = trackValidator.label_tp_fake.value(),
431  label_tp_effic_refvector = False,
432  label_tp_fake_refvector = False,
433  doSimPlots = False,
434  doSimTrackPlots = False,
435  doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidatorFromPV"
436 )
437 
438 # For efficiency of all TPs vs. all tracks
439 trackValidatorAllTPEffic = trackValidator.clone(
440  dirName = "Tracking/TrackAllTPEffic/",
441  label = [x for x in trackValidator.label.value() if "Pt09" not in x],
442  doSimPlots = False,
443  doRecoTrackPlots = True, # Fake rate of all tracks vs. all TPs is already included in trackValidator, but we want the reco plots for other reasons
444  doPVAssociationPlots = False,
445  doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidator"
446 )
447 trackValidatorAllTPEffic.histoProducerAlgoBlock.generalTpSelector.signalOnly = False
448 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsEta.signalOnly = False
449 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPhi.signalOnly = False
450 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPt.signalOnly = False
451 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXR.signalOnly = False
452 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXZ.signalOnly = False
453 for _eraName, _postfix, _era in _relevantEras:
454  _setForEra(trackValidatorAllTPEffic, _eraName, _era, label = ["generalTracks", locals()["_generalTracksHp"+_postfix]])
455 
456 # Built tracks, in the standard sequence mainly for monitoring the track selection MVA
457 tpClusterProducerPreSplitting = tpClusterProducer.clone(pixelClusterSrc = "siPixelClustersPreSplitting")
458 quickTrackAssociatorByHitsPreSplitting = quickTrackAssociatorByHits.clone(cluster2TPSrc = "tpClusterProducerPreSplitting")
459 _trackValidatorSeedingBuilding = trackValidator.clone( # common for built tracks and seeds (in trackingOnly)
460  associators = ["quickTrackAssociatorByHits"],
461  UseAssociators = True,
462  dodEdxPlots = False,
463  doPVAssociationPlots = False,
464  doSimPlots = False,
465  doResolutionPlotsForLabels = ["disabled"],
466 )
467 trackValidatorBuilding = _trackValidatorSeedingBuilding.clone(
468  dirName = "Tracking/TrackBuilding/",
469  doMVAPlots = True,
470 )
471 trackValidatorBuildingPreSplitting = trackValidatorBuilding.clone(
472  associators = ["quickTrackAssociatorByHitsPreSplitting"],
473  doMVAPlots = False,
474  doSummaryPlots = False,
475 )
476 for _eraName, _postfix, _era in _relevantErasAndFastSim:
477  _setForEra(trackValidatorBuilding, _eraName, _era, label = locals()["_trackProducers"+_postfix])
478 fastSim.toModify(trackValidatorBuilding, doMVAPlots=False)
479 for _eraName, _postfix, _era in _relevantEras:
480  _setForEra(trackValidatorBuilding, _eraName, _era, mvaLabels = locals()["_mvaSelectors"+_postfix])
481  _setForEra(trackValidatorBuildingPreSplitting, _eraName, _era, label = locals()["_trackProducersPreSplitting"+_postfix])
482 
483 
484 # For conversions
485 trackValidatorConversion = trackValidator.clone(
486  dirName = "Tracking/TrackConversion/",
487  label = [
488  "convStepTracks",
489  "conversionStepTracks",
490  "ckfInOutTracksFromConversions",
491  "ckfOutInTracksFromConversions",
492  ],
493  label_tp_effic = "trackingParticlesConversion",
494  label_tp_effic_refvector = True,
495  associators = ["quickTrackAssociatorByHits"],
496  UseAssociators = True,
497  doSimPlots = True,
498  dodEdxPlots = False,
499  doPVAssociationPlots = False,
500  calculateDrSingleCollection = False,
501 )
502 from RecoTracker.ConversionSeedGenerators.ConversionStep_cff import convLayerPairs as _convLayerPairs
503 def _uniqueFirstLayers(layerList):
504  firstLayers = [layerSet.split("+")[0] for layerSet in layerList]
505  ret = []
506  for l in firstLayers:
507  if not l in ret:
508  ret.append(l)
509  # For conversions add also the mono-TEC to the list as 'TEC'
510  # is used for both matched and unmatched rphi/stereo hits
511  if l.startswith("TEC"):
512  ret.append("M"+l)
513  return ret
514 # PhotonConversionTrajectorySeedProducerFromSingleLeg keeps only the
515 # first hit of the pairs in the seed, bookkeeping those is the best we
516 # can do without major further development
517 trackValidatorConversion.histoProducerAlgoBlock.seedingLayerSets = _uniqueFirstLayers(_convLayerPairs.layerList.value())
518 # relax lip and tip
519 for n in ["Eta", "Phi", "Pt", "VTXR", "VTXZ"]:
520  pset = getattr(trackValidatorConversion.histoProducerAlgoBlock, "TpSelectorForEfficiencyVs"+n)
521  pset.lip = trackValidatorConversion.lipTP.value()
522  pset.tip = trackValidatorConversion.tipTP.value()
523 
524 # For electrons
525 trackValidatorGsfTracks = trackValidatorConversion.clone(
526  dirName = "Tracking/TrackGsf/",
527  label = ["electronGsfTracks"],
528  label_tp_effic = "trackingParticlesElectron",
529 )
530 # add the additional seeding layers from ElectronSeeds
531 for _eraName, _postfix, _era in _relevantEras:
532  _setForEra(trackValidatorGsfTracks.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=trackValidator.histoProducerAlgoBlock.seedingLayerSets.value()+locals()["_seedingLayerSetsForElectrons"+_postfix])
533 
534 
535 
536 # for B-hadrons
537 trackValidatorBHadron = trackValidator.clone(
538  dirName = "Tracking/TrackBHadron/",
539  label_tp_effic = "trackingParticlesBHadron",
540  label_tp_effic_refvector = True,
541  doSimPlots = True,
542  doRecoTrackPlots = False, # Fake rate is defined wrt. all TPs, and that is already included in trackValidator
543  dodEdxPlots = False,
544 )
545 for _eraName, _postfix, _era in _relevantEras:
546  _setForEra(trackValidatorBHadron, _eraName, _era,
547  label = ["generalTracks", locals()["_generalTracksHp"+_postfix], "cutsRecoTracksBtvLike"]
548  )
549 
550 
551 # the track selectors
552 tracksValidationSelectors = cms.Task(
553  tracksValidationSelectorsByAlgo,
554  tracksValidationSelectorsByAlgoHp,
555  tracksValidationSelectorsByOriginalAlgo,
556  cutsRecoTracksBtvLike,
557  ak4JetTracksAssociatorExplicitAll,
558  cutsRecoTracksAK4PFJets
559 )
560 tracksValidationTruth = cms.Task(
561  tpClusterProducer,
562  tpClusterProducerPreSplitting,
563  quickTrackAssociatorByHits,
564  quickTrackAssociatorByHitsPreSplitting,
565  trackingParticleRecoTrackAsssociation,
566  VertexAssociatorByPositionAndTracks,
567  trackingParticleNumberOfLayersProducer
568 )
569 fastSim.toModify(tracksValidationTruth, lambda x: x.remove(tpClusterProducer))
570 
571 tracksPreValidation = cms.Task(
572  highPtJetsForTrk,
573  tracksValidationSelectors,
574  tracksValidationSelectorsPt09,
575  tracksValidationSelectorsFromPV,
576  tracksValidationSelectorsFromPVPt09,
577  tracksValidationTruth,
578  trackingParticlesSignal,
579  trackingParticlesElectron,
580  trackingParticlesConversion
581 )
582 fastSim.toReplaceWith(tracksPreValidation, tracksPreValidation.copyAndExclude([
583  trackingParticlesElectron,
584  trackingParticlesConversion,
585 ]))
586 
587 tracksValidation = cms.Sequence(
588  trackValidator +
589  trackValidatorTPPtLess09 +
590  trackValidatorFromPV +
591  trackValidatorFromPVAllTP +
592  trackValidatorAllTPEffic +
593  trackValidatorBuilding +
594  trackValidatorBuildingPreSplitting +
595  trackValidatorConversion +
596  trackValidatorGsfTracks,
597  tracksPreValidation
598 )
599 fastSim.toReplaceWith(tracksValidation, tracksValidation.copyAndExclude([
600  trackValidatorBuildingPreSplitting,
601  trackValidatorConversion,
602  trackValidatorGsfTracks,
603 ]))
604 
605 ### Then define stuff for standalone mode (i.e. MTV with RECO+DIGI input)
606 
607 # Select by originalAlgo and algoMask
608 _taskForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
609  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["ByAlgoMask", "algorithmMaskContains"],
610  names = "_selectorsByAlgoMask", task = "_tracksValidationSelectorsByAlgoMaskStandalone")
611 
612 # Select pT>0.9 by iteration
613 # Need to avoid generalTracks+HP because those are already included in the standard validator
614 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
615  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["Pt09", "generalTracksPt09"],
616  names = "_selectorsPt09Standalone", task = "_tracksValidationSelectorsPt09Standalone")
617 
618 # Select fromPV by iteration
619 # Need to avoid generalTracks+HP because those are already included in the standard validator
620 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
621  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPV", "generalTracksFromPV"],
622  names = "_selectorsFromPVStandalone", task = "_tracksValidationSelectorsFromPVStandalone")
623 
624 # Select pt>0.9 and fromPV by iteration
625 # Need to avoid generalTracks+HP because those are already included in the standard validator
626 _taskForEachEra(_addSelectorsBySrc, modDict = globals(),
627  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPVPt09", "generalTracksFromPVPt09"],
628  names = "_selectorsFromPVPt09Standalone", task = "_tracksValidationSelectorsFromPVPt09Standalone")
629 
630 # MTV instances
631 trackValidatorStandalone = trackValidator.clone(
632  cores = "highPtJets"
633 )
634 trackValidatorTPPtLess09Standalone = trackValidatorTPPtLess09.clone(
635  cores = "highPtJets"
636 )
637 for _eraName, _postfix, _era in _relevantEras:
638  _setForEra(trackValidatorStandalone, _eraName, _era, label = trackValidator.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
639  _setForEra(trackValidatorTPPtLess09Standalone, _eraName, _era, label = trackValidatorTPPtLess09.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
640 
641 trackValidatorFromPVStandalone = trackValidatorFromPV.clone(
642  cores = "highPtJets"
643 )
644 for _eraName, _postfix, _era in _relevantEras:
645  _setForEra(trackValidatorFromPVStandalone, _eraName, _era, label = trackValidatorFromPV.label + locals()["_selectorsFromPVStandalone"+_postfix] + locals()["_selectorsFromPVPt09Standalone"+_postfix])
646 # do resolutions as in the standard version
647 
648 trackValidatorFromPVAllTPStandalone = trackValidatorFromPVAllTP.clone(
649  label = trackValidatorFromPVStandalone.label.value(),
650  cores = "highPtJets"
651 
652 )
653 trackValidatorAllTPEfficStandalone = trackValidatorAllTPEffic.clone(
654  label = [ x for x in trackValidator.label.value() if x not in ["cutsRecoTracksBtvLike", "cutsRecoTracksAK4PFJets"] and "Pt09" not in x],
655  cores = "highPtJets"
656 
657 )
658 
659 trackValidatorConversionStandalone = trackValidatorConversion.clone(
660  label = [x for x in trackValidatorConversion.label if x != "convStepTracks"],
661  cores = "highPtJets"
662 )
663 
664 trackValidatorBHadronStandalone = trackValidatorBHadron.clone(
665  label = [x for x in trackValidatorStandalone.label if "Pt09" not in x],
666  cores = "highPtJets"
667 )
668 
669 trackValidatorGsfTracksStandalone = trackValidatorGsfTracks.clone(
670  cores = "highPtJets"
671 )
672 
673 # sequences
674 tracksPreValidationStandalone = tracksPreValidation.copy()
675 tracksPreValidationStandalone.add(trackingParticlesBHadron)
676 tracksPreValidationStandalone.replace(highPtJetsForTrk,highPtJets)
677 fastSim.toReplaceWith(tracksPreValidationStandalone, tracksPreValidation)
678 
679 tracksValidationSelectorsStandalone = cms.Task(
680  tracksValidationSelectorsByAlgoMaskStandalone,
681  tracksValidationSelectorsPt09Standalone,
682  tracksValidationSelectorsFromPVStandalone,
683  tracksValidationSelectorsFromPVPt09Standalone
684 )
685 
686 # we copy this for both Standalone and TrackingOnly
687 # and later make modifications from it which change based on era
688 _trackValidatorsBase = cms.Sequence(
689  trackValidatorStandalone +
690  trackValidatorTPPtLess09Standalone +
691  trackValidatorFromPVStandalone +
692  trackValidatorFromPVAllTPStandalone +
693  trackValidatorAllTPEfficStandalone +
694  trackValidatorConversionStandalone +
695  trackValidatorGsfTracksStandalone +
696  trackValidatorBHadronStandalone
697 )
698 trackValidatorsStandalone = _trackValidatorsBase.copy()
699 fastSim.toModify(trackValidatorsStandalone, lambda x: x.remove(trackValidatorConversionStandalone) )
700 
701 tracksValidationStandalone = cms.Sequence(
702  ak4PFL1FastL2L3CorrectorChain +
703  trackValidatorsStandalone,
704  tracksPreValidationStandalone,
705  tracksValidationSelectorsStandalone
706 )
707 
708 ### TrackingOnly mode (i.e. MTV with DIGI input + tracking-only reconstruction)
709 
710 # selectors
711 tracksValidationSelectorsTrackingOnly = tracksValidationSelectors.copyAndExclude([ak4JetTracksAssociatorExplicitAll,cutsRecoTracksAK4PFJets]) # selectors using track information only (i.e. no PF)
712 _taskForEachEra(_addSeedToTrackProducers, args=["_seedProducers"], names="_seedSelectors", task="_tracksValidationSeedSelectorsTrackingOnly", includeFastSim=True, modDict=globals())
713 _taskForEachEra(_addSeedToTrackProducers, args=["_seedProducersPreSplitting"], names="_seedSelectorsPreSplitting", task="_tracksValidationSeedSelectorsPreSplittingTrackingOnly", modDict=globals())
714 tracksValidationSeedSelectorsTrackingOnly.add(tracksValidationSeedSelectorsPreSplittingTrackingOnly)
715 
716 # MTV instances
717 trackValidatorTrackingOnly = trackValidatorStandalone.clone(
718  label = [ x for x in trackValidatorStandalone.label if x != "cutsRecoTracksAK4PFJets"],
719  cores = "highPtJetsForTrk"
720  )
721 
722 trackValidatorSeedingTrackingOnly = _trackValidatorSeedingBuilding.clone(
723  dirName = "Tracking/TrackSeeding/",
724  label = _seedSelectors,
725  doSeedPlots = True,
726 )
727 trackValidatorSeedingPreSplittingTrackingOnly = trackValidatorSeedingTrackingOnly.clone(
728  associators = ["quickTrackAssociatorByHitsPreSplitting"],
729  label = _seedSelectorsPreSplitting,
730  doSummaryPlots = False,
731 
732 )
733 for _eraName, _postfix, _era in _relevantErasAndFastSim:
734  _setForEra(trackValidatorSeedingTrackingOnly, _eraName, _era, label = locals()["_seedSelectors"+_postfix])
735 for _eraName, _postfix, _era in _relevantEras:
736  _setForEra(trackValidatorSeedingPreSplittingTrackingOnly, _eraName, _era, label = locals()["_seedSelectorsPreSplitting"+_postfix])
737 
738 
739 trackValidatorConversionTrackingOnly = trackValidatorConversion.clone(label = [x for x in trackValidatorConversion.label if x not in ["ckfInOutTracksFromConversions", "ckfOutInTracksFromConversions"]])
740 
741 trackValidatorBHadronTrackingOnly = trackValidatorBHadron.clone(label = [x for x in trackValidatorTrackingOnly.label if "Pt09" not in x])
742 
743 trackValidatorTPPtLess09TrackingOnly = trackValidatorTPPtLess09Standalone.clone(cores = "highPtJetsForTrk")
744 trackValidatorFromPVTrackingOnly = trackValidatorFromPVStandalone.clone(cores = "highPtJetsForTrk")
745 trackValidatorFromPVAllTPTrackingOnly = trackValidatorFromPVAllTPStandalone.clone(cores = "highPtJetsForTrk")
746 trackValidatorAllTPEfficTrackingOnly = trackValidatorAllTPEfficStandalone.clone(cores = "highPtJetsForTrk")
747 # sequences
748 tracksPreValidationTrackingOnly = tracksPreValidationStandalone.copy()
749 tracksPreValidationTrackingOnly.replace(tracksValidationSelectors, tracksValidationSelectorsTrackingOnly)
750 tracksPreValidationTrackingOnly.replace(highPtJets,highPtJetsForTrk)
751 
752 trackValidatorsTrackingOnly = _trackValidatorsBase.copy()
753 trackValidatorsTrackingOnly.replace(trackValidatorStandalone, trackValidatorTrackingOnly)
754 trackValidatorsTrackingOnly.replace(trackValidatorTPPtLess09Standalone,trackValidatorTPPtLess09TrackingOnly)
755 trackValidatorsTrackingOnly.replace(trackValidatorFromPVStandalone,trackValidatorFromPVTrackingOnly)
756 trackValidatorsTrackingOnly.replace(trackValidatorFromPVAllTPStandalone,trackValidatorFromPVAllTPTrackingOnly)
757 trackValidatorsTrackingOnly.replace(trackValidatorAllTPEfficStandalone,trackValidatorAllTPEfficTrackingOnly)
758 trackValidatorsTrackingOnly += trackValidatorSeedingTrackingOnly
759 trackValidatorsTrackingOnly += trackValidatorSeedingPreSplittingTrackingOnly
760 trackValidatorsTrackingOnly += trackValidatorBuilding
761 trackValidatorsTrackingOnly += trackValidatorBuildingPreSplitting
762 trackValidatorsTrackingOnly.replace(trackValidatorConversionStandalone, trackValidatorConversionTrackingOnly)
763 trackValidatorsTrackingOnly.remove(trackValidatorGsfTracksStandalone)
764 trackValidatorsTrackingOnly.replace(trackValidatorBHadronStandalone, trackValidatorBHadronTrackingOnly)
765 fastSim.toReplaceWith(trackValidatorsTrackingOnly, trackValidatorsTrackingOnly.copyAndExclude([
766  trackValidatorBuildingPreSplitting,
767  trackValidatorSeedingPreSplittingTrackingOnly,
768  trackValidatorConversionTrackingOnly,
769  trackValidatorBHadronTrackingOnly
770 ]))
771 
772 
773 tracksValidationTrackingOnly = cms.Sequence(
774  trackValidatorsTrackingOnly,
775  tracksPreValidationTrackingOnly,
776  tracksValidationSelectorsStandalone,
777  tracksValidationSeedSelectorsTrackingOnly
778 )
779 
780 
781 ### Pixel tracking only mode (placeholder for now)
782 trackingParticlePixelTrackAsssociation = trackingParticleRecoTrackAsssociation.clone(
783  label_tr = "pixelTracks",
784  associator = "quickTrackAssociatorByHitsPreSplitting",
785 )
786 PixelVertexAssociatorByPositionAndTracks = VertexAssociatorByPositionAndTracks.clone(
787  trackAssociation = "trackingParticlePixelTrackAsssociation"
788 )
789 
790 trackValidatorPixelTrackingOnly = trackValidator.clone(
791  dirName = "Tracking/PixelTrack/",
792  label = ["pixelTracks"],
793  doResolutionPlotsForLabels = [],
794  trackCollectionForDrCalculation = "pixelTracks",
795  associators = ["trackingParticlePixelTrackAsssociation"],
796  label_vertex = "pixelVertices",
797  vertexAssociator = "PixelVertexAssociatorByPositionAndTracks",
798  dodEdxPlots = False,
799  cores = cms.InputTag(""),
800 )
801 
802 tracksValidationTruthPixelTrackingOnly = tracksValidationTruth.copy()
803 tracksValidationTruthPixelTrackingOnly.replace(trackingParticleRecoTrackAsssociation, trackingParticlePixelTrackAsssociation)
804 tracksValidationTruthPixelTrackingOnly.replace(VertexAssociatorByPositionAndTracks, PixelVertexAssociatorByPositionAndTracks)
805 tracksValidationPixelTrackingOnly = cms.Sequence(
806  trackValidatorPixelTrackingOnly,
807  tracksValidationTruthPixelTrackingOnly
808 )
809 
810 
811 ### Lite mode (only generalTracks and HP)
812 trackValidatorLite = trackValidator.clone(
813  label = ["generalTracks", "cutsRecoTracksHp"]
814 )
815 tracksValidationLite = cms.Sequence(
816  cutsRecoTracksHp +
817  trackValidatorLite,
818  tracksValidationTruth
819 )
820 
821 ## customization for timing
822 from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
823 phase2_timing_layer.toModify( generalTracksFromPV,
824  timesTag = cms.InputTag('trackTimeValueMapProducer:generalTracksConfigurableFlatResolutionModel'),
825  timeResosTag = cms.InputTag('trackTimeValueMapProducer:generalTracksConfigurableFlatResolutionModelResolution'),
826  nSigmaDtVertex = cms.double(3) )
827 phase2_timing_layer.toModify( trackValidatorStandalone,
828  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
829 phase2_timing_layer.toModify( trackValidatorFromPVStandalone,
830  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
831 phase2_timing_layer.toModify( trackValidatorFromPVAllTPStandalone,
832  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
833 phase2_timing_layer.toModify( trackValidatorConversionStandalone,
834  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
835 phase2_timing_layer.toModify( trackValidatorGsfTracks,
836  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
837 
838 from Configuration.Eras.Modifier_phase2_timing_layer_tile_cff import phase2_timing_layer_tile
839 from Configuration.Eras.Modifier_phase2_timing_layer_bar_cff import phase2_timing_layer_bar
840 (phase2_timing_layer_tile | phase2_timing_layer_bar).toModify( generalTracksFromPV,
841  timesTag = cms.InputTag('tofPID:t0'),
842  timeResosTag = cms.InputTag('tofPID:sigmat0') )
Definition: vlib.h:256
def _setForEra(module, eraName, era, kwargs)
def _translateArgs(args, postfix, modDict)
def _uniqueFirstLayers(layerList)
_addSelectorsByOriginalAlgoMask
Then define stuff for standalone mode (i.e.
def _getSeedingLayers(seedProducers, config)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def _taskForEachEra(function, args, names, task, modDict, plainArgs=[], modifyTask=None, includeFastSim=False)