CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
customiseTrackingNtuple.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 def _label(tag):
4  if hasattr(tag, "getModuleLabel"):
5  t = tag
6  else:
7  t = cms.InputTag(tag)
8  return t.getModuleLabel()+t.getProductInstanceLabel()
9 
10 def customiseTrackingNtupleTool(process, isRECO = True, mergeIters = False):
11  process.load("Validation.RecoTrack.trackingNtuple_cff")
12  process.TFileService = cms.Service("TFileService",
13  fileName = cms.string('trackingNtuple.root')
14  )
15 
16  if process.trackingNtuple.includeSeeds.value():
17  if isRECO:
18  if not hasattr(process, "reconstruction_step"):
19  raise Exception("TrackingNtuple includeSeeds=True needs reconstruction which is missing")
20  else: #assumes HLT with PF iter
21  if not hasattr(process, "HLTIterativeTrackingIter02"):
22  raise Exception("TrackingNtuple includeSeeds=True needs HLTIterativeTrackingIter02 which is missing")
23 
24  # Replace validation_step with ntuplePath
25  if not hasattr(process, "validation_step"):
26  raise Exception("TrackingNtuple customise assumes process.validation_step exists")
27 
28 
29  # Should replay mixing for pileup simhits?
30  usePileupSimHits = hasattr(process, "mix") and hasattr(process.mix, "input") and len(process.mix.input.fileNames) > 0
31 # process.eda = cms.EDAnalyzer("EventContentAnalyzer")
32 
33  if not isRECO:
34  if not hasattr(process,"hltMultiTrackValidation"):
35  process.load("Validation.RecoTrack.HLTmultiTrackValidator_cff")
36  process.trackingNtupleSequence = process.hltMultiTrackValidation.copy()
38  process.hltSiStripRecHits = SiStripRecHitConverter_cfi.siStripMatchedRecHits.clone(
39  ClusterProducer = "hltSiStripRawToClustersFacility",
40  StripCPE = "hltESPStripCPEfromTrackAngle:hltESPStripCPEfromTrackAngle"
41  )
42  process.trackingNtupleSequence.insert(0,process.trackingParticlesIntime+process.simHitTPAssocProducer)
43  process.trackingNtupleSequence.remove(process.hltTrackValidator)
44  process.trackingNtupleSequence += process.hltSiStripRecHits + process.trackingNtuple
45 
46  #combine all *StepTracks (TODO: write one for HLT)
47  if mergeIters and isRECO:
48  process.mergedStepTracks = cms.EDProducer("TrackSimpleMerger",
49  src = cms.VInputTag(m.replace("Seeds", "Tracks").replace("seedTracks", "") for m in process.trackingNtuple.seedTracks)
50  )
51  process.trackingNtupleSequence.insert(0,process.mergedStepTracks)
52  process.trackingNtuple.tracks = "mergedStepTracks"
53 
54  ntuplePath = cms.Path(process.trackingNtupleSequence)
55 
56  if process.trackingNtuple.includeAllHits and process.trackingNtuple.includeTrackingParticles and usePileupSimHits:
57  ntuplePath.insert(0, cms.SequencePlaceholder("mix"))
58 
59  process.load("Validation.RecoTrack.crossingFramePSimHitToPSimHits_cfi")
60  instanceLabels = [_label(tag) for tag in process.simHitTPAssocProducer.simHitSrc]
61  process.crossingFramePSimHitToPSimHits.src = ["mix:"+l for l in instanceLabels]
62  process.simHitTPAssocProducer.simHitSrc = ["crossingFramePSimHitToPSimHits:"+l for l in instanceLabels]
63  process.trackingNtupleSequence.insert(0, process.crossingFramePSimHitToPSimHits)
64 
65  # Bit of a hack but works
66  modifier = cms.Modifier()
67  modifier._setChosen()
68  modifier.toReplaceWith(process.prevalidation_step, ntuplePath)
69  modifier.toReplaceWith(process.validation_step, cms.EndPath())
70 
71  # remove the validation_stepN and prevalidatin_stepN of phase2 validation...
72  for p in [process.paths_(), process.endpaths_()]:
73  for pathName, path in p.items():
74  if "prevalidation_step" in pathName:
75  if len(pathName.replace("prevalidation_step", "")) > 0:
76  modifier.toReplaceWith(path, cms.Path())
77  elif "validation_step" in pathName:
78  if len(pathName.replace("validation_step", "")) > 0:
79  modifier.toReplaceWith(path, cms.EndPath())
80 
81  # Remove all output modules
82  for outputModule in process.outputModules_().values():
83  for path in process.paths_().values():
84  path.remove(outputModule)
85  for path in process.endpaths_().values():
86  path.remove(outputModule)
87 
88 
89  return process
90 
92  customiseTrackingNtupleTool(process, isRECO = True)
93  return process
94 
96  customiseTrackingNtupleTool(process, isRECO = True, mergeIters = True)
97  return process
98 
100  import Validation.RecoTrack.TrackValidation_cff as _TrackValidation_cff
101  _seedProducers = [
102  "hltIter0PFLowPixelSeedsFromPixelTracks",
103  "hltIter1PFLowPixelSeedsFromPixelTracks",
104  "hltIter2PFlowPixelSeeds",
105  "hltDoubletRecoveryPFlowPixelSeeds"
106  ]
107  _candidatesProducers = [
108  "hltIter0PFlowCkfTrackCandidates",
109  "hltIter1PFlowCkfTrackCandidates",
110  "hltIter2PFlowCkfTrackCandidates",
111  "hltDoubletRecoveryPFlowCkfTrackCandidates"
112  ]
113  (_seedSelectors, _tmpTask) = _TrackValidation_cff._addSeedToTrackProducers(_seedProducers, globals())
114  _seedSelectorsTask = cms.Task()
115  for modName in _seedSelectors:
116  if not hasattr(process, modName):
117  setattr(process,modName, globals()[modName].clone(beamSpot = "hltOnlineBeamSpot"))
118  _seedSelectorsTask.add(getattr(process, modName))
119 
120  customiseTrackingNtupleTool(process, isRECO = False)
121 
122  process.trackingNtupleSequence.insert(0,cms.Sequence(_seedSelectorsTask))
123  if process.hltSiStripRawToClustersFacility.onDemand.value():
124  #make sure that all iter tracking is done before running the ntuple-related modules
125  process.trackingNtupleSequence.insert(0,process.hltMergedTracks)
126 
127  process.trackingNtuple.tracks = "hltMergedTracks"
128  process.trackingNtuple.seedTracks = _seedSelectors
129  process.trackingNtuple.trackCandidates = _candidatesProducers
130  process.trackingNtuple.clusterTPMap = "hltTPClusterProducer"
131  process.trackingNtuple.trackAssociator = "hltTrackAssociatorByHits"
132  process.trackingNtuple.beamSpot = "hltOnlineBeamSpot"
133  process.trackingNtuple.pixelRecHits = "hltSiPixelRecHits"
134  process.trackingNtuple.stripRphiRecHits = "hltSiStripRecHits:rphiRecHit"
135  process.trackingNtuple.stripStereoRecHits = "hltSiStripRecHits:stereoRecHit"
136  process.trackingNtuple.stripMatchedRecHits = "hltSiStripRecHits:matchedRecHit"
137  process.trackingNtuple.vertices = "hltPixelVertices"
138  process.trackingNtuple.TTRHBuilder = "hltESPTTRHBWithTrackAngle"
139  process.trackingNtuple.parametersDefiner = "hltLhcParametersDefinerForTP"
140  process.trackingNtuple.includeMVA = False
141 
142  return process
143 
144 def extendedContent(process):
145  process.trackingParticlesIntime.intimeOnly = False
146  process.trackingNtuple.includeOOT = True
147  process.trackingNtuple.keepEleSimHits = True
148 
149  process.trackingNtuple.saveSimHitsP3 = True
150  process.trackingNtuple.addSeedCurvCov = True
151 
152  return process
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135