Geant4  10.02.p03
G4INCL::ParticleSpecies Class Reference

#include <G4INCLParticleSpecies.hh>

Collaboration diagram for G4INCL::ParticleSpecies:

Public Member Functions

 ParticleSpecies ()
 Convert a string to a particle species. More...
 
 ParticleSpecies (std::string const &pS)
 
 ParticleSpecies (ParticleType const t)
 
 ParticleSpecies (const G4int A, const G4int Z)
 

Public Attributes

ParticleType theType
 
G4int theA
 
G4int theZ
 

Private Member Functions

void parseNuclide (std::string const &pS)
 Parse a nuclide name. More...
 
G4bool parseElement (std::string const &pS)
 Parse an element name. More...
 
G4bool parseIUPACElement (std::string const &s)
 Parse a IUPAC element name. More...
 

Detailed Description

Definition at line 53 of file G4INCLParticleSpecies.hh.

Constructor & Destructor Documentation

◆ ParticleSpecies() [1/4]

G4INCL::ParticleSpecies::ParticleSpecies ( )
inline

Convert a string to a particle species.

Definition at line 56 of file G4INCLParticleSpecies.hh.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParticleSpecies() [2/4]

G4INCL::ParticleSpecies::ParticleSpecies ( std::string const &  pS)

Definition at line 54 of file G4INCLParticleSpecies.cc.

54  {
55  // Normalise the string to lower case
56  if(pS=="p" || pS=="proton") {
57  theA = 1;
58  theZ = 1;
60  } else if(pS=="n" || pS=="neutron") {
61  theA = 1;
62  theZ = 0;
64  } else if(pS=="delta++" || pS=="deltaplusplus") {
65  theA = 1;
66  theZ = 2;
68  } else if(pS=="delta+" || pS=="deltaplus") {
69  theA = 1;
70  theZ = 1;
72  } else if(pS=="delta0" || pS=="deltazero") {
73  theA = 1;
74  theZ = 0;
76  } else if(pS=="delta-" || pS=="deltaminus") {
77  theA = 1;
78  theZ = -1;
80  } else if(pS=="pi+" || pS=="pion+" || pS=="piplus" || pS=="pionplus") {
81  theA = 0;
82  theZ = 1;
84  } else if(pS=="pi0" || pS=="pion0" || pS=="pizero" || pS=="pionzero") {
85  theA = 0;
86  theZ = 0;
88  } else if(pS=="pi-" || pS=="pion-" || pS=="piminus" || pS=="pionminus") {
89  theA = 0;
90  theZ = -1;
92  } else if(pS=="d" || pS=="deuteron") {
93  theA = 2;
94  theZ = 1;
96  } else if(pS=="t" || pS=="triton") {
97  theA = 3;
98  theZ = 1;
100  } else if(pS=="a" || pS=="alpha") {
101  theA = 4;
102  theZ = 2;
104  } else
105  parseNuclide(pS);
106  }
void parseNuclide(std::string const &pS)
Parse a nuclide name.
Here is the call graph for this function:

◆ ParticleSpecies() [3/4]

G4INCL::ParticleSpecies::ParticleSpecies ( ParticleType const  t)

Definition at line 108 of file G4INCLParticleSpecies.cc.

108  :
109  theType(t),
112  {}
G4int getChargeNumber(const ParticleType t)
Get charge number from particle type.
G4int getMassNumber(const ParticleType t)
Get mass number from particle type.

◆ ParticleSpecies() [4/4]

G4INCL::ParticleSpecies::ParticleSpecies ( const G4int  A,
const G4int  Z 
)

Definition at line 114 of file G4INCLParticleSpecies.cc.

Member Function Documentation

◆ parseElement()

G4bool G4INCL::ParticleSpecies::parseElement ( std::string const &  pS)
private

Parse an element name.

Note: this function is UGLY. Look at it at your own peril.

Parameters
pSa normalised string (lowercase)
Returns
true if the parsing succeeded

Definition at line 237 of file G4INCLParticleSpecies.cc.

237  {
239 
240  if(theZ<0)
242 
243  if(theZ<0)
244  return false;
245  else
246  return true;
247  }
static const double s
Definition: G4SIunits.hh:168
G4int parseElement(std::string pS)
Get the name of the element from the atomic number.
G4int parseIUPACElement(std::string const &pS)
Parse a IUPAC element name.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseIUPACElement()

G4bool G4INCL::ParticleSpecies::parseIUPACElement ( std::string const &  s)
private

Parse a IUPAC element name.

Note: this function is UGLY. Look at it at your own peril.

Parameters
sa normalised string (lowercase)
Returns
true if the parsing succeeded

Definition at line 249 of file G4INCLParticleSpecies.cc.

249  {
251  if(theZ==0)
252  return false;
253  else
254  return true;
255  }
static const double s
Definition: G4SIunits.hh:168
G4int parseIUPACElement(std::string const &pS)
Parse a IUPAC element name.
Here is the call graph for this function:

◆ parseNuclide()

void G4INCL::ParticleSpecies::parseNuclide ( std::string const &  pS)
private

Parse a nuclide name.

Note: this function is UGLY. Look at it at your own peril.

Parameters
pSa normalised string (lowercase)

Definition at line 120 of file G4INCLParticleSpecies.cc.

120  {
121  theType = Composite;
122 
123  // Allowed characters
124  const std::string separators("-_");
125  std::string allowed("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
126  allowed += separators;
127 
128  // There must be at least one character
129  if(pS.find_first_not_of(allowed)!=std::string::npos) {
130  // Malformed input string
131  // Setting unknown particle species
132  (*this) = ParticleSpecies(UnknownParticle);
133  return;
134  }
135  if(pS.size()<1) {
136  // Malformed input string
137  // Setting unknown particle species
138  (*this) = ParticleSpecies(UnknownParticle);
139  return;
140  }
141 
142  std::size_t firstSeparator = pS.find_first_of(separators);
143  std::size_t lastSeparator = pS.find_last_of(separators);
144  if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
145  // Several separators in malformed input string
146  // Setting unknown particle species
147  (*this) = ParticleSpecies(UnknownParticle);
148  return;
149  }
150 
151  // Identify the type of the first character
152  G4int (*predicate)(G4int);
153  G4bool startsWithAlpha = std::isalpha(pS.at(0));
154  if(startsWithAlpha) {
155  predicate=std::isdigit;
156  } else if(std::isdigit(pS.at(0))) {
157  predicate=std::isalpha;
158  } else {
159  // Non-alphanumeric character in string
160  // Setting unknown particle species
161  (*this) = ParticleSpecies(UnknownParticle);
162  return;
163  }
164 
165  G4bool hasIsotope = true;
166  size_t endFirstSection, beginSecondSection;
167  if(firstSeparator==std::string::npos) {
168  // No separator, Fe56 or 56Fe style
169  // Identify the end of the first section
170 
171  // Find the first character that is not of the same type as the first one
172  beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
173 
174  if(beginSecondSection>=pS.size()) {
175  if(startsWithAlpha) {
176  // Only alphabetic characters are present -- must be an element name
177  hasIsotope = false;
178  } else {
179  // Only numeric characters in the string
180  // Setting unknown particle species
181  (*this) = ParticleSpecies(UnknownParticle);
182  return;
183  }
184  }
185 
186  endFirstSection = beginSecondSection;
187 
188  } else {
189  // One separator, Fe-56 or 56-Fe style
190  endFirstSection = firstSeparator;
191  beginSecondSection = firstSeparator+1;
192  }
193 
194  std::string firstSection(pS.substr(0,endFirstSection));
195  std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
196  std::stringstream parsingStream;
197 
198  // Parse the sections
199  G4bool success;
200  if(startsWithAlpha) {
201  parsingStream.str(secondSection);
202  success = parseElement(firstSection);
203  } else {
204  parsingStream.str(firstSection);
205  success = parseElement(secondSection);
206  }
207  if(!success) {
208  // Couldn't parse the element section
209  // Setting unknown particle species
210  (*this) = ParticleSpecies(UnknownParticle);
211  return;
212  }
213 
214  if(hasIsotope) {
215  parsingStream >> theA;
216  if(parsingStream.fail()) {
217  // Couldn't parse the mass section
218  // Setting unknown particle species
219  (*this) = ParticleSpecies(UnknownParticle);
220  return;
221  }
222  } else
223  theA = 0;
224 
225  // Check that Z<=A
226  if(theZ>theA && hasIsotope) {
227  // Setting unknown particle species
228  (*this) = ParticleSpecies(UnknownParticle);
229  return;
230  }
231 
232  // Special particle type for protons
233  if(theZ==1 && theA==1)
234  theType = Proton;
235  }
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
ParticleSpecies()
Convert a string to a particle species.
G4bool parseElement(std::string const &pS)
Parse an element name.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ theA

G4int G4INCL::ParticleSpecies::theA

Definition at line 66 of file G4INCLParticleSpecies.hh.

◆ theType

ParticleType G4INCL::ParticleSpecies::theType

Definition at line 65 of file G4INCLParticleSpecies.hh.

◆ theZ

G4int G4INCL::ParticleSpecies::theZ

Definition at line 66 of file G4INCLParticleSpecies.hh.


The documentation for this class was generated from the following files: