ATLAS Offline Software
SimulationMetadata.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 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.doEMECFCS" in flag and not flags.Sim.FastCalo.doEMECFCS:
39  # This flag is only written to metadata in case FCS is used in EMEC region (1.5 < AbsEta < 3.2, Ekin < 8 GeV) 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 
77  simMDlog = logging.getLogger('Sim_Metadata')
78  from IOVDbMetaDataTools import ParameterDbFiller
80  myRunNumber, myEndRunNumber = getMinMaxRunNumbers(flags)
81  simMDlog.debug('ParameterDbFiller BeginRun = %s', str(myRunNumber) )
82  dbFiller.setBeginRun(myRunNumber)
83  simMDlog.debug('ParameterDbFiller EndRun = %s', str(myEndRunNumber) )
84  dbFiller.setEndRun(myEndRunNumber)
85 
86  fillAtlasMetadata(flags, dbFiller)
87 
88  #-------------------------------------------------
89  # Make the MetaData Db
90  #-------------------------------------------------
91  dbFiller.genSimDb()
92 
93  return writeSimulationParameters(flags)
94 
95 
97  """Read digitization parameters metadata"""
98  from IOVDbSvc.IOVDbSvcConfig import addFolders
99  if flags.Common.ProductionStep not in [ProductionStep.Simulation, ProductionStep.FastChain]:
100  return addFolders(flags, folderName, className="AthenaAttributeList", tag="HEAD")
101 
102  # Here we are in a job which runs simulation, so the
103  # /Simulation/Parameters metadata is not present in the
104  # input file and will be created during the job
105  return addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM", className="AthenaAttributeList")
106 
107 
109  """Write digitization parameters metadata"""
110  from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg, addFolders
111  acc = IOVDbSvcCfg(flags, FoldersToMetaData=[folderName])
112  acc.merge(addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM"))
113  return acc
python.SimulationMetadata.readSimulationParameters
def readSimulationParameters(flags)
Definition: SimulationMetadata.py:96
python.ParameterDbFiller.ParameterDbFiller
Definition: ParameterDbFiller.py:26
python.SimulationMetadata.writeSimulationParameters
def writeSimulationParameters(flags)
Definition: SimulationMetadata.py:108
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:72
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:19
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.SimulationMetadata.fillAtlasMetadata
def fillAtlasMetadata(flags, dbFiller)
Definition: SimulationMetadata.py:10
python.SimulationMetadata.writeSimulationParametersMetadata
def writeSimulationParametersMetadata(flags)
Definition: SimulationMetadata.py:76
str
Definition: BTagTrackIpAccessor.cxx:11
python.EventIdOverrideConfig.getMinMaxRunNumbers
def getMinMaxRunNumbers(flags)
Definition: EventIdOverrideConfig.py:101