Geant4  10.02.p02
G4ParticleHPNames.cc
Go to the documentation of this file.
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 //
40 #include "G4ParticleHPNames.hh"
41 #include "G4ParticleHPManager.hh"
42 #include "G4SandiaTable.hh"
43 #include "G4HadronicException.hh"
44 #include <fstream>
45 
46  const G4String G4ParticleHPNames::theString[100] = {"Hydrogen", "Helium",
47  "Lithium", "Berylium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine",
48  "Neon", "Sodium", "Magnesium", "Aluminum", "Silicon", "Phosphorous",
49  "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium",
50  "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel",
51  "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine",
52  "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium",
53  "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver",
54  "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon",
55  "Cesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium",
56  "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium",
57  "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium",
58  "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinium", "Gold",
59  "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon",
60  "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium",
61  "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium",
62  "Einsteinium","Fermium"};
63 
64 
66 
67 //G4ParticleHPDataUsed G4ParticleHPNames::GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool & aFlag)
69 {
70 
72 
73  //G4cout << Z << " " << A << " " << M << " " << base << " " << rest << G4endl;
74 
75  //Excited isomer indicator
76  std::stringstream ss;
77  G4String sM;
78  if ( M > 0 )
79  {
80  ss << "m";
81  ss << M;
82  ss >> sM;
83  ss.clear();
84  }
85 
86  G4ParticleHPDataUsed result;
87  aFlag = true;
88 if(getenv("NeutronHPNames")) G4cout << "Names::GetName entered for Z = " << Z << ", A = " << A <<G4endl;
89 
90  G4int myA = A;
91  G4int myZ = Z;
92 
93  if(Z>92.5&&!getenv("AllowForHeavyElements") )
94  {
95  //G4cerr << "Please contact Hans-Peter.Wellisch@cern.ch"<<G4endl;
96  G4cerr << "Please contact Geant4 Hadron Group Coordinator"<<G4endl;
97  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPNames::GetName - data with Z>92 are not provided");
98  }
99 
100  G4String * theName = 0;
101  G4String theFileName("");
102 
103 // G4int inc = 1;
104 
105  G4int flip_Z = 1;
106  G4int delta_Z = 0;
107 
108  G4int flip_A = 1;
109  G4int delta_A = 0;
110 
111  //std::ifstream * check = new std::ifstream(".dummy");
112  std::istringstream* check = NULL;
113  G4bool first = true;
114 if(getenv("NeutronHPNames")) G4cout << "entered GetName!!!"<<G4endl;
115  do
116  {
117  aFlag = true;
118  G4String * biff = new G4String(); // delete here as theName
119  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
120 
121  if(theName!=0) delete theName;
122  theName = biff;
123  result.SetName(*theName);
124  result.SetA(myA);
125  result.SetZ(myZ);
126  result.SetM(M);
127 if(getenv("NeutronHPNames")) G4cout <<"HPWD 1 "<<*theName<<G4endl;
128 
129  // T.K. debug for memory leak
130  if ( check != NULL ) {
131  //check->close();
132  delete check;
133  }
134 
135  //check = new std::ifstream(*theName);
136  check = new std::istringstream(std::ios::in);
138  if ( !(*check) )
139  {
140  //check->close();
141  delete check;
142  check = 0;
143  aFlag = false;
144  if ( first )
145  {
146  aFlag = true;
147  first = false;
148  biff = new G4String(); // delete here as theName
149  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
150  delete theName;
151  theName = biff;
152 if(getenv("NeutronHPNames")) G4cout <<"HPWD 2 "<<*theName<<G4endl;
153  result.SetName(*theName);
154  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
155  result.SetA(natA);
156  result.SetZ(myZ);
157  result.SetM(M);
158  //check = new std::ifstream(*theName);
159  check = new std::istringstream(std::ios::in);
161  if ( !(*check) )
162  {
163  //check->close();
164  delete check;
165  check = 0;
166  aFlag = false;
167  }
168  else
169  {
170  biff = new G4String(); // delete here as theName
171  *biff = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
172  if ( rest=="/CrossSection" ) *biff = base+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
173  delete theName;
174  theName = biff;
175 if(getenv("NeutronHPNames")) G4cout <<"HPWD 3 "<<*theName<<G4endl;
176  result.SetName(*theName);
177  natA = myZ/G4SandiaTable::GetZtoA(myZ);
178  result.SetA(natA);
179  result.SetZ(myZ);
180  result.SetM(M);
181  result.SetNaturalAbundanceFlag();
182  }
183  }
184  }
185  else
186  {
187 // 070706 T. Koi Modified
188 /*
189  biff = new G4String(); // delete here as theName
190  *biff = base+"/"+rest+itoa(myZ)+"_"+itoa(myA)+"_"+theString[myZ-1];
191  if(theName!=0) delete theName;
192  theName = biff;
193 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4 "<<*theName<<G4endl;
194  result.SetName(*theName);
195  result.SetA(myA);
196  result.SetZ(myZ);
197 */
198 
199  G4double tmpA = myA;
200  //std::ifstream* file = NULL;
201  std::istringstream* file = NULL;
202  G4String fileName;
203 
204  if ( rest == "/CrossSection" )
205  {
206 
207  //fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
208  fileName = base+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
209 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4a "<<*theName<<G4endl;
210 
211  }
212  else
213  {
214 
215 // For FS
216  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
217  //file = new std::ifstream(fileName);
218  file = new std::istringstream(std::ios::in);
220 
221  if ( *file )
222  {
223 
224 // isotope FS
225 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b1 "<<*theName<<G4endl;
226  }
227  else
228  {
229 
230 // _nat_ FS
231  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
232 
233  delete file;
234  //file = new std::ifstream(fileName);
235  file = new std::istringstream(std::ios::in);
237  if ( *file )
238  {
239 
240 // FS neither isotope nor _nat_
241 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b2a "<<*theName<<G4endl;
242  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
243  tmpA = natA;
244  }
245  else
246  {
247 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b2c "<<*theName<<G4endl;
248  fileName="INVALID";
249  }
250  }
251 
252  delete file;
253 
254  }
255 
256  result.SetName(fileName);
257  result.SetA(tmpA);
258  result.SetZ(myZ);
259  result.SetM(M);
260 
261  }
262 
263  do
264  {
265 // if (std::abs(myZ-Z)>theMaxOffSet||myZ==0||myA==0)
266  if ( delta_Z > theMaxOffSet )
267  {
268  //if ( inc > 0 )
269  //{
270  // inc*= -1;
271  // myZ = Z;
272  // myA = A;
273  //}
274  //else
275  //{
276  G4cout <<"G4ParticleHPNames: Sorry, this material does not come near to any data."<<G4endl;
277  G4cout <<"G4ParticleHPNames: Please make sure G4NEUTRONHPDATA points to the" << G4endl;
278  G4cout <<" directory, the neutron scattering data are located in." << G4endl;
279  G4cout << "G4ParticleHPNames: The material was: A="<<A<<", Z="<<Z<<G4endl;
280  //throw G4HadronicException(__FILE__, __LINE__, "In case the data sets are at present not available in the neutron data library, please contact Hans-Peter.Wellisch@cern.ch");
281  throw G4HadronicException(__FILE__, __LINE__, "In case the data sets are at present not available in the neutron data library, please contact Hadron Group Coordinator");
282  delete theName;
283  theFileName = "";
284  return result;
285  //}
286  }
287 
288  //if ( std::abs( myA - A ) > theMaxOffSet )
289  if ( delta_A > 2*theMaxOffSet )
290  {
291  delta_A = 0;
292  flip_A = 1;
293 
294  first = true;
295 
296  if ( flip_Z > 0 )
297  {
298  delta_Z +=1;
299  }
300  myZ = Z + flip_Z * delta_Z;
301  flip_Z *= -1;
302 
303  myA = A;
304  if ( myZ > 100 )
305  {
306  myZ = 100;
307  }
308  if ( myZ < 1 )
309  {
310  myZ = 1;
311  }
312 
313 // myZ += inc;
314  }
315  else
316  {
317  if ( flip_A > 0 )
318  {
319  delta_A += 1;
320  }
321  myA = A + flip_A * delta_A;
322  flip_A *= -1;
323 
324  if ( myA < 1 )
325  {
326  myA = 1;
327  }
328 
329 // myA += inc;
330  }
331 
332  }
333  while( myZ == 0 || myA == 0 ); // No meaning // Loop checking, 11.05.2015, T. Koi
334 
335  }
336  while((!check) || (!(*check))); // Loop checking, 11.05.2015, T. Koi
337 
338  if(getenv("NeutronHPNamesLogging") || getenv("NeutronHPNames"))
339  {
340  G4cout << "Names::GetName: last theName proposal = "<< G4endl;
341  G4cout << *theName <<" "<<A<<" "<<Z<<" "<<result.GetName()<<G4endl;
342  }
343 
344 // administration and anouncement for lacking of exact data in NDL
345  if ( Z != result.GetZ() || A != result.GetA() )
346  {
347  if ( rest == "/CrossSection" )
348  {
349  G4String reac = base;
350  G4String dir = getenv("G4NEUTRONHPDATA");
351  reac.erase ( 0 , dir.length() );
352  if ( G4ParticleHPManager::GetInstance()->GetSkipMissingIsotopes() && !( Z == result.GetZ() && result.IsThisNaturalAbundance() ) )
353  {
354  if ( verboseLevel > 0 ) {
355  G4cout << "NeutronHP: " << reac << " file for Z = " << Z << ", A = " << A << " is not found and CrossSection set to 0." << G4endl;
356  }
357  G4String new_name = base+"/"+rest+"/"+"0_0_Zero";
358  result.SetName( new_name );
359  }
360  else
361  {
362  //080901 Add protection that deuteron data do not selected for hydrogen and so on by T. Koi
363  //160216 Increase protencted isotopes for fixing problem on charged particle HP
364  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) ) )
365  || ( reac.find("Capture") != reac.size() && ( (Z == 1 && A == 3) || (Z == 2 && A == 4) ) )
366  || ( reac.find("Fission") != reac.size() && ( (Z == 88 && A == 224) || (Z == 88 && A == 225) || (Z == 89 && A == 225) || (Z == 88 && A == 226) ) ) )
367 
368  {
369  G4String new_name = base+"/"+rest+"/"+"0_0_Zero";
370  result.SetName( new_name );
371  }
372  else
373  {
374  if ( verboseLevel > 0 ) {
375  G4cout << "NeutronHP: " << reac << " file for Z = " << Z << ", A = " << A << " is not found and NeutronHP will use " << result.GetName() << G4endl;
376  }
377  }
378  }
379  }
380  }
381 
382  delete theName;
383  if(aFlag)
384  {
385  //check->close();
386  delete check;
387  check = NULL;
388  }
389  return result;
390  }
static G4ParticleHPManager * GetInstance()
static const G4String theString[100]
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
bool G4bool
Definition: G4Types.hh:79
void GetDataStream2(G4String, std::istringstream &iss)
void SetName(G4String aName)
static G4double GetZtoA(G4int Z)
G4String itoa(int current)
#define G4endl
Definition: G4ios.hh:61
G4ParticleHPDataUsed GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool &active)
void SetA(G4double anA)
double G4double
Definition: G4Types.hh:76
G4GLOB_DLL std::ostream G4cerr