ATLAS Offline Software
ThinInDetClustersConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 #
3 # Heavily Inspired by ThinInDetForwardTrackParticles.py
4 
5 __doc__ = """
6  Instantiate the InDetTrackParticles Cluster Thinning
7  """
8 
9 from AthenaCommon.Logging import logging
10 from AthenaConfiguration.ComponentFactory import CompFactory
11 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12 
13 def ThinInDetClustersCfg(flags, name="ThinInDetClustersAlg", **kwargs):
14  mlog = logging.getLogger(name)
15  mlog.info("Starting InDetTrackParticle Cluster Thinning configuration")
16  acc = ComponentAccumulator()
17 
18  kwargs.setdefault("StreamName", "StreamAOD")
19 
20  if not flags.Detector.EnablePixel:
21  kwargs.setdefault("InDetTrackStatesPixKey", "")
22  kwargs.setdefault("InDetTrackMeasurementsPixKey", "")
23  if not flags.Detector.EnableSCT:
24  kwargs.setdefault("InDetTrackStatesSctKey", "")
25  kwargs.setdefault("InDetTrackMeasurementsSctKey", "")
26  if not flags.Detector.EnableTRT:
27  kwargs.setdefault("InDetTrackStatesTrtKey", "")
28  kwargs.setdefault("InDetTrackMeasurementsTrtKey", "")
29 
30  if not flags.Tracking.thinPixelClustersOnTrack:
31  kwargs.setdefault("ThinPixelHitsOnTrack", False)
32  if not flags.Tracking.thinSCTClustersOnTrack:
33  kwargs.setdefault("ThinSCTHitsOnTrack", False)
34  if not flags.Tracking.thinTRTClustersOnTrack:
35  kwargs.setdefault("ThinTRTHitsOnTrack", False)
36 
37  kwargs.setdefault("InDetTrackParticlesKey", "InDetTrackParticles")
38  kwargs.setdefault("SelectionString", "InDetTrackParticles.pt>10*GeV")
39 
40 
43 
44  if flags.Tracking.thinPixelClustersOnTrack and not flags.Tracking.writeExtendedSi_PRDInfo:
45  msg = "Requested to thin pixel hits on track, but flags.Tracking.writeExtendedSi_PRDInfo is set to false, so the relevant containers will not be written to the AOD. Cannot add ThinInDetClustersAlg."
46  mlog.error( msg )
47  raise RuntimeError( msg )
48 
49  if flags.Tracking.thinSCTClustersOnTrack and not flags.Tracking.writeExtendedSi_PRDInfo:
50  msg = "Requested to thin SCT hits on track, but flags.Tracking.writeExtendedSi_PRDInfo is set to false, so the relevant containers will not be written to the AOD. Cannot add ThinInDetClustersAlg."
51  mlog.error( msg )
52  raise RuntimeError( msg )
53 
54  if flags.Tracking.thinTRTClustersOnTrack and not flags.Tracking.writeExtendedTRT_PRDInfo:
55  msg = "Requested to thin TRT hits on track, but flags.Tracking.writeExtendedTRT_PRDInfo is set to false, so the relevant containers will not be written to the AOD. Cannot add ThinInDetClustersAlg."
56  mlog.error( msg )
57  raise RuntimeError( msg )
58 
59  nTrackContainers = len(flags.Tracking.thinInDetClustersTrackContainers)
60  nSelectionStrings = len(flags.Tracking.thinInDetClustersSelectionStrings)
61  nPixelMSOSContainers = len(flags.Tracking.thinInDetClustersPixelMSOSContainers)
62  nSCTMSOSContainers = len(flags.Tracking.thinInDetClustersSCTMSOSContainers)
63  nTRTMSOSContainers = len(flags.Tracking.thinInDetClustersTRTMSOSContainers)
64 
65  if not nTrackContainers == nSelectionStrings:
66  msg = f"Number of selection strings ({nSelectionStrings}) does not match number of track containers ({nTrackContainers}). Cannot add ThinInDetClustersAlg."
67  mlog.error( msg )
68  raise RuntimeError( msg )
69 
70  if flags.Tracking.thinPixelClustersOnTrack:
71  if not nTrackContainers == nPixelMSOSContainers:
72  msg = f"Number of pixel MSOS containers ({nPixelMSOSContainers}) does not match number of track containers ({nTrackContainers}). Cannot add ThinInDetClustersAlg."
73  mlog.error( msg )
74  raise RuntimeError( msg )
75 
76  if flags.Tracking.thinSCTClustersOnTrack:
77  if not nTrackContainers == nSCTMSOSContainers:
78  msg = f"Number of SCT MSOS containers ({nSCTMSOSContainers}) does not match number of track containers ({nTrackContainers}). Cannot add ThinInDetClustersAlg."
79  mlog.error( msg )
80  raise RuntimeError( msg )
81 
82  if flags.Tracking.thinTRTClustersOnTrack:
83  if not nTrackContainers == nTRTMSOSContainers:
84  msg = f"Number of TRT MSOS containers ({nTRTMSOSContainers}) does not match number of track containers ({nTrackContainers}). Cannot add ThinInDetClustersAlg."
85  mlog.error( msg )
86  raise RuntimeError( msg )
87 
88  for idx,trackContainer in enumerate(flags.Tracking.thinInDetClustersTrackContainers):
89  selectionString = flags.Tracking.thinInDetClustersSelectionStrings[idx]
90  if trackContainer not in selectionString:
91  mlog.warning(f"Track container {trackContainer} is not used in the associated selection string: {selectionString}.")
92 
93 
96 
97  for idx,trackContainer in enumerate(flags.Tracking.thinInDetClustersTrackContainers):
98  kwargs["InDetTrackParticlesKey"]= trackContainer
99  kwargs["SelectionString"] = flags.Tracking.thinInDetClustersSelectionStrings[idx]
100 
101  # TODO: Test selection strings for seeds and candidates
102  # Change selections without keyword-based argument without changing code (flags)
103 
104  # Thin hits on track from requested detector technologies
105  if flags.Tracking.thinPixelClustersOnTrack:
106  kwargs["ThinPixelHitsOnTrack"] = True
107  kwargs["InDetTrackStatesPixKey"] = flags.Tracking.thinInDetClustersPixelMSOSContainers[idx]
108  kwargs["InDetTrackMeasurementsPixKey"] = "PixelClusters"
109  if flags.Tracking.thinSCTClustersOnTrack:
110  kwargs["ThinSCTHitsOnTrack"] = True
111  kwargs["InDetTrackStatesSctKey"] = flags.Tracking.thinInDetClustersSCTMSOSContainers[idx]
112  kwargs["InDetTrackMeasurementsSctKey"] = "SCT_Clusters"
113  if flags.Tracking.thinTRTClustersOnTrack:
114  kwargs["ThinTRTHitsOnTrack"] = True
115  kwargs["InDetTrackStatesTrtKey"] = flags.Tracking.thinInDetClustersTRTMSOSContainers[idx]
116  kwargs["InDetTrackMeasurementsTrtKey"] = "TRT_DriftCircles"
117 
118  acc.addEventAlgo(CompFactory.ThinInDetClustersAlg(name+"_"+trackContainer, **kwargs))
119 
120  return acc
121 
122 
123 if __name__ == "__main__":
124  from AthenaConfiguration.AllConfigFlags import initConfigFlags
125  from AthenaConfiguration.TestDefaults import defaultTestFiles
126  from AthenaConfiguration.ComponentAccumulator import printProperties
127  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
128  flags = initConfigFlags()
129  flags.Input.Files = defaultTestFiles.RDO_RUN2
130  flags.Tracking.writeExtendedSi_PRDInfo=True
131  flags.Tracking.writeExtendedTRT_PRDInfo=True
132  flags.Tracking.thinPixelClustersOnTrack=True
133  flags.Tracking.thinSCTClustersOnTrack=True
134  flags.Tracking.thinTRTClustersOnTrack=True
135  flags.Output.doWriteAOD = True # To test the AOD parts
136  flags.lock()
137  acc = MainServicesCfg(flags)
138  acc.merge(ThinInDetClustersCfg(flags))
139  mlog = logging.getLogger("ThinInDetClustersConfigTest")
141  mlog,
142  acc.getEventAlgo("ThinInDetClustersAlg"),
143  nestLevel=1,
144  printDefaults=True,
145  )
146 
147  with open("thinindetclusterscfg.pkl", "wb") as f:
148  acc.store(f)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.ThinInDetClustersConfig.ThinInDetClustersCfg
def ThinInDetClustersCfg(flags, name="ThinInDetClustersAlg", **kwargs)
Definition: ThinInDetClustersConfig.py:13
extractSporadic.printProperties
def printProperties(h, q, hLB)
Definition: extractSporadic.py:8
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19