Geant4-11
Public Member Functions | Data Fields | Private Member Functions
G4INCL::ParticleSpecies Class Reference

#include <G4INCLParticleSpecies.hh>

Public Member Functions

G4int getPDGCode () const
 Set a PDG Code (MONTE CARLO PARTICLE NUMBERING) More...
 
 ParticleSpecies ()
 Convert a string to a particle species. More...
 
 ParticleSpecies (const G4int A, const G4int Z)
 
 ParticleSpecies (const G4int A, const G4int Z, const G4int S)
 
 ParticleSpecies (ParticleType const t)
 
 ParticleSpecies (std::string const &pS)
 

Data Fields

G4int theA
 
G4int theS
 
ParticleType theType
 
G4int theZ
 

Private Member Functions

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

Detailed Description

Definition at line 53 of file G4INCLParticleSpecies.hh.

Constructor & Destructor Documentation

◆ ParticleSpecies() [1/5]

G4INCL::ParticleSpecies::ParticleSpecies ( )
inline

Convert a string to a particle species.

Definition at line 56 of file G4INCLParticleSpecies.hh.

Referenced by parseNuclide().

◆ ParticleSpecies() [2/5]

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;
59 theS = 0;
61 } else if(pS=="n" || pS=="neutron") {
62 theA = 1;
63 theZ = 0;
64 theS = 0;
66 } else if(pS=="delta++" || pS=="deltaplusplus") {
67 theA = 1;
68 theZ = 2;
69 theS = 0;
71 } else if(pS=="delta+" || pS=="deltaplus") {
72 theA = 1;
73 theZ = 1;
74 theS = 0;
76 } else if(pS=="delta0" || pS=="deltazero") {
77 theA = 1;
78 theZ = 0;
79 theS = 0;
81 } else if(pS=="delta-" || pS=="deltaminus") {
82 theA = 1;
83 theZ = -1;
84 theS = 0;
86 } else if(pS=="pi+" || pS=="pion+" || pS=="piplus" || pS=="pionplus") {
87 theA = 0;
88 theZ = 1;
89 theS = 0;
91 } else if(pS=="pi0" || pS=="pion0" || pS=="pizero" || pS=="pionzero") {
92 theA = 0;
93 theZ = 0;
94 theS = 0;
96 } else if(pS=="pi-" || pS=="pion-" || pS=="piminus" || pS=="pionminus") {
97 theA = 0;
98 theZ = -1;
99 theS = 0;
101 } else if(pS=="lambda" || pS=="l" || pS=="l0") {
102 theA = 1;
103 theZ = 0;
104 theS = -1;
106 } else if(pS=="s+" || pS=="sigma+" || pS=="sigmaplus") {
107 theA = 1;
108 theZ = 1;
109 theS = -1;
111 } else if(pS=="s0" || pS=="sigma0" || pS=="sigmazero") {
112 theA = 1;
113 theZ = 0;
114 theS = -1;
116 } else if(pS=="s-" || pS=="sigma-" || pS=="sigmaminus") { //Sm = Samarium
117 theA = 1;
118 theZ = -1;
119 theS = -1;
121 } else if(pS=="k+" || pS=="kaon+" || pS=="kplus" || pS=="kaonplus") {
122 theA = 0;
123 theZ = 1;
124 theS = 1;
126 } else if(pS=="k0" || pS=="kaon0" || pS=="kzero" || pS=="kaonzero") {
127 theA = 0;
128 theZ = 0;
129 theS = 1;
131 } else if(pS=="k0b" || pS=="kzb" || pS=="kaon0bar" || pS=="kzerobar" || pS=="kaonzerobar") {
132 theA = 0;
133 theZ = 0;
134 theS = -1;
136 } else if(pS=="k-" || pS=="kaon-" || pS=="kminus" || pS=="kaonminus") {
137 theA = 0;
138 theZ = -1;
139 theS = -1;
141 } else if(pS=="k0s" || pS=="kshort" || pS=="ks" || pS=="kaonshort") {
142 theA = 0;
143 theZ = 0;
144// theS not defined
146 } else if(pS=="k0l" || pS=="klong" || pS=="kl" || pS=="kaonlong") {
147 theA = 0;
148 theZ = 0;
149// theS not defined
151 } else if(pS=="d" || pS=="deuteron") {
152 theA = 2;
153 theZ = 1;
154 theS = 0;
156 } else if(pS=="t" || pS=="triton") {
157 theA = 3;
158 theZ = 1;
159 theS = 0;
161 } else if(pS=="a" || pS=="alpha") {
162 theA = 4;
163 theZ = 2;
164 theS = 0;
166 } else if(pS=="eta") {
167 theA = 0;
168 theZ = 0;
169 theS = 0;
171 } else if(pS=="omega") {
172 theA = 0;
173 theZ = 0;
174 theS = 0;
176 } else if(pS=="etaprime" || pS=="etap") {
177 theA = 0;
178 theZ = 0;
179 theS = 0;
181 } else if(pS=="photon") {
182 theA = 0;
183 theZ = 0;
184 theS = 0;
186 } else
187 parseNuclide(pS);
188 }
void parseNuclide(std::string const &pS)
Parse a nuclide name.

