33 #define INCLXX_IN_GEANT4_MODE 1
55 std::string pSNorm = pS;
56 std::transform(pSNorm.begin(), pSNorm.end(), pSNorm.begin(), ::tolower);
57 if(pSNorm==
"p" || pSNorm==
"proton") {
61 }
else if(pSNorm==
"n" || pSNorm==
"neutron") {
65 }
else if(pSNorm==
"delta++" || pSNorm==
"deltaplusplus") {
69 }
else if(pSNorm==
"delta+" || pSNorm==
"deltaplus") {
73 }
else if(pSNorm==
"delta0" || pSNorm==
"deltazero") {
77 }
else if(pSNorm==
"delta-" || pSNorm==
"deltaminus") {
81 }
else if(pSNorm==
"pi+" || pSNorm==
"pion+" || pSNorm==
"piplus" || pSNorm==
"pionplus") {
85 }
else if(pSNorm==
"pi0" || pSNorm==
"pion0" || pSNorm==
"pizero" || pSNorm==
"pionzero") {
89 }
else if(pSNorm==
"pi-" || pSNorm==
"pion-" || pSNorm==
"piminus" || pSNorm==
"pionminus") {
93 }
else if(pSNorm==
"d" || pSNorm==
"deuteron") {
97 }
else if(pSNorm==
"t" || pSNorm==
"triton") {
101 }
else if(pSNorm==
"a" || pSNorm==
"alpha") {
106 parseNuclide(pSNorm);
121 void ParticleSpecies::parseNuclide(std::string
const &pS) {
125 const std::string separators(
"-_");
126 std::string
allowed(
"0123456789abcdefghijklmnopqrstuvwxyz");
130 if(pS.find_first_not_of(
allowed)!=std::string::npos) {
143 std::size_t firstSeparator = pS.find_first_of(separators);
144 std::size_t lastSeparator = pS.find_last_of(separators);
145 if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
154 G4bool startsWithAlpha = std::isalpha(pS.at(0));
155 if(startsWithAlpha) {
156 predicate=std::isdigit;
157 }
else if(std::isdigit(pS.at(0))) {
158 predicate=std::isalpha;
167 size_t endFirstSection, beginSecondSection;
168 if(firstSeparator==std::string::npos) {
173 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
175 if(beginSecondSection>=pS.size()) {
176 if(startsWithAlpha) {
187 endFirstSection = beginSecondSection;
191 endFirstSection = firstSeparator;
192 beginSecondSection = firstSeparator+1;
195 std::string firstSection(pS.substr(0,endFirstSection));
196 std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
197 std::stringstream parsingStream;
201 if(startsWithAlpha) {
202 parsingStream.str(secondSection);
203 success = parseElement(firstSection);
205 parsingStream.str(firstSection);
206 success = parseElement(secondSection);
216 parsingStream >>
theA;
217 if(parsingStream.fail()) {
227 if(
theZ>theA && hasIsotope) {
234 if(
theZ==1 && theA==1)
238 G4bool ParticleSpecies::parseElement(std::string
const &
s) {
250 G4bool ParticleSpecies::parseIUPACElement(std::string
const &s) {
G4int getChargeNumber(const ParticleType t)
Get charge number from particle type.
G4int getMassNumber(const ParticleType t)
Get mass number from particle type.
G4int parseElement(std::string pS)
Get the name of the element from the atomic number.
ParticleSpecies()
Convert a string to a particle species.
G4int parseIUPACElement(std::string const &pS)
Parse a IUPAC element name.