ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4INCLParticleSpecies.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 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) {
212  theType = Composite;
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
224  (*this) = ParticleSpecies(UnknownParticle);
225  return;
226  }
227  if(pS.size()<1) {
228  // Malformed input string
229  // Setting unknown particle species
230  (*this) = ParticleSpecies(UnknownParticle);
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
239  (*this) = ParticleSpecies(UnknownParticle);
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
253  (*this) = ParticleSpecies(UnknownParticle);
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
273  (*this) = ParticleSpecies(UnknownParticle);
274  return;
275  }
276  }
277 
278  endFirstSection = beginSecondSection;
279 
280  } else {
281  // One separator, Fe-56 or 56-Fe style
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  // Parse the sections
291  G4bool success;
292  if(startsWithAlpha) {
293  parsingStream.str(secondSection);
294  success = parseElement(firstSection);
295  } else {
296  parsingStream.str(firstSection);
297  success = parseElement(secondSection);
298  }
299  if(!success) {
300  // Couldn't parse the element section
301  // Setting unknown particle species
302  (*this) = ParticleSpecies(UnknownParticle);
303  return;
304  }
305 
306  if(hasIsotope) {
307  parsingStream >> theA;
308  if(parsingStream.fail()) {
309  // Couldn't parse the mass section
310  // Setting unknown particle species
311  (*this) = ParticleSpecies(UnknownParticle);
312  return;
313  }
314  } else
315  theA = 0;
316 
317  // Check that Z<=A
318  if(theZ>theA && hasIsotope) {
319  // Setting unknown particle species
320  (*this) = ParticleSpecies(UnknownParticle);
321  return;
322  }
323 
324  // Special particle type for protons
325  if(theZ==1 && theA==1)
326  theType = Proton;
327  }
328 
329  G4bool ParticleSpecies::parseElement(std::string const &s) {
331 
332  if(theZ<0)
334 
335  if(theZ<0)
336  return false;
337  else
338  return true;
339  }
340 
343  if(theZ==0)
344  return false;
345  else
346  return true;
347  }
348 
350  switch (theType) {
351  case Proton:
352  return 2212;
353  break;
354  case Neutron:
355  return 2112;
356  break;
357  case DeltaPlusPlus:
358  return 2224;
359  break;
360  case DeltaPlus:
361  return 2214;
362  break;
363  case DeltaZero:
364  return 2114;
365  break;
366  case DeltaMinus:
367  return 1114;
368  break;
369  case PiPlus:
370  return 211;
371  break;
372  case PiZero:
373  return 111;
374  break;
375  case PiMinus:
376  return -211;
377  break;
378  case Eta:
379  return 221;
380  break;
381  case Omega:
382  return 223;
383  break;
384  case EtaPrime:
385  return 331;
386  break;
387  case Photon:
388  return 22;
389  break;
390  case Lambda:
391  return 3122;
392  break;
393  case SigmaPlus:
394  return 3222;
395  break;
396  case SigmaZero:
397  return 3212;
398  break;
399  case SigmaMinus:
400  return 3112;
401  break;
402  case KPlus:
403  return 321;
404  break;
405  case KZero:
406  return 311;
407  break;
408  case KZeroBar:
409  return -311;
410  break;
411  case KShort:
412  return 310;
413  break;
414  case KLong:
415  return 130;
416  break;
417  case KMinus:
418  return -321;
419  break;
420  case Composite:
421  if(theA == 1 && theZ == 1 && theS == 0) return 2212;
422  else if(theA == 1 && theZ == 0 && theS == 0) return 2112;
423  else if(theA == 1 && theZ == 0 && theS == -1) return 3122;
424  else return theA+theZ*1000-theS*1e6; // Here -theS because hyper-nucleus -> theS < 0
425  break;
426  default:
427  INCL_ERROR("ParticleSpecies::getPDGCode: Unknown particle type." << '\n');
428  return 0;
429  break;
430  }
431  }
432 }
433