References G4INCL::Composite, G4INCL::DeltaMinus, G4INCL::DeltaPlus, G4INCL::DeltaPlusPlus, G4INCL::DeltaZero, G4INCL::Eta, G4INCL::EtaPrime, G4INCL::KLong, G4INCL::KMinus, G4INCL::KPlus, G4INCL::KShort, G4INCL::KZero, G4INCL::KZeroBar, G4INCL::Lambda, G4INCL::Neutron, G4INCL::Omega, parseNuclide(), G4INCL::Photon, G4INCL::PiMinus, G4INCL::PiPlus, G4INCL::PiZero, G4INCL::Proton, G4INCL::SigmaMinus, G4INCL::SigmaPlus, G4INCL::SigmaZero, theA, theS, theType, and theZ.

◆ ParticleSpecies() [3/5]

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

Definition at line 190 of file G4INCLParticleSpecies.cc.

190 :
191 theType(t),
195 {}
G4int getMassNumber(const ParticleType t)
Get mass number from particle type.
G4int getStrangenessNumber(const ParticleType t)
Get strangeness number from particle type.
G4int getChargeNumber(const ParticleType t)
Get charge number from particle type.

◆ ParticleSpecies() [4/5]

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

Definition at line 197 of file G4INCLParticleSpecies.cc.

197 :
199 theA(A),
200 theZ(Z),
201 theS(0)
202 {}
const G4int Z[17]
const G4double A[17]

◆ ParticleSpecies() [5/5]

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

Definition at line 204 of file G4INCLParticleSpecies.cc.

204 :
206 theA(A),
207 theZ(Z),
208 theS(S)
209 {}
G4double S(G4double temp)

Member Function Documentation

◆ getPDGCode()

G4int G4INCL::ParticleSpecies::getPDGCode ( ) const

Set a PDG Code (MONTE CARLO PARTICLE NUMBERING)

Parameters

return integer (identifying number for each particle)

Definition at line 365 of file G4INCLParticleSpecies.cc.

365 {
366 switch (theType) {
367 case Proton:
368 return 2212;
369 break;
370 case Neutron:
371 return 2112;
372 break;
373 case DeltaPlusPlus:
374 return 2224;
375 break;
376 case DeltaPlus:
377 return 2214;
378 break;
379 case DeltaZero:
380 return 2114;
381 break;
382 case DeltaMinus:
383 return 1114;
384 break;
385 case PiPlus:
386 return 211;
387 break;
388 case PiZero:
389 return 111;
390 break;
391 case PiMinus:
392 return -211;
393 break;
394 case Eta:
395 return 221;
396 break;
397 case Omega:
398 return 223;
399 break;
400 case EtaPrime:
401 return 331;
402 break;
403 case Photon:
404 return 22;
405 break;
406 case Lambda:
407 return 3122;
408 break;
409 case SigmaPlus:
410 return 3222;
411 break;
412 case SigmaZero:
413 return 3212;
414 break;
415 case SigmaMinus:
416 return 3112;
417 break;
418 case KPlus:
419 return 321;
420 break;
421 case KZero:
422 return 311;
423 break;
424 case KZeroBar:
425 return -311;
426 break;
427 case KShort:
428 return 310;
429 break;
430 case KLong:
431 return 130;
432 break;
433 case KMinus:
434 return -321;
435 break;
436 case Composite:
437 if(theA == 1 && theZ == 1 && theS == 0) return 2212;
438 else if(theA == 1 && theZ == 0 && theS == 0) return 2112;
439 else if(theA == 1 && theZ == 0 && theS == -1) return 3122;
440 else return theA+theZ*1000-theS*1e6; // Here -theS because hyper-nucleus -> theS < 0
441 break;
442 default:
443 INCL_ERROR("ParticleSpecies::getPDGCode: Unknown particle type." << '\n');
444 return 0;
445 break;
446 }
447 }
static const G4double e6[46]
#define INCL_ERROR(x)

References G4INCL::Composite, G4INCL::DeltaMinus, G4INCL::DeltaPlus, G4INCL::DeltaPlusPlus, G4INCL::DeltaZero, e6, G4INCL::Eta, G4INCL::EtaPrime, INCL_ERROR, G4INCL::KLong, G4INCL::KMinus, G4INCL::KPlus, G4INCL::KShort, G4INCL::KZero, G4INCL::KZeroBar, G4INCL::Lambda, G4INCL::Neutron, G4INCL::Omega, G4INCL::Photon, G4INCL::PiMinus, G4INCL::PiPlus, G4INCL::PiZero, G4INCL::Proton, G4INCL::SigmaMinus, G4INCL::SigmaPlus, G4INCL::SigmaZero, theA, theS, theType, and theZ.

Referenced by G4INCL::Nucleus::fillEventInfo(), and G4INCL::EventInfo::remnantToParticle().

◆ 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 345 of file G4INCLParticleSpecies.cc.

