Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LevelReader.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 // $Id: G4LevelReader.cc 77025 2013-11-20 16:11:51Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 header file
31 //
32 // File name: G4NucLevel
33 //
34 // Author: V.Ivanchenko (M.Kelsey reading method is used)
35 //
36 // Creation date: 4 January 2012
37 //
38 // Modifications:
39 //
40 // -------------------------------------------------------------------
41 
42 #include "G4LevelReader.hh"
43 #include "G4NucLevel.hh"
44 #include "G4SystemOfUnits.hh"
45 
47  : nLevels(0),nLevelMax(50),fVerbose(0),fMinProbability(1.e-10)
48 {
49  fLevelEnergy = fNewEnergy = fDeltaEnergy = fNewTime
50  = fHalfLifeTime = fProbability = fICC = fx = 0.0;
51  eGamma.resize(nLevelMax,0.0);
52  wGamma.resize(nLevelMax,0.0);
53  kICC.resize(nLevelMax,0.0);
54  for(G4int i=0; i<30; ++i) { buffer[i] = 0; }
55 }
56 
58 {}
59 
61  std::vector<G4NucLevel*>* levels,
62  const G4String& filename)
63 {
64  std::ifstream inFile(filename);
65  if (!inFile.is_open()) {
66  if (fVerbose > 0) {
67  G4cout << " G4LevelReader: nuclide ("
68  << Z << "," << A
69  << ") does not have a gamma levels file" << G4endl;
70  }
71  return;
72  }
73 
74  // Read file with gamma data and fill levels
75  fLevelEnergy = 0.0;
76  nLevels = 0;
77 
78  // read next line
79  while(Read(inFile)) {
80 
81  // create new level and start fill the next
82  if(fNewEnergy != fLevelEnergy) {
83  if(0 < nLevels) { MakeNewLevel(levels); }
84  fLevelEnergy = fNewEnergy;
85  fHalfLifeTime = fNewTime;
86  nLevels = 0;
87  }
88 
89  // fill data on a new daughter level
90  eGamma[nLevels] = fDeltaEnergy*keV;
91  wGamma[nLevels] = std::max(fProbability*0.01,fMinProbability);
92  kICC[nLevels] = fICC;
93  ++nLevels;
94 
95  // check buffer size - should never happen
96  if(nLevels > nLevelMax) {
97  nLevelMax += 10;
98  eGamma.resize(nLevelMax);
99  wGamma.resize(nLevelMax);
100  kICC.resize(nLevelMax);
101  }
102  }
103  // end of reading
104  if(0 < nLevels) {
105  MakeNewLevel(levels);
106  inFile.close();
107  }
108 }
109 
110 G4bool G4LevelReader::Read(std::ifstream& dataFile)
111 {
112  // Each item will return iostream status
113  return (ReadDataItem(dataFile, fNewEnergy) &&
114  ReadDataItem(dataFile, fDeltaEnergy) &&
115  ReadDataItem(dataFile, fProbability) &&
116  ReadDataItem(dataFile, fx) &&
117  ReadDataItem(dataFile, fNewTime) &&
118  ReadDataItem(dataFile, fx) &&
119  ReadDataItem(dataFile, fICC) &&
120  ReadDataItem(dataFile, fx) &&
121  ReadDataItem(dataFile, fx) &&
122  ReadDataItem(dataFile, fx) &&
123  ReadDataItem(dataFile, fx) &&
124  ReadDataItem(dataFile, fx) &&
125  ReadDataItem(dataFile, fx) &&
126  ReadDataItem(dataFile, fx) &&
127  ReadDataItem(dataFile, fx) &&
128  ReadDataItem(dataFile, fx) &&
129  ReadDataItem(dataFile, fx) );
130 }
131 
132 G4bool
133 G4LevelReader::ReadDataItem(std::istream& dataFile, G4double& x)
134 {
135  // G4bool okay = (dataFile >> buffer) != 0; // Get next token
136  // if (okay) x = strtod(buffer, NULL);
137  G4bool okay = true;
138  dataFile >> buffer;
139  if(dataFile.fail()) { okay = false; }
140  else { x = strtod(buffer, NULL); }
141 
142  return okay;
143 }
144 
145 void G4LevelReader::MakeNewLevel(std::vector<G4NucLevel*>* levels)
146 {
147  // first normalize probabilities
148  G4double norm = 0.0;
149  for(size_t i=0; i<nLevels; ++i) { norm += wGamma[i]; }
150 
151  // should never happen
152  if(norm <= 0.0) { return; }
153 
154  norm = 1.0/norm;
155  for(size_t i=0; i<nLevels; ++i) { wGamma[i] *= norm; }
156 
157  // correct probabilities on ICC factor
158  norm = 0.0;
159  for(size_t i=0; i<nLevels; ++i) {
160  wGamma[i] /= (1.0 + kICC[i]);
161  norm += wGamma[i];
162  }
163  norm = 1.0/norm;
164  fHalfLifeTime *= norm*second;
165 
166  // cumulative sum
167  if(1 == nLevels) {
168  wGamma[0] = 1.0;
169  } else if(2 == nLevels) {
170  wGamma[0] *= norm;
171  wGamma[1] = 1.0;
172  } else {
173  wGamma[0] *= norm;
174  for(size_t i=1; i<nLevels-1; ++i) {
175  wGamma[i] = wGamma[i]*norm + wGamma[i-1];
176  }
177  wGamma[nLevels-1] = 1.0;
178  }
179  G4NucLevel* p = new G4NucLevel(fLevelEnergy, fHalfLifeTime,
180  eGamma, wGamma);
181  levels->push_back(p);
182  return;
183 }
184 
const char * p
Definition: xmltok.h:285
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void FillLevels(G4int Z, G4int A, std::vector< G4NucLevel * > *levels, const G4String &filename)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76