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