Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4INCLNuclearMassTable.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 // INCL++ intra-nuclear cascade model
27 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28 // Davide Mancusi, CEA
29 // Alain Boudard, CEA
30 // Sylvie Leray, CEA
31 // Joseph Cugnon, University of Liege
32 //
33 #define INCLXX_IN_GEANT4_MODE 1
34 
35 #include "globals.hh"
36 
37 /** \file G4INCLNuclearMassTable.cc
38  * \brief Functions that encapsulate a mass table
39  *
40  * \date 22nd October 2013
41  * \author Davide Mancusi
42  */
43 
44 #ifndef INCLXX_IN_GEANT4_MODE
45 
47 #include "G4INCLParticleTable.hh"
48 #include "G4INCLGlobals.hh"
49 #include <algorithm>
50 #include <istream>
51 
52 namespace G4INCL {
53 
54  namespace {
55 
56  G4ThreadLocal G4double **theTable = NULL;
57  G4ThreadLocal G4int AMax = 0;
58  G4ThreadLocal G4int *ZMaxArray = NULL;
59  G4ThreadLocal G4double protonMass = 0.;
60  G4ThreadLocal G4double neutronMass = 0.;
61 
62  const G4double amu = 931.494061; // atomic mass unit in MeV/c^2
63  const G4double eMass = 0.5109988; // electron mass in MeV/c^2
64 
65  G4double getWeizsaeckerMass(const G4int A, const G4int Z) {
66  const G4int Npairing = (A-Z)%2; // pairing
67  const G4int Zpairing = Z%2;
68  const G4double fA = (G4double) A;
69  const G4double fZ = (G4double) Z;
71  - 15.67*fA // nuclear volume
72  + 17.23*Math::pow23(fA) // surface energy
73  + 93.15*((fA/2.-fZ)*(fA/2.-fZ))/fA // asymmetry
74  + 0.6984523*fZ*fZ*Math::powMinus13(fA); // coulomb
75  if( Npairing == Zpairing ) binding += (Npairing+Zpairing-1) * 12.0 / std::sqrt(fA); // pairing
76 
79  }
80 
81  void setMass(const G4int A, const G4int Z, const G4double mass) {
82  theTable[A][Z] = mass;
83  }
84 
85  class MassRecord {
86  public:
87  MassRecord() :
88  A(0),
89  Z(0),
90  excess(0.)
91  {}
92 
93  MassRecord(const G4int a, const G4int z, const G4double e) :
94  A(a),
95  Z(z),
96  excess(e)
97  {}
98 
99  friend std::istream &operator>>(std::istream &in, MassRecord &record);
100 
101  G4int A;
102  G4int Z;
103  G4double excess;
104  };
105 
106  std::istream &operator>>(std::istream &in, MassRecord &record) {
107  return (in >> record.A >> record.Z >> record.excess);
108  }
109 
110  G4bool compareA(const MassRecord &lhs, const MassRecord &rhs) {
111  return (lhs.A < rhs.A);
112  }
113 
114  }
115 
116  namespace NuclearMassTable {
117 
118  void initialize(const std::string &path, const G4double pMass, const G4double nMass) {
119  protonMass = pMass;
120  neutronMass = nMass;
121 
122  // Clear the existing tables, if any
123  deleteTable();
124 
125  // File name
126  std::string fileName(path + "/walletlifetime.dat");
127  INCL_DEBUG("Reading real nuclear masses from file " << fileName << std::endl);
128 
129  // Open the file stream
130  std::ifstream massTableIn(fileName.c_str());
131  if(!massTableIn.good()) {
132  std::cerr << "Cannot open " << fileName << " data file." << std::endl;
133  std::abort();
134  return;
135  }
136 
137  // read the file
138  std::vector<MassRecord> records;
139  MassRecord record;
140  while(massTableIn.good()) {
141  massTableIn >> record;
142  records.push_back(record);
143  }
144  massTableIn.close();
145  INCL_DEBUG("Read " << records.size() << " nuclear masses" << std::endl);
146 
147  // determine the max A
148  AMax = std::max_element(records.begin(), records.end(), compareA)->A;
149  INCL_DEBUG("Max A in nuclear-mass table = " << AMax << std::endl);
150  ZMaxArray = new G4int[AMax+1];
151  std::fill(ZMaxArray, ZMaxArray+AMax+1, 0);
152  theTable = new G4double*[AMax+1];
153  std::fill(theTable, theTable+AMax+1, static_cast<G4double*>(NULL));
154 
155  // determine the max A per Z
156  for(std::vector<MassRecord>::const_iterator i=records.begin(), e=records.end(); i!=e; ++i) {
157  ZMaxArray[i->A] = std::max(ZMaxArray[i->A], i->Z);
158  }
159 
160  // allocate the arrays
161  for(G4int A=1; A<=AMax; ++A) {
162  theTable[A] = new G4double[ZMaxArray[A]+1];
163  std::fill(theTable[A], theTable[A]+ZMaxArray[A]+1, -1.);
164  }
165 
166  // fill the actual masses
167  for(std::vector<MassRecord>::const_iterator i=records.begin(), e=records.end(); i!=e; ++i) {
168  setMass(i->A, i->Z, i->A*amu + i->excess - i->Z*eMass);
169  }
170  }
171 
172  G4double getMass(const G4int A, const G4int Z) {
173  if(A>AMax || Z>ZMaxArray[A]) {
174  INCL_DEBUG("Real mass unavailable for isotope A=" << A << ", Z=" << Z
175  << ", using Weizsaecker's formula"
176  << std::endl);
177  return getWeizsaeckerMass(A,Z);
178  }
179 
180  const G4double mass = theTable[A][Z];
181  if(mass<0.) {
182  INCL_DEBUG("Real mass unavailable for isotope A=" << A << ", Z=" << Z
183  << ", using Weizsaecker's formula"
184  << std::endl);
185  return getWeizsaeckerMass(A,Z);
186  } else
187  return mass;
188  }
189 
190  void deleteTable() {
191  delete[] ZMaxArray;
192  ZMaxArray = NULL;
193  for(G4int A=1; A<=AMax; ++A)
194  delete[] theTable[A];
195  delete[] theTable;
196  theTable = NULL;
197  }
198  }
199 
200 }
201 
202 #endif // INCLXX_IN_GEANT4_MODE
G4double z
Definition: TRTMaterials.hh:39
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
G4double pow23(G4double x)
G4double getRealMass(const G4INCL::ParticleType t)
Get particle mass (in MeV/c^2)
bool G4bool
Definition: G4Types.hh:79
Functions that encapsulate a mass table.
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:120
double G4double
Definition: G4Types.hh:76
#define INCL_DEBUG(x)
G4double powMinus13(G4double x)
void initialize(Config const *const theConfig=0)
Initialize the particle table.