GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
Misc.cc
Go to the documentation of this file.
1#include <string>
2#include <stdexcept>
3
4#include "Misc.hh"
5
6namespace GamR {
7 namespace TK {
8 // Convert an isotope identifier string, e.g. 3He or Li5 into corresponding Z and A. Returns 0 on success, and 1 on failure setting Z=-1 and A=0.
9 int GetZA(std::string Nuclide, int &Z, double &A)
10 {
11 std::string Elm;
12 std::string mass = "0";
13 for(int i=0;i<Nuclide.size();i++) {
14 if(Nuclide[i]=='-') continue;
15 else if(int(Nuclide[i])<58) mass += Nuclide[i];
16 else Elm += Nuclide[i];
17 }
18 Z=0;
19 // Check for particle IDs before going through the element list
20 if(Elm=="p") {
21 Z = 1;
22 A = 1;
23 return 0;
24 }
25 if(Elm=="d") {
26 Z = 1;
27 A = 2;
28 return 0;
29 }
30 if(Elm=="t") {
31 Z = 1;
32 A = 3;
33 return 0;
34 }
35 if(Elm=="a") {
36 Z = 2;
37 A = 4;
38 return 0;
39 }
40 while(Elements[Z]!=Elm) {
41 Z++;
42 if(Z>92) {
43 Z=-1;
44 A=0;
45 return 1;
46 }
47 }
48 if(Z==0) mass = "1";
49 try { A=stof(mass); }
50 catch (const std::invalid_argument& ia) { A = 0.; }
51 return 0;
52 }
53
54 std::string GetElement(int Z, float A) {
55 if (Z < 93) {
56 return Elements[Z]+std::to_string((int)A);
57 }
58 else {
59 return "Invalid Z";
60 }
61 }
62
63 }
64}
std::string GetElement(int Z, float A)
Definition Misc.cc:54
int GetZA(std::string Nuclide, int &Z, double &A)
Definition Misc.cc:9
const std::string Elements[93]
Definition Misc.hh:6
Definition Gain.cc:19