ATLAS Offline Software
SimulationMetadata.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 from AthenaConfiguration.Enums import FlagEnum, ProductionStep
5 from AthenaKernel.EventIdOverrideConfig import getMinMaxRunNumbers
6 
7 folderName = "/Simulation/Parameters"
8 
9 
10 def fillAtlasMetadata(flags, dbFiller):
11  simMDlog = logging.getLogger('Sim_Metadata')
12  #add all flags to the metadata
13  #todo - only add certain ones?
14  #in future this should be a ConfigFlags method...?
15  for flag in sorted(flags._flagdict): #only sim
16  if flag.startswith("Sim."):
17  if "GenerationConfiguration" in flag:
18  # This flag is only temporarily defined in the SimConfigFlags module
19  continue
20  if "Twiss" in flag and not flags.Detector.GeometryForward:
21  # The various Twiss flags should only be written out when Forward Detector simulation is enabled
22  continue
23  if "UseShadowEvent" in flag and not flags.Sim.UseShadowEvent:
24  # This flag is added temporarily to allow a new approach to quasi-stable particle simulation to be tested.
25  continue
26  if "VertexTimeWidth" in flag and not flags.Sim.VertexTimeSmearing:
27  # This flag is only written to metadata when vertex time smearing is enabled
28  continue
29  if "RunOnGPU" in flag and not flags.Sim.ISF.Simulator.usesFastCaloSim():
30  # This flag is only written to metadata when FastCaloSim/FastCaloGAN is enabled
31  continue
32  if "FastCalo.ParamsInputFilename" in flag and not flags.Sim.ISF.Simulator.usesFastCaloSim():
33  # This flag is only written to metadata when FastCaloSim/FastCaloGAN is enabled
34  continue
35  if "SimplifiedGeoPath" in flag and not flags.Sim.SimplifiedGeoPath:
36  # This flag is only written to metadata in case the FastCaloSim simplified geometry path is set
37  continue
38  if "FastCalo.doPunchThrough" in flag and not flags.Sim.FastCalo.doPunchThrough:
39  # This flag is only written to metadata in case PunchThroughG4Tool is set
40  continue
41 
42  key = flag.split(".")[-1] #use final part of flag as the key
43  value = flags._get(flag)
44  if isinstance(value, FlagEnum):
45  value = value.value
46  if not isinstance(value, str):
47  value = str(value)
48  dbFiller.addSimParam(key, value)
49  simMDlog.info('SimulationMetaData: setting "%s" to be %s', key, value)
50 
51  dbFiller.addSimParam('G4Version', flags.Sim.G4Version)
52  dbFiller.addSimParam('RunType', 'atlas')
53  dbFiller.addSimParam('beamType', flags.Beam.Type.value)
54  dbFiller.addSimParam('SimLayout', flags.GeoModel.AtlasVersion)
55  dbFiller.addSimParam('MagneticField', 'AtlasFieldSvc') # TODO hard-coded for now for consistency with old-style configuration.
56 
57  #---------
58 
59  from AthenaConfiguration.DetectorConfigFlags import getEnabledDetectors
60  simDets = ['Truth'] + getEnabledDetectors(flags)
61  simMDlog.info("Setting 'SimulatedDetectors' = %r", simDets)
62  dbFiller.addSimParam('SimulatedDetectors', repr(simDets))
63 
64 
65  dbFiller.addSimParam('hitFileMagicNumber', '0')
66 
67  if flags.Sim.ISFRun:
68  dbFiller.addSimParam('Simulator', flags.Sim.ISF.Simulator.value)
69  dbFiller.addSimParam('SimulationFlavour', flags.Sim.ISF.Simulator.value.replace('MT', '')) # used by egamma
70  else:
71  # TODO hard-code for now, but set flag properly later
72  dbFiller.addSimParam('Simulator', 'AtlasG4')
73  dbFiller.addSimParam('SimulationFlavour', 'AtlasG4')
74 
75 
76  if flags.Common.isOverlay and flags.Overlay.DataOverlay:
77  dbFiller.addSimParam('IsDataOverlay', 'True')
78 
79 
81  simMDlog = logging.getLogger('Sim_Metadata')
82  from IOVDbMetaDataTools import ParameterDbFiller
84  myRunNumber, myEndRunNumber = getMinMaxRunNumbers(flags)
85  simMDlog.debug('ParameterDbFiller BeginRun = %s', str(myRunNumber) )
86  dbFiller.setBeginRun(myRunNumber)
87  simMDlog.debug('ParameterDbFiller EndRun = %s', str(myEndRunNumber) )
88  dbFiller.setEndRun(myEndRunNumber)
89 
90  fillAtlasMetadata(flags, dbFiller)
91 
92  #-------------------------------------------------
93  # Make the MetaData Db
94  #-------------------------------------------------
95  dbFiller.genSimDb()
96 
97  return writeSimulationParameters(flags)
98 
99 
101  """Read digitization parameters metadata"""
102  from IOVDbSvc.IOVDbSvcConfig import addFolders
103  if flags.Common.ProductionStep not in [ProductionStep.Simulation, ProductionStep.FastChain]:
104  return addFolders(flags, folderName, className="AthenaAttributeList", tag="HEAD")
105 
106  # Here we are in a job which runs simulation, so the
107  # /Simulation/Parameters metadata is not present in the
108  # input file and will be created during the job
109  return addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM", className="AthenaAttributeList")
110 
111 
113  """Write digitization parameters metadata"""
114  from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg, addFolders
115  acc = IOVDbSvcCfg(flags, FoldersToMetaData=[folderName])
116  acc.merge(addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM"))
117  return acc
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
python.SimulationMetadata.readSimulationParameters
def readSimulationParameters(flags)
Definition: SimulationMetadata.py:100
python.ParameterDbFiller.ParameterDbFiller
Definition: ParameterDbFiller.py:24
python.SimulationMetadata.writeSimulationParameters
def writeSimulationParameters(flags)
Definition: SimulationMetadata.py:112
python.DetectorConfigFlags.getEnabledDetectors
def getEnabledDetectors(flags, geometry=False)
Definition: DetectorConfigFlags.py:147
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:86
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:28
python.SimulationMetadata.fillAtlasMetadata
def fillAtlasMetadata(flags, dbFiller)
Definition: SimulationMetadata.py:10
python.SimulationMetadata.writeSimulationParametersMetadata
def writeSimulationParametersMetadata(flags)
Definition: SimulationMetadata.py:80
str
Definition: BTagTrackIpAccessor.cxx:11
python.EventIdOverrideConfig.getMinMaxRunNumbers
def getMinMaxRunNumbers(flags)
Definition: EventIdOverrideConfig.py:101