CMS 3D CMS Logo

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