Geant4  10.00.p03
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 
65 //G4NeutronHPDataUsed G4NeutronHPNames::GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool & aFlag)
67 {
68 
70 
71  //G4cout << Z << " " << A << " " << M << " " << base << " " << rest << G4endl;
72 
73  //Excited isomer indicator
74  std::stringstream ss;
75  G4String sM;
76  if ( M > 0 )
77  {
78  ss << "m";
79  ss << M;
80  ss >> sM;
81  ss.clear();
82  }
83 
84  G4NeutronHPDataUsed result;
85  aFlag = true;
86 if(getenv("NeutronHPNames")) G4cout << "Names::GetName entered for Z = " << Z << ", A = " << A <<G4endl;
87 
88  G4int myA = A;
89  G4int myZ = Z;
90 
91  if(Z>92.5&&!getenv("AllowForHeavyElements") )
92  {
93  //G4cerr << "Please contact Hans-Peter.Wellisch@cern.ch"<<G4endl;
94  G4cerr << "Please contact Geant4 Hadron Group Coordinator"<<G4endl;
95  throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPNames::GetName - data with Z>92 are not provided");
96  }
97 
98  G4String * theName = 0;
99  G4String theFileName("");
100 
101 // G4int inc = 1;
102 
103  G4int flip_Z = 1;
104  G4int delta_Z = 0;
105 
106  G4int flip_A = 1;
107  G4int delta_A = 0;
108 
109  //std::ifstream * check = new std::ifstream(".dummy");
110  std::istringstream* check = NULL;
111  G4bool first = true;
112 if(getenv("NeutronHPNames")) G4cout << "entered GetName!!!"<<G4endl;
113  do
114  {
115  aFlag = true;
116  G4String * biff = new G4String(); // delete here as theName
117  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
118 
119  if(theName!=0) delete theName;
120  theName = biff;
121  result.SetName(*theName);
122  result.SetA(myA);
123  result.SetZ(myZ);
124  result.SetM(M);
125 if(getenv("NeutronHPNames")) G4cout <<"HPWD 1 "<<*theName<<G4endl;
126 
127  // T.K. debug for memory leak
128  if ( check != NULL ) {
129  //check->close();
130  delete check;
131  }
132 
133  //check = new std::ifstream(*theName);
134  check = new std::istringstream(std::ios::in);
136  if ( !(*check) )
137  {
138  //check->close();
139  delete check;
140  check = 0;
141  aFlag = false;
142  if ( first )
143  {
144  aFlag = true;
145  first = false;
146  biff = new G4String(); // delete here as theName
147  *biff = base+"/CrossSection/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
148  if(theName!=0) delete theName;
149  theName = biff;
150 if(getenv("NeutronHPNames")) G4cout <<"HPWD 2 "<<*theName<<G4endl;
151  result.SetName(*theName);
152  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
153  result.SetA(natA);
154  result.SetZ(myZ);
155  result.SetM(M);
156  //check = new std::ifstream(*theName);
157  check = new std::istringstream(std::ios::in);
159  if ( !(*check) )
160  {
161  //check->close();
162  delete check;
163  check = 0;
164  aFlag = false;
165  }
166  else
167  {
168  biff = new G4String(); // delete here as theName
169  if(theName!=0) delete theName;
170  *biff = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
171  if ( rest=="/CrossSection" ) *biff = base+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
172  theName = biff;
173 if(getenv("NeutronHPNames")) G4cout <<"HPWD 3 "<<*theName<<G4endl;
174  result.SetName(*theName);
175  natA = myZ/G4SandiaTable::GetZtoA(myZ);
176  result.SetA(natA);
177  result.SetZ(myZ);
178  result.SetM(M);
179  result.SetNaturalAbundanceFlag();
180  }
181  }
182  }
183  else
184  {
185 // 070706 T. Koi Modified
186 /*
187  biff = new G4String(); // delete here as theName
188  *biff = base+"/"+rest+itoa(myZ)+"_"+itoa(myA)+"_"+theString[myZ-1];
189  if(theName!=0) delete theName;
190  theName = biff;
191 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4 "<<*theName<<G4endl;
192  result.SetName(*theName);
193  result.SetA(myA);
194  result.SetZ(myZ);
195 */
196 
197  G4double tmpA = myA;
198  //std::ifstream* file = NULL;
199  std::istringstream* file = NULL;
200  G4String fileName;
201 
202  if ( rest == "/CrossSection" )
203  {
204 
205  //fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
206  fileName = base+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
207 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4a "<<*theName<<G4endl;
208 
209  }
210  else
211  {
212 
213 // For FS
214  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+itoa(myA)+sM+"_"+theString[myZ-1];
215  //file = new std::ifstream(fileName);
216  file = new std::istringstream(std::ios::in);
218 
219  if ( *file )
220  {
221 
222 // isotope FS
223 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b1 "<<*theName<<G4endl;
224  }
225  else
226  {
227 
228 // _nat_ FS
229  fileName = base+"/"+rest+"/"+itoa(myZ)+"_"+"nat"+"_"+theString[myZ-1];
230 
231  delete file;
232  //file = new std::ifstream(fileName);
233  file = new std::istringstream(std::ios::in);
235  if ( *file )
236  {
237 
238 // FS neither isotope nor _nat_
239 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b2a "<<*theName<<G4endl;
240  G4double natA = myZ/G4SandiaTable::GetZtoA(myZ);
241  tmpA = natA;
242  }
243  else
244  {
245 if(getenv("NeutronHPNames")) G4cout <<"HPWD 4b2c "<<*theName<<G4endl;
246  fileName="INVALID";
247  }
248  }
249 
250  delete file;
251 
252  }
253 
254  result.SetName(fileName);
255  result.SetA(tmpA);
256  result.SetZ(myZ);
257  result.SetM(M);
258 
259  }
260 
261  do
262  {
263 // if (std::abs(myZ-Z)>theMaxOffSet||myZ==0||myA==0)
264  if ( delta_Z > theMaxOffSet )
265  {
266  //if ( inc > 0 )
267  //{
268  // inc*= -1;
269  // myZ = Z;
270  // myA = A;
271  //}
272  //else
273  //{
274  G4cout <<"G4NeutronHPNames: Sorry, this material does not come near to any data."<<G4endl;
275  G4cout <<"G4NeutronHPNames: Please make sure G4NEUTRONHPDATA points to the" << G4endl;
276  G4cout <<" directory, the neutron scattering data are located in." << G4endl;
277  G4cout << "G4NeutronHPNames: The material was: A="<<A<<", Z="<<Z<<G4endl;
278  //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");
279  throw G4HadronicException(__FILE__, __LINE__, "In case the data sets are at present not available in the neutron data library, please contact Hadron Group Coordinator");
280  delete theName;
281  theFileName = "";
282  return result;
283  //}
284  }
285 
286  //if ( std::abs( myA - A ) > theMaxOffSet )
287  if ( delta_A > 2*theMaxOffSet )
288  {
289  delta_A = 0;
290  flip_A = 1;
291 
292  first = true;
293 
294  if ( flip_Z > 0 )
295  {
296  delta_Z +=1;
297  }
298  myZ = Z + flip_Z * delta_Z;
299  flip_Z *= -1;
300 
301  myA = A;
302  if ( myZ > 100 )
303  {
304  myZ = 100;
305  }
306  if ( myZ < 1 )
307  {
308  myZ = 1;
309  }
310 
311 // myZ += inc;
312  }
313  else
314  {
315  if ( flip_A > 0 )
316  {
317  delta_A += 1;
318  }
319  myA = A + flip_A * delta_A;
320  flip_A *= -1;
321 
322  if ( myA < 1 )
323  {
324  myA = 1;
325  }
326 
327 // myA += inc;
328  }
329 
330  }
331  while( myZ == 0 || myA == 0 ); // No meaning
332 
333  }
334  while((!check) || (!(*check)));
335 
336  if(getenv("NeutronHPNamesLogging") || getenv("NeutronHPNames"))
337  {
338  G4cout << "Names::GetName: last theName proposal = "<< G4endl;
339  G4cout << *theName <<" "<<A<<" "<<Z<<" "<<result.GetName()<<G4endl;
340  }
341 
342 // administration and anouncement for lacking of exact data in NDL
343  if ( Z != result.GetZ() || A != result.GetA() )
344  {
345  if ( rest == "/CrossSection" )
346  {
347  G4String reac = base;
348  G4String dir = getenv("G4NEUTRONHPDATA");
349  reac.erase ( 0 , dir.length() );
350  if ( getenv ( "G4NEUTRONHP_SKIP_MISSING_ISOTOPES" ) && !( 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  }
void SetName(G4String aName)
static G4NeutronHPManager * GetInstance()
G4String itoa(int current)
void GetDataStream(G4String, std::istringstream &iss)
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
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