19#include "BDSBunchPtc.hh"
21#include "BDSException.hh"
22#include "BDSGlobalConstants.hh"
23#include "BDSParticleCoordsFull.hh"
24#include "BDSUtilities.hh"
26#include "parser/beam.h"
28#include "CLHEP/Units/PhysicalConstants.h"
34BDSBunchPtc::BDSBunchPtc():
36 matchDistrFileLength(false),
38 fileName(
"./inrays.madx"),
44BDSBunchPtc::~BDSBunchPtc()
46 for (std::vector<double*>::iterator i =
ptcData.begin();i!=
ptcData.end();++i)
56 {
throw BDSException(__METHOD_NAME__,
"\"" +
fileName +
"\" file doesn't exist - exiting as no input");}
60 while (std::getline(ifstr,line))
62 int isComment = line.compare(0, 1,
"!");
76 std::regex rex(
"\\sx\\s*=\\s*([0-9eE.+-]+)");
77 std::regex rey(
"\\sy\\s*=\\s*([0-9eE.+-]+)");
78 std::regex repx(
"px\\s*=\\s*([0-9eE.+-]+)");
79 std::regex repy(
"py\\s*=\\s*([0-9eE.+-]+)");
80 std::regex ret(
"\\st\\s*=\\s*([0-9eE.+-]+)");
81 std::regex rept(
"pt\\s*=\\s*([0-9eE.+-]+)");
92 std::regex_search(line,smx, rex);
93 std::regex_search(line,smy, rey);
94 std::regex_search(line,smpx,repx);
95 std::regex_search(line,smpy,repy);
96 std::regex_search(line,smt, ret);
97 std::regex_search(line,smpt, rept);
99 if(smx.size() == 2) x = std::stod(smx[1]);
100 if(smy.size() == 2) y = std::stod(smy[1]);
101 if(smpx.size() == 2) px = std::stod(smpx[1]);
102 if(smpy.size() == 2) py = std::stod(smpy[1]);
103 if(smt.size() == 2) t = std::stod(smt[1]);
104 if(smpt.size() == 2) pt = std::stod(smpt[1]);
107 G4cout << __METHOD_NAME__ <<
"read line " << line << G4endl;
108 G4cout << __METHOD_NAME__ <<
"values " << x <<
" " << px <<
" " << y <<
" " << py <<
" " << t <<
" " << pt << G4endl;
111 double* values =
new double[6];
134 G4Transform3D beamlineTransformIn,
135 const G4double beamlineSIn)
138 G4cout << __METHOD_NAME__ <<
" " << beam.
distrFile << G4endl;
167 G4double t = (z-
Z0)*CLHEP::m / CLHEP::c_light +
T0 * CLHEP::s;
170 G4double betaSquared = std::pow(
beta,2.0);
172 G4double E =
E0 * (ptcVal + 1.0);
179 G4cout << __METHOD_NAME__ <<
"End of file reached. Returning to beginning of file." << G4endl;
std::vector< double * > ptcData
Data.
G4bool loopedOver
Whether we've reset to loop over the file again.
G4String fileName
File name.
void LoadPtcFile()
Load the PTC file into memory.
G4bool matchDistrFileLength
Whether to only run the number of particles in the file.
virtual BDSParticleCoordsFull GetNextParticleLocal()
G4int nRays
Number of rays in file (1 counting).
void SetDistrFile(const G4String &distrFileNameIn)
Assign the distribution file by finding the full path of it.
G4double beta
Velocity w.r.t. speed of light. Needed to convert mom. to energy.
G4int iRay
Iterator counter for current ray.
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
The base class for bunch distribution generators.
G4double Yp0
Centre of distributions.
G4double T0
Centre of distributions.
G4double S0
Centre of distributions.
G4double Z0
Centre of distributions.
G4double X0
Centre of distributions.
G4double Zp0
Centre of distributions.
G4double Xp0
Centre of distributions.
G4double E0
Centre of distributions.
G4double Y0
Centre of distributions.
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0)
Calculate zp safely based on other components.
General exception with possible name of object and message.
void SetNumberToGenerate(G4int number)
Setter.
static BDSGlobalConstants * Instance()
Access method.
A set of particle coordinates including energy and weight.
Wrapper for particle definition.
G4double Beta() const
Accessor.
Improve type-safety of native enum data type in C++.
bool matchDistrFileLength
beam parameters
std::string distrFile
beam parameters
G4String GetFullPath(G4String filename, bool excludeNameFromPath=false, bool useCWDForPrefix=false)