Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
lPoPs.cc
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5
6#include "PoPs.h"
7#include "PoPs_mass.h"
8
9#if defined __cplusplus
10namespace GIDI {
11using namespace GIDI;
12#endif
13
14static struct ZLabels {
15 int Z;
16 char const *Symbol;
17} Zs[] = { { 0, "n" }, { 1, "H" }, { 2, "He" }, { 3, "Li" }, { 4, "Be" }, { 5, "B" }, { 6, "C" }, { 7, "N" }, { 8, "O" },
18 { 9, "F" }, { 10, "Ne" }, { 11, "Na" }, { 12, "Mg" }, { 13, "Al" }, { 14, "Si" }, { 15, "P" }, { 16, "S" }, { 17, "Cl" },
19 { 18, "Ar" }, { 19, "K" }, { 20, "Ca" }, { 21, "Sc" }, { 22, "Ti" }, { 23, "V" }, { 24, "Cr" }, { 25, "Mn" }, { 26, "Fe" },
20 { 27, "Co" }, { 28, "Ni" }, { 29, "Cu" }, { 30, "Zn" }, { 31, "Ga" }, { 32, "Ge" }, { 33, "As" }, { 34, "Se" }, { 35, "Br" },
21 { 36, "Kr" }, { 37, "Rb" }, { 38, "Sr" }, { 39, "Y" }, { 40, "Zr" }, { 41, "Nb" }, { 42, "Mo" }, { 43, "Tc" }, { 44, "Ru" },
22 { 45, "Rh" }, { 46, "Pd" }, { 47, "Ag" }, { 48, "Cd" }, { 49, "In" }, { 50, "Sn" }, { 51, "Sb" }, { 52, "Te" }, { 53, "I" },
23 { 54, "Xe" }, { 55, "Cs" }, { 56, "Ba" }, { 57, "La" }, { 58, "Ce" }, { 59, "Pr" }, { 60, "Nd" }, { 61, "Pm" }, { 62, "Sm" },
24 { 63, "Eu" }, { 64, "Gd" }, { 65, "Tb" }, { 66, "Dy" }, { 67, "Ho" }, { 68, "Er" }, { 69, "Tm" }, { 70, "Yb" }, { 71, "Lu" },
25 { 72, "Hf" }, { 73, "Ta" }, { 74, "W" }, { 75, "Re" }, { 76, "Os" }, { 77, "Ir" }, { 78, "Pt" }, { 79, "Au" }, { 80, "Hg" },
26 { 81, "Tl" }, { 82, "Pb" }, { 83, "Bi" }, { 84, "Po" }, { 85, "At" }, { 86, "Rn" }, { 87, "Fr" }, { 88, "Ra" }, { 89, "Ac" },
27 { 90, "Th" }, { 91, "Pa" }, { 92, "U" }, { 93, "Np" }, { 94, "Pu" }, { 95, "Am" }, { 96, "Cm" }, { 97, "Bk" }, { 98, "Cf" },
28 { 99, "Es" }, { 100, "Fm" }, { 101, "Md" }, { 102, "No" }, { 103, "Lr" }, { 104, "Rf" }, { 105, "Db" }, { 106, "Sg" }, { 107, "Bh" },
29 { 108, "Hs" }, { 109, "Mt" } };
30static const int nZs = sizeof( Zs ) / sizeof( Zs[0] );
31
32static char const *lPoPs_ZSymbol( int Z );
33/*
34========================================================================
35*/
36int lPoPs_addParticleIfNeeded( statusMessageReporting *smr, char const *name, char const *special ) {
37
38 int index = PoPs_particleIndex( name ), ZA, Z = 0, A = 0,/* level = 0,*/ ispecial;
39 char *endptr, name_[256], AStr[32];
40 char const *ZStr, *alias = NULL;
41 PoP *pop, *pop_;
42 /* enum PoPs_genre genre = PoPs_genre_unknown; */
43 char const *yiNames[] = { "p", "h2", "h3", "he3", "he4", "photon" };
44 char const *yiAliases[] = { "h1", "d", "t", "he3", "a", "g" };
45 /* enum PoPs_genre yiGenres[] = { PoPs_genre_baryon, PoPs_genre_nucleus, PoPs_genre_nucleus, PoPs_genre_nucleus,
46 PoPs_genre_nucleus, PoPs_genre_photon }; */
47
48 if( special == NULL ) special = "";
49 if( index < 0 ) {
50 if( isdigit( name[0] ) ) {
51 ZA = (int) strtol( name, &endptr, 10 );
52 if( *endptr != 0 ) {
53 smr_setReportError2( smr, PoPs_smr_ID, PoPs_errorToken_badName, "string '%s' not a value ZA", name );
54 return( -1 );
55 }
56 Z = ZA / 1000;
57 A = ZA % 1000;
58 /*level = 0;*/
59 ispecial = 0;
60 if( strcmp( special, "LLNL" ) == 0 ) {
61 if( ( ZA > 1 ) && ( ZA < 8 ) ) {
62 strcpy( name_, yiNames[ZA-2] );
63 alias = yiAliases[ZA-2];
64 /* genre = yiGenres[ZA-2];*/
65 ispecial = 1; }
66 else if( ( ZA == 1801 ) || ( ZA == 1901 ) ) {
67 strcpy( name_, yiNames[0] );
68 alias = yiAliases[0];
69 /* genre = yiGenres[0]; */
70 ispecial = 1; }
71 else if( ZA == 1902 ) {
72 strcpy( name_, yiNames[1] );
73 alias = yiAliases[1];
74 /* genre = yiGenres[1]; */
75 ispecial = 1; }
76 else if( ZA == 4809 ) {
77 strcpy( name_, "Be9" );
78 /* genre = PoPs_genre_atom; */
79 ispecial = 1; }
80 else if( ZA == 4909 ) {
81 strcpy( name_, "Be9" );
82 /* genre = PoPs_genre_atom; */
83 ispecial = 1; }
84 else if( ZA == 6912 ) {
85 strcpy( name_, "C12" );
86 /* genre = PoPs_genre_atom; */
87 ispecial = 1; }
88 else if( ZA == 8916 ) {
89 strcpy( name_, "O16" );
90 /* genre = PoPs_genre_atom; */
91 ispecial = 1; }
92 else if( ZA == 95242 ) {
93 strcpy( name_, "Am242_e2" );
94 /*level = 2;*/
95 /* genre = PoPs_genre_atom; */
96 ispecial = 1; }
97 else if( Z == 99 ) {
98 if( ( 120 <= A ) && ( A < 126 ) ) {
99 snprintf( name_, sizeof name_, "FissionProductENDL99%d", A );
100 /* genre = PoPs_genre_atom; */
101 ispecial = 1;
102 }
103 }
104 }
105 if( ispecial == 0 ) {
106 if( ZA == 1 ) {
107 AStr[0] = 0; }
108 else if( A == 0 ) {
109 strcpy( AStr, "_natural" ); }
110 else {
111 snprintf( AStr, sizeof AStr, "%d", A );
112 }
113 if( ( ZStr = lPoPs_ZSymbol( Z ) ) == NULL ) {
114 smr_setReportError2( smr, PoPs_smr_ID, PoPs_errorToken_badName, "string '%s' not a value ZA; Z = %d is not supported", name, Z );
115 return( -1 );
116 }
117 snprintf( name_, sizeof name_, "%s%s", ZStr, AStr );
118 /* genre = PoPs_genre_atom; */
119 /* if( ZA == 1 ) genre = PoPs_genre_baryon; */
120 } }
121 else {
122 strcpy( name_, name );
123 ZA = -1;
124 if( strcmp( name, "neutron" ) == 0 ) {
125 strcpy( name_, "n" );
126 alias = name;
127 /* genre = PoPs_genre_baryon; */ }
128 else if( strcmp( name, "electron" ) == 0 ) {
129 strcpy( name_, "e-" );
130 alias = name;
131 /* genre = PoPs_genre_lepton; */ }
132 else if( strcmp( name, "positron" ) == 0 ) {
133 strcpy( name_, "e+" );
134 alias = name;
135 /* genre = PoPs_genre_lepton; */ }
136 else if( ( strcmp( name, "h1" ) == 0 ) || ( strcmp( name, "proton" ) == 0 ) ) {
137 ZA = 2; }
138 else if( ( strcmp( name, "d" ) == 0 ) || ( strcmp( name, "deuteron" ) == 0 ) ) {
139 ZA = 3; }
140 else if( ( strcmp( name, "t" ) == 0 ) || ( strcmp( name, "triton" ) == 0 ) ) {
141 ZA = 4; }
142 else if( strcmp( name, "helium3" ) == 0 ) {
143 ZA = 5; }
144 else if( ( strcmp( name, "a" ) == 0 ) || ( strcmp( name, "alpha" ) == 0 ) || ( strcmp( name, "helium4" ) == 0 ) ) {
145 ZA = 6; }
146 else if( ( strcmp( name, "g" ) == 0 ) || ( strcmp( name, "gamma" ) == 0 ) ) {
147 ZA = 7; }
148 else if( strcmp( name, "FP" ) == 0 ) {
149 strcpy( name_, "FissionProductENDL99120" );
150 /* genre = PoPs_genre_atom; */
151 }
152 if( ZA != -1 ) {
153 strcpy( name_, yiNames[ZA-2] );
154 alias = name;
155 /* genre = yiGenres[ZA-2]; */
156 }
157 }
158
159 if( ( pop = PoPs_particleCreateLoadInfo( smr, name_ ) ) == NULL ) {
160 smr_setReportError2( smr, PoPs_smr_ID, PoPs_errorToken_badName, "particle '%s' converted to name '%s' not in database", name, name_ );
161 return( -1 );
162 }
163 if( ( pop_ = PoPs_addParticleIfNeeded( smr, pop ) ) != pop ) PoP_free( pop ); /* Still need to add alias as index was < 0. */
164 index = pop_->index;
165
166 if( PoPs_particleIndex( name ) < 0 ) {
167 if( ( pop = PoP_makeAlias( smr, name_, name ) ) == NULL ) return( -1 );
168 if( ( pop_ = PoPs_addParticleIfNeeded( smr, pop ) ) != pop ) return( -1 ); /* pop_ should be pop as index was < 0. */
169 }
170
171 if( alias != NULL ) {
172 if( PoPs_particleIndex( alias ) < 0 ) {
173 if( ( pop = PoP_makeAlias( smr, name_, alias ) ) == NULL ) return( -1 );
174 if( ( pop_ = PoPs_addParticleIfNeeded( smr, pop ) ) != pop ) return( -1 ); /* Required for some yis. */
175 }
176 }
177 }
178 return( index );
179}
180/*
181========================================================================
182*/
183static char const *lPoPs_ZSymbol( int Z ) {
184
185 //Coverity #63066
186 if( ( Z < 0 ) || ( Z >= nZs ) ) return( NULL );
187 return( Zs[Z].Symbol );
188}
189
190#if defined __cplusplus
191}
192#endif
const G4int Z[17]
const G4double A[17]
@ PoPs_errorToken_badName
Definition: PoPs.h:35
int PoPs_particleIndex(char const *name)
Definition: PoPs.cc:204
int lPoPs_addParticleIfNeeded(statusMessageReporting *smr, char const *name, char const *special)
Definition: lPoPs.cc:36
PoP * PoPs_particleCreateLoadInfo(statusMessageReporting *smr, const char *name)
Definition: PoPs_data.cc:61
PoP * PoP_makeAlias(statusMessageReporting *smr, char const *name, char const *alias)
Definition: PoPs.cc:647
int PoPs_smr_ID
Definition: PoPs.cc:35
PoP * PoPs_addParticleIfNeeded(statusMessageReporting *smr, PoP *pop)
Definition: PoPs.cc:113
PoP * PoP_free(PoP *pop)
Definition: PoPs.cc:558
#define smr_setReportError2(smr, libraryID, code, fmt,...)
Definition: PoPs.h:45
int index
Definition: PoPs.h:46