source: trunk/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPNames.cc @ 829

Last change on this file since 829 was 819, checked in by garnier, 16 years ago

import all except CVS

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