CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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:
49  process.mergedStepTracks = _mod.TrackCollectionMerger.clone(
50  trackProducers = cms.VInputTag(m.replace("Seeds", "Tracks").replace("seedTracks", "") for m in process.trackingNtuple.seedTracks),
51  inputClassifiers = cms.vstring(m.replace("StepSeeds", "Step").replace("seedTracks", "").replace("dSeeds", "dTracks")
52  .replace("InOut", "InOutClassifier").replace("tIn", "tInClassifier")
53  for m in process.trackingNtuple.seedTracks),
54  minQuality = "any",
55  enableMerging = False
56  )
57  process.trackingNtupleSequence.insert(0,process.mergedStepTracks)
58  process.trackingNtuple.tracks = "mergedStepTracks"
59  process.trackingNtuple.includeMVA = True
60  process.trackingNtuple.trackMVAs = ["mergedStepTracks"]
61 
62  ntuplePath = cms.Path(process.trackingNtupleSequence)
63 
64  if process.trackingNtuple.includeAllHits and process.trackingNtuple.includeTrackingParticles and usePileupSimHits:
65  ntuplePath.insert(0, cms.SequencePlaceholder("mix"))
66 
67  process.load("Validation.RecoTrack.crossingFramePSimHitToPSimHits_cfi")
68  instanceLabels = [_label(tag) for tag in process.simHitTPAssocProducer.simHitSrc]
69  process.crossingFramePSimHitToPSimHits.src = ["mix:"+l for l in instanceLabels]
70  process.simHitTPAssocProducer.simHitSrc = ["crossingFramePSimHitToPSimHits:"+l for l in instanceLabels]
71  process.trackingNtupleSequence.insert(0, process.crossingFramePSimHitToPSimHits)
72 
73  # Bit of a hack but works
74  modifier = cms.Modifier()
75  modifier._setChosen()
76  modifier.toReplaceWith(process.prevalidation_step, ntuplePath)
77  modifier.toReplaceWith(process.validation_step, cms.EndPath())
78 
79  # remove the validation_stepN and prevalidatin_stepN of phase2 validation...
80  for p in [process.paths_(), process.endpaths_()]:
81  for pathName, path in p.items():
82  if "prevalidation_step" in pathName:
83  if len(pathName.replace("prevalidation_step", "")) > 0:
84  modifier.toReplaceWith(path, cms.Path())
85  elif "validation_step" in pathName:
86  if len(pathName.replace("validation_step", "")) > 0:
87  modifier.toReplaceWith(path, cms.EndPath())
88 
89  # Remove all output modules
90  for outputModule in process.outputModules_().values():
91  for path in process.paths_().values():
92  path.remove(outputModule)
93  for path in process.endpaths_().values():
94  path.remove(outputModule)
95 
96 
97  return process
98 
100  customiseTrackingNtupleTool(process, isRECO = True)
101  return process
102 
104  customiseTrackingNtupleTool(process, isRECO = True, mergeIters = True)
105  return process
106 
108  import Validation.RecoTrack.TrackValidation_cff as _TrackValidation_cff
109  _seedProducers = [
110  "hltIter0PFLowPixelSeedsFromPixelTracks",
111  "hltIter1PFLowPixelSeedsFromPixelTracks",
112  "hltIter2PFlowPixelSeeds",
113  "hltDoubletRecoveryPFlowPixelSeeds"
114  ]
115  _candidatesProducers = [
116  "hltIter0PFlowCkfTrackCandidates",
117  "hltIter1PFlowCkfTrackCandidates",
118  "hltIter2PFlowCkfTrackCandidates",
119  "hltDoubletRecoveryPFlowCkfTrackCandidates"
120  ]
121  (_seedSelectors, _tmpTask) = _TrackValidation_cff._addSeedToTrackProducers(_seedProducers, globals())
122  _seedSelectorsTask = cms.Task()
123  for modName in _seedSelectors:
124  if not hasattr(process, modName):
125  setattr(process,modName, globals()[modName].clone(beamSpot = "hltOnlineBeamSpot"))
126  _seedSelectorsTask.add(getattr(process, modName))
127 
128  customiseTrackingNtupleTool(process, isRECO = False)
129 
130  process.trackingNtupleSequence.insert(0,cms.Sequence(_seedSelectorsTask))
131  if process.hltSiStripRawToClustersFacility.onDemand.value():
132  #make sure that all iter tracking is done before running the ntuple-related modules
133  process.trackingNtupleSequence.insert(0,process.hltMergedTracks)
134 
135  process.trackingNtuple.tracks = "hltMergedTracks"
136  process.trackingNtuple.seedTracks = _seedSelectors
137  process.trackingNtuple.trackCandidates = _candidatesProducers
138  process.trackingNtuple.clusterTPMap = "hltTPClusterProducer"
139  process.trackingNtuple.trackAssociator = "hltTrackAssociatorByHits"
140  process.trackingNtuple.beamSpot = "hltOnlineBeamSpot"
141  process.trackingNtuple.pixelRecHits = "hltSiPixelRecHits"
142  process.trackingNtuple.stripRphiRecHits = "hltSiStripRecHits:rphiRecHit"
143  process.trackingNtuple.stripStereoRecHits = "hltSiStripRecHits:stereoRecHit"
144  process.trackingNtuple.stripMatchedRecHits = "hltSiStripRecHits:matchedRecHit"
145  process.trackingNtuple.vertices = "hltPixelVertices"
146  process.trackingNtuple.TTRHBuilder = "hltESPTTRHBWithTrackAngle"
147  process.trackingNtuple.parametersDefiner = "hltLhcParametersDefinerForTP"
148  process.trackingNtuple.includeMVA = False
149 
150  return process
151 
152 def extendedContent(process):
153  process.trackingParticlesIntime.intimeOnly = False
154  process.trackingNtuple.includeOOT = True
155  process.trackingNtuple.keepEleSimHits = True
156 
157  process.trackingNtuple.saveSimHitsP3 = True
158  process.trackingNtuple.addSeedCurvCov = True
159 
160  process.trackingNtuple.includeOnTrackHitData = True
161  process.trackingNtuple.includeTrackCandidates = True
162 
163  return process
def replace(string, replacements)
def customiseTrackingNtupleMergeIters(process)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def customiseTrackingNtupleTool(process, isRECO=True, mergeIters=False)