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  seedingLayersName = None
198  seedingLayers = None
199  if hasattr(seedProd, "OrderedHitsFactoryPSet"): # old seeding framework
200  seedingLayersName = seedProd.OrderedHitsFactoryPSet.SeedingLayers.getModuleLabel()
201  elif hasattr(seedProd, "seedingHitSets"): # new seeding framework
202  seedingLayersName = _findSeedingLayers(seedProd.seedingHitSets.getModuleLabel())
203  elif hasattr(seedProd, "layerList"): # FastSim:
204  seedingLayers = seedProd.layerList.value()
205  else:
206  continue
207 
208  if seedingLayersName is not None:
209  seedingLayers = getattr(config, seedingLayersName).layerList.value()
210  for layerSet in seedingLayers:
211  if layerSet not in seedingLayersMerged:
212  seedingLayersMerged.append(layerSet)
213 
214  return seedingLayersMerged
215 import RecoTracker.IterativeTracking.iterativeTk_cff as _iterativeTk_cff
216 import RecoTracker.IterativeTracking.ElectronSeeds_cff as _ElectronSeeds_cff
217 for _eraName, _postfix, _era in _relevantErasAndFastSim:
218  _stdLayers = _getSeedingLayers(locals()["_seedProducers"+_postfix], _iterativeTk_cff)
219  _eleLayers = []
220  if "_electronSeedProducers"+_postfix in locals(): # doesn't exist for FastSim
221  for _layer in _getSeedingLayers(locals()["_electronSeedProducers"+_postfix], _ElectronSeeds_cff):
222  if _layer not in _stdLayers:
223  _eleLayers.append(_layer)
224 
225  locals()["_seedingLayerSets"+_postfix] = _stdLayers
226  locals()["_seedingLayerSetsForElectrons"+_postfix] = _eleLayers
227 
228 
229 # MVA selectors
230 def _getMVASelectors(postfix):
231  mvaSel = _utils.getMVASelectors(postfix)
232 
233  pset = cms.untracked.PSet()
234  for iteration, (trackProducer, classifiers) in mvaSel.iteritems():
235  setattr(pset, trackProducer, cms.untracked.vstring(classifiers))
236  return pset
237 for _eraName, _postfix, _era in _relevantEras:
238  locals()["_mvaSelectors"+_postfix] = _getMVASelectors(_postfix)
239 
240 # Validation iterative steps
241 _sequenceForEachEra(_addSelectorsByAlgo, args=["_algos"], names="_selectorsByAlgo", sequence="_tracksValidationSelectorsByAlgo", modDict=globals())
242 
243 # high purity
244 _sequenceForEachEra(_addSelectorsByHp, args=["_algos"], names="_selectorsByAlgoHp", sequence="_tracksValidationSelectorsByAlgoHp", modDict=globals())
245 
246 # by originalAlgo
247 for _eraName, _postfix, _era in _relevantEras:
248  locals()["_selectorsByAlgoAndHp"+_postfix] = locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix]
249  # For ByAlgoMask
250  locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix] = filter(lambda n: n not in ["generalTracks", "cutsRecoTracksHp"], locals()["_selectorsByAlgoAndHp"+_postfix])
251  # For ByOriginalAlgo
252  locals()["_selectorsByAlgoAndHpNoGenTkDupMerge"+_postfix] = filter(lambda n: n not in ["cutsRecoTracksDuplicateMerge", "cutsRecoTracksDuplicateMergeHp"], locals()["_selectorsByAlgoAndHpNoGenTk"+_postfix])
253 _sequenceForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
254  args = ["_selectorsByAlgoAndHpNoGenTkDupMerge"], plainArgs = ["ByOriginalAlgo", "originalAlgorithm"],
255  names = "_selectorsByOriginalAlgo", sequence = "_tracksValidationSelectorsByOriginalAlgo")
256 
257 
258 for _eraName, _postfix, _era in _relevantEras:
259  selectors = locals()["_selectorsByAlgoHp"+_postfix]
260  locals()["_generalTracksHp"+_postfix] = selectors[0]
261  locals()["_selectorsByAlgoHp"+_postfix] = selectors[1:]
262 
263 # BTV-like selection
264 import PhysicsTools.RecoAlgos.btvTracks_cfi as btvTracks_cfi
265 cutsRecoTracksBtvLike = btvTracks_cfi.btvTrackRefs.clone()
266 
267 # Select tracks associated to AK4 jets
269 ak4JetTracksAssociatorExplicitAll = ak4JTA_cff.ak4JetTracksAssociatorExplicit.clone(
270  jets = "ak4PFJets"
271 )
273 import CommonTools.RecoAlgos.jetTracksAssociationToTrackRefs_cfi as jetTracksAssociationToTrackRefs_cfi
274 cutsRecoTracksAK4PFJets = jetTracksAssociationToTrackRefs_cfi.jetTracksAssociationToTrackRefs.clone(
275  association = "ak4JetTracksAssociatorExplicitAll",
276  jets = "ak4PFJets",
277  correctedPtMin = 10,
278 )
279 
280 
281 ## Select signal TrackingParticles, and do the corresponding associations
282 trackingParticlesSignal = _trackingParticleRefSelector.clone(
283  signalOnly = True,
284  chargedOnly = False,
285  tip = 1e5,
286  lip = 1e5,
287  minRapidity = -10,
288  maxRapidity = 10,
289  ptMin = 0,
290 )
291 
292 # select tracks with pT > 0.9 GeV (for upgrade fake rates)
293 generalTracksPt09 = cutsRecoTracks_cfi.cutsRecoTracks.clone(ptMin=0.9)
294 # and then the selectors
295 _sequenceForEachEra(_addSelectorsBySrc, modDict=globals(),
296  args=[["_generalTracksHp"]],
297  plainArgs=["Pt09", "generalTracksPt09"],
298  names="_selectorsPt09", sequence="_tracksValidationSelectorsPt09",
299  modifySequence=lambda seq:seq.insert(0, generalTracksPt09))
300 
301 # select tracks from the PV
302 from CommonTools.RecoAlgos.TrackWithVertexRefSelector_cfi import trackWithVertexRefSelector as _trackWithVertexRefSelector
303 generalTracksFromPV = _trackWithVertexRefSelector.clone(
304  src = "generalTracks",
305  ptMin = 0,
306  ptMax = 1e10,
307  ptErrorCut = 1e10,
308  quality = "loose",
309  vertexTag = "offlinePrimaryVertices",
310  nVertices = 1,
311  vtxFallback = False,
312  zetaVtx = 0.1, # 1 mm
313  rhoVtx = 1e10, # intentionally no dxy cut
314 )
315 # and then the selectors
316 _sequenceForEachEra(_addSelectorsBySrc, modDict=globals(),
317  args=[["_generalTracksHp"]],
318  plainArgs=["FromPV", "generalTracksFromPV"],
319  names="_selectorsFromPV", sequence="_tracksValidationSelectorsFromPV",
320  modifySequence=lambda seq: seq.insert(0, generalTracksFromPV))
321 
322 # select tracks with pT > 0.9 GeV from the PV
323 generalTracksFromPVPt09 = generalTracksPt09.clone(src="generalTracksFromPV")
324 # and then the selectors
325 _sequenceForEachEra(_addSelectorsBySrc, modDict=globals(),
326  args=[["_generalTracksHp"]],
327  plainArgs=["FromPVPt09", "generalTracksFromPVPt09"],
328  names="_selectorsFromPVPt09", sequence="_tracksValidationSelectorsFromPVPt09",
329  modifySequence=lambda seq: seq.insert(0, generalTracksFromPVPt09))
330 
331 ## Select conversion TrackingParticles, and define the corresponding associator
332 trackingParticlesConversion = _trackingParticleConversionRefSelector.clone()
333 
334 ## Select electron TPs
335 trackingParticlesElectron = _trackingParticleRefSelector.clone(
336  pdgId = [-11, 11],
337  signalOnly = False,
338  tip = 1e5,
339  lip = 1e5,
340  minRapidity = -10,
341  maxRapidity = 10,
342  ptMin = 0,
343 )
344 
345 # Select B-hadron TPs
346 trackingParticlesBHadron = _trackingParticleBHadronRefSelector.clone()
347 
348 ## MTV instances
349 trackValidator = Validation.RecoTrack.MultiTrackValidator_cfi.multiTrackValidator.clone(
350  useLogPt = cms.untracked.bool(True),
351  dodEdxPlots = True,
352  doPVAssociationPlots = True
353  #,minpT = cms.double(-1)
354  #,maxpT = cms.double(3)
355  #,nintpT = cms.int32(40)
356 )
357 fastSim.toModify(trackValidator,
358  dodEdxPlots = False)
359 
360 for _eraName, _postfix, _era in _relevantEras:
361  _setForEra(trackValidator, _eraName, _era,
362  label = ["generalTracks", locals()["_generalTracksHp"+_postfix]] +
363  locals()["_selectorsByAlgo"+_postfix] + locals()["_selectorsByAlgoHp"+_postfix] +
364  locals()["_selectorsByOriginalAlgo"+_postfix] +
365  ["generalTracksPt09"] + locals()["_selectorsPt09"+_postfix] +
366  [
367  "cutsRecoTracksBtvLike",
368  "cutsRecoTracksAK4PFJets"
369  ],
370  doResolutionPlotsForLabels = [
371  "generalTracks",
372  locals()["_generalTracksHp"+_postfix],
373  "generalTracksPt09",
374  "cutsRecoTracksBtvLike",
375  ]
376  )
377  _setForEra(trackValidator.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=locals()["_seedingLayerSets"+_postfix])
378 
379 # for low-pT
380 trackValidatorTPPtLess09 = trackValidator.clone(
381  dirName = "Tracking/TrackTPPtLess09/",
382  label = [x for x in trackValidator.label.value() if ("Pt09" not in x) and ("BtvLike" not in x) and ("AK4PFJets" not in x)],
383  ptMaxTP = 0.9, # set maximum pT globally
384  histoProducerAlgoBlock = dict(
385  TpSelectorForEfficiencyVsEta = dict(ptMin=0.05), # enough to set min pT here
386  TpSelectorForEfficiencyVsPhi = dict(ptMin=0.05),
387  TpSelectorForEfficiencyVsVTXR = dict(ptMin=0.05),
388  TpSelectorForEfficiencyVsVTXZ = dict(ptMin=0.05),
389  ),
390  doSimPlots = False, # same as in trackValidator, no need to repeat here
391  doRecoTrackPlots = False, # fake rates are same as in trackValidator, no need to repeat here
392  doResolutionPlotsForLabels = ["disabled"], # resolutions are same as in trackValidator, no need to repeat here
393 )
394 
395 # For efficiency of signal TPs vs. signal tracks, and fake rate of
396 # signal tracks vs. signal TPs
397 trackValidatorFromPV = trackValidator.clone(
398  dirName = "Tracking/TrackFromPV/",
399  label_tp_effic = "trackingParticlesSignal",
400  label_tp_fake = "trackingParticlesSignal",
401  label_tp_effic_refvector = True,
402  label_tp_fake_refvector = True,
403  trackCollectionForDrCalculation = "generalTracksFromPV",
404  doPlotsOnlyForTruePV = True,
405  doPVAssociationPlots = False,
406  doResolutionPlotsForLabels = ["disabled"],
407 )
408 for _eraName, _postfix, _era in _relevantEras:
409  _setForEra(trackValidatorFromPV, _eraName, _era,
410  label = ["generalTracksFromPV"] + locals()["_selectorsFromPV"+_postfix] + ["generalTracksFromPVPt09"] + locals()["_selectorsFromPVPt09"+_postfix],
411  doResolutionPlotsForLabels = [] # for standard "FromPV" do resolution plots for all input collections as they are already limited
412  )
413 
414 # For fake rate of signal tracks vs. all TPs, and pileup rate of
415 # signal tracks vs. non-signal TPs
416 trackValidatorFromPVAllTP = trackValidatorFromPV.clone(
417  dirName = "Tracking/TrackFromPVAllTP/",
418  label_tp_effic = trackValidator.label_tp_effic.value(),
419  label_tp_fake = trackValidator.label_tp_fake.value(),
420  label_tp_effic_refvector = False,
421  label_tp_fake_refvector = False,
422  doSimPlots = False,
423  doSimTrackPlots = False,
424  doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidatorFromPV"
425 )
426 
427 # For efficiency of all TPs vs. all tracks
428 trackValidatorAllTPEffic = trackValidator.clone(
429  dirName = "Tracking/TrackAllTPEffic/",
430  label = [x for x in trackValidator.label.value() if "Pt09" not in x],
431  doSimPlots = False,
432  doRecoTrackPlots = True, # Fake rate of all tracks vs. all TPs is already included in trackValidator, but we want the reco plots for other reasons
433  doPVAssociationPlots = False,
434  doResolutionPlotsForLabels = ["disabled"], # resolution plots are the same as in "trackValidator"
435 )
436 trackValidatorAllTPEffic.histoProducerAlgoBlock.generalTpSelector.signalOnly = False
437 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsEta.signalOnly = False
438 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPhi.signalOnly = False
439 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsPt.signalOnly = False
440 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXR.signalOnly = False
441 trackValidatorAllTPEffic.histoProducerAlgoBlock.TpSelectorForEfficiencyVsVTXZ.signalOnly = False
442 for _eraName, _postfix, _era in _relevantEras:
443  _setForEra(trackValidatorAllTPEffic, _eraName, _era, label = ["generalTracks", locals()["_generalTracksHp"+_postfix]])
444 
445 # Built tracks, in the standard sequence mainly for monitoring the track selection MVA
446 _trackValidatorSeedingBuilding = trackValidator.clone( # common for built tracks and seeds (in trackingOnly)
447  associators = ["quickTrackAssociatorByHits"],
448  UseAssociators = True,
449  dodEdxPlots = False,
450  doPVAssociationPlots = False,
451  doSimPlots = False,
452  doResolutionPlotsForLabels = ["disabled"],
453 )
454 trackValidatorBuilding = _trackValidatorSeedingBuilding.clone(
455  dirName = "Tracking/TrackBuilding/",
456  doMVAPlots = True,
457 )
458 for _eraName, _postfix, _era in _relevantErasAndFastSim:
459  _setForEra(trackValidatorBuilding, _eraName, _era, label = locals()["_trackProducers"+_postfix])
460 fastSim.toModify(trackValidatorBuilding, doMVAPlots=False)
461 for _eraName, _postfix, _era in _relevantEras:
462  _setForEra(trackValidatorBuilding, _eraName, _era, mvaLabels = locals()["_mvaSelectors"+_postfix])
463 
464 
465 # For conversions
466 trackValidatorConversion = trackValidator.clone(
467  dirName = "Tracking/TrackConversion/",
468  label = [
469  "convStepTracks",
470  "conversionStepTracks",
471  "ckfInOutTracksFromConversions",
472  "ckfOutInTracksFromConversions",
473  ],
474  label_tp_effic = "trackingParticlesConversion",
475  label_tp_effic_refvector = True,
476  associators = ["quickTrackAssociatorByHits"],
477  UseAssociators = True,
478  doSimPlots = True,
479  dodEdxPlots = False,
480  doPVAssociationPlots = False,
481  calculateDrSingleCollection = False,
482 )
483 from RecoTracker.ConversionSeedGenerators.ConversionStep_cff import convLayerPairs as _convLayerPairs
484 def _uniqueFirstLayers(layerList):
485  firstLayers = [layerSet.split("+")[0] for layerSet in layerList]
486  ret = []
487  for l in firstLayers:
488  if not l in ret:
489  ret.append(l)
490  return ret
491 # PhotonConversionTrajectorySeedProducerFromSingleLeg keeps only the
492 # first hit of the pairs in the seed, bookkeeping those is the best we
493 # can do without major further development
494 trackValidatorConversion.histoProducerAlgoBlock.seedingLayerSets = _uniqueFirstLayers(_convLayerPairs.layerList.value())
495 # relax lip and tip
496 for n in ["Eta", "Phi", "Pt", "VTXR", "VTXZ"]:
497  pset = getattr(trackValidatorConversion.histoProducerAlgoBlock, "TpSelectorForEfficiencyVs"+n)
498  pset.lip = trackValidatorConversion.lipTP.value()
499  pset.tip = trackValidatorConversion.tipTP.value()
500 
501 # For electrons
502 trackValidatorGsfTracks = trackValidatorConversion.clone(
503  dirName = "Tracking/TrackGsf/",
504  label = ["electronGsfTracks"],
505  label_tp_effic = "trackingParticlesElectron",
506 )
507 # add the additional seeding layers from ElectronSeeds
508 for _eraName, _postfix, _era in _relevantEras:
509  _setForEra(trackValidatorGsfTracks.histoProducerAlgoBlock, _eraName, _era, seedingLayerSets=trackValidator.histoProducerAlgoBlock.seedingLayerSets.value()+locals()["_seedingLayerSetsForElectrons"+_postfix])
510 
511 
512 
513 # for B-hadrons
514 trackValidatorBHadron = trackValidator.clone(
515  dirName = "Tracking/TrackBHadron/",
516  label_tp_effic = "trackingParticlesBHadron",
517  label_tp_effic_refvector = True,
518  doSimPlots = True,
519  doRecoTrackPlots = False, # Fake rate is defined wrt. all TPs, and that is already included in trackValidator
520  dodEdxPlots = False,
521 )
522 for _eraName, _postfix, _era in _relevantEras:
523  _setForEra(trackValidatorBHadron, _eraName, _era,
524  label = ["generalTracks", locals()["_generalTracksHp"+_postfix], "cutsRecoTracksBtvLike"]
525  )
526 
527 
528 # the track selectors
529 tracksValidationSelectors = cms.Sequence(
530  tracksValidationSelectorsByAlgo +
531  tracksValidationSelectorsByAlgoHp +
532  tracksValidationSelectorsByOriginalAlgo +
533  cutsRecoTracksBtvLike +
534  ak4JetTracksAssociatorExplicitAll +
535  cutsRecoTracksAK4PFJets
536 )
537 tracksValidationTruth = cms.Sequence(
538  tpClusterProducer +
539  quickTrackAssociatorByHits +
540  trackingParticleRecoTrackAsssociation +
541  VertexAssociatorByPositionAndTracks +
542  trackingParticleNumberOfLayersProducer
543 )
544 fastSim.toModify(tracksValidationTruth, lambda x: x.remove(tpClusterProducer))
545 
546 tracksPreValidation = cms.Sequence(
547  tracksValidationSelectors +
548  tracksValidationSelectorsPt09 +
549  tracksValidationSelectorsFromPV +
550  tracksValidationSelectorsFromPVPt09 +
551  tracksValidationTruth +
552  cms.ignore(trackingParticlesSignal) +
553  cms.ignore(trackingParticlesElectron) +
554  trackingParticlesConversion
555 )
556 fastSim.toReplaceWith(tracksPreValidation, tracksPreValidation.copyAndExclude([
557  trackingParticlesElectron,
558  trackingParticlesConversion,
559 ]))
560 
561 tracksValidation = cms.Sequence(
562  tracksPreValidation +
563  trackValidator +
564  trackValidatorTPPtLess09 +
565  trackValidatorFromPV +
566  trackValidatorFromPVAllTP +
567  trackValidatorAllTPEffic +
568  trackValidatorBuilding +
569  trackValidatorConversion +
570  trackValidatorGsfTracks
571 )
572 fastSim.toReplaceWith(tracksValidation, tracksValidation.copyAndExclude([
573  trackValidatorConversion,
574  trackValidatorGsfTracks,
575 ]))
576 
577 ### Then define stuff for standalone mode (i.e. MTV with RECO+DIGI input)
578 
579 # Select by originalAlgo and algoMask
580 _sequenceForEachEra(_addSelectorsByOriginalAlgoMask, modDict = globals(),
581  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["ByAlgoMask", "algorithmMaskContains"],
582  names = "_selectorsByAlgoMask", sequence = "_tracksValidationSelectorsByAlgoMaskStandalone")
583 
584 # Select pT>0.9 by iteration
585 # Need to avoid generalTracks+HP because those are already included in the standard validator
586 _sequenceForEachEra(_addSelectorsBySrc, modDict = globals(),
587  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["Pt09", "generalTracksPt09"],
588  names = "_selectorsPt09Standalone", sequence = "_tracksValidationSelectorsPt09Standalone")
589 
590 # Select fromPV by iteration
591 # Need to avoid generalTracks+HP because those are already included in the standard validator
592 _sequenceForEachEra(_addSelectorsBySrc, modDict = globals(),
593  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPV", "generalTracksFromPV"],
594  names = "_selectorsFromPVStandalone", sequence = "_tracksValidationSelectorsFromPVStandalone")
595 
596 # Select pt>0.9 and fromPV by iteration
597 # Need to avoid generalTracks+HP because those are already included in the standard validator
598 _sequenceForEachEra(_addSelectorsBySrc, modDict = globals(),
599  args = ["_selectorsByAlgoAndHpNoGenTk"], plainArgs = ["FromPVPt09", "generalTracksFromPVPt09"],
600  names = "_selectorsFromPVPt09Standalone", sequence = "_tracksValidationSelectorsFromPVPt09Standalone")
601 
602 # MTV instances
603 trackValidatorStandalone = trackValidator.clone()
604 trackValidatorTPPtLess09Standalone = trackValidatorTPPtLess09.clone()
605 for _eraName, _postfix, _era in _relevantEras:
606  _setForEra(trackValidatorStandalone, _eraName, _era, label = trackValidator.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
607  _setForEra(trackValidatorTPPtLess09Standalone, _eraName, _era, label = trackValidatorTPPtLess09.label + locals()["_selectorsByAlgoMask"+_postfix] + locals()["_selectorsPt09Standalone"+_postfix])
608 
609 trackValidatorFromPVStandalone = trackValidatorFromPV.clone()
610 for _eraName, _postfix, _era in _relevantEras:
611  _setForEra(trackValidatorFromPVStandalone, _eraName, _era, label = trackValidatorFromPV.label + locals()["_selectorsFromPVStandalone"+_postfix] + locals()["_selectorsFromPVPt09Standalone"+_postfix])
612 # do resolutions as in the standard version
613 
614 trackValidatorFromPVAllTPStandalone = trackValidatorFromPVAllTP.clone(
615  label = trackValidatorFromPVStandalone.label.value()
616 )
617 trackValidatorAllTPEfficStandalone = trackValidatorAllTPEffic.clone(
618  label = [ x for x in trackValidator.label.value() if x not in ["cutsRecoTracksBtvLike", "cutsRecoTracksAK4PFJets"] and "Pt09" not in x]
619 )
620 
621 trackValidatorConversionStandalone = trackValidatorConversion.clone( label = [x for x in trackValidatorConversion.label if x != "convStepTracks"])
622 
623 trackValidatorBHadronStandalone = trackValidatorBHadron.clone(label = [x for x in trackValidatorStandalone.label if "Pt09" not in x])
624 
625 # sequences
626 tracksPreValidationStandalone = tracksPreValidation.copy()
627 tracksPreValidationStandalone += trackingParticlesBHadron
628 fastSim.toReplaceWith(tracksPreValidationStandalone, tracksPreValidation)
629 
630 tracksValidationSelectorsStandalone = cms.Sequence(
631  tracksValidationSelectorsByAlgoMaskStandalone +
632  tracksValidationSelectorsPt09Standalone +
633  tracksValidationSelectorsFromPVStandalone +
634  tracksValidationSelectorsFromPVPt09Standalone
635 )
636 
637 # we copy this for both Standalone and TrackingOnly
638 # and later make modifications from it which change based on era
639 _trackValidatorsBase = cms.Sequence(
640  trackValidatorStandalone +
641  trackValidatorTPPtLess09Standalone +
642  trackValidatorFromPVStandalone +
643  trackValidatorFromPVAllTPStandalone +
644  trackValidatorAllTPEfficStandalone +
645  trackValidatorConversionStandalone +
646  trackValidatorGsfTracks +
647  trackValidatorBHadronStandalone
648 )
649 trackValidatorsStandalone = _trackValidatorsBase.copy()
650 fastSim.toModify(trackValidatorsStandalone, lambda x: x.remove(trackValidatorConversionStandalone) )
651 
652 tracksValidationStandalone = cms.Sequence(
653  ak4PFL1FastL2L3CorrectorChain +
654  tracksPreValidationStandalone +
655  tracksValidationSelectorsStandalone +
656  trackValidatorsStandalone
657 )
658 
659 ### TrackingOnly mode (i.e. MTV with DIGI input + tracking-only reconstruction)
660 
661 # selectors
662 tracksValidationSelectorsTrackingOnly = tracksValidationSelectors.copyAndExclude([ak4JetTracksAssociatorExplicitAll,cutsRecoTracksAK4PFJets]) # selectors using track information only (i.e. no PF)
663 _sequenceForEachEra(_addSeedToTrackProducers, args=["_seedProducers"], names="_seedSelectors", sequence="_tracksValidationSeedSelectorsTrackingOnly", includeFastSim=True, modDict=globals())
664 
665 # MTV instances
666 trackValidatorTrackingOnly = trackValidatorStandalone.clone(label = [ x for x in trackValidatorStandalone.label if x != "cutsRecoTracksAK4PFJets"] )
667 
668 trackValidatorSeedingTrackingOnly = _trackValidatorSeedingBuilding.clone(
669  dirName = "Tracking/TrackSeeding/",
670  label = _seedSelectors,
671  doSeedPlots = True,
672 )
673 for _eraName, _postfix, _era in _relevantErasAndFastSim:
674  _setForEra(trackValidatorSeedingTrackingOnly, _eraName, _era, label = locals()["_seedSelectors"+_postfix])
675 
676 
677 trackValidatorConversionTrackingOnly = trackValidatorConversion.clone(label = [x for x in trackValidatorConversion.label if x not in ["ckfInOutTracksFromConversions", "ckfOutInTracksFromConversions"]])
678 
679 trackValidatorBHadronTrackingOnly = trackValidatorBHadron.clone(label = [x for x in trackValidatorTrackingOnly.label if "Pt09" not in x])
680 
681 # sequences
682 tracksPreValidationTrackingOnly = tracksPreValidationStandalone.copy()
683 tracksPreValidationTrackingOnly.replace(tracksValidationSelectors, tracksValidationSelectorsTrackingOnly)
684 
685 trackValidatorsTrackingOnly = _trackValidatorsBase.copy()
686 trackValidatorsTrackingOnly.replace(trackValidatorStandalone, trackValidatorTrackingOnly)
687 trackValidatorsTrackingOnly += trackValidatorSeedingTrackingOnly
688 trackValidatorsTrackingOnly += trackValidatorBuilding
689 trackValidatorsTrackingOnly.replace(trackValidatorConversionStandalone, trackValidatorConversionTrackingOnly)
690 trackValidatorsTrackingOnly.remove(trackValidatorGsfTracks)
691 trackValidatorsTrackingOnly.replace(trackValidatorBHadronStandalone, trackValidatorBHadronTrackingOnly)
692 fastSim.toModify(trackValidatorsTrackingOnly, lambda x: x.remove(trackValidatorConversionTrackingOnly))
693 fastSim.toModify(trackValidatorsTrackingOnly, lambda x: x.remove(trackValidatorBHadronTrackingOnly))
694 
695 
696 tracksValidationTrackingOnly = cms.Sequence(
697  tracksPreValidationTrackingOnly +
698  tracksValidationSelectorsStandalone +
699  tracksValidationSeedSelectorsTrackingOnly +
700  trackValidatorsTrackingOnly
701 )
702 
703 
704 
705 ### Lite mode (only generalTracks and HP)
706 trackValidatorLite = trackValidator.clone(
707  label = ["generalTracks", "cutsRecoTracksHp"]
708 )
709 tracksValidationLite = cms.Sequence(
710  cutsRecoTracksHp +
711  tracksValidationTruth +
712  trackValidatorLite
713 )
714 
715 ## customization for timing
716 from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
717 phase2_timing_layer.toModify( generalTracksFromPV,
718  vertexTag = cms.InputTag('offlinePrimaryVertices4D'),
719  timesTag = cms.InputTag('trackTimeValueMapProducer:generalTracksConfigurableFlatResolutionModel'),
720  timeResosTag = cms.InputTag('trackTimeValueMapProducer:generalTracksConfigurableFlatResolutionModelResolution'),
721  nSigmaDtVertex = cms.double(3) )
722 phase2_timing_layer.toModify( trackValidatorStandalone,
723  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
724 phase2_timing_layer.toModify( trackValidatorFromPVStandalone,
725  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
726 phase2_timing_layer.toModify( trackValidatorFromPVAllTPStandalone,
727  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
728 phase2_timing_layer.toModify( trackValidatorConversionStandalone,
729  label_vertex = cms.untracked.InputTag('offlinePrimaryVertices4D') )
730 phase2_timing_layer.toModify( trackValidatorGsfTracks,
731  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