Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4INCLParticleSpecies.cc
이 파일의 문서화 페이지로 가기
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 
45 #include "G4INCLParticleSpecies.hh"
46 #include "G4INCLParticleTable.hh"
47 #include <algorithm>
48 #include <cctype>
49 #include <sstream>
50 #include <algorithm>
51 
52 namespace 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 = -99;
146  } else if(pS=="k0l" || pS=="klong" || pS=="kl" || pS=="kaonlong") {
147  theA = 0;
148  theZ = 0;
149  theS = 99;
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) {
212  theType = Composite;
213 
214  // Allowed characters
215  const std::string separators("-_");
216  std::string allowed("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
217  allowed += separators;
218 
219  // There must be at least one character
220  if(pS.find_first_not_of(allowed)!=std::string::npos) {
221  // Malformed input string
222  // Setting unknown particle species
223  (*this) = ParticleSpecies(UnknownParticle);
224  return;
225  }
226  if(pS.size()<1) {
227  // Malformed input string
228  // Setting unknown particle species
229  (*this) = ParticleSpecies(UnknownParticle);
230  return;
231  }
232 
233  std::size_t firstSeparator = pS.find_first_of(separators);
234  std::size_t lastSeparator = pS.find_last_of(separators);
235  if(firstSeparator!=std::string::npos && firstSeparator!=lastSeparator) {
236  // Several separators in malformed input string
237  // Setting unknown particle species
238  (*this) = ParticleSpecies(UnknownParticle);
239  return;
240  }
241 
242  // Identify the type of the first character
243  G4int (*predicate)(G4int);
244  G4bool startsWithAlpha = std::isalpha(pS.at(0));
245  if(startsWithAlpha) {
246  predicate=std::isdigit;
247  } else if(std::isdigit(pS.at(0))) {
248  predicate=std::isalpha;
249  } else {
250  // Non-alphanumeric character in string
251  // Setting unknown particle species
252  (*this) = ParticleSpecies(UnknownParticle);
253  return;
254  }
255 
256  G4bool hasIsotope = true;
257  size_t endFirstSection, beginSecondSection;
258  if(firstSeparator==std::string::npos) {
259  // No separator, Fe56 or 56Fe style
260  // Identify the end of the first section
261 
262  // Find the first character that is not of the same type as the first one
263  beginSecondSection = std::find_if(pS.begin()+1, pS.end(), predicate) - pS.begin();
264 
265  if(beginSecondSection>=pS.size()) {
266  if(startsWithAlpha) {
267  // Only alphabetic characters are present -- must be an element name
268  hasIsotope = false;
269  } else {
270  // Only numeric characters in the string
271  // Setting unknown particle species
272  (*this) = ParticleSpecies(UnknownParticle);
273  return;
274  }
275  }
276 
277  endFirstSection = beginSecondSection;
278 
279  } else {
280  // One separator, Fe-56 or 56-Fe style
281  endFirstSection = firstSeparator;
282  beginSecondSection = firstSeparator+1;
283  }
284 
285  std::string firstSection(pS.substr(0,endFirstSection));
286  std::string secondSection(pS.substr(beginSecondSection,std::string::npos));
287  std::stringstream parsingStream;
288 
289  // Parse the sections
290  G4bool success;
291  if(startsWithAlpha) {
292  parsingStream.str(secondSection);
293  success = parseElement(firstSection);
294  } else {
295  parsingStream.str(firstSection);
296  success = parseElement(secondSection);
297  }
298  if(!success) {
299  // Couldn't parse the element section
300  // Setting unknown particle species
301  (*this) = ParticleSpecies(UnknownParticle);
302  return;
303  }
304 
305  if(hasIsotope) {
306  parsingStream >> theA;
307  if(parsingStream.fail()) {
308  // Couldn't parse the mass section
309  // Setting unknown particle species
310  (*this) = ParticleSpecies(UnknownParticle);
311  return;
312  }
313  } else
314  theA = 0;
315 
316  // Check that Z<=A
317  if(theZ>theA && hasIsotope) {
318  // Setting unknown particle species
319  (*this) = ParticleSpecies(UnknownParticle);
320  return;
321  }
322 
323  // Special particle type for protons
324  if(theZ==1 && theA==1)
325  theType = Proton;
326  }
327 
328  G4bool ParticleSpecies::parseElement(std::string const &s) {
330 
331  if(theZ<0)
333 
334  if(theZ<0)
335  return false;
336  else
337  return true;
338  }
339 
342  if(theZ==0)
343  return false;
344  else
345  return true;
346  }
347 
349  switch (theType) {
350  case Proton:
351  return 2212;
352  break;
353  case Neutron:
354  return 2112;
355  break;
356  case DeltaPlusPlus:
357  return 2224;
358  break;
359  case DeltaPlus:
360  return 2214;
361  break;
362  case DeltaZero:
363  return 2114;
364  break;
365  case DeltaMinus:
366  return 1114;
367  break;
368  case PiPlus:
369  return 211;
370  break;
371  case PiZero:
372  return 111;
373  break;
374  case PiMinus:
375  return -211;
376  break;
377  case Eta:
378  return 221;
379  break;
380  case Omega:
381  return 223;
382  break;
383  case EtaPrime:
384  return 331;
385  break;
386  case Photon:
387  return 22;
388  break;
389  case Lambda:
390  return 3122;
391  break;
392  case SigmaPlus:
393  return 3222;
394  break;
395  case SigmaZero:
396  return 3212;
397  break;
398  case SigmaMinus:
399  return 3112;
400  break;
401  case KPlus:
402  return 321;
403  break;
404  case KZero:
405  return 311;
406  break;
407  case KZeroBar:
408  return -311;
409  break;
410  case KShort:
411  return 310;
412  break;
413  case KLong:
414  return 130;
415  break;
416  case KMinus:
417  return -321;
418  break;
419  case Composite:
420  if(theA == 1 && theZ == 1 && theS == 0) return 2212;
421  else if(theA == 1 && theZ == 0 && theS == 0) return 2112;
422  else if(theA == 1 && theZ == 0 && theS == -1) return 3122;
423  else return theA+theZ*1000-theS*1e6; // Here -theS because hyper-nucleus -> theS < 0
424  break;
425  default:
426  INCL_ERROR("ParticleSpecies::getPDGCode: Unknown particle type." << '\n');
427  return 0;
428  break;
429  }
430  }
431 }
432 
G4int parseIUPACElement(std::string const &pS)
Parse a IUPAC element name.
G4int getChargeNumber(const ParticleType t)
Get charge number from particle type.
G4int getPDGCode() const
Set a PDG Code (MONTE CARLO PARTICLE NUMBERING)
void parseNuclide(std::string const &pS)
Parse a nuclide name.
G4int getStrangenessNumber(const ParticleType t)
Get strangeness number from particle type.
double S(double temp)
Float_t Z
G4int getMassNumber(const ParticleType t)
Get mass number from particle type.
const XML_Char * s
Definition: expat.h:262
bool G4bool
Definition: G4Types.hh:79
#define INCL_ERROR(x)
double A(double temperature)
int G4int
Definition: G4Types.hh:78
G4bool parseElement(std::string const &pS)
Parse an element name.
G4bool parseIUPACElement(std::string const &s)
Parse a IUPAC element name.
G4int parseElement(std::string pS)
Get the name of the element from the atomic number.
ParticleSpecies()
Convert a string to a particle species.