20#include "BDSException.hh"
21#include "BDSIonDefinition.hh"
25#include "CLHEP/Units/SystemOfUnits.h"
37 overrideCharge(false),
44 G4String message(
"Invalid ion definition: \"" + definition +
"\" -> A is less than Z");
48 {G4cout << __METHOD_NAME__ <<
"Using ion with -ve charge -> implies at least 1 extra electron." << G4endl;}
58 overrideCharge(false),
63 G4String message(
"Invalid ion definition: A is less than Z");
68 G4String message(
"Invalid ion definition: Charge is greater than Z");
73 nElectrons = z - (G4int)charge;
74 G4cout << __METHOD_NAME__ << nElectrons <<
" bound electrons to ion inferred from charge, A and Z." << G4endl;
77 {G4cout << __METHOD_NAME__ <<
"Using ion with -ve charge -> implies at least 1 extra electron." << G4endl;}
82 out <<
"A: " << io.a <<
" Z: " << io.z <<
" Q: " << io.
charge <<
" E: "
89 std::regex wspace(
"\\s+");
93 std::vector<G4int*> vals = {&a, &z};
95 std::sregex_token_iterator wordsBegin(definition.begin(), definition.end(), wspace, -1);
96 std::sregex_token_iterator wordsEnd;
97 for (
auto i = wordsBegin; i != wordsEnd; ++i, ++counter)
101 std::string word = (*i).str();
108 G4double value = std::stod(word);
110 {
energy = value*CLHEP::keV;}
112 {
charge = value*CLHEP::eplus;}
117 if (word.find(
".") != std::string::npos)
118 {
throw BDSException(__METHOD_NAME__,
"value in beam ion definition \"" + word +
"\" must be an integer");}
119 (*vals[counter-1]) = std::stoi(word);
121 {
charge = (G4double)*vals[counter-1] * CLHEP::eplus;}
124 catch (
const std::invalid_argument&)
125 {
throw BDSException(__METHOD_NAME__,
"Invalid ion definition " + definition );}
131 G4cout << __METHOD_NAME__ <<
nElectrons <<
" bound electrons to ion inferred from charge, A and Z." << G4endl;
135 G4String message(
"Invalid ion definition: Charge is greater than Z");
General exception with possible name of object and message.
Class to parse an ion particle definition.
G4int nElectrons
Inferred number of bound electrons if any.
G4bool overrideCharge
Whether to specify the charge.
G4double energy
Excitation energy. G4units.
void Parse(const G4String &definition)
Parse the definition.
BDSIonDefinition()=delete
No default constructor.
G4double charge
In units of eplus.