Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
27// -------------------------------------------------------------------
28//
29// GEANT4 header file
30//
31// File name: G4NucLevel
32//
33// Author: V.Ivanchenko (M.Kelsey reading method is used)
34//
35// Creation date: 4 January 2012
36//
37// Modifications:
38//
39// -------------------------------------------------------------------
40
41#include "G4LevelReader.hh"
42#include "G4NucleiProperties.hh"
43#include "G4NucLevel.hh"
44#include "G4NuclearLevelData.hh"
46#include "G4SystemOfUnits.hh"
47#include "G4Pow.hh"
48#include <fstream>
49#include <sstream>
50
51namespace
52{
53 G4int nfloting = 13;
54 G4String fFloatingLevels[13] = {
55 "-", "+X", "+Y", "+Z", "+U", "+V", "+W", "+R", "+S", "+T", "+A", "+B", "+C"};
56}
57
59 : fData(ptr)
60{
61 fAlphaMax = (G4float)1.e15;
62 fTimeFactor = CLHEP::second/G4Pow::GetInstance()->logZ(2);
63 fDirectory = G4String(G4FindDataDir("G4LEVELGAMMADATA"));
64
65 vTrans.resize(fTransMax,0);
66 vRatio.resize(fTransMax,0.0f);
67 vGammaCumProbability.resize(fTransMax,0.0f);
68 vGammaProbability.resize(fTransMax,0.0f);
69 vShellProbability.resize(fTransMax,nullptr);
70
71 vEnergy.resize(fLevelMax,0.0);
72 vSpin.resize(fLevelMax,0);
73 vLevel.resize(fLevelMax,nullptr);
74}
75
76G4bool G4LevelReader::ReadData(std::istringstream& stream, G4double& x)
77{
78 stream >> x;
79 return !stream.fail();
80}
81
82G4bool G4LevelReader::ReadDataItem(std::istream& dataFile, G4double& x)
83{
84 x = 0.0;
85 for(G4int i=0; i<nbufmax; ++i) { buffer[i] = ' '; }
86 G4bool okay = true;
87 dataFile >> buffer;
88 if(dataFile.fail()) { okay = false; }
89 else { x = std::strtod(buffer, 0); }
90
91 return okay;
92}
93
94G4bool G4LevelReader::ReadDataItem(std::istream& dataFile, G4float& x)
95{
96 x = 0.0f;
97 for(G4int i=0; i<nbuf1; ++i) { buff1[i] = ' '; }
98 G4bool okay = true;
99 dataFile >> buff1;
100 if(dataFile.fail()) { okay = false; }
101 else { x = std::atof(buff1); }
102
103 return okay;
104}
105
106G4bool G4LevelReader::ReadDataItem(std::istream& dataFile, G4int& ix)
107{
108 ix = 0;
109 for(G4int i=0; i<nbuf2; ++i) { buff2[i] = ' '; }
110 G4bool okay = true;
111 dataFile >> buff2;
112 if(dataFile.fail()) { okay = false; }
113 else { ix = std::atoi(buff2); }
114
115 return okay;
116}
117
118const std::vector<G4float>* G4LevelReader::NormalizedICCProbability(G4int Z)
119{
120 std::vector<G4float>* vec = nullptr;
121 G4int LL = 3;
122 G4int M = 5;
123 G4int N = 1;
124 if(Z <= 27) {
125 M = N = 0;
126 if(Z <= 4) {
127 LL = 1;
128 } else if(Z <= 6) {
129 LL = 2;
130 } else if(Z <= 10) {
131 } else if(Z <= 12) {
132 M = 1;
133 } else if(Z <= 17) {
134 M = 2;
135 } else if(Z == 18) {
136 M = 3;
137 } else if(Z <= 20) {
138 M = 3;
139 N = 1;
140 } else {
141 M = 4;
142 N = 1;
143 }
144 if(LL < 3) { for(G4int i=LL+1; i<=4; ++i) { fICC[i] = 0.0f; } }
145 if(M < 5) { for(G4int i=M+4; i<=8; ++i) { fICC[i] = 0.0f; } }
146 if(N < 1) { fICC[9] = 0.0f; }
147 }
148 G4float norm = 0.0f;
149 for(G4int i=0; i<10; ++i) {
150 norm += fICC[i];
151 fICC[i] = norm;
152 }
153 if(norm == 0.0f && fAlpha > 0.0f) {
154 fICC[0] = norm = 1.0f;
155 }
156 if(norm > 0.0f) {
157 norm = 1.0f/norm;
158 vec = new std::vector<G4float>;
159 G4float x;
160 for(G4int i=0; i<10; ++i) {
161 x = fICC[i]*norm;
162 if(x > 0.995f || 9 == i) {
163 vec->push_back(1.0f);
164 break;
165 }
166 vec->push_back(x);
167 }
168 if (fVerbose > 3) {
169 G4long prec = G4cout.precision(3);
170 G4cout << "# InternalConv: ";
171 std::size_t nn = vec->size();
172 for(std::size_t i=0; i<nn; ++i) { G4cout << " " << (*vec)[i]; }
173 G4cout << G4endl;
174 G4cout.precision(prec);
175 }
176 }
177 return vec;
178}
179
180const G4LevelManager*
182{
183 std::ostringstream ss;
184 ss << fDirectory << "/z" << Z << ".a" << A;
185 std::ifstream infile(ss.str(), std::ios::in);
186
187 // file is not opened
188 if (!infile.is_open()) {
189 if(fVerbose > 1) {
191 ed << "Regular file " << ss.str() << " is not opened! Z="
192 << Z << " A=" << A;
193 G4Exception("G4LevelReader::LevelManager(..)","had014",
194 JustWarning, ed, "Check file path");
195 }
196 return nullptr;
197 }
198 // file is opened
199 if (fVerbose > 1) {
200 G4cout << "G4LevelReader: open file " << ss.str() << " for Z= "
201 << Z << " A= " << A << G4endl;
202 }
203 return LevelManager(Z, A, infile);
204}
205
206const G4LevelManager*
208{
209 std::ifstream infile(filename, std::ios::in);
210
211 // file is not opened
212 if (!infile.is_open()) {
213 if(fVerbose > 1) {
215 ed << "External file " << filename << " is not opened! Z="
216 << Z << " A=" << A;
217 G4Exception("G4LevelReader::LevelManager(..)","had014",
218 FatalException, ed, "Check file path");
219 }
220 return nullptr;
221 }
222 // file is opened
223 if (fVerbose > 1) {
224 G4cout << "G4LevelReader: open external file " << filename
225 << " for Z= " << Z << " A= " << A << G4endl;
226 }
227 return LevelManager(Z, A, infile);
228}
229
230const G4LevelManager*
231G4LevelReader::LevelManager(G4int Z, G4int A, std::ifstream& infile)
232{
233 G4bool allLevels = fData->GetParameters()->StoreICLevelData();
234 fPol = " ";
235 G4int i = 0;
236 for(;;) {
237 infile >> i1 >> fPol; // Level number and floating level
238 // normal end of file
239 if(infile.eof()) {
240 if(fVerbose > 1) {
241 G4cout << "### End of file Z= " << Z << " A= " << A
242 << " Nlevels= " << i << G4endl;
243 }
244 break;
245 }
246 // problematic end of file
247 if(i1 != i) {
249 ed << " G4LevelReader: wrong data file for Z= " << Z << " A= " << A
250 << " level #" << i << " has index " << i1;
251 G4Exception("G4LevelReader::LevelManager(..)","had014",
252 JustWarning, ed, "Check G4LEVELGAMMADATA");
253 break;
254 }
255 // start reading new level data
256 if(fVerbose > 2) {
257 G4cout << "New line: i1= " << i1 << " fPol= <" << fPol << "> " << G4endl;
258 }
259 // read new level data
260 if(!(ReadDataItem(infile, fEnergy) &&
261 ReadDataItem(infile, fTime) &&
262 ReadDataItem(infile, fSpin) &&
263 ReadDataItem(infile, ntrans))) {
264 if(fVerbose > 1) {
265 G4cout << "### Incomplete end of file Z= " << Z << " A= " << A
266 << " Nlevels= " << i << G4endl;
267 }
268 break;
269 }
270 fEnergy *= CLHEP::keV;
271 for(k=0; k<nfloting; ++k) {
272 if(fPol == fFloatingLevels[k]) {
273 break;
274 }
275 }
276 // if a previous level has not transitions it may be ignored
277 if(0 < i) {
278 // protection
279 if(fEnergy < vEnergy[i-1]) {
280 G4cout << "### G4LevelReader: broken level " << i
281 << " E(MeV)= " << fEnergy << " < " << vEnergy[i-1]
282 << " for isotope Z= " << Z << " A= "
283 << A << " level energy increased" << G4endl;
284 fEnergy = vEnergy[i-1];
285 }
286 }
287 vEnergy[i] = fEnergy;
288 if (fTime > 0.0) { fTime *= fTimeFactor; }
289 else if (fTime < 0.0) { fTime = DBL_MAX; }
290
291 G4int twos = G4lrint(fSpin + fSpin);
292 twos = std::max(twos, -100);
293 vSpin[i] = 100 + twos + k*100000;
294 if (fVerbose > 2) {
295 G4cout << " Level #" << i1 << " E(MeV)=" << fEnergy/CLHEP::MeV
296 << " LTime(s)=" << fTime << " 2S=" << vSpin[i]
297 << " meta=" << vSpin[i]/100000 << " idx=" << i
298 << " ntr=" << ntrans << G4endl;
299 }
300 vLevel[i] = nullptr;
301 if (ntrans == 0) {
302 vLevel[i] = new G4NucLevel(0, fTime,
303 vTrans,
304 vGammaCumProbability,
305 vGammaProbability,
306 vRatio,
307 vShellProbability);
308 } else if (ntrans > 0) {
309
310 // there are transitions
311 if(ntrans > fTransMax) {
312 fTransMax = ntrans;
313 vTrans.resize(fTransMax);
314 vRatio.resize(fTransMax);
315 vGammaCumProbability.resize(fTransMax);
316 vGammaProbability.resize(fTransMax);
317 vShellProbability.resize(fTransMax);
318 }
319 fNorm1 = 0.0f;
320 for(G4int j=0; j<ntrans; ++j) {
321
322 if(!(ReadDataItem(infile, i2) &&
323 ReadDataItem(infile, fTransEnergy) &&
324 ReadDataItem(infile, fProb) &&
325 ReadDataItem(infile, tnum) &&
326 ReadDataItem(infile, vRatio[j]) &&
327 ReadDataItem(infile, fAlpha))) {
328 if(fVerbose > 1) {
329 G4cout << "### Fail to read transition j= " << j
330 << " Z= " << Z << " A= " << A << G4endl;
331 }
332 break;
333 }
334 if(i2 >= i) {
335 G4cout << "### G4LevelReader: broken transition " << j
336 << " from level " << i << " to " << i2
337 << " for isotope Z= " << Z << " A= "
338 << A << " - use ground level" << G4endl;
339 i2 = 0;
340 }
341 vTrans[j] = i2*10000 + tnum;
342 fAlpha = std::min(std::max(fAlpha,0.f), fAlphaMax);
343 G4float x = 1.0f + fAlpha;
344 fNorm1 += x*fProb;
345 vGammaCumProbability[j] = fNorm1;
346 vGammaProbability[j] = 1.0f/x;
347 vShellProbability[j] = nullptr;
348 if(fVerbose > 2) {
349 G4long prec = G4cout.precision(4);
350 G4cout << "### Transition #" << j << " to level " << i2
351 << " i2= " << i2 << " Etrans(MeV)= " << fTransEnergy*CLHEP::keV
352 << " fProb= " << fProb << " MultiP= " << tnum
353 << " fMpRatio= " << fRatio << " fAlpha= " << fAlpha
354 << G4endl;
355 G4cout.precision(prec);
356 }
357 if(fAlpha > 0.0f) {
358 for(k=0; k<10; ++k) {
359 //infile >> fICC[k];
360 if(!ReadDataItem(infile,fICC[k])) {
361 //if(infile.fail()) {
362 if(fVerbose > 1) {
363 G4cout << "### Fail to read conversion coeff k= " << k
364 << " for transition j= " << j
365 << " Z= " << Z << " A= " << A << G4endl;
366 }
367 for(kk=k; kk<10; ++kk) { fICC[kk] = 0.f; }
368 break;
369 }
370 }
371 if(allLevels) {
372 vShellProbability[j] = NormalizedICCProbability(Z);
373 }
374 }
375 }
376 if(0.0f < fNorm1) { fNorm1 = 1.0f/fNorm1; }
377 G4int nt = ntrans - 1;
378 for(k=0; k<nt; ++k) {
379 vGammaCumProbability[k] *= fNorm1;
380 if(fVerbose > 3) {
381 G4cout << "Probabilities[" << k
382 << "]= " << vGammaCumProbability[k]
383 << " " << vGammaProbability[k]
384 << " idxTrans= " << vTrans[k]/10000
385 << G4endl;
386 }
387 }
388 vGammaCumProbability[nt] = 1.0f;
389 if(fVerbose > 3) {
390 G4cout << "Probabilities[" << nt << "]= "
391 << vGammaCumProbability[nt]
392 << " " << vGammaProbability[nt]
393 << " IdxTrans= " << vTrans[nt]/10000
394 << G4endl;
395 }
396 if(fVerbose > 2) {
397 G4cout << " New G4NucLevel: Ntrans= " << ntrans
398 << " Time(ns)= " << fTime << G4endl;
399 }
400 vLevel[i] = new G4NucLevel((std::size_t)ntrans, fTime,
401 vTrans,
402 vGammaCumProbability,
403 vGammaProbability,
404 vRatio,
405 vShellProbability);
406 }
407 ++i;
408 if(i == fLevelMax) {
409 fLevelMax += 10;
410 vEnergy.resize(fLevelMax, 0.0);
411 vSpin.resize(fLevelMax, 0);
412 vLevel.resize(fLevelMax, nullptr);
413 }
414 }
415 G4LevelManager* lman = nullptr;
416 if (1 <= i) {
417 lman = new G4LevelManager(Z, A, (std::size_t)i, vEnergy, vSpin, vLevel);
418 if (fVerbose > 1) {
419 G4cout << "=== Reader: new manager for Z=" << Z << " A=" << A
420 << " Nlevels=" << i << " E[0]="
421 << vEnergy[0]/CLHEP::MeV << " MeV E1="
422 << vEnergy[i-1]/CLHEP::MeV << " MeV"
423 << G4endl;
424 }
425 }
426 return lman;
427}
const char * G4FindDataDir(const char *)
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define M(row, col)
float G4float
Definition G4Types.hh:84
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4double A[17]
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
const G4LevelManager * MakeLevelManager(G4int Z, G4int A, const G4String &filename)
const G4LevelManager * CreateLevelManager(G4int Z, G4int A)
G4LevelReader(G4NuclearLevelData *)
G4DeexPrecoParameters * GetParameters()
static G4Pow * GetInstance()
Definition G4Pow.cc:41
G4double logZ(G4int Z) const
Definition G4Pow.hh:137
#define N
Definition crc32.c:57
int G4lrint(double ad)
Definition templates.hh:134
#define DBL_MAX
Definition templates.hh:62