ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LevelReader.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4LevelReader.cc
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"
45 #include "G4DeexPrecoParameters.hh"
46 #include "G4SystemOfUnits.hh"
47 #include "G4Pow.hh"
48 #include <vector>
49 #include <fstream>
50 #include <sstream>
51 
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;
61  char* directory = std::getenv("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 
93 G4bool G4LevelReader::ReadData(std::istringstream& stream, G4double& x)
94 {
95  stream >> x;
96  return stream.fail() ? false : true;
97 }
98 
99 G4bool 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 
111 G4bool 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 
123 G4bool 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 
135 G4bool 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 
146 const 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  G4int prec = G4cout.precision(3);
198  G4cout << "# InternalConv: ";
199  G4int nn = vec->size();
200  for(G4int i=0; i<nn; ++i) { G4cout << " " << (*vec)[i]; }
201  G4cout << G4endl;
202  G4cout.precision(prec);
203  }
204  }
205  return vec;
206 }
207 
208 const 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 
218 const 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 
233 const G4LevelManager*
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  vSpin[i] = (G4int)(100 + fSpin + fSpin) + k*100000;
323  if(fVerbose > 2) {
324  G4cout << " Level #" << i1 << " E(MeV)= " << ener/CLHEP::MeV
325  << " LTime(s)= " << fTime << " 2S= " << vSpin[i]
326  << " meta= " << vSpin[i]/100000 << " idx= " << i
327  << " ntr= " << ntrans << G4endl;
328  }
329  vLevel[i] = nullptr;
330  if(ntrans == 0 && fTime < 0.0) {
331  vLevel[i] = new G4NucLevel(0, fTime,
332  vTrans,
335  vRatio,
337  } else if(ntrans > 0) {
338 
339  // there are transitions
340  if(ntrans > fTransMax) {
341  fTransMax = ntrans;
342  vTrans.resize(fTransMax);
343  vRatio.resize(fTransMax);
347  }
348  fNorm1 = 0.0f;
349  for(G4int j=0; j<ntrans; ++j) {
350 
351  if(!(ReadDataItem(infile,i2) &&
352  ReadDataItem(infile,tener) &&
353  ReadDataItem(infile,fProb) &&
354  ReadDataItem(infile,tnum) &&
355  ReadDataItem(infile,vRatio[j]) &&
356  ReadDataItem(infile,fAlpha))) {
357  //infile >>i2 >> tener >> fProb >> vTrans[j] >> fRatio >> fAlpha;
358  //if(infile.fail()) {
359  if(fVerbose > 1) {
360  G4cout << "### Fail to read transition j= " << j
361  << " Z= " << Z << " A= " << A << G4endl;
362  }
363  break;
364  }
365  if(i2 >= i) {
366  G4cout << "### G4LevelReader: broken transition " << j
367  << " from level " << i << " to " << i2
368  << " for isotope Z= " << Z << " A= "
369  << A << " - use ground level" << G4endl;
370  i2 = 0;
371  }
372  vTrans[j] = i2*10000 + tnum;
374  G4float x = 1.0f + fAlpha;
375  fNorm1 += x*fProb;
377  vGammaProbability[j] = 1.0f/x;
378  vShellProbability[j] = nullptr;
379  if(fVerbose > 2) {
380  G4int prec = G4cout.precision(4);
381  G4cout << "### Transition #" << j << " to level " << i2
382  << " i2= " << i2 << " Etrans(MeV)= " << tener*CLHEP::keV
383  << " fProb= " << fProb << " MultiP= " << tnum
384  << " fMpRatio= " << fRatio << " fAlpha= " << fAlpha
385  << G4endl;
386  G4cout.precision(prec);
387  }
388  if(fAlpha > 0.0f) {
389  for(k=0; k<10; ++k) {
390  //infile >> fICC[k];
391  if(!ReadDataItem(infile,fICC[k])) {
392  //if(infile.fail()) {
393  if(fVerbose > 1) {
394  G4cout << "### Fail to read convertion coeff k= " << k
395  << " for transition j= " << j
396  << " Z= " << Z << " A= " << A << G4endl;
397  }
398  for(kk=k; kk<10; ++kk) { fICC[kk] = 0.f; }
399  break;
400  }
401  }
402  if(allLevels) {
404  if(!vShellProbability[j]) { vGammaProbability[j] = 1.0f; }
405  }
406  }
407  }
408  if(0.0f < fNorm1) { fNorm1 = 1.0f/fNorm1; }
409  G4int nt = ntrans - 1;
410  for(k=0; k<nt; ++k) {
412  if(fVerbose > 3) {
413  G4cout << "Probabilities[" << k
414  << "]= " << vGammaCumProbability[k]
415  << " " << vGammaProbability[k]
416  << " idxTrans= " << vTrans[k]/10000
417  << G4endl;
418  }
419  }
420  vGammaCumProbability[nt] = 1.0f;
421  if(fVerbose > 3) {
422  G4cout << "Probabilities[" << nt << "]= "
423  << vGammaCumProbability[nt]
424  << " " << vGammaProbability[nt]
425  << " IdxTrans= " << vTrans[nt]/10000
426  << G4endl;
427  }
428  if(fVerbose > 2) {
429  G4cout << " New G4NucLevel: Ntrans= " << ntrans
430  << " Time(ns)= " << fTime << G4endl;
431  }
432  vLevel[i] = new G4NucLevel((size_t)ntrans, fTime,
433  vTrans,
436  vRatio,
438  }
439  }
440  G4LevelManager* lman = nullptr;
441  if(1 <= i) {
442  lman = new G4LevelManager(Z, A, (size_t)i,vEnergy,vSpin,vLevel);
443  if(fVerbose > 1) {
444  G4cout << "=== Reader: new manager for Z= " << Z << " A= " << A
445  << " Nlevels= " << i << " E[0]= "
446  << vEnergy[0]/CLHEP::MeV << " MeV E1= "
447  << vEnergy[i-1]/CLHEP::MeV << " MeV "
448  << G4endl;
449  }
450  }
451 
452  return lman;
453 }