Skip to content
Snippets Groups Projects

Remove print statements from Forward Detector configuration

Merged John Derek Chapman requested to merge jchapman/athena:FwdConfigPrint_main into master
2 files
+ 25
21
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -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
Loading