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 
95  from InDetTrackPerfMon.ConfigUtils import getTag
96  kwargs.setdefault( "TestTag", getTag( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType ) )
97  kwargs.setdefault( "RefTag", getTag( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType ) )
98 
99  kwargs.setdefault( "MatchingType", flags.PhysVal.IDTPM.currentTrkAna.MatchingType )
100  kwargs.setdefault( "MatchingTruthProb", flags.PhysVal.IDTPM.currentTrkAna.truthProbCut )
101 
102  if ( ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.TestType and "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.TestType) or
103  ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.RefType and "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.RefType ) ):
104  kwargs.setdefault( "ChainNames", flags.PhysVal.IDTPM.currentTrkAna.ChainNames )
105 
106  kwargs.setdefault( "plotTrackParameters", flags.PhysVal.IDTPM.currentTrkAna.plotTrackParameters )
107  kwargs.setdefault( "plotTrackMultiplicities", flags.PhysVal.IDTPM.currentTrkAna.plotTrackMultiplicities )
108  kwargs.setdefault( "plotEfficiencies", flags.PhysVal.IDTPM.currentTrkAna.plotEfficiencies )
109  kwargs.setdefault( "plotTechnicalEfficiencies", flags.PhysVal.IDTPM.currentTrkAna.plotTechnicalEfficiencies )
110  kwargs.setdefault( "plotResolutions", flags.PhysVal.IDTPM.currentTrkAna.plotResolutions )
111  kwargs.setdefault( "plotFakeRates", flags.PhysVal.IDTPM.currentTrkAna.plotFakeRates )
112  kwargs.setdefault( "unlinkedAsFakes", flags.PhysVal.IDTPM.currentTrkAna.unlinkedAsFakes )
113  kwargs.setdefault( "plotDuplicateRates", flags.PhysVal.IDTPM.currentTrkAna.plotDuplicateRates )
114  kwargs.setdefault( "plotHitsOnTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnTracks )
115  kwargs.setdefault( "plotHitsOnTracksReference", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnTracksReference )
116  kwargs.setdefault( "plotHitsOnMatchedTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnMatchedTracks )
117  kwargs.setdefault( "plotHitsOnFakeTracks", flags.PhysVal.IDTPM.currentTrkAna.plotHitsOnFakeTracks )
118  kwargs.setdefault( "plotOfflineElectrons", flags.PhysVal.IDTPM.currentTrkAna.plotOfflineElectrons )
119  kwargs.setdefault( "ResolutionMethod", flags.PhysVal.IDTPM.currentTrkAna.ResolutionMethod )
120  kwargs.setdefault( "isITk", flags.Detector.GeometryITk )
121 
122  kwargs.setdefault("EtaBins", flags.Tracking.ITkMainPass.etaBins if flags.Detector.GeometryITk else [-1, 9999.]) # for technical efficiencies
123  kwargs.setdefault("MinSilHits", flags.Tracking.ITkMainPass.minClusters if flags.Detector.GeometryITk else [flags.Tracking.MainPass.minClusters]) # for technical efficiencies
124 
125  trkAnaSvc = CompFactory.TrackAnalysisDefinitionSvc( name, **kwargs )
126  acc.addService( trkAnaSvc )
127  return acc
128 
129 
130 def InDetTrackPerfMonToolCfg( flags, name="InDetTrackPerfMonTool", **kwargs ):
131  '''
132  Main IDTPM tool instance CA-based configuration
133  '''
134  acc = ComponentAccumulator()
135 
136  kwargs.setdefault( "OfflineTrkParticleContainerName",
137  flags.PhysVal.IDTPM.currentTrkAna.OfflineTrkKey )
138  kwargs.setdefault( "TruthParticleContainerName",
139  flags.PhysVal.IDTPM.currentTrkAna.TruthPartKey )
140 
141  kwargs.setdefault( "AnaTag", flags.PhysVal.IDTPM.currentTrkAna.anaTag )
142 
143  if flags.Output.doWriteAOD_IDTPM :
144  kwargs.setdefault( "writeOut", True )
145  kwargs.setdefault( "TrkAnaInfoKey",
146  "TrkAnaInfo"+flags.PhysVal.IDTPM.currentTrkAna.anaTag )
147 
148  if "TrackAnalysisInfoWriteTool" not in kwargs :
149  kwargs.setdefault( "TrackAnalysisInfoWriteTool", acc.popToolsAndMerge(
151  name="TrackAnalysisInfoWriteTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
152 
153 
154  acc.merge( TrackAnalysisDefinitionSvcCfg( flags,
155  name="TrkAnaDefSvc"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) )
156 
157 
158  acc.merge( PlotsDefinitionSvcCfg( flags,
159  name="PlotsDefSvc"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) )
160 
161 
163  if ( ( "Truth" in flags.PhysVal.IDTPM.currentTrkAna.RefType ) or
164  ( "Truth" in flags.PhysVal.IDTPM.currentTrkAna.TestType ) ):
165  from InDetTrackPerfMon.InDetAlgorithmConfig import TruthHitDecoratorAlgCfg
166  acc.merge( TruthHitDecoratorAlgCfg( flags ) )
167 
168 
169  if ( ( flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject ) and
170  ( "Truth" not in flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject ) ):
171  from InDetTrackPerfMon.InDetAlgorithmConfig import OfflineObjectDecoratorAlgCfg
172  acc.merge( OfflineObjectDecoratorAlgCfg( flags ) )
173 
174 
175  if "TrackQualitySelectionTool" not in kwargs:
176  from InDetTrackPerfMon.InDetSelectionConfig import TrackQualitySelectionToolCfg
177  kwargs.setdefault( "TrackQualitySelectionTool", acc.popToolsAndMerge(
179  name="TrackQualitySelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
180 
181  if ( ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.TestType ) or
182  ( "Trigger" in flags.PhysVal.IDTPM.currentTrkAna.RefType ) ):
183 
184  kwargs.setdefault( "TriggerTrkParticleContainerName",
185  flags.PhysVal.IDTPM.currentTrkAna.TrigTrkKey )
186 
187  if ( "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.TestType and "EFTrigger" not in flags.PhysVal.IDTPM.currentTrkAna.RefType ):
188  if "TrigDecisionTool" not in kwargs:
189  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
190  kwargs.setdefault( "TrigDecisionTool",
191  acc.getPrimaryAndMerge( TrigDecisionToolCfg(flags) ) )
192 
193  if "RoiSelectionTool" not in kwargs:
194  from InDetTrackPerfMon.InDetSelectionConfig import RoiSelectionToolCfg
195  kwargs.setdefault( "RoiSelectionTool", acc.popToolsAndMerge(
196  RoiSelectionToolCfg( flags,
197  name="RoiSelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
198 
199  if "TrackRoiSelectionTool" not in kwargs:
200  from InDetTrackPerfMon.InDetSelectionConfig import TrackRoiSelectionToolCfg
201  kwargs.setdefault( "TrackRoiSelectionTool", acc.popToolsAndMerge(
203  name="TrackRoiSelectionTool"+flags.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
204 
205  if "TrackMatchingTool" not in kwargs:
206  from InDetTrackPerfMon.InDetMatchingConfig import TrackMatchingToolCfg
207  matchToolCfg = TrackMatchingToolCfg( flags )
208  if matchToolCfg is not None :
209  kwargs.setdefault( "doMatch", True ) # = False by default
210  kwargs.setdefault( "TrackMatchingTool", acc.popToolsAndMerge( matchToolCfg ) )
211 
212  acc.setPrivateTools( CompFactory.InDetTrackPerfMonTool( name, **kwargs ) )
213  return acc
214 
215 
216 def InDetTrackPerfMonCfg( flags ):
217  '''
218  CA-based configuration of all tool instances (= TrackAnalyses)
219  '''
220  log = logging.getLogger( "InDetTrackPerfMonCfg" )
221  acc = ComponentAccumulator()
222 
223 
224  tools = []
225 
226  for trkAnaName in flags.PhysVal.IDTPM.trkAnaNames :
227 
228  flags_thisTrkAna = flags.cloneAndReplace( "PhysVal.IDTPM.currentTrkAna",
229  "PhysVal.IDTPM."+trkAnaName )
230 
231  if flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.enabled:
232  log.debug( "Scheduling TrackAnalysis: %s",
233  flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.anaTag )
234 
235  tools.append(
236  acc.popToolsAndMerge( InDetTrackPerfMonToolCfg( flags_thisTrkAna,
237  name="InDetTrackPerfMonTool"+
238  flags_thisTrkAna.PhysVal.IDTPM.currentTrkAna.anaTag ) ) )
239 
240  from PhysValMonitoring.PhysValMonitoringConfig import PhysValMonitoringCfg
241  acc.merge( PhysValMonitoringCfg( flags, tools=tools ) )
242 
243 
244  if flags.Output.doWriteAOD_IDTPM :
245  from InDetTrackPerfMon.InDetOutputConfig import InDetOutputCfg
246  acc.merge( InDetOutputCfg(flags) )
247 
248  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
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:130
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:212
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:244
InDetTrackPerfMonConfig.TrackAnalysisInfoWriteToolCfg
def TrackAnalysisInfoWriteToolCfg(flags, name="TrackAnalysisInfoWriteTool", **kwargs)
Definition: InDetTrackPerfMonConfig.py:67
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:216