40 constexpr const char* photonParticleName =
"PHOTON";
64 "The \"BEAM\" statement defines data for the particles "
68 "PARTICLE",
"Name of particle to be used",
69 {
"PHOTON",
"ELECTRON",
"POSITRON",
"MUON",
"PION",
"PROTON",
"ANTIPROTON",
"DEUTERON",
70 "HMINUS",
"H2P",
"ALPHA",
"CARBON",
"XENON",
"URANIUM"});
93 "SOURCES",
"Name of the emission sources list (EMISSIONSOURCELIST).");
96 "GLOBALPROCESSES",
"Global physics processes active for this beam.");
99 "DAUGHTERBEAM",
"Name of the BEAM that receives decay daughter particles.");
103 "Initial polarization vector P = {Px, Py, Pz} for this beam "
104 "(rest-frame Pauli expectation values along lab-frame axes). "
105 "Must be length-3 with |P| in [0, 1]. Only valid for PARTICLE=MUON; "
106 "setting POLARIZATION on any other species is rejected. Setting "
107 "POLARIZATION (even {0,0,0}) enables per-particle spin tracking for this "
108 "beam (Thomas-BMT integration); leaving it unset disables spin tracking. "
109 "For muons produced by an upstream decay (e.g. PionDecay) the per-particle "
110 "value is overwritten by the decay, but POLARIZATION must still be set to "
111 "enable the spin storage that receives it.");
128 :
Definition(name, parent), reference(parent->reference) {}
134 return dynamic_cast<Beam*
>(object) != 0;
144 throw OpalException(
"Beam::execute()",
"\"ENERGY\" must be set for PARTICLE=PHOTON.");
149 "\"MASS\" is not allowed for PARTICLE=PHOTON. Use \"ENERGY\".");
153 "Beam::execute()",
"\"CHARGE\" is not allowed for PARTICLE=PHOTON.");
158 "\"PC\" is not allowed for PARTICLE=PHOTON. Use \"ENERGY\".");
163 "\"GAMMA\" is not allowed for PARTICLE=PHOTON. Use \"ENERGY\".");
167 "Beam::execute()",
"\"SOURCES\" is not allowed for PARTICLE=PHOTON.");
174 "\"BCURRENT\" and \"BFREQ\" are no longer used in OPALX. "
175 "Use \"BCHARGE\" [C] to specify the bunch charge directly.");
183 "The beam particle hasn't been set. "
184 "Set either \"PARTICLE\" or \"MASS\" and \"CHARGE\".");
188 throw OpalException(
"Beam::execute()",
"\"NALLOC\" must be set.");
195 "Beam::execute()",
"\"ENERGY\" should be greater than 0 for PARTICLE=PHOTON.");
205 if (name !=
"DECAY") {
207 "Beam::execute()",
"Unsupported entry in \"GLOBALPROCESSES\": \"" + name
208 +
"\". Supported values: DECAY.");
225 if (pol.size() != 3) {
227 "Beam::execute()",
"\"POLARIZATION\" must be a length-3 vector {Px, Py, Pz}.");
235 "\"POLARIZATION\" can only be set when \"PARTICLE\" is also set.");
241 "\"POLARIZATION\" is only supported for PARTICLE=MUON; got \""
243 +
"\". For muons produced by PionDecay, leave POLARIZATION unset — "
244 "the daughter polarization is determined by the pion decay.");
246 const double pMag2 = pol[0] * pol[0] + pol[1] * pol[1] + pol[2] * pol[2];
247 if (pMag2 > 1.0 + 1.0e-12) {
249 "Beam::execute()",
"\"POLARIZATION\" magnitude must be in [0, 1]; got |P| = "
250 + std::to_string(std::sqrt(pMag2)) +
".");
257 "Beam::getEmissionSourceListName()",
258 "\"SOURCES\" must be set for a beam (name of EMISSIONSOURCELIST).");
264 "Beam::getEmissionSourceListName()",
265 "\"SOURCES\" must not be empty for a beam (name of EMISSIONSOURCELIST).");
281 return {0.0, 0.0, 0.0};
294 throw OpalException(
"Beam::find()",
"Beam \"" + name +
"\" not found.");
305 "Beam::getNumAlloc()",
306 "Wrong allocation size for beam! \"NALLOC\" must be positive");
378 throw OpalException(
"Beam::update()",
"\"GAMMA\" should be greater than 1.");
385 throw OpalException(
"Beam::update()",
"\"ENERGY\" should be greater than \"MASS\".");
392 throw OpalException(
"Beam::update()",
"\"PC\" should be greater than 0.");
402 os <<
"* ************* B E A M ************************************************************ "
407 <<
"* CHARGE " << (charge > 0 ?
'+' :
'-') <<
"e * " << std::abs(charge) <<
" \n"
412 os <<
"* ********************************************************************************** "
std::string getParticleName() const
Return Particle's name.
std::string getEmissionSourceListName() const
double getCurrent() const
Return the beam current in A (legacy; no longer used in OPALX)
void validatePolarization() const
double getChargePerParticle() const
Charge per macro particle in C.
bool hasPolarization() const
virtual void execute()
Check the BEAM data.
double getBunchCharge() const
Return the bunch charge in C.
double getMomentum() const
static Beam * find(const std::string &name)
Find named BEAM.
double getCharge() const
Return the charge number in elementary charge.
virtual Beam * clone(const std::string &name)
Make clone.
bool isPhoton() const
True if this beam is configured as a photon beam.
size_t getNumAlloc() const
Return the allocation size (macroparticles) for this beam.
double getFrequency() const
Return the beam frequency in MHz.
double getMassPerParticle() const
Mass per macro particle in GeV/c^2.
double getMass() const
Return Particle's rest mass in GeV.
virtual void update()
Update the BEAM data.
void print(std::ostream &os) const
Print the object.
Beam()
Exemplar constructor.
bool hasExplicitEnergy() const
True if PC, ENERGY, or GAMMA was explicitly provided by the user.
const PartData & getReference() const
Return the embedded OPALX PartData.
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
std::string getDaughterBeamName() const
Return the name of the daughter beam (for decay products), or empty if not set.
std::vector< double > getPolarization() const
std::vector< std::string > getGlobalProcessNames() const
Return the configured global process names for this beam.
The base class for all OPAL definitions.
The base class for all OPAL objects.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
const std::string & getOpalName() const
Return object name.
void setOpalName(const std::string &name)
Set object name.
std::vector< Attribute > itsAttr
The object attributes.
bool builtin
Built-in flag.
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
void define(Object *newObject)
Define a new object.
void setM(double m)
Set reference mass expressed in eV/c^2.
void setGamma(double gamma)
Set gamma.
double getP() const
The constant reference momentum per particle.
KOKKOS_INLINE_FUNCTION double getM() const
The constant mass per particle.
void setP(double p)
Set reference momentum.
void setE(double E)
Set reference energy.
void setAnomaly(double a)
void setQ(double q)
Set reference charge expressed in proton charges,.
static double getParticleMass(const ParticleType &type)
static double getParticleCharge(const ParticleType &type)
static double getParticleAnomaly(const ParticleType &type)
static ParticleType getParticleType(const std::string &str)
double getReal(const Attribute &attr)
Return real value.
Attribute makeUpperCaseStringArray(const std::string &name, const std::string &help)
Make uppercase string array attribute.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
void setReal(Attribute &attr, double val)
Set real value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Representation objects and parsers for attribute expressions.
constexpr double m_p
The proton rest mass in GeV.
constexpr double q_e
The elementary charge in As.