ATLAS Offline Software
InDetTrackPerfMonConfig.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''@file InDetTrackPerfMonConfig.py
6 @author M. Aparo
7 @date 2023-02-17
8 @brief Main CA-based python configuration for InDetTrackPerfMonTool
9 '''
10 
11 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12 from AthenaConfiguration.ComponentFactory import CompFactory
13 from AthenaCommon.Logging import logging
14 
15 
16 def JsonPlotsDefReadToolCfg( flags, name="JsonPlotsDefReadTool", **kwargs ):
17  '''
18  Tool to read the plots definitions from an input file in JSON format
19  '''
20  log = logging.getLogger( "JsonPlotsDefReadTool" )
21  acc = ComponentAccumulator()
22 
23 
24  from InDetTrackPerfMon.ConfigUtils import getPlotsDefList
25  plotsDefList = getPlotsDefList( flags )
26  log.debug( "Loading the following plot definitions:" )
27  for plotDef in plotsDefList : log.debug( "\t-> %s", plotDef )
28 
29  kwargs.setdefault( "PlotsDefs", plotsDefList )
30 
31  acc.setPrivateTools(
32  CompFactory.IDTPM.JsonPlotsDefReadTool( name, **kwargs ) )
33  return acc
34 
35 
36 def PlotsDefReadToolCfg( flags, name="PlotsDefReadTool", **kwargs ):
37  '''
38  CA-based configuration for the Tool to read the plots definition
39  '''
40  log = logging.getLogger( "PlotsDefReadTool" )
41 
42  if flags.PhysVal.IDTPM.plotsDefFormat == "JSON" :
44  flags, name = "JsonPlotsDefReadTool" +
45  flags.PhysVal.IDTPM.currentTrkAna.anaTag, **kwargs )
46 
47  log.error( "Non supported plots definition file type %s",
48  flags.PhysVal.IDTPM.plotsDefFormat )
49  return None
50 
51 
52 def PlotsDefinitionSvcCfg( flags, name="PlotsDefSvc", **kwargs ):
53  '''
54  CA-based configuration for the PlotsDefinition Service
55  '''
56  acc = ComponentAccumulator()
57 
58  if "PlotsDefReadTool" not in kwargs:
59  kwargs.setdefault( "PlotsDefReadTool", acc.popToolsAndMerge(
60  PlotsDefReadToolCfg( flags ) ) )
61 
62  acc.addService(
63  CompFactory.PlotsDefinitionSvc( name, **kwargs ) )
64  return acc
65 
66 
67 def TrackAnalysisInfoWriteToolCfg( flags, name="TrackAnalysisInfoWriteTool", **kwargs ):
68  '''
69  Tool to write TrackAnalysisInfo to StoreGate
70  '''
71  acc = ComponentAccumulator()
72 
73  kwargs.setdefault( "AnaTag", flags.PhysVal.IDTPM.currentTrkAna.anaTag )
74 
75  acc.setPrivateTools( CompFactory.IDTPM.TrackAnalysisInfoWriteTool( name, **kwargs ) )
76  return acc
77 
78 
79 def TrackAnalysisDefinitionSvcCfg( flags, name="TrkAnaDefSvc", **kwargs ):
80  '''
81  CA-based configuration for the TrackAnalysisDefinition Service
82  '''
83  acc = ComponentAccumulator()
84 
85  kwargs.setdefault( "DirName", flags.PhysVal.IDTPM.DirName )
86  kwargs.setdefault( "sortPlotsByChain", flags.PhysVal.IDTPM.sortPlotsByChain )
87  kwargs.setdefault( "SubFolder", flags.PhysVal.IDTPM.currentTrkAna.SubFolder )
88  kwargs.setdefault( "TrkAnaTag", flags.PhysVal.IDTPM.currentTrkAna.anaTag )
89 
90  kwargs.setdefault( "TestType", flags.PhysVal.IDTPM.currentTrkAna.TestType )
91  kwargs.setdefault( "RefType", flags.PhysVal.IDTPM.currentTrkAna.RefType )
92 
93  kwargs.setdefault( "pileupSwitch", flags.PhysVal.IDTPM.currentTrkAna.pileupSwitch )
94  kwargs.setdefault( "hasFullPileupTruth",
95  ( "xAOD::TruthPileupEventContainer#TruthPileupEvents" in flags.Input.TypedCollections ) )
96 
97  from InDetTrackPerfMon.ConfigUtils import getTag
98  kwargs.setdefault( "TestTag", getTag( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType ) )
99  kwargs.setdefault( "RefTag", getTag( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType ) )
100 
101  kwargs.setdefault( "MatchingType", flags.PhysVal.IDTPM.currentTrkAna.MatchingType )
102  kwargs.setdefault( "MatchingTruthProb", flags.PhysVal.IDTPM.currentTrkAna.truthProbCut )
103 
104  if ( ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.TestType and "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.TestType) or
105  ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.RefType and "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.RefType ) ):
106  kwargs.setdefault( "ChainNames", flags.PhysVal.IDTPM.currentTrkAna.ChainNames )
107 
108  kwargs.setdefault( "plotTrackParameters", flags.PhysVal.IDTPM.currentTrkAna.plotTrackParameters )
109  kwargs.setdefault( "plotTrackMultiplicities", flags.PhysVal.IDTPM.currentTrkAna.plotTrackMultiplicities )
110  kwargs.setdefault( "plotEfficiencies", flags.PhysVal.IDTPM.currentTrkAna.plotEfficiencies )
111  kwargs.setdefault( "plotTechnicalEfficiencies", flags.PhysVal.IDTPM.currentTrkAna.plotTechnicalEfficiencies )
112  kwargs.setdefault( "plotResolutions", flags.PhysVal.IDTPM.currentTrkAna.plotResolutions )
113  kwargs.setdefault( "plotFakeRates", flags.PhysVal.IDTPM.currentTrkAna.plotFakeRates )
114  kwargs.setdefault( "unlinkedAsFakes", flags.PhysVal.IDTPM.currentTrkAna.unlinkedAsFakes )
115  kwargs.setdefault( "plotDuplicateRates", flags.PhysVal.IDTPM.currentTrkAna.plotDuplicateRates )
116  kwargs.setdefault( "plotHitsOnTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnTracks )
117  kwargs.setdefault( "plotHitsOnTracksReference", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnTracksReference )
118  kwargs.setdefault( "plotHitsOnMatchedTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnMatchedTracks )
119  kwargs.setdefault( "plotHitsOnFakeTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnFakeTracks )
120  kwargs.setdefault( "plotVertexParameters", flags.PhysVal.IDTPM.currentTrkAna.plotVertexParameters )
121  kwargs.setdefault( "useSelectedVertexTracks", flags.PhysVal.IDTPM.currentTrkAna.useSelectedVertexTracks )
122  kwargs.setdefault( "plotOfflineElectrons", flags.PhysVal.IDTPM.currentTrkAna.plotOfflineElectrons )
123  kwargs.setdefault( "ResolutionMethod", flags.PhysVal.IDTPM.currentTrkAna.ResolutionMethod )
124  kwargs.setdefault( "isITk", flags.Detector.GeometryITk )
125 
126  kwargs.setdefault("EtaBins", flags.Tracking.ITkMainPass.etaBins if flags.Detector.GeometryITk else [-1, 9999.]) # for technical efficiencies
127  kwargs.setdefault("MinSilHits", flags.Tracking.ITkMainPass.minClusters if flags.Detector.GeometryITk else [flags.Tracking.MainPass.minClusters]) # for technical efficiencies
128 
129  trkAnaSvc = CompFactory.TrackAnalysisDefinitionSvc( name, **kwargs )
130  acc.addService( trkAnaSvc )
131  return acc
132 
133 
134 def InDetTrackPerfMonToolCfg( flags, name="InDetTrackPerfMonTool", **kwargs ):
135  '''
136  Main IDTPM tool instance CA-based configuration
137  '''
138  acc = ComponentAccumulator()
139 
140  kwargs.setdefault( "OfflineTrkParticleContainerName",
141  flags.PhysVal.IDTPM.currentTrkAna.OfflineTrkKey )
142  kwargs.setdefault( "TruthParticleContainerName",
143  flags.PhysVal.IDTPM.currentTrkAna.TruthPartKey )
144 
145  kwargs.setdefault( "OfflineVertexContainerName",
146  flags.PhysVal.IDTPM.currentTrkAna.OfflineVtxKey )
147  kwargs.setdefault( "TruthVertexContainerName",
148  flags.PhysVal.IDTPM.currentTrkAna.TruthVtxKey )
149 
150  kwargs.setdefault( "AnaTag", flags.PhysVal.IDTPM.currentTrkAna.anaTag )
151 
152  if flags.Output.doWriteAOD_IDTPM :
153  kwargs.setdefault( "writeOut", True )
154  kwargs.setdefault( "TrkAnaInfoKey",
155  "TrkAnaInfo"+flags.PhysVal.IDTPM.currentTrkAna.anaTag )
156 
157  if "TrackAnalysisInfoWriteTool" not in kwargs :
158  kwargs.setdefault( "TrackAnalysisInfoWriteTool", acc.popToolsAndMerge(
160  name="TrackAnalysisInfoWriteTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
161 
162 
163  acc.merge( TrackAnalysisDefinitionSvcCfg( flags,
164  name="TrkAnaDefSvc"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) )
165 
166 
167  acc.merge( PlotsDefinitionSvcCfg( flags,
168  name="PlotsDefSvc"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) )
169 
170 
172  if ( ( "Truth" in flags.PhysVal.IDTPM.currentTrkAna.RefType ) or
173  ( "Truth" in flags.PhysVal.IDTPM.currentTrkAna.TestType ) ):
174  from InDetTrackPerfMon.InDetAlgorithmConfig import TruthHitDecoratorAlgCfg, TruthDecoratorAlgCfg
175  acc.merge( TruthHitDecoratorAlgCfg( flags ) )
176  acc.merge( TruthDecoratorAlgCfg( flags ) )
177 
178 
179  if ( ( flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject ) and
180  ( "Truth" not in flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject ) ):
181  from InDetTrackPerfMon.InDetAlgorithmConfig import OfflineObjectDecoratorAlgCfg
182  acc.merge( OfflineObjectDecoratorAlgCfg( flags ) )
183 
184 
185  if "TrackQualitySelectionTool" not in kwargs:
186  from InDetTrackPerfMon.InDetSelectionConfig import TrackQualitySelectionToolCfg
187  kwargs.setdefault( "TrackQualitySelectionTool", acc.popToolsAndMerge(
189  name="TrackQualitySelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
190 
191  if "VertexQualitySelectionTool" not in kwargs:
192  from InDetTrackPerfMon.InDetSelectionConfig import VertexQualitySelectionToolCfg
193  kwargs.setdefault( "VertexQualitySelectionTool", acc.popToolsAndMerge(
195  name="VertexQualitySelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
196 
197  if ( ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.TestType ) or
198  ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.RefType ) ):
199 
200  kwargs.setdefault( "TriggerTrkParticleContainerName",
201  flags.PhysVal.IDTPM.currentTrkAna.TrigTrkKey )
202 
203  kwargs.setdefault( "TriggerVertexContainerName",
204  flags.PhysVal.IDTPM.currentTrkAna.TrigVtxKey )
205 
206  if ( "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.TestType and
207  "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.RefType ):
208 
209  if "TrigDecisionTool" not in kwargs:
210  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
211  kwargs.setdefault( "TrigDecisionTool",
212  acc.getPrimaryAndMerge( TrigDecisionToolCfg(flags) ) )
213 
214  if "RoiSelectionTool" not in kwargs:
215  from InDetTrackPerfMon.InDetSelectionConfig import RoiSelectionToolCfg
216  kwargs.setdefault( "RoiSelectionTool", acc.popToolsAndMerge(
217  RoiSelectionToolCfg( flags,
218  name="RoiSelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
219 
220  if "TrackRoiSelectionTool" not in kwargs:
221  from InDetTrackPerfMon.InDetSelectionConfig import TrackRoiSelectionToolCfg
222  kwargs.setdefault( "TrackRoiSelectionTool", acc.popToolsAndMerge(
224  name="TrackRoiSelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
225 
226  if "VertexRoiSelectionTool" not in kwargs:
227  from InDetTrackPerfMon.InDetSelectionConfig import VertexRoiSelectionToolCfg
228  kwargs.setdefault( "VertexRoiSelectionTool", acc.popToolsAndMerge(
230  name="VertexRoiSelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
231 
232  if "TrackMatchingTool" not in kwargs:
233  from InDetTrackPerfMon.InDetMatchingConfig import TrackMatchingToolCfg
234  matchToolCfg = TrackMatchingToolCfg( flags )
235  if matchToolCfg is not None :
236  kwargs.setdefault( "doMatch", True ) # = False by default
237  kwargs.setdefault( "TrackMatchingTool", acc.popToolsAndMerge( matchToolCfg ) )
238 
239  acc.setPrivateTools( CompFactory.InDetTrackPerfMonTool( name, **kwargs ) )
240  return acc
241 
242 
243 def InDetTrackPerfMonCfg( flags ):
244  '''
245  CA-based configuration of all tool instances (= TrackAnalyses)
246  '''
247  log = logging.getLogger( "InDetTrackPerfMonCfg" )
248  acc = ComponentAccumulator()
249 
250 
251  tools = []
252 
253  for trkAnaName in flags.PhysVal.IDTPM.trkAnaNames :
254 
255  flags_thisTrkAna = flags.cloneAndReplace( "PhysVal.IDTPM.currentTrkAna",
256  "PhysVal.IDTPM."+trkAnaName )
257 
258  if flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.enabled:
259  log.debug( "Scheduling TrackAnalysis: %s",
260  flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.anaTag )
261 
262  tools.append(
263  acc.popToolsAndMerge( InDetTrackPerfMonToolCfg( flags_thisTrkAna,
264  name="InDetTrackPerfMonTool"+
265  flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
266 
267  from PhysValMonitoring.PhysValMonitoringConfig import PhysValMonitoringCfg
268  acc.merge( PhysValMonitoringCfg( flags, tools=tools ) )
269 
270 
271  if flags.Output.doWriteAOD_IDTPM :
272  from InDetTrackPerfMon.InDetOutputConfig import InDetOutputCfg
273  acc.merge( InDetOutputCfg(flags) )
274 
275  return acc
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
InDetMatchingConfig.TrackMatchingToolCfg
def TrackMatchingToolCfg(flags, **kwargs)
Definition: InDetMatchingConfig.py:97
InDetTrackPerfMonConfig.JsonPlotsDefReadToolCfg
def JsonPlotsDefReadToolCfg(flags, name="JsonPlotsDefReadTool", **kwargs)
Definition: InDetTrackPerfMonConfig.py:16
InDetSelectionConfig.VertexRoiSelectionToolCfg
def VertexRoiSelectionToolCfg(flags, name="VertexRoiSelectionTool", **kwargs)
Definition: InDetSelectionConfig.py:43
InDetOutputConfig.InDetOutputCfg
def InDetOutputCfg(flags, **kwargs)
Definition: InDetOutputConfig.py:15
InDetTrackPerfMonConfig.PlotsDefinitionSvcCfg
def PlotsDefinitionSvcCfg(flags, name="PlotsDefSvc", **kwargs)
Definition: InDetTrackPerfMonConfig.py:52
InDetSelectionConfig.TrackRoiSelectionToolCfg
def TrackRoiSelectionToolCfg(flags, name="TrackRoiSelectionTool", **kwargs)
Definition: InDetSelectionConfig.py:33
InDetAlgorithmConfig.OfflineObjectDecoratorAlgCfg
def OfflineObjectDecoratorAlgCfg(flags, name="OfflineObjectDecoratorAlg", **kwargs)
Definition: InDetAlgorithmConfig.py:103
InDetTrackPerfMonConfig.InDetTrackPerfMonToolCfg
def InDetTrackPerfMonToolCfg(flags, name="InDetTrackPerfMonTool", **kwargs)
Definition: InDetTrackPerfMonConfig.py:134
PhysValMonitoringConfig.PhysValMonitoringCfg
def PhysValMonitoringCfg(flags, name="PhysValMonManager", tools=None, **kwargs)
Definition: PhysValMonitoringConfig.py:81
ConfigUtils.getPlotsDefList
def getPlotsDefList(flags)
Definition: ConfigUtils.py:104
InDetSelectionConfig.TrackQualitySelectionToolCfg
def TrackQualitySelectionToolCfg(flags, name="TrackQualitySelectionTool", **kwargs)
Definition: InDetSelectionConfig.py:233
InDetSelectionConfig.RoiSelectionToolCfg
def RoiSelectionToolCfg(flags, name="RoiSelectionTool", **kwargs)
Definition: InDetSelectionConfig.py:15
InDetAlgorithmConfig.TruthHitDecoratorAlgCfg
def TruthHitDecoratorAlgCfg(flags, name="InDetPhysValTruthDecoratorAlg", **kwargs)
Definition: InDetAlgorithmConfig.py:15
python.TriggerInterface.TrigDecisionToolCfg
def TrigDecisionToolCfg(flags)
Definition: TriggerInterface.py:14
ConfigUtils.getTag
def getTag(flags, key)
Definition: ConfigUtils.py:263
InDetSelectionConfig.VertexQualitySelectionToolCfg
def VertexQualitySelectionToolCfg(flags, name="VertexQualitySelectionTool", **kwargs)
Definition: InDetSelectionConfig.py:263
InDetTrackPerfMonConfig.TrackAnalysisInfoWriteToolCfg
def TrackAnalysisInfoWriteToolCfg(flags, name="TrackAnalysisInfoWriteTool", **kwargs)
Definition: InDetTrackPerfMonConfig.py:67
InDetAlgorithmConfig.TruthDecoratorAlgCfg
def TruthDecoratorAlgCfg(flags, name="TruthDecoratorAlg", **kwargs)
Definition: InDetAlgorithmConfig.py:141
InDetTrackPerfMonConfig.PlotsDefReadToolCfg
def PlotsDefReadToolCfg(flags, name="PlotsDefReadTool", **kwargs)
Definition: InDetTrackPerfMonConfig.py:36
InDetTrackPerfMonConfig.TrackAnalysisDefinitionSvcCfg
def TrackAnalysisDefinitionSvcCfg(flags, name="TrkAnaDefSvc", **kwargs)
Definition: InDetTrackPerfMonConfig.py:79
InDetTrackPerfMonConfig.InDetTrackPerfMonCfg
def InDetTrackPerfMonCfg(flags)
Definition: InDetTrackPerfMonConfig.py:243