Skip to content
Snippets Groups Projects
Commit e5849748 authored by John Derek Chapman's avatar John Derek Chapman Committed by Tadej Novak
Browse files

Improve ComponentAccumulator-based configuration of Forward Detector Simulation

The various Twiss flags should only be written to the /Simulation/Parameters metadata when Forward Detector simulation is enabled
parent f7cae9f5
No related branches found
No related tags found
No related merge requests found
Showing
with 112 additions and 35 deletions
...@@ -135,7 +135,7 @@ def initConfigFlags(): ...@@ -135,7 +135,7 @@ def initConfigFlags():
acf.addFlag('Beam.BunchSpacing', 25) # former global.BunchSpacing acf.addFlag('Beam.BunchSpacing', 25) # former global.BunchSpacing
acf.addFlag('Beam.Type', lambda prevFlags : BeamType(GetFileMD(prevFlags.Input.Files).get('beam_type', 'collisions')), enum=BeamType)# former global.BeamType acf.addFlag('Beam.Type', lambda prevFlags : BeamType(GetFileMD(prevFlags.Input.Files).get('beam_type', 'collisions')), enum=BeamType)# former global.BeamType
acf.addFlag("Beam.NumberOfCollisions", lambda prevFlags : 2. if prevFlags.Beam.Type is BeamType.Collisions else 0.) # former global.NumberOfCollisions acf.addFlag("Beam.NumberOfCollisions", lambda prevFlags : 2. if prevFlags.Beam.Type is BeamType.Collisions else 0.) # former global.NumberOfCollisions
acf.addFlag('Beam.Energy', lambda prevFlags : GetFileMD(prevFlags.Input.Files).get('beam_energy',7*TeV)) # former global.BeamEnergy acf.addFlag('Beam.Energy', lambda prevFlags : float(GetFileMD(prevFlags.Input.Files).get('beam_energy', 6.8*TeV))) # This is the energy of each individual beam in MeV # former global.BeamEnergy
acf.addFlag('Beam.estimatedLuminosity', lambda prevFlags : ( 1E33*(prevFlags.Beam.NumberOfCollisions)/2.3 ) *\ acf.addFlag('Beam.estimatedLuminosity', lambda prevFlags : ( 1E33*(prevFlags.Beam.NumberOfCollisions)/2.3 ) *\
(25./prevFlags.Beam.BunchSpacing)) # former flobal.estimatedLuminosity (25./prevFlags.Beam.BunchSpacing)) # former flobal.estimatedLuminosity
acf.addFlag('Beam.BunchStructureSource', lambda prevFlags: BunchStructureSource.MC if prevFlags.Input.isMC else BunchStructureSource.TrigConf) acf.addFlag('Beam.BunchStructureSource', lambda prevFlags: BunchStructureSource.MC if prevFlags.Input.isMC else BunchStructureSource.TrigConf)
......
...@@ -19,10 +19,10 @@ def resolveTwissBeamFilePath(twiss_beam): ...@@ -19,10 +19,10 @@ def resolveTwissBeamFilePath(twiss_beam):
def buildTwissFilePath(flags, filename, twiss_path=None): def buildTwissFilePath(flags, filename, twiss_path=None):
twiss_energy = '%1.1fTeV'%(float(flags.Beam.Energy)*0.000001) # flags.Sim.TwissEnergy possibly obsolete? twiss_energy = '%1.1fTeV'%(float(flags.Sim.TwissEnergy)*0.000001) # flags.Sim.TwissEnergy possibly obsolete?
twiss_beta = '%07.2fm'%(0.001*flags.Sim.TwissFileBeta) # assumes flags.Sim.TwissFileBeta is in mm twiss_beta = '%07.2fm'%(0.001*flags.Sim.TwissFileBeta) # assumes flags.Sim.TwissFileBeta is in mm
if not (flags.Sim.TwissFileNomReal and flags.Sim.TwissFileVersion): if not (flags.Sim.TwissFileNomReal and flags.Sim.TwissFileVersion):
print ("ForwardRegionPropertiesCfg: ERROR Need to either provide file names or set file name and file version flags.") print (f"ForwardRegionPropertiesCfg: ERROR Need to either provide file names or set file name (currently {filename}) and file version flags (currently flags.Sim.TwissFileNomReal = {flags.Sim.TwissFileNomReal} and flags.Sim.TwissFileVersion = {flags.Sim.TwissFileVersion}.")
raise Exception('Not enough information to locate Twiss files. Need to either provide file names or set file name and file version flags.') raise Exception('Not enough information to locate Twiss files. Need to either provide file names or set file name and file version flags.')
twiss_nomreal = flags.Sim.TwissFileNomReal twiss_nomreal = flags.Sim.TwissFileNomReal
twiss_version = flags.Sim.TwissFileVersion twiss_version = flags.Sim.TwissFileVersion
...@@ -33,7 +33,7 @@ def buildTwissFilePath(flags, filename, twiss_path=None): ...@@ -33,7 +33,7 @@ def buildTwissFilePath(flags, filename, twiss_path=None):
print("buildTwissFilePath: WARNING TwissFilePATH environment variable is empty.") print("buildTwissFilePath: WARNING TwissFilePATH environment variable is empty.")
twiss_beam = os.path.join(twiss_path, twiss_energy, twiss_beta, twiss_nomreal, twiss_version, filename) twiss_beam = os.path.join(twiss_path, twiss_energy, twiss_beta, twiss_nomreal, twiss_version, filename)
if not os.access(twiss_beam,os.R_OK): if not os.access(twiss_beam,os.R_OK):
raise Exception('Failed to find %s at %s'%(filename, twiss_beam)) raise Exception(f'Failed to find {filename} at {twiss_beam}')
return twiss_beam return twiss_beam
...@@ -52,14 +52,14 @@ def ForwardRegionPropertiesCfg(flags, name="ForwardRegionProperties", **kwargs): ...@@ -52,14 +52,14 @@ def ForwardRegionPropertiesCfg(flags, name="ForwardRegionProperties", **kwargs):
twiss_beam1 = buildTwissFilePath(flags, 'beam1.tfs') twiss_beam1 = buildTwissFilePath(flags, 'beam1.tfs')
twiss_beam2 = buildTwissFilePath(flags, 'beam2.tfs') twiss_beam2 = buildTwissFilePath(flags, 'beam2.tfs')
import re,math import re,math
twiss_energy = '%1.1fTeV'%(float(flags.Beam.Energy)*0.000001) # flags.Sim.TwissEnergy possibly obsolete? twiss_energy = '%1.1fTeV'%(float(flags.Sim.TwissEnergy)*0.000001)
twiss_momentum = math.sqrt(float(re.findall("\\d+.\\d+", twiss_energy)[0])**2 - (0.938e-3)**2)*1e3 twiss_momentum = math.sqrt(float(re.findall("\\d+.\\d+", twiss_energy)[0])**2 - (0.938e-3)**2)*1e3
else: else:
# Have to sort out twiss momentum based on file name # Have to sort out twiss momentum based on file name
tmp = twiss_beam1.split('TeV')[0] tmp = twiss_beam1.split('TeV')[0]
tmp_spot = len(tmp) tmp_spot = len(tmp)
if flags.Beam.Energy: if flags.Sim.TwissEnergy:
twiss_energy = '%1.1fTeV'%(float(flags.Beam.Energy)*0.000001) twiss_energy = '%1.1fTeV'%(float(flags.Sim.TwissEnergy)*0.000001)
else: else:
while True: while True:
try: try:
......
...@@ -5,7 +5,10 @@ from AthenaConfiguration.ComponentFactory import CompFactory ...@@ -5,7 +5,10 @@ from AthenaConfiguration.ComponentFactory import CompFactory
def ForwardTransportModelCfg(flags, name="ForwardTransportModel", **kwargs): def ForwardTransportModelCfg(flags, name="ForwardTransportModel", **kwargs):
result = ComponentAccumulator() result = ComponentAccumulator()
kwargs.setdefault("ForwardTransportSvcName", "ForwardTransportSvc") from ForwardTransportSvc.ForwardTransportSvcConfig import ForwardTransportSvcCfg
serviceName ="ForwardTransportSvc"
result.merge(ForwardTransportSvcCfg(flags, serviceName, **kwargs))
kwargs.setdefault("ForwardTransportSvcName", serviceName) #Not a ServiceHandle
kwargs.setdefault("RegionNames" , ["FWDBeamLine"] ) kwargs.setdefault("RegionNames" , ["FWDBeamLine"] )
result.setPrivateTools(CompFactory.ForwardTransportModelTool(name, **kwargs)) result.setPrivateTools(CompFactory.ForwardTransportModelTool(name, **kwargs))
return result return result
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaConfiguration.ComponentFactory import CompFactory
from ForwardRegionProperties.ForwardRegionPropertiesConfig import resolveTwissBeamFilePath, buildTwissFilePath
def ForwardTransportSvcCfg(flags, name="ForwardTransportSvc", **kwargs):
# Settings of optics to be used
twiss_beam1 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam1)
twiss_beam2 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam2)
if twiss_beam1 is None or twiss_beam2 is None:
print("ForwardTransportSvcCfg: Attempting to build TwissFileBeam paths manually")
# Getting paths to the twiss files, momentum calculation; you can switch to local files
twiss_beam1 = buildTwissFilePath(flags, 'beam1.tfs')
twiss_beam2 = buildTwissFilePath(flags, 'beam2.tfs')
# properties of the field set according to the optics settings above
kwargs.setdefault("TwissFile1", twiss_beam1)
kwargs.setdefault("TwissFile2", twiss_beam2)
kwargs.setdefault("PositionC1", 149)
kwargs.setdefault("PositionC2", 184)
kwargs.setdefault("ApertureC1", 999)
kwargs.setdefault("ApertureC2", 999)
if flags.Detector.GeometryALFA:
return ALFAForwardTransportSvcCfg(name, **kwargs)
if flags.Detector.GeometryZDC:
return ZDCForwardTransportSvcCfg (name, **kwargs)
print ("ForwardTransportSvcCfg: WARNING ALFA and ZDC are deactivated.")
return ComponentAccumulator()
def ALFAForwardTransportSvcCfg(name="ForwardTransportSvc", **kwargs):
print ("ALFAForwardTransportSvc")
result = ComponentAccumulator()
kwargs.setdefault("EndMarker", 236.888)
kwargs.setdefault("TransportFlag", 1)
kwargs.setdefault("EtaCut", 7.5)
kwargs.setdefault("XiCut", 0.8)
result.addService(CompFactory.ForwardTransportSvc(name,**kwargs), create=True, primary=True)
return result
def ZDCForwardTransportSvcCfg(name="ForwardTransportSvc", **kwargs):
print ("ZDCForwardTransportSvc")
result = ComponentAccumulator()
kwargs.setdefault("EndMarker", 141.580)
kwargs.setdefault("TransportFlag", 0)
kwargs.setdefault("EtaCut", 7.5)
kwargs.setdefault("XiCut", 0)
result.addService(CompFactory.ForwardTransportSvc(name,**kwargs), create=True, primary=True)
return result
...@@ -20,12 +20,11 @@ if __name__ == '__main__': ...@@ -20,12 +20,11 @@ if __name__ == '__main__':
flags = initConfigFlags() flags = initConfigFlags()
flags.Input.Files = defaultTestFiles.EVNT flags.Input.Files = defaultTestFiles.EVNT
# Arbitrary configuration for Twiss Files # Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '3.5TeV/0090.00m/nominal/v02/beam1.tfs' flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '3.5TeV/0090.00m/nominal/v02/beam2.tfs' flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal' flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v02' flags.Sim.TwissFileVersion = 'v01'
flags.Beam.Energy = '3500000'
# Finalize # Finalize
flags.lock() flags.lock()
......
#!/usr/bin/env python #!/usr/bin/env python
"""Run tests on G4AtlasToolsConfig """Run tests on G4AtlasToolsConfig
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
""" """
if __name__ == '__main__': if __name__ == '__main__':
...@@ -31,6 +31,12 @@ if __name__ == '__main__': ...@@ -31,6 +31,12 @@ if __name__ == '__main__':
# Setup detector flags # Setup detector flags
from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
setupDetectorFlags(flags, ['BCM', 'Pixel', 'SCT', 'TRT', 'LAr', 'MBTS'], toggle_geometry=True) setupDetectorFlags(flags, ['BCM', 'Pixel', 'SCT', 'TRT', 'LAr', 'MBTS'], toggle_geometry=True)
# Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v01'
# Finalize # Finalize
flags.lock() flags.lock()
......
#!/usr/bin/env python #!/usr/bin/env python
"""Run tests on G4AtlasFieldConfig """Run tests on G4AtlasFieldConfig
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
""" """
if __name__ == '__main__': if __name__ == '__main__':
...@@ -20,12 +20,11 @@ if __name__ == '__main__': ...@@ -20,12 +20,11 @@ if __name__ == '__main__':
flags = initConfigFlags() flags = initConfigFlags()
flags.Input.Files = defaultTestFiles.EVNT flags.Input.Files = defaultTestFiles.EVNT
# Arbitrary configuration for Twiss Files # Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '3.5TeV/0090.00m/nominal/v02/beam1.tfs' flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '3.5TeV/0090.00m/nominal/v02/beam2.tfs' flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal' flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v02' flags.Sim.TwissFileVersion = 'v01'
flags.Beam.Energy = '3500000'
# Finalize # Finalize
flags.lock() flags.lock()
......
#!/usr/bin/env python #!/usr/bin/env python
"""Run tests on G4Geometry Tool configuration """Run tests on G4Geometry Tool configuration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
""" """
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
...@@ -35,7 +35,12 @@ if __name__ == '__main__': ...@@ -35,7 +35,12 @@ if __name__ == '__main__':
flags.Sim.WorldRRange = 15000 flags.Sim.WorldRRange = 15000
flags.Sim.WorldZRange = 27000 flags.Sim.WorldZRange = 27000
flags.Sim.TwissFileNomReal = "nominal" #so it doesn't crash # Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v01'
# Finalize # Finalize
flags.lock() flags.lock()
......
#!/usr/bin/env python #!/usr/bin/env python
"""Run tests on G4Geometry Tool configuration """Run tests on G4Geometry Tool configuration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
""" """
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
...@@ -34,7 +34,12 @@ if __name__ == '__main__': ...@@ -34,7 +34,12 @@ if __name__ == '__main__':
flags.Sim.WorldRRange = 15000 flags.Sim.WorldRRange = 15000
flags.Sim.WorldZRange = 27000 flags.Sim.WorldZRange = 27000
flags.Sim.TwissFileNomReal = "nominal" #so it doesn't crash # Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v01'
# Finalize # Finalize
flags.lock() flags.lock()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"""Run tests on G4PhysicsRegionConfig configuration """Run tests on G4PhysicsRegionConfig configuration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
from __future__ import print_function from __future__ import print_function
""" """
...@@ -22,7 +22,12 @@ if __name__ == '__main__': ...@@ -22,7 +22,12 @@ if __name__ == '__main__':
inputDir = defaultTestFiles.d inputDir = defaultTestFiles.d
flags = initConfigFlags() flags = initConfigFlags()
flags.Input.Files = defaultTestFiles.EVNT flags.Input.Files = defaultTestFiles.EVNT
# Arbitrary configuration for Twiss Files
flags.Sim.TwissFileBeam1 = '4.0TeV/0090.00m/nominal/v01/beam1.tfs'
flags.Sim.TwissFileBeam2 = '4.0TeV/0090.00m/nominal/v01/beam2.tfs'
flags.Sim.TwissFileBeta = 90000 # in mm
flags.Sim.TwissFileNomReal = 'nominal'
flags.Sim.TwissFileVersion = 'v01'
# Finalize # Finalize
flags.lock() flags.lock()
......
...@@ -4,6 +4,7 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags, isGaudiEnv ...@@ -4,6 +4,7 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags, isGaudiEnv
from AthenaConfiguration.AutoConfigFlags import GetFileMD from AthenaConfiguration.AutoConfigFlags import GetFileMD
from SimulationConfig.SimEnums import BeamPipeSimMode, CalibrationRun, CavernBackground, \ from SimulationConfig.SimEnums import BeamPipeSimMode, CalibrationRun, CavernBackground, \
LArParameterization, SimulationFlavour, TruthStrategy, VertexSource LArParameterization, SimulationFlavour, TruthStrategy, VertexSource
from AthenaCommon.SystemOfUnits import m
#todo? add in the explanatory text from previous implementation #todo? add in the explanatory text from previous implementation
...@@ -61,10 +62,10 @@ def createSimConfigFlags(): ...@@ -61,10 +62,10 @@ def createSimConfigFlags():
# Forward region # Forward region
scf.addFlag("Sim.TwissFileBeam1", False) scf.addFlag("Sim.TwissFileBeam1", False)
scf.addFlag("Sim.TwissFileBeam2", False) scf.addFlag("Sim.TwissFileBeam2", False)
scf.addFlag("Sim.TwissEnergy", 8000000.) scf.addFlag("Sim.TwissEnergy", lambda prevFlags : float(prevFlags.Beam.Energy)) # energy of each beam
scf.addFlag("Sim.TwissFileBeta", 550.) scf.addFlag("Sim.TwissFileBeta", 90.*m)
scf.addFlag("Sim.TwissFileNomReal", False) # "nominal", "real" / default to one of these?! scf.addFlag("Sim.TwissFileNomReal", 'nominal') # "nominal", "real" / default to one of these?!
scf.addFlag("Sim.TwissFileVersion", "v01") scf.addFlag("Sim.TwissFileVersion", "v02")
# G4AtlasAlg # G4AtlasAlg
scf.addFlag("Sim.ReleaseGeoModel", False) scf.addFlag("Sim.ReleaseGeoModel", False)
......
...@@ -17,6 +17,9 @@ def fillAtlasMetadata(flags, dbFiller): ...@@ -17,6 +17,9 @@ def fillAtlasMetadata(flags, dbFiller):
if "GenerationConfiguration" in flag: if "GenerationConfiguration" in flag:
# This flag is only temporarily defined in the SimConfigFlags module # This flag is only temporarily defined in the SimConfigFlags module
continue continue
if "Twiss" in flag and not flags.Detector.GeometryForward:
# The various Twiss flags should only be written out when Forward Detector simulation is enabled
continue
key = flag.split(".")[-1] #use final part of flag as the key key = flag.split(".")[-1] #use final part of flag as the key
value = flags._get(flag) value = flags._get(flag)
if isinstance(value, FlagEnum): if isinstance(value, FlagEnum):
......
...@@ -61,7 +61,7 @@ AtlasG4_tf.py \ ...@@ -61,7 +61,7 @@ AtlasG4_tf.py \
rc2=$? rc2=$?
mv log.AtlasG4Tf log.AtlasG4Tf_CG mv log.AtlasG4Tf log.AtlasG4Tf_CG
echo "art-result: $rc simOLD" echo "art-result: $rc2 simOLD"
if [ $status -eq 0 ] if [ $status -eq 0 ]
then then
status=$rc2 status=$rc2
......
...@@ -60,7 +60,7 @@ AtlasG4_tf.py \ ...@@ -60,7 +60,7 @@ AtlasG4_tf.py \
rc2=$? rc2=$?
mv log.AtlasG4Tf log.AtlasG4Tf_CG mv log.AtlasG4Tf log.AtlasG4Tf_CG
echo "art-result: $rc simOLD" echo "art-result: $rc2 simOLD"
if [ $status -eq 0 ] if [ $status -eq 0 ]
then then
status=$rc2 status=$rc2
......
...@@ -60,7 +60,7 @@ AtlasG4_tf.py \ ...@@ -60,7 +60,7 @@ AtlasG4_tf.py \
rc2=$? rc2=$?
mv log.AtlasG4Tf log.AtlasG4Tf_CG mv log.AtlasG4Tf log.AtlasG4Tf_CG
echo "art-result: $rc simOLD" echo "art-result: $rc2 simOLD"
if [ $status -eq 0 ] if [ $status -eq 0 ]
then then
status=$rc2 status=$rc2
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
# Format is "test" : "version" # Format is "test" : "version"
references_map = { references_map = {
# Simulation # Simulation
"s3761": "v9", "s3761": "v10",
"s3779": "v7", "s3779": "v7",
"s4005": "v6", "s4005": "v7",
"s4006": "v10", "s4006": "v11",
"s4007": "v10", "s4007": "v11",
"s4008": "v4", "s4008": "v4",
# Overlay # Overlay
"d1590": "v14", "d1590": "v14",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment