ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleHPNames.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleHPNames.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 // neutron_hp -- source file
27 // J.P. Wellisch, Nov-1996
28 // A prototype of the low energy neutron transport model.
29 //
30 // 24-Jan-07 Enable to use exact data only and add warnig when substitute file is used T. Koi
31 // 30-Jan-07 Modified method of searching substitute isotope data by T. Koi
32 // 07-06-12 fix memory leaking by T. Koi
33 // 07-06-25 Change data selection logic when G4NEUTRONHP_SKIP_MISSING_ISOTOPES is turn on
34 // Natural Abundance data are allowed. by T. Koi
35 // 07-07-06 Allow _nat_ final state even for isotoped cross sections by T. Koi
36 // 08-09-01 Add protection that deuteron data do not selected for hydrogen and so on by T. Koi
37 //
38 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
39 // June-2019 - E. Mendoza --> Modification to allow using an incomplete data library if the G4NEUTRONHP_SKIP_MISSING_ISOTOPES environmental flag is defined. The missing XS are set to 0.
40 // Oct-2019 - E. Mendoza --> remove restriction of using isotopes with Z>92
41 
42 #include "G4ParticleHPNames.hh"
43 #include "G4ParticleHPManager.hh"
44 #include "G4SandiaTable.hh"
45 #include "G4HadronicException.hh"
46 #include <fstream>
47 
48  const G4String G4ParticleHPNames::theString[100] = {"Hydrogen", "Helium",
49  "Lithium", "Berylium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine",
50  "Neon", "Sodium", "Magnesium", "Aluminum", "Silicon", "Phosphorous",
51  "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium",
52  "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel",
53  "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine",
54  "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium",
55  "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver",
56  "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon",
57  "Cesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium",
58  "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium",
59  "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium",
60  "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinium", "Gold",
61  "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon",
62  "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium",
63  "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium",
64  "Einsteinium","Fermium"};
65 
66 
68 
69 //G4ParticleHPDataUsed G4ParticleHPNames::GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool & aFlag)
71 {
73 
74  //G4cout << Z << " " << A << " " << M << " " << base << " " << rest << G4endl;
75 
76  //Excited isomer indicator
77  std::stringstream ss;
78  G4String sM;
79  if (M > 0) {
80  ss << "m";
81  ss << M;
82  ss >> sM;
83  ss.clear();
84  }
85 
86  G4ParticleHPDataUsed result;
87  aFlag = true;
88  if (std::getenv("NeutronHPNames") ) G4cout << "Names::GetName entered for Z = " << Z << ", A = " << A <<G4endl;
89 
90  G4int myA = A;
91  G4int myZ = Z;
92 
93  G4String * theName = 0;
94  G4String theFileName("");
95 
96 // G4int inc = 1;
97 
98  G4int flip_Z = 1;
99  G4int delta_Z = 0;
100 
101  G4int flip_A = 1;
102  G4int delta_A = 0;
103 
104  //std::ifstream * check = new std::ifstream(".dummy");
105  std::istringstream* check = NULL;
106  G4bool first = true;
107  if (std::getenv("NeutronHPNames")) G4cout << "entered GetName!!!"<<G4endl;
108 
109  do
110  {
111  aFlag = true;
112  G4String * biff = new G4String(); // delete here as theName
113  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
114 
115  if(theName!=0) delete theName;
116  theName = biff;
117  result.SetName(*theName);
118  result.SetA(myA);
119  result.SetZ(myZ);
120  result.SetM(M);
121 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 1 "<<*theName<<G4endl;
122 
123  // T.K. debug for memory leak
124  if ( check != NULL ) {
125  //check->close();
126  delete check;
127  }
128 
129  //check = new std::ifstream(*theName);
130  check = new std::istringstream(std::ios::in);
132  if ( !(*check) )
133  {
134  //check->close();
135  delete check;
136  check = 0;
137  aFlag = false;
138  if ( first )
139  {
140  aFlag = true;
141  first = false;
142  biff = new G4String(); // delete here as theName
143  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
144  delete theName;
145  theName = biff;
146 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 2 "<<*theName<<G4endl;
147  result.SetName(*theName);
148  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
149  result.SetA(natA);
150  result.SetZ(myZ);
151  result.SetM(M);
152  //check = new std::ifstream(*theName);
153  check = new std::istringstream(std::ios::in);
155  if ( !(*check) )
156  {
157  //check->close();
158  delete check;
159  check = 0;
160  aFlag = false;
161  }
162  else
163  {
164  biff = new G4String(); // delete here as theName
165  *biff = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
166  if ( rest=="/CrossSection" ) *biff = base+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
167  delete theName;
168  theName = biff;
169 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 3 "<<*theName<<G4endl;
170  result.SetName(*theName);
171  natA = myZ/G4SandiaTable::GetZtoA(myZ);
172  result.SetA(natA);
173  result.SetZ(myZ);
174  result.SetM(M);
175  result.SetNaturalAbundanceFlag();
176  }
177  }
178  }
179  else
180  {
181 // 070706 T. Koi Modified
182 /*
183  biff = new G4String(); // delete here as theName
184  *biff = base+"/"+rest+itoa(myZ)+"_"+itoa(myA)+"_"+theString[myZ-1];
185  if(theName!=0) delete theName;
186  theName = biff;
187 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 4 "<<*theName<<G4endl;
188  result.SetName(*theName);
189  result.SetA(myA);
190  result.SetZ(myZ);
191 */
192 
193  G4double tmpA = myA;
194  //std::ifstream* file = NULL;
195  std::istringstream* file = NULL;
196  G4String fileName;
197 
198  if ( rest == "/CrossSection" )
199  {
200 
201  //fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
202  fileName = base+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
203 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 4a "<<*theName<<G4endl;
204 
205  } else {
206 
207 // For FS
208  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
209  file = new std::istringstream(std::ios::in);
211 
212  if (*file) {
213 
214 // isotope FS
215 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 4b1 "<<*theName<<G4endl;
216  } else {
217 
218 // _nat_ FS
219  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
220 
221  delete file;
222  //file = new std::ifstream(fileName);
223  file = new std::istringstream(std::ios::in);
225  if (*file) {
226 
227 // FS neither isotope nor _nat_
228 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 4b2a "<<*theName<<G4endl;
229  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
230  tmpA = natA;
231  } else {
232 if(std::getenv("NeutronHPNames")) G4cout <<"HPWD 4b2c "<<*theName<<G4endl;
233  fileName="INVALID";
234  }
235  }
236 
237  delete file;
238  }
239 
240  result.SetName(fileName);
241  result.SetA(tmpA);
242  result.SetZ(myZ);
243  result.SetM(M);
244  }
245 
246  do
247  {
248  if (delta_Z > theMaxOffSet) {
249  if (!G4ParticleHPManager::GetInstance()->GetSkipMissingIsotopes() ) {
250  G4cout << "G4ParticleHPNames: There are no data available for some isotopes in this material " << G4endl;
251  G4cout << "G4ParticleHPNames: nor are there data for nearby isotopes." << G4endl;
252  G4cout << "G4ParticleHPNames: Please make sure G4NEUTRONHPDATA points to the directory " << G4endl;
253  G4cout << "G4ParticleHPNames: in which the neutron scattering data are located." << G4endl;
254  G4cout << "G4ParticleHPNames: The material was A = " << A << ", Z = " << Z << G4endl;
255  throw G4HadronicException(__FILE__, __LINE__, "In case the data sets are at present not available in the neutron data library, please contact Hadron Group Coordinator");
256  } else {
257  check = new std::istringstream(std::ios::in);
258  break;
259  }
260  }
261 
262  //if ( std::abs( myA - A ) > theMaxOffSet )
263  if (delta_A > 2*theMaxOffSet) {
264  delta_A = 0;
265  flip_A = 1;
266 
267  first = true;
268 
269  if ( flip_Z > 0 )
270  {
271  delta_Z +=1;
272  }
273  myZ = Z + flip_Z * delta_Z;
274  flip_Z *= -1;
275 
276  myA = A;
277  if ( myZ > 100 )
278  {
279  myZ = 100;
280  }
281  if ( myZ < 1 )
282  {
283  myZ = 1;
284  }
285 
286 // myZ += inc;
287  } else {
288  if ( flip_A > 0 )
289  {
290  delta_A += 1;
291  }
292  myA = A + flip_A * delta_A;
293  flip_A *= -1;
294 
295  if ( myA < 1 )
296  {
297  myA = 1;
298  }
299 
300 // myA += inc;
301  }
302 
303  }
304  while( myZ == 0 || myA == 0 ); // No meaning // Loop checking, 11.05.2015, T. Koi
305 
306  }
307  while((!check) || (!(*check))); // Loop checking, 11.05.2015, T. Koi
308 
309  if(std::getenv("NeutronHPNamesLogging") || std::getenv("NeutronHPNames"))
310  {
311  G4cout << "Names::GetName: last theName proposal = "<< G4endl;
312  G4cout << *theName <<" "<<A<<" "<<Z<<" "<<result.GetName()<<G4endl;
313  }
314 
315 // administration and anouncement for lacking of exact data in NDL
316  if ( Z != result.GetZ() || A != result.GetA() )
317  {
318  if ( rest == "/CrossSection" )
319  {
320  G4String reac = base;
321  G4String dir = std::getenv("G4NEUTRONHPDATA");
322  reac.erase ( 0 , dir.length() );
323  if ( G4ParticleHPManager::GetInstance()->GetSkipMissingIsotopes() && !( Z == result.GetZ() && result.IsThisNaturalAbundance() ) )
324  {
325  if ( verboseLevel > 0 ) {
326  G4cout << "NeutronHP: " << reac << " file for Z = " << Z << ", A = " << A << " is not found and CrossSection set to 0." << G4endl;
327  }
328  G4String new_name = base+"/"+rest+"/"+"0_0_Zero";
329  result.SetName( new_name );
330  }
331  else
332  {
333  //080901 Add protection that deuteron data do not selected for hydrogen and so on by T. Koi
334  //160216 Increase protencted isotopes for fixing problem on charged particle HP
335  if ( ( reac.find("Inelastic") != reac.size() && ( (Z == 1 && A == 1) || (Z == 1 && A == 2) || (Z == 1 && A == 3) || (Z == 2 && A == 3) || (Z == 2 && A == 4) ) )
336  || ( reac.find("Capture") != reac.size() && ( (Z == 1 && A == 3) || (Z == 2 && A == 4) ) )
337  || ( reac.find("Fission") != reac.size() && ( (Z == 88 && A == 224) || (Z == 88 && A == 225) || (Z == 89 && A == 225) || (Z == 88 && A == 226) ) ) )
338 
339  {
340  G4String new_name = base+"/"+rest+"/"+"0_0_Zero";
341  result.SetName( new_name );
342  }
343  else
344  {
345  if ( verboseLevel > 0 ) {
346  G4cout << "NeutronHP: " << reac << " file for Z = " << Z << ", A = " << A << " is not found and NeutronHP will use " << result.GetName() << G4endl;
347  }
348  }
349  }
350  }
351  }
352 
353  delete theName;
354  if(aFlag)
355  {
356  //check->close();
357  delete check;
358  check = NULL;
359  }
360  return result;
361  }