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