3 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory
import CompFactory
5 from AthenaConfiguration.AccumulatorCache
import AccumulatorCache
9 if not isinstance(twiss_beam, str):
11 if os.access(twiss_beam,os.R_OK):
13 twiss_path = os.getenv(
'TwissFilesPATH')
15 msg.warning(
"resolveTwissBeamFilePath: TwissFilesPATH environment variable is empty.")
16 twiss_beam_path = twiss_path +
'/' + twiss_beam
17 if os.access(twiss_beam_path,os.R_OK):
18 return twiss_beam_path
19 msg.warning(f
'resolveTwissBeamFilePath: Could not find twiss beam file at {twiss_beam} or {twiss_beam_path}')
24 twiss_energy =
'%1.1fTeV'%(
float(flags.Sim.TwissEnergy)*0.000001)
25 twiss_beta =
'%07.2fm'%(0.001*flags.Sim.TwissFileBeta)
26 if not (flags.Sim.TwissFileNomReal
and flags.Sim.TwissFileVersion):
27 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}.")
28 raise Exception(
'Not enough information to locate Twiss files. Need to either provide file names or set file name and file version flags.')
29 twiss_nomreal = flags.Sim.TwissFileNomReal
30 twiss_version = flags.Sim.TwissFileVersion
33 twiss_path = os.getenv(
'TwissFilesPATH')
35 msg.warning(
"buildTwissFilePath: TwissFilesPATH environment variable is empty.")
36 twiss_beam = os.path.join(twiss_path, twiss_energy, twiss_beta, twiss_nomreal, twiss_version, filename)
37 if not os.access(twiss_beam,os.R_OK):
38 raise Exception(f
'Failed to find {filename} at {twiss_beam}')
46 from AthenaCommon.Logging
import logging
47 msg = logging.getLogger(
"ForwardRegionPropertiesCfg")
53 if twiss_beam1
is None or twiss_beam2
is None:
54 msg.info(
"Attempting to build TwissFileBeam paths manually")
59 twiss_energy =
'%1.1fTeV'%(
float(flags.Sim.TwissEnergy)*0.000001)
60 twiss_momentum = math.sqrt(
float(re.findall(
"\\d+.\\d+", twiss_energy)[0])**2 - (0.938e-3)**2)*1e3
63 tmp = twiss_beam1.split(
'TeV')[0]
65 if flags.Sim.TwissEnergy:
66 twiss_energy =
'%1.1fTeV'%(
float(flags.Sim.TwissEnergy)*0.000001)
70 tmp_energy =
float( tmp[tmp_spot:] )
73 twiss_energy =
float( tmp[tmp_spot+1:] )
77 twiss_momentum = math.sqrt(
float(re.findall(
"\\d+.\\d+", twiss_energy)[0])**2 - (0.938e-3)**2)*1e3
80 kwargs.setdefault(
"twissFileB1", twiss_beam1)
81 kwargs.setdefault(
"twissFileB2", twiss_beam2)
82 kwargs.setdefault(
"momentum", twiss_momentum)
83 result.setPrivateTools(CompFactory.ForwardRegionProperties(name, **kwargs))