Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  if "FastCalo.doPunchThrough" in flag and not flags.Sim.FastCalo.doPunchThrough:
42  # This flag is only written to metadata in case PunchThroughG4Tool is set
43  continue
44 
45  key = flag.split(".")[-1] #use final part of flag as the key
46  value = flags._get(flag)
47  if isinstance(value, FlagEnum):
48  value = value.value
49  if not isinstance(value, str):
50  value = str(value)
51  dbFiller.addSimParam(key, value)
52  simMDlog.info('SimulationMetaData: setting "%s" to be %s', key, value)
53 
54  dbFiller.addSimParam('G4Version', flags.Sim.G4Version)
55  dbFiller.addSimParam('RunType', 'atlas')
56  dbFiller.addSimParam('beamType', flags.Beam.Type.value)
57  dbFiller.addSimParam('SimLayout', flags.GeoModel.AtlasVersion)
58  dbFiller.addSimParam('MagneticField', 'AtlasFieldSvc') # TODO hard-coded for now for consistency with old-style configuration.
59 
60  #---------
61 
62  from AthenaConfiguration.DetectorConfigFlags import getEnabledDetectors
63  simDets = ['Truth'] + getEnabledDetectors(flags)
64  simMDlog.info("Setting 'SimulatedDetectors' = %r", simDets)
65  dbFiller.addSimParam('SimulatedDetectors', repr(simDets))
66 
67 
68  dbFiller.addSimParam('hitFileMagicNumber', '0')
69 
70  if flags.Sim.ISFRun:
71  dbFiller.addSimParam('Simulator', flags.Sim.ISF.Simulator.value)
72  dbFiller.addSimParam('SimulationFlavour', flags.Sim.ISF.Simulator.value.replace('MT', '')) # used by egamma
73  else:
74  # TODO hard-code for now, but set flag properly later
75  dbFiller.addSimParam('Simulator', 'AtlasG4')
76  dbFiller.addSimParam('SimulationFlavour', 'AtlasG4')
77 
78 
80  simMDlog = logging.getLogger('Sim_Metadata')
81  from IOVDbMetaDataTools import ParameterDbFiller
83  myRunNumber, myEndRunNumber = getMinMaxRunNumbers(flags)
84  simMDlog.debug('ParameterDbFiller BeginRun = %s', str(myRunNumber) )
85  dbFiller.setBeginRun(myRunNumber)
86  simMDlog.debug('ParameterDbFiller EndRun = %s', str(myEndRunNumber) )
87  dbFiller.setEndRun(myEndRunNumber)
88 
89  fillAtlasMetadata(flags, dbFiller)
90 
91  #-------------------------------------------------
92  # Make the MetaData Db
93  #-------------------------------------------------
94  dbFiller.genSimDb()
95 
96  return writeSimulationParameters(flags)
97 
98 
100  """Read digitization parameters metadata"""
101  from IOVDbSvc.IOVDbSvcConfig import addFolders
102  if flags.Common.ProductionStep not in [ProductionStep.Simulation, ProductionStep.FastChain]:
103  return addFolders(flags, folderName, className="AthenaAttributeList", tag="HEAD")
104 
105  # Here we are in a job which runs simulation, so the
106  # /Simulation/Parameters metadata is not present in the
107  # input file and will be created during the job
108  return addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM", className="AthenaAttributeList")
109 
110 
112  """Write digitization parameters metadata"""
113  from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg, addFolders
114  acc = IOVDbSvcCfg(flags, FoldersToMetaData=[folderName])
115  acc.merge(addFolders(flags, folderName, detDb="SimParams.db", db="SIMPARAM"))
116  return acc
python.SimulationMetadata.readSimulationParameters
def readSimulationParameters(flags)
Definition: SimulationMetadata.py:99
python.ParameterDbFiller.ParameterDbFiller
Definition: ParameterDbFiller.py:26
python.SimulationMetadata.writeSimulationParameters
def writeSimulationParameters(flags)
Definition: SimulationMetadata.py:111
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:81
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:28
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:79
str
Definition: BTagTrackIpAccessor.cxx:11
python.EventIdOverrideConfig.getMinMaxRunNumbers
def getMinMaxRunNumbers(flags)
Definition: EventIdOverrideConfig.py:101