Geant4 11.1.1
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=="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 }
189
191 theType(t),
192 theA(ParticleTable::getMassNumber(theType)),
193 theZ(ParticleTable::getChargeNumber(theType)),
194 theS(ParticleTable::getStrangenessNumber(theType))
195 {}
196
198 theType(Composite),
199 theA(A),
200 theZ(Z),
201 theS(0)
202 {}
203
205 theType(Composite),
206 theA(A),
207 theZ(Z),
208 theS(S)
209 {}
210
211 void ParticleSpecies::parseNuclide(std::string const &pS) {
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 }
344
345 G4bool ParticleSpecies::parseElement(std::string const &s) {
347
348 if(theZ<0)
350
351 if(theZ<0)
352 return false;
353 else
354 return true;
355 }
356
357 G4bool ParticleSpecies::parseIUPACElement(std::string const &s) {
359 if(theZ==0)
360 return false;
361 else
362 return true;
363 }
364
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 }
448}
449
@ allowed
G4double S(G4double temp)
#define INCL_ERROR(x)
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
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.