35#define INCLXX_IN_GEANT4_MODE 1
57 std::string pSNorm = pS;
58 std::transform(pSNorm.begin(), pSNorm.end(), pSNorm.begin(), ::tolower);
59 if(pSNorm==
"p" || pSNorm==
"proton") {
63 }
else if(pSNorm==
"n" || pSNorm==
"neutron") {
67 }
else if(pSNorm==
"delta++" || pSNorm==
"deltaplusplus") {
71 }
else if(pSNorm==
"delta+" || pSNorm==
"deltaplus") {
75 }
else if(pSNorm==
"delta0" || pSNorm==
"deltazero") {
79 }
else if(pSNorm==
"delta-" || pSNorm==
"deltaminus") {
83 }
else if(pSNorm==
"pi+" || pSNorm==
"pion+" || pSNorm==
"piplus" || pSNorm==
"pionplus") {
87 }
else if(pSNorm==
"pi0" || pSNorm==
"pion0" || pSNorm==
"pizero" || pSNorm==
"pionzero") {
91 }
else if(pSNorm==
"pi-" || pSNorm==
"pion-" || pSNorm==
"piminus" || pSNorm==
"pionminus") {
95 }
else if(pSNorm==
"d" || pSNorm==
"deuteron") {
99 }
else if(pSNorm==
"t" || pSNorm==
"triton") {
103 }
else if(pSNorm==
"a" || pSNorm==
"alpha") {
108 parseNuclide(pSNorm);
123 void ParticleSpecies::parseNuclide(std::string
const &pS) {
127 const std::string separators(
"-_");
128 std::string
allowed(
"0123456789abcdefghijklmnopqrstuvwxyz");
132 if(pS.find_first_not_of(
allowed)!=std::string::npos) {
145 std::size_t firstSeparator = pS.find_first_of(separators);
146 std::size_t lastSeparator = pS.find_last_of(separators);
147 if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
156 G4bool startsWithAlpha = std::isalpha(pS.at(0));
157 if(startsWithAlpha) {
158 predicate=std::isdigit;
159 }
else if(std::isdigit(pS.at(0))) {
160 predicate=std::isalpha;
169 size_t endFirstSection, beginSecondSection;
170 if(firstSeparator==std::string::npos) {
175 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
177 if(beginSecondSection>=pS.size()) {
178 if(startsWithAlpha) {
189 endFirstSection = beginSecondSection;
193 endFirstSection = firstSeparator;
194 beginSecondSection = firstSeparator+1;
197 std::string firstSection(pS.substr(0,endFirstSection));
198 std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
199 std::stringstream parsingStream;
203 if(startsWithAlpha) {
204 parsingStream.str(secondSection);
205 success = parseElement(firstSection);
207 parsingStream.str(firstSection);
208 success = parseElement(secondSection);
218 parsingStream >>
theA;
219 if(parsingStream.fail()) {
240 G4bool ParticleSpecies::parseElement(std::string
const &s) {
244 std::transform(elementName.begin(), elementName.end(), elementName.begin(), ::tolower);
245 if(s.compare(elementName)==0)
248 return parseIUPACElement(s);
251 G4bool ParticleSpecies::parseIUPACElement(std::string
const &s) {
ParticleSpecies()
Convert a string to a particle species.
static G4int parseIUPACElement(std::string const &pS)
Parse a IUPAC element name.
static const G4int elementTableSize
static std::string getElementName(const G4int Z)
Get the name of the element from the atomic number.