Geant4  9.6.p02
 All Classes 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$
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); // Get next token
136  if (okay) x = strtod(buffer, NULL);
137 
138  return okay;
139 }
140 
141 void G4LevelReader::MakeNewLevel(std::vector<G4NucLevel*>* levels)
142 {
143  // first normalize probabilities
144  G4double norm = 0.0;
145  for(size_t i=0; i<nLevels; ++i) { norm += wGamma[i]; }
146 
147  // should never happen
148  if(norm <= 0.0) { return; }
149 
150  norm = 1.0/norm;
151  for(size_t i=0; i<nLevels; ++i) { wGamma[i] *= norm; }
152 
153  // correct probabilities on ICC factor
154  norm = 0.0;
155  for(size_t i=0; i<nLevels; ++i) {
156  wGamma[i] /= (1.0 + kICC[i]);
157  norm += wGamma[i];
158  }
159  norm = 1.0/norm;
160  fHalfLifeTime *= norm*second;
161 
162  // cumulative sum
163  if(1 == nLevels) {
164  wGamma[0] = 1.0;
165  } else if(2 == nLevels) {
166  wGamma[0] *= norm;
167  wGamma[1] = 1.0;
168  } else {
169  wGamma[0] *= norm;
170  for(size_t i=1; i<nLevels-1; ++i) {
171  wGamma[i] = wGamma[i]*norm + wGamma[i-1];
172  }
173  wGamma[nLevels-1] = 1.0;
174  }
175  G4NucLevel* p = new G4NucLevel(fLevelEnergy, fHalfLifeTime,
176  eGamma, wGamma);
177  levels->push_back(p);
178  return;
179 }
180