Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4INCLParticleSpecies.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// INCL++ intra-nuclear cascade model
27// Alain Boudard, CEA-Saclay, France
28// Joseph Cugnon, University of Liege, Belgium
29// Jean-Christophe David, CEA-Saclay, France
30// Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
31// Sylvie Leray, CEA-Saclay, France
32// Davide Mancusi, CEA-Saclay, France
33//
34#define INCLXX_IN_GEANT4_MODE 1
35
36#include "globals.hh"
37
38/*
39 * G4INCLParticleSpecies.cc
40 *
41 * \date Nov 25, 2011
42 * \author Davide Mancusi
43 */
44
47#include <algorithm>
48#include <cctype>
49#include <sstream>
50#include <algorithm>
51
52namespace G4INCL {
53
54 ParticleSpecies::ParticleSpecies(std::string const &pS) {
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=="xi-" || pS=="x-") {
122 theA = 1;
123 theZ = -1;
124 theS = -2;
126 } else if(pS=="xi0" || pS=="x0") {
127 theA = 1;
128 theZ = 0;
129 theS = -2;
131 } else if(pS=="pb" || pS=="pbar" || pS=="antiproton") {
132 theA = -1;
133 theZ = -1;
134 theS = 0;
136 } else if(pS=="nb" || pS=="nbar" || pS=="antineutron") {
137 theA = -1;
138 theZ = 0;
139 theS = 0;
141 } else if(pS=="s+b" || pS=="antisigma+" || pS=="antisigmaplus") {
142 theA = -1;
143 theZ = -1;
144 theS = 1;
146 } else if(pS=="s0b" || pS=="antisigma0" || pS=="antisigmazero") {
147 theA = -1;
148 theZ = 0;
149 theS = 1;
151 } else if(pS=="s-b" || pS=="antisigma-" || pS=="antisigmaminus") { //Sm = Samarium; Whats wrong with the sign?
152 theA = -1;
153 theZ = 1;
154 theS = 1;
156 } else if(pS=="antilambda" || pS=="lb" || pS=="l0b") {
157 theA = -1;
158 theZ = 0;
159 theS = 1;
161 } else if(pS=="antixi-" || pS=="x-b") {
162 theA = -1;
163 theZ = 1;
164 theS = 2;
166 } else if(pS=="antixi0" || pS=="x0b") {
167 theA = -1;
168 theZ = 0;
169 theS = 2;
171 } else if(pS=="k+" || pS=="kaon+" || pS=="kplus" || pS=="kaonplus") {
172 theA = 0;
173 theZ = 1;
174 theS = 1;
176 } else if(pS=="k0" || pS=="kaon0" || pS=="kzero" || pS=="kaonzero") {
177 theA = 0;
178 theZ = 0;
179 theS = 1;
181 } else if(pS=="k0b" || pS=="kzb" || pS=="kaon0bar" || pS=="kzerobar" || pS=="kaonzerobar") {
182 theA = 0;
183 theZ = 0;
184 theS = -1;
186 } else if(pS=="k-" || pS=="kaon-" || pS=="kminus" || pS=="kaonminus") {
187 theA = 0;
188 theZ = -1;
189 theS = -1;
191 } else if(pS=="k0s" || pS=="kshort" || pS=="ks" || pS=="kaonshort") {
192 theA = 0;
193 theZ = 0;
194// theS not defined
196 } else if(pS=="k0l" || pS=="klong" || pS=="kl" || pS=="kaonlong") {
197 theA = 0;
198 theZ = 0;
199// theS not defined
201 } else if(pS=="d" || pS=="deuteron") {
202 theA = 2;
203 theZ = 1;
204 theS = 0;
206 } else if(pS=="t" || pS=="triton") {
207 theA = 3;
208 theZ = 1;
209 theS = 0;
211 } else if(pS=="a" || pS=="alpha") {
212 theA = 4;
213 theZ = 2;
214 theS = 0;
216 } else if(pS=="eta") {
217 theA = 0;
218 theZ = 0;
219 theS = 0;
221 } else if(pS=="omega") {
222 theA = 0;
223 theZ = 0;
224 theS = 0;
226 } else if(pS=="etaprime" || pS=="etap") {
227 theA = 0;
228 theZ = 0;
229 theS = 0;
231 } else if(pS=="photon") {
232 theA = 0;
233 theZ = 0;
234 theS = 0;
236 } else if (pS=="db" || pS=="dbar" || pS=="antideuteron"){
237 theA = -2;
238 theZ = -1;
239 theS = 0;
241 } else
242 parseNuclide(pS);
243 }
244
246 theType(t),
247 theA(ParticleTable::getMassNumber(theType)),
248 theZ(ParticleTable::getChargeNumber(theType)),
249 theS(ParticleTable::getStrangenessNumber(theType))
250 {}
251
252 ParticleSpecies::ParticleSpecies(const int A, const int Z){
253 if (A>=0){
255 theA = A;
256 theZ = Z;
257 theS = 0;
258 } else {
260 theA = A;
261 theZ = Z;
262 theS = 0;
263 }
264 }
265
266 ParticleSpecies::ParticleSpecies(const int A, const int Z, const int S){
267 if (A>=0){
269 theA = A;
270 theZ = Z;
271 theS = S;
272 } else {
274 theA = A;
275 theZ = Z;
276 theS = S;
277 }
278 }
279
280 void ParticleSpecies::parseNuclide(std::string const &pS) {
282 theS = 0; // no hypernuclei projectile or target for now
283
284 // Allowed characters
285 const std::string separators("-_");
286 std::string allowed("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
287 allowed += separators;
288
289 // There must be at least one character
290 if(pS.find_first_not_of(allowed)!=std::string::npos) {
291 // Malformed input string
292 // Setting unknown particle species
294 return;
295 }
296 if(pS.size()<1) {
297 // Malformed input string
298 // Setting unknown particle species
300 return;
301 }
302
303 std::size_t firstSeparator = pS.find_first_of(separators);
304 std::size_t lastSeparator = pS.find_last_of(separators);
305 if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
306 // Several separators in malformed input string
307 // Setting unknown particle species
309 return;
310 }
311
312 // Identify the type of the first character
313 G4int (*predicate)(G4int);
314 G4bool startsWithAlpha = std::isalpha(pS.at(0));
315 if(startsWithAlpha) {
316 predicate=std::isdigit;
317 } else if(std::isdigit(pS.at(0))) {
318 predicate=std::isalpha;
319 } else {
320 // Non-alphanumeric character in string
321 // Setting unknown particle species
323 return;
324 }
325
326 G4bool hasIsotope = true;
327 size_t endFirstSection, beginSecondSection;
328 if(firstSeparator==std::string::npos) {
329 // No separator, Fe56 or 56Fe style
330 // Identify the end of the first section
331
332 // Find the first character that is not of the same type as the first one
333 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
334
335 if(beginSecondSection>=pS.size()) {
336 if(startsWithAlpha) {
337 // Only alphabetic characters are present -- must be an element name
338 hasIsotope = false;
339 } else {
340 // Only numeric characters in the string
341 // Setting unknown particle species
343 return;
344 }
345 }
346
347 endFirstSection = beginSecondSection;
348
349 } else {
350 // One separator, Fe-56 or 56-Fe style or hypercluster style: Fe56-1 (iron 56 including 1 lambda)
351 endFirstSection = firstSeparator;
352 beginSecondSection = firstSeparator+1;
353 }
354
355 std::string firstSection(pS.substr(0,endFirstSection));
356 std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
357 std::stringstream parsingStream;
358
359 if(std::isalpha(firstSection.at(0)) && std::isdigit(firstSection.at(endFirstSection-1))) { // Hypernucleus, must be Fe56-1 style
360 std::stringstream parseStrangeness;
361 parseStrangeness.str(secondSection);
362 parseStrangeness >> theS;
363 if(parsingStream.fail()) {
364 // Couldn't parse the strange charge section
365 // Setting unknown particle species
367 return;
368 }
369 theS *= (-1);
370 beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin(); // predicate == std::isdigit(G4int) in this case
371 firstSection = pS.substr(0, beginSecondSection);
372 secondSection = pS.substr(beginSecondSection, endFirstSection);
373 }
374
375 // Parse the sections
376 G4bool success;
377 if(startsWithAlpha) {
378 parsingStream.str(secondSection);
379 success = parseElement(firstSection);
380 } else {
381 parsingStream.str(firstSection);
382 success = parseElement(secondSection);
383 }
384 if(!success) {
385 // Couldn't parse the element section
386 // Setting unknown particle species
388 return;
389 }
390
391 if(hasIsotope) {
392 parsingStream >> theA;
393 if(parsingStream.fail()) {
394 // Couldn't parse the mass section
395 // Setting unknown particle species
397 return;
398 }
399 } else
400 theA = 0;
401
402 // Check that Z<=A
403 if(theZ>theA && hasIsotope) {
404 // Setting unknown particle species
406 return;
407 }
408
409 // Special particle type for protons
410 if(theZ==1 && theA==1)
411 theType = Proton;
412 }
413
414 G4bool ParticleSpecies::parseElement(std::string const &s) {
416
417 if(theZ<0)
419
420 if(theZ<0)
421 return false;
422 else
423 return true;
424 }
425
426 G4bool ParticleSpecies::parseIUPACElement(std::string const &s) {
428 if(theZ==0)
429 return false;
430 else
431 return true;
432 }
433
435 switch (theType) {
436 case Proton:
437 return 2212;
438 break;
439 case Neutron:
440 return 2112;
441 break;
442 case DeltaPlusPlus:
443 return 2224;
444 break;
445 case DeltaPlus:
446 return 2214;
447 break;
448 case DeltaZero:
449 return 2114;
450 break;
451 case DeltaMinus:
452 return 1114;
453 break;
454 case PiPlus:
455 return 211;
456 break;
457 case PiZero:
458 return 111;
459 break;
460 case PiMinus:
461 return -211;
462 break;
463 case Eta:
464 return 221;
465 break;
466 case Omega:
467 return 223;
468 break;
469 case EtaPrime:
470 return 331;
471 break;
472 case Photon:
473 return 22;
474 break;
475 case Lambda:
476 return 3122;
477 break;
478 case SigmaPlus:
479 return 3222;
480 break;
481 case SigmaZero:
482 return 3212;
483 break;
484 case SigmaMinus:
485 return 3112;
486 break;
487 case antiProton:
488 return -2212;
489 break;
490 case XiMinus:
491 return 3312;
492 break;
493 case XiZero:
494 return 3322;
495 break;
496 case antiNeutron:
497 return -2112;
498 break;
499 case antiLambda:
500 return -3122;
501 break;
502 case antiSigmaPlus:
503 return -3222;
504 break;
505 case antiSigmaZero:
506 return -3212;
507 break;
508 case antiSigmaMinus:
509 return -3112;
510 break;
511 case antiXiMinus:
512 return -3312;
513 break;
514 case antiXiZero:
515 return -3322;
516 break;
517 case KPlus:
518 return 321;
519 break;
520 case KZero:
521 return 311;
522 break;
523 case KZeroBar:
524 return -311;
525 break;
526 case KShort:
527 return 310;
528 break;
529 case KLong:
530 return 130;
531 break;
532 case KMinus:
533 return -321;
534 break;
535 case Composite:
536 if(theA == 1 && theZ == 1 && theS == 0) return 2212;
537 else if(theA == 1 && theZ == 0 && theS == 0) return 2112;
538 else if(theA == 1 && theZ == 0 && theS == -1) return 3122;
539 else return theA+theZ*1000-theS*1e6; // Here -theS because hyper-nucleus -> theS < 0
540 break;
541 case antiComposite:
542 if(theA == 1 && theZ == 1 && theS == 0) return -2212;
543 else if(theA == 1 && theZ == 0 && theS == 0) return -2112;
544 else if(theA == 1 && theZ == 0 && theS == -1) return -3122;
545 else return -(theA + theZ*1000 - theS*1e6);
546 break;
547 default:
548 INCL_ERROR("ParticleSpecies::getPDGCode: Unknown particle type." << '\n');
549 return 0;
550 break;
551 }
552 }
553}
554
@ allowed
G4double S(G4double temp)
#define INCL_ERROR(x)
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4double A[17]
G4int getPDGCode() const
Set a PDG Code (MONTE CARLO PARTICLE NUMBERING).
ParticleSpecies()
Convert a string to a particle species.
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.