3 from AthenaConfiguration.AthConfigFlags
import AthConfigFlags
4 from AthenaConfiguration.AutoConfigFlags
import getDefaultDetectors
9 'BCM',
'Pixel',
'SCT',
'TRT',
10 'BCMPrime',
'PLR',
'ITkPixel',
'ITkStrip',
'HGTD',
11 'LAr',
'Tile',
'MBTS',
12 'CSC',
'MDT',
'RPC',
'TGC',
'sTGC',
'MM',
13 'Lucid',
'ZDC',
'ALFA',
'AFP',
'FwdRegion',
18 'ID': [
'BCM',
'Pixel',
'SCT',
'TRT'],
19 'ITk': [
'BCMPrime',
'ITkPixel',
'ITkStrip',
'PLR'],
20 'Calo': [
'LAr',
'Tile',
'MBTS'],
21 'Muon': [
'CSC',
'MDT',
'RPC',
'TGC',
'sTGC',
'MM'],
22 'Forward': [
'Lucid',
'ZDC',
'ALFA',
'AFP',
'FwdRegion'],
27 dcf = AthConfigFlags()
31 dcf.addFlag(
'Detector.GeometryBpipe',
True)
34 dcf.addFlag(
'Detector.GeometryBCM',
lambda prevFlags :
'BCM' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
35 dcf.addFlag(
'Detector.GeometryPixel',
lambda prevFlags :
'Pixel' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
36 dcf.addFlag(
'Detector.GeometrySCT',
lambda prevFlags :
'SCT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
37 dcf.addFlag(
'Detector.GeometryTRT',
lambda prevFlags :
'TRT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
38 dcf.addFlag(
'Detector.GeometryID',
lambda prevFlags : (prevFlags.Detector.GeometryBCM
39 or prevFlags.Detector.GeometryPixel
or prevFlags.Detector.GeometrySCT
40 or prevFlags.Detector.GeometryTRT))
43 dcf.addFlag(
'Detector.GeometryPLR',
lambda prevFlags :
'PLR' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
44 dcf.addFlag(
'Detector.GeometryBCMPrime',
lambda prevFlags :
'BCMPrime' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
45 dcf.addFlag(
'Detector.GeometryITkPixel',
lambda prevFlags :
'ITkPixel' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
46 dcf.addFlag(
'Detector.GeometryITkStrip',
lambda prevFlags :
'ITkStrip' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
47 dcf.addFlag(
'Detector.GeometryITk',
lambda prevFlags : (prevFlags.Detector.GeometryBCMPrime
48 or prevFlags.Detector.GeometryITkPixel
49 or prevFlags.Detector.GeometryITkStrip
50 or prevFlags.Detector.GeometryPLR))
52 dcf.addFlag(
'Detector.GeometryHGTD',
lambda prevFlags :
'HGTD' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
55 dcf.addFlag(
'Detector.GeometryLAr',
lambda prevFlags :
'LAr' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
56 dcf.addFlag(
'Detector.GeometryTile',
lambda prevFlags :
'Tile' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
57 dcf.addFlag(
'Detector.GeometryMBTS',
lambda prevFlags : (prevFlags.Detector.GeometryLAr
and 'MBTS' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath)))
58 dcf.addFlag(
'Detector.GeometryCalo',
lambda prevFlags : (prevFlags.Detector.GeometryLAr
or prevFlags.Detector.GeometryTile))
61 dcf.addFlag(
'Detector.GeometryCSC',
lambda prevFlags :
'CSC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
62 dcf.addFlag(
'Detector.GeometryMDT',
lambda prevFlags :
'MDT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
63 dcf.addFlag(
'Detector.GeometryRPC',
lambda prevFlags :
'RPC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
64 dcf.addFlag(
'Detector.GeometryTGC',
lambda prevFlags :
'TGC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
65 dcf.addFlag(
'Detector.GeometrysTGC',
lambda prevFlags :
'sTGC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
66 dcf.addFlag(
'Detector.GeometryMM',
lambda prevFlags :
'MM' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
67 dcf.addFlag(
'Detector.GeometryMuon',
lambda prevFlags : (prevFlags.Detector.GeometryCSC
or prevFlags.Detector.GeometryMDT
68 or prevFlags.Detector.GeometryRPC
or prevFlags.Detector.GeometryTGC
69 or prevFlags.Detector.GeometrysTGC
or prevFlags.Detector.GeometryMM))
72 dcf.addFlag(
'Detector.GeometryLucid',
lambda prevFlags :
'Lucid' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=
not prevFlags.Input.isMC))
73 dcf.addFlag(
'Detector.GeometryZDC',
lambda prevFlags :
'ZDC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=
not prevFlags.Input.isMC))
74 dcf.addFlag(
'Detector.GeometryALFA',
lambda prevFlags :
'ALFA' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=
not prevFlags.Input.isMC))
75 dcf.addFlag(
'Detector.GeometryAFP',
lambda prevFlags :
'AFP' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=
not prevFlags.Input.isMC))
76 dcf.addFlag(
'Detector.GeometryFwdRegion',
lambda prevFlags :
'FwdRegion' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=
not prevFlags.Input.isMC))
77 dcf.addFlag(
'Detector.GeometryForward',
lambda prevFlags : (prevFlags.Detector.GeometryLucid
or prevFlags.Detector.GeometryZDC
78 or prevFlags.Detector.GeometryALFA
or prevFlags.Detector.GeometryAFP
79 or prevFlags.Detector.GeometryFwdRegion))
82 dcf.addFlag(
'Detector.GeometryCavern',
False)
88 dcf.addFlag(
'Detector.EnableBCM',
lambda prevFlags : prevFlags.Detector.GeometryBCM)
89 dcf.addFlag(
'Detector.EnablePixel',
lambda prevFlags : prevFlags.Detector.GeometryPixel)
90 dcf.addFlag(
'Detector.EnableSCT',
lambda prevFlags : prevFlags.Detector.GeometrySCT)
91 dcf.addFlag(
'Detector.EnableTRT',
lambda prevFlags : prevFlags.Detector.GeometryTRT)
92 dcf.addFlag(
'Detector.EnableID',
lambda prevFlags : prevFlags.Detector.GeometryID
and
93 (prevFlags.Detector.EnableBCM
94 or prevFlags.Detector.EnablePixel
or prevFlags.Detector.EnableSCT
95 or prevFlags.Detector.EnableTRT))
98 dcf.addFlag(
'Detector.EnablePLR',
lambda prevFlags : prevFlags.Detector.GeometryPLR)
99 dcf.addFlag(
'Detector.EnableBCMPrime',
lambda prevFlags : prevFlags.Detector.GeometryBCMPrime)
100 dcf.addFlag(
'Detector.EnableITkPixel',
lambda prevFlags : prevFlags.Detector.GeometryITkPixel)
101 dcf.addFlag(
'Detector.EnableITkStrip',
lambda prevFlags : prevFlags.Detector.GeometryITkStrip)
102 dcf.addFlag(
'Detector.EnableITk',
lambda prevFlags : prevFlags.Detector.GeometryITk
and
103 (prevFlags.Detector.EnableBCMPrime
104 or prevFlags.Detector.EnableITkPixel
105 or prevFlags.Detector.EnableITkStrip
106 or prevFlags.Detector.EnablePLR))
108 dcf.addFlag(
'Detector.EnableHGTD',
lambda prevFlags : prevFlags.Detector.GeometryHGTD)
111 dcf.addFlag(
'Detector.EnableLAr',
lambda prevFlags : prevFlags.Detector.GeometryLAr)
112 dcf.addFlag(
'Detector.EnableTile',
lambda prevFlags : prevFlags.Detector.GeometryTile)
113 dcf.addFlag(
'Detector.EnableMBTS',
lambda prevFlags : prevFlags.Detector.GeometryMBTS)
114 dcf.addFlag(
'Detector.EnableL1Calo',
lambda prevFlags : (prevFlags.Detector.EnableLAr
or prevFlags.Detector.EnableTile))
115 dcf.addFlag(
'Detector.EnableCalo',
lambda prevFlags : prevFlags.Detector.GeometryCalo
and
116 (prevFlags.Detector.EnableLAr
or prevFlags.Detector.EnableTile))
119 dcf.addFlag(
'Detector.EnableCSC',
lambda prevFlags : prevFlags.Detector.GeometryCSC)
120 dcf.addFlag(
'Detector.EnableMDT',
lambda prevFlags : prevFlags.Detector.GeometryMDT)
121 dcf.addFlag(
'Detector.EnableRPC',
lambda prevFlags : prevFlags.Detector.GeometryRPC)
122 dcf.addFlag(
'Detector.EnableTGC',
lambda prevFlags : prevFlags.Detector.GeometryTGC)
123 dcf.addFlag(
'Detector.EnablesTGC',
lambda prevFlags : prevFlags.Detector.GeometrysTGC)
124 dcf.addFlag(
'Detector.EnableMM',
lambda prevFlags : prevFlags.Detector.GeometryMM)
125 dcf.addFlag(
'Detector.EnableMuon',
lambda prevFlags : prevFlags.Detector.GeometryMuon
and
126 (prevFlags.Detector.EnableCSC
or prevFlags.Detector.EnableMDT
127 or prevFlags.Detector.EnableRPC
or prevFlags.Detector.EnableTGC
128 or prevFlags.Detector.EnablesTGC
or prevFlags.Detector.EnableMM))
131 dcf.addFlag(
'Detector.EnableLucid',
lambda prevFlags : prevFlags.Detector.GeometryLucid)
133 dcf.addFlag(
'Detector.EnableZDC',
lambda prevFlags : prevFlags.Detector.GeometryZDC)
134 dcf.addFlag(
'Detector.EnableZDC_ZDC',
lambda prevFlags : prevFlags.Detector.GeometryZDC)
135 dcf.addFlag(
'Detector.EnableZDC_RPD',
lambda prevFlags : prevFlags.Detector.GeometryZDC)
136 dcf.addFlag(
'Detector.EnableALFA',
lambda prevFlags : prevFlags.Detector.GeometryALFA)
137 dcf.addFlag(
'Detector.EnableAFP',
lambda prevFlags : prevFlags.Detector.GeometryAFP)
138 dcf.addFlag(
'Detector.EnableFwdRegion',
lambda prevFlags : prevFlags.Detector.GeometryFwdRegion)
139 dcf.addFlag(
'Detector.EnableForward',
lambda prevFlags : prevFlags.Detector.GeometryForward
and
140 (prevFlags.Detector.EnableLucid
or prevFlags.Detector.EnableZDC
141 or prevFlags.Detector.EnableALFA
or prevFlags.Detector.EnableAFP
142 or prevFlags.Detector.EnableFwdRegion))
149 flags._loadDynaFlags(
'Detector')
151 for d
in allDetectors:
153 name = f
'Detector.Geometry{d}' if geometry
else f
'Detector.Enable{d}'
154 if flags.hasFlag(name):
155 if flags[name]
is not False:
162 from AthenaCommon.Logging
import logging
163 log = logging.getLogger(
'DetectorConfigFlags')
165 flags._loadDynaFlags(
'Detector')
167 ignored_detectors = [
'None',
'Truth',
'DBM']
168 def compatibility_layer(detector):
169 if detector ==
'pixel':
174 groups = {d
for d
in detectors
if d
in allGroups.keys()}
175 detectors = {compatibility_layer(d)
for d
in detectors
if d
not in allGroups.keys()}
177 log.debug(
"Evaluating detector group '%s'", g)
180 for d
in allGroups[g]:
181 log.debug(
"Appending detector '%s'", d)
185 for d
in allGroups[g]:
186 if d
in getDefaultDetectors(flags.GeoModel.AtlasVersion,flags.GeoModel.SQLiteDB,flags.GeoModel.SQLiteDBFullPath):
187 log.debug(
"Appending detector '%s'", d)
192 if d
not in allDetectors
and d
not in ignored_detectors:
193 log.warning(
"Unknown detector '%s'", d)
196 return [d
for d
in allDetectors
if d
in detectors]
200 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
201 detectors = eval(
GetFileMD(flags.Input.Files).
get(key,
'[]'))
206 from AthenaConfiguration.Enums
import LHCPeriod
207 if (flags.GeoModel.Run < LHCPeriod.Run4
and 'LAr' in detectors
208 or 'TileHitVector#MBTSHits' in flags.Input.TypedCollections
209 or 'TileTTL1Container#TileTTL1MBTS' in flags.Input.TypedCollections):
210 detectors.append(
'MBTS')
212 if keep_beampipe
and flags.Detector.GeometryBpipe:
213 detectors.append(
'Bpipe')
220 flags._loadDynaFlags(
'Detector')
223 for d
in allDetectors:
225 name = f
'Detector.Geometry{d}' if geometry
else f
'Detector.Enable{d}'
226 if flags.hasFlag(name):
233 if flags[name]
is not False:
244 from AthenaCommon.Logging
import logging
245 log = logging.getLogger(
'DetectorConfigFlags')
250 subtypes = [
'Geo.',
'Enbl.']
251 format_header = f
'%-{item_len * 2}s'
252 if 'metadata_simulated' in info_dict.keys()
or 'metadata_digitized' in info_dict.keys():
254 if 'metadata_simulated' in info_dict.keys():
255 subtypes.append(
'Sim.')
256 metadata_len += item_len
257 if 'metadata_digitized' in info_dict.keys():
258 subtypes.append(
'Digi.')
259 metadata_len += item_len
260 types.append(
'Metadata' if item_len > 8
else 'Meta.')
261 format_header += f
'%-{metadata_len}s'
262 if 'requested_geometry' in info_dict.keys():
263 types.append(
'Requested')
264 subtypes += [
'Geo.',
'Enbl.']
265 format_header += f
'%-{item_len * 2}s'
267 types.append(
'Final')
268 subtypes += [
'Geo.',
'Enbl.']
269 format_header += f
'%-{item_len * 2}s'
272 for d
in allDetectors:
273 detector_len =
max(detector_len, len(d) + 2)
275 format_header = f
'%{detector_len}s ' + format_header
276 format_subheader = f
'%{detector_len}s ' + len(subtypes) * f
'%-{item_len}s'
277 format = f
'%{detector_len}s : ' + len(subtypes) * f
'%-{item_len}s'
278 data = [allDetectors] + [v
for _, v
in info_dict.items()]
279 data =
list(map(list, zip(*data)))
282 log.info(format_header, *([
''] + types))
283 log.info(format_subheader, *([
''] + subtypes))
286 log.info(format, *row)
289 def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False):
290 """Setup detector flags from metadata or a list"""
293 from AthenaCommon.Logging
import logging
294 log = logging.getLogger(
'DetectorConfigFlags')
301 final_set = initial_set
313 if digitized_set
and digitized_set != initial_set:
314 final_set = digitized_set
315 elif simulated_set
and simulated_set != initial_set:
316 final_set = simulated_set
318 requested_inconsistency_set =
set()
319 if custom_list
is not None and custom_list:
324 info_dict[
'requested_geometry'] = info_dict[
'initial_geometry']
328 requested_inconsistency_set = requested_set.difference(final_set)
329 final_set = requested_set.intersection(final_set)
331 final_set = requested_set
338 if requested_inconsistency_set:
339 log.error(
'Requested detectors %s which are not enabled in the input file.',
list(requested_inconsistency_set))
340 raise ValueError(
list(requested_inconsistency_set))
342 if initial_set != final_set:
343 diff_enable = final_set.difference(initial_set)
344 if 'Bpipe' in diff_enable
and (keep_beampipe
or flags.Detector.GeometryBpipe):
345 diff_enable.remove(
'Bpipe')
346 diff_disable = initial_set.difference(final_set)
355 """Setup (toggle) detectors from a pre-defined list"""
358 from AthenaCommon.Logging
import logging
359 log = logging.getLogger(
'DetectorConfigFlags')
365 log.info(
'Required detectors: %s', detectors)
367 log.debug(
'Setting detectors to: %s', detectors)
370 for d
in allDetectors:
371 status = d
in detectors
372 name = f
'Detector.Enable{d}'
373 if flags.hasFlag(name):
374 if flags[name] != status:
377 log.warning(
"Flag '%s' should be %s but is set to %s", name, status,
not status)
379 log.debug(
"Toggling '%s' from %s to %s", name,
not status, status)
380 flags._set(name, status)
382 name = f
'Detector.Geometry{d}'
383 if flags.hasFlag(name):
384 if flags[name] != status:
387 log.warning(
"Flag '%s' should be %s but is set to %s", name, status,
not status)
389 log.debug(
"Toggling '%s' from %s to %s", name,
not status, status)
390 flags._set(name, status)
396 """Enable detectors from a list"""
399 from AthenaCommon.Logging
import logging
400 log = logging.getLogger(
'DetectorConfigFlags')
405 log.info(
'Enabling detectors: %s', detectors)
409 name = f
'Detector.Enable{d}'
410 if flags.hasFlag(name):
411 if flags[name]
is not True:
413 log.info(
"Enabling '%s'", name)
414 flags._set(name,
True)
416 name = f
'Detector.Geometry{d}'
417 if flags.hasFlag(name):
418 if flags[name]
is not True:
420 log.info(
"Enabling '%s'", name)
421 flags._set(name,
True)
427 """Disable detectors from a list"""
430 from AthenaCommon.Logging
import logging
431 log = logging.getLogger(
'DetectorConfigFlags')
436 log.info(
'Disabling detectors: %s', detectors)
440 name = f
'Detector.Enable{d}'
441 if flags.hasFlag(name):
442 if flags[name]
is not False:
444 log.info(
"Disabling '%s'", name)
445 flags._set(name,
False)
447 name = f
'Detector.Geometry{d}'
448 if flags.hasFlag(name):
449 if flags[name]
is not False:
451 log.info(
"Disabling '%s'", name)
452 flags._set(name,
False)