345 {
347
348 if(theZ<0)
350
351 if(theZ<0)
352 return false;
353 else
354 return true;
355 }
static constexpr double s
Definition: G4SIunits.hh:154
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.

References G4INCL::ParticleTable::parseElement(), G4INCL::ParticleTable::parseIUPACElement(), s, and theZ.

Referenced by parseNuclide().

◆ 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 357 of file G4INCLParticleSpecies.cc.

357 {
359 if(theZ==0)
360 return false;
361 else
362 return true;
363 }

References G4INCL::ParticleTable::parseIUPACElement(), s, and theZ.

◆ 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 211 of file G4INCLParticleSpecies.cc.

211 {
213 theS = 0; // no hypernuclei projectile or target for now
214
215 // Allowed characters
216 const std::string separators("-_");
217 std::string allowed("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
218 allowed += separators;
219
220 // There must be at least one character
221 if(pS.find_first_not_of(allowed)!=std::string::npos) {
222 // Malformed input string
223 // Setting unknown particle species
225 return;
226 }
227 if(pS.size()<1) {
228 // Malformed input string
229 // Setting unknown particle species
231 return;
232 }
233
234 std::size_t firstSeparator = pS.find_first_of(separators);
235 std::size_t lastSeparator = pS.find_last_of(separators);
236 if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
237 // Several separators in malformed input string
238 // Setting unknown particle species
240 return;
241 }
242
243 // Identify the type of the first character
244 G4int (*predicate)(G4int);
245 G4bool startsWithAlpha = std::isalpha(pS.at(0));
246 if(startsWithAlpha) {
247 predicate=std::isdigit;
248 } else if(std::isdigit(pS.at(0))) {
249 predicate=std::isalpha;
250 } else {
251 // Non-alphanumeric character in string
252 // Setting unknown particle species
254 return;
255 }
256
257 G4bool hasIsotope = true;
258 size_t endFirstSection, beginSecondSection;
259 if(firstSeparator==std::string::npos) {
260 // No separator, Fe56 or 56Fe style
261 // Identify the end of the first section
262
263 // Find the first character that is not of the same type as the first one
264 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
265
266 if(beginSecondSection>=pS.size()) {
267 if(startsWithAlpha) {
268 // Only alphabetic characters are present -- must be an element name
269 hasIsotope = false;
270 } else {
271 // Only numeric characters in the string
272 // Setting unknown particle species
274 return;
275 }
276 }
277
278 endFirstSection = beginSecondSection;
279
280 } else {
281 // One separator, Fe-56 or 56-Fe style or hypercluster style: Fe56-1 (iron 56 including 1 lambda)
282 endFirstSection = firstSeparator;
283 beginSecondSection = firstSeparator+1;
284 }
285
286 std::string firstSection(pS.substr(0,endFirstSection));
287 std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
288 std::stringstream parsingStream;
289
290 if(std::isalpha(firstSection.at(0)) && std::isdigit(firstSection.at(endFirstSection-1))) { // Hypernucleus, must be Fe56-1 style
291 std::stringstream parseStrangeness;
292 parseStrangeness.str(secondSection);
293 parseStrangeness >> theS;
294 if(parsingStream.fail()) {
295 // Couldn't parse the strange charge section
296 // Setting unknown particle species
298 return;
299 }
300 theS *= (-1);
301 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin(); // predicate == std::isdigit(G4int) in this case
302 firstSection = pS.substr(0, beginSecondSection);
303 secondSection = pS.substr(beginSecondSection, endFirstSection);
304 }
305
306 // Parse the sections
307 G4bool success;
308 if(startsWithAlpha) {
309 parsingStream.str(secondSection);
310 success = parseElement(firstSection);
311 } else {
312 parsingStream.str(firstSection);
313 success = parseElement(secondSection);
314 }
315 if(!success) {
316 // Couldn't parse the element section
317 // Setting unknown particle species
319 return;
320 }
321
322 if(hasIsotope) {
323 parsingStream >> theA;
324 if(parsingStream.fail()) {
325 // Couldn't parse the mass section
326 // Setting unknown particle species
328 return;
329 }
330 } else
331 theA = 0;
332
333 // Check that Z<=A
334 if(theZ>theA && hasIsotope) {
335 // Setting unknown particle species
337 return;
338 }
339
340 // Special particle type for protons
341 if(theZ==1 && theA==1)
342 theType = Proton;
343 }
@ allowed
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
ParticleSpecies()
Convert a string to a particle species.
G4bool parseElement(std::string const &pS)
Parse an element name.

References allowed, G4INCL::Composite, parseElement(), ParticleSpecies(), G4INCL::Proton, theA, theS, theType, theZ, and G4INCL::UnknownParticle.

Referenced by ParticleSpecies().

Field Documentation

◆ theA

G4int G4INCL::ParticleSpecies::theA

◆ theS

G4int G4INCL::ParticleSpecies::theS

◆ theType

ParticleType G4INCL::ParticleSpecies::theType

◆ theZ

G4int G4INCL::ParticleSpecies::theZ

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