Skip to content
Snippets Groups Projects
Commit 7dd41af3 authored by Tadej Novak's avatar Tadej Novak
Browse files

Merge branch 'FwdConfigPrint_main' into 'master'

Remove print statements from Forward Detector configuration

See merge request !60682
parents 22a3cbaf b6f3bf09
No related branches found
No related tags found
1 merge request!60682Remove print statements from Forward Detector configuration
......@@ -4,7 +4,7 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaConfiguration.ComponentFactory import CompFactory
from AthenaConfiguration.AccumulatorCache import AccumulatorCache
def resolveTwissBeamFilePath(twiss_beam):
def resolveTwissBeamFilePath(twiss_beam, msg):
import os
if not isinstance(twiss_beam, str):
return None
......@@ -12,17 +12,19 @@ def resolveTwissBeamFilePath(twiss_beam):
return twiss_beam
twiss_path = os.getenv('TwissFilesPATH')
if not twiss_path:
print("resolveTwissBeamFilePath: WARNING TwissFilePATH environment variable is empty.")
if os.access(twiss_path+twiss_beam,os.R_OK):
return twiss_path+twiss_beam
msg.warning("resolveTwissBeamFilePath: TwissFilePATH environment variable is empty.")
twiss_beam_path = twiss_path + '/' + twiss_beam
if os.access(twiss_beam_path,os.R_OK):
return twiss_beam_path
msg.warning(f'resolveTwissBeamFilePath: Could not find twiss beam file at {twiss_beam} or {twiss_beam_path}')
return None
def buildTwissFilePath(flags, filename, twiss_path=None):
def buildTwissFilePath(flags, msg, filename, twiss_path=None):
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
if not (flags.Sim.TwissFileNomReal and flags.Sim.TwissFileVersion):
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}.")
msg.error(f"buildTwissFilePath: 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.')
twiss_nomreal = flags.Sim.TwissFileNomReal
twiss_version = flags.Sim.TwissFileVersion
......@@ -30,7 +32,7 @@ def buildTwissFilePath(flags, filename, twiss_path=None):
if not twiss_path:
twiss_path = os.getenv('TwissFilesPATH')
if not twiss_path:
print("buildTwissFilePath: WARNING TwissFilePATH environment variable is empty.")
msg.warning("buildTwissFilePath: TwissFilePATH environment variable is empty.")
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):
raise Exception(f'Failed to find {filename} at {twiss_beam}')
......@@ -41,16 +43,18 @@ def buildTwissFilePath(flags, filename, twiss_path=None):
# so maintain that behaviour for now.
@AccumulatorCache
def ForwardRegionPropertiesCfg(flags, name="ForwardRegionProperties", **kwargs):
from AthenaCommon.Logging import logging
msg = logging.getLogger("ForwardRegionPropertiesCfg")
result = ComponentAccumulator()
# Settings of optics to be used
twiss_beam1 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam1)
twiss_beam2 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam2)
twiss_beam1 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam1, msg)
twiss_beam2 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam2, msg)
twiss_momentum = -1.
if twiss_beam1 is None or twiss_beam2 is None:
print("ForwardRegionPropertiesCfg: Attempting to build TwissFileBeam paths manually")
msg.info("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')
twiss_beam1 = buildTwissFilePath(flags, msg, 'beam1.tfs')
twiss_beam2 = buildTwissFilePath(flags, msg, 'beam2.tfs')
import re,math
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
......
......@@ -5,14 +5,16 @@ 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)
from AthenaCommon.Logging import logging
msg = logging.getLogger("ForwardTransportSvcCfg")
# Settings of optics to be used
twiss_beam1 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam1, msg)
twiss_beam2 = resolveTwissBeamFilePath(flags.Sim.TwissFileBeam2, msg)
if twiss_beam1 is None or twiss_beam2 is None:
print("ForwardTransportSvcCfg: Attempting to build TwissFileBeam paths manually")
msg.info("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')
twiss_beam1 = buildTwissFilePath(flags, msg, 'beam1.tfs')
twiss_beam2 = buildTwissFilePath(flags, msg, 'beam2.tfs')
# properties of the field set according to the optics settings above
kwargs.setdefault("TwissFile1", twiss_beam1)
......@@ -25,12 +27,11 @@ def ForwardTransportSvcCfg(flags, name="ForwardTransportSvc", **kwargs):
return ALFAForwardTransportSvcCfg(name, **kwargs)
if flags.Detector.GeometryZDC:
return ZDCForwardTransportSvcCfg (name, **kwargs)
print ("ForwardTransportSvcCfg: WARNING ALFA and ZDC are deactivated.")
msg.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)
......@@ -41,7 +42,6 @@ def ALFAForwardTransportSvcCfg(name="ForwardTransportSvc", **kwargs):
def ZDCForwardTransportSvcCfg(name="ForwardTransportSvc", **kwargs):
print ("ZDCForwardTransportSvc")
result = ComponentAccumulator()
kwargs.setdefault("EndMarker", 141.580)
kwargs.setdefault("TransportFlag", 0)
......
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