Geant4  10.02.p02
G4NeutronCaptureXS.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: G4NeutronCaptureXS.cc 91903 2015-08-10 12:10:36Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class file
31 //
32 //
33 // File name: G4NeutronCaptureXS
34 //
35 // Author Ivantchenko, Geant4, 3-Aug-09
36 //
37 // Modifications:
38 //
39 
40 #include <fstream>
41 #include <sstream>
42 
43 #include "G4SystemOfUnits.hh"
44 #include "G4NeutronCaptureXS.hh"
45 #include "G4Element.hh"
46 #include "G4ElementTable.hh"
47 #include "G4PhysicsLogVector.hh"
48 #include "G4PhysicsVector.hh"
49 #include "G4DynamicParticle.hh"
50 #include "Randomize.hh"
51 
52 // factory
53 #include "G4CrossSectionFactory.hh"
54 //
56 
57 using namespace std;
58 
60  0,
61  0, 0, 6, 0,10,12,14,16, 0, 0, //1-10
62  0, 0, 0,28, 0, 0, 0,36, 0,40, //11-20
63  0, 0, 0, 0, 0,54, 0,58,63,64, //21-30
64  0,70, 0, 0, 0, 0, 0, 0, 0,90, //31-40
65  0, 0, 0, 0, 0, 0,107,106, 0,112, //41-50
66  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //51-60
67  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //61-70
68  0, 0, 0,180, 0, 0, 0, 0, 0, 0, //71-80
69  0,204, 0, 0, 0, 0, 0, 0, 0, 0, //81-90
70  0,235};
72  0,
73  0, 0, 7, 0,11,13,15,18, 0, 0, //1-10
74  0, 0, 0,30, 0, 0, 0,40, 0,48, //11-20
75  0, 0, 0, 0, 0,58, 0,64,65,70, //21-30
76  0,76, 0, 0, 0, 0, 0, 0, 0,96, //31-40
77  0, 0, 0, 0, 0, 0,109,116, 0,124, //41-50
78  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //51-60
79  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //61-70
80  0, 0, 0,186, 0, 0, 0, 0, 0, 0, //71-80
81  0,208, 0, 0, 0, 0, 0, 0, 0, 0, //81-90
82  0,238};
83 
85 
87  : G4VCrossSectionDataSet(Default_Name()),
88  emax(20*MeV),elimit(1.0e-10*eV)
89 {
90  // verboseLevel = 0;
91  if(verboseLevel > 0){
92  G4cout << "G4NeutronCaptureXS::G4NeutronCaptureXS: Initialise for Z < "
93  << MAXZCAPTURE << G4endl;
94  }
95  isMaster = false;
96 }
97 
99 {
100  if(isMaster) { delete data; data = 0; }
101 }
102 
103 void G4NeutronCaptureXS::CrossSectionDescription(std::ostream& outFile) const
104 {
105  outFile << "G4NeutronCaptureXS calculates the neutron capture cross sections\n"
106  << "on nuclei using data from the high precision neutron database.\n"
107  << "These data are simplified and smoothed over the resonance region\n"
108  << "in order to reduce CPU time. G4NeutronCaptureXS is valid up to\n"
109  << "20 MeV for all targets through U.\n";
110 }
111 
112 G4bool
114  G4int, const G4Material*)
115 {
116  return true;
117 }
118 
119 G4bool
121  G4int /*ZZ*/, G4int /*AA*/,
122  const G4Element*, const G4Material*)
123 {
124  return true;
125 }
126 
127 G4double
129  G4int Z, const G4Material*)
130 {
131  G4double xs = 0.0;
132  G4double ekin = aParticle->GetKineticEnergy();
133  if(ekin > emax || Z < 1 || Z >= MAXZCAPTURE) { return xs; }
134  if(ekin < elimit) { ekin = elimit; }
135 
136  // element was not initialised
138  if(!pv) {
139  Initialise(Z);
140  pv = data->GetElementData(Z);
141  if(!pv) { return xs; }
142  }
143 
144  G4double e1 = pv->Energy(0);
145  if(ekin < e1) { xs = (*pv)[0]*std::sqrt(e1/ekin); }
146  else if(ekin <= pv->GetMaxEnergy()) { xs = pv->Value(ekin); }
147 
148  if(verboseLevel > 0){
149  G4cout << "ekin= " << ekin << ", xs= " << xs << G4endl;
150  }
151  return xs;
152 }
153 
154 G4double
156  G4int Z, G4int A,
157  const G4Isotope*, const G4Element*,
158  const G4Material*)
159 {
160  G4double xs = 0.0;
161  G4double ekin = aParticle->GetKineticEnergy();
162  if(ekin <= emax && Z > 0 && Z < MAXZCAPTURE) {
163  xs = IsoCrossSection(ekin, Z, A);
164  }
165  return xs;
166 }
167 
169 {
170  G4double xs = 0.0;
171  if(ekin < elimit) { ekin = elimit; }
172 
173  // element was not initialised
175  if(!pv) {
176  Initialise(Z);
177  pv = data->GetElementData(Z);
178  }
179 
180  // isotope cross section exist
181  if(pv && amin[Z] > 0 && A >= amin[Z] && A <= amax[Z]) {
182  pv = data->GetComponentDataByID(Z, A - amin[Z]);
183  if(pv) {
184 
185  G4double e1 = pv->Energy(1);
186  if(ekin < e1) { xs = (*pv)[1]*std::sqrt(e1/ekin); }
187  else if(ekin <= pv->GetMaxEnergy()) { xs = pv->Value(ekin); }
188  }
189  }
190  if(verboseLevel > 0) {
191  G4cout << "G4NeutronCaptureXS::IsoCrossSection: Ekin(MeV)= " << ekin/MeV
192  << " xs(b)= " << xs/barn
193  << " Z= " << Z << " A= " << A << G4endl;
194  }
195  return xs;
196 }
197 
199  G4double kinEnergy)
200 {
201  size_t nIso = anElement->GetNumberOfIsotopes();
202  G4IsotopeVector* isoVector = anElement->GetIsotopeVector();
203  G4Isotope* iso = (*isoVector)[0];
204 
205  // more than 1 isotope
206  if(1 < nIso) {
207  G4int Z = G4lrint(anElement->GetZ());
208 
209  G4double* abundVector = anElement->GetRelativeAbundanceVector();
210  G4double q = G4UniformRand();
211  G4double sum = 0.0;
212 
213  // is there isotope wise cross section?
214  size_t j;
215  if(0 == amin[Z] || Z >= MAXZCAPTURE) {
216  for (j = 0; j<nIso; ++j) {
217  sum += abundVector[j];
218  if(q <= sum) {
219  iso = (*isoVector)[j];
220  break;
221  }
222  }
223  } else {
224 
225  // element may be not initialised in unit test
226  if(!data->GetElementData(Z)) { Initialise(Z); }
227  size_t nn = temp.size();
228  if(nn < nIso) { temp.resize(nIso, 0.); }
229 
230  for (j=0; j<nIso; ++j) {
231  sum += abundVector[j]*IsoCrossSection(kinEnergy, Z,
232  (*isoVector)[j]->GetN());
233  temp[j] = sum;
234  }
235  sum *= q;
236  for (j = 0; j<nIso; ++j) {
237  if(temp[j] >= sum) {
238  iso = (*isoVector)[j];
239  break;
240  }
241  }
242  }
243  }
244  return iso;
245 }
246 
247 void
249 {
250  if(verboseLevel > 0){
251  G4cout << "G4NeutronCaptureXS::BuildPhysicsTable for "
252  << p.GetParticleName() << G4endl;
253  }
254  if(p.GetParticleName() != "neutron") {
256  ed << p.GetParticleName() << " is a wrong particle type -"
257  << " only neutron is allowed";
258  G4Exception("G4NeutronCaptureXS::BuildPhysicsTable(..)","had012",
259  FatalException, ed, "");
260  return;
261  }
262 
263  if(!data) {
264  isMaster = true;
265  data = new G4ElementData();
266  data->SetName("NeutronCapture");
267  temp.resize(13,0.0);
268  }
269 
270  // it is possible re-initialisation for the second run
271  if(isMaster) {
272 
273  // check environment variable
274  // Build the complete string identifying the file with the data set
275  char* path = getenv("G4NEUTRONXSDATA");
276 
277  // Access to elements
278  const G4ElementTable* theElmTable = G4Element::GetElementTable();
279  size_t numOfElm = G4Element::GetNumberOfElements();
280  if(numOfElm > 0) {
281  for(size_t i=0; i<numOfElm; ++i) {
282  G4int Z = G4int(((*theElmTable)[i])->GetZ());
283  if(Z < 1) { Z = 1; }
284  else if(Z >= MAXZCAPTURE) { Z = MAXZCAPTURE-1; }
285  //G4cout << "Z= " << Z << G4endl;
286  // Initialisation
287  if(!data->GetElementData(Z)) { Initialise(Z, path); }
288  }
289  }
290  }
291 }
292 
293 void
295 {
296  if(data->GetElementData(Z) || Z < 1 || Z >= MAXZCAPTURE) { return; }
297  const char* path = p;
298 
299  // check environment variable
300  if(!p) {
301  path = getenv("G4NEUTRONXSDATA");
302  if (!path) {
303  G4Exception("G4NeutronCaptureXS::Initialise(..)","had013",FatalException,
304  "Environment variable G4NEUTRONXSDATA is not defined");
305  return;
306  }
307  }
308 
309  // upload element data
310  std::ostringstream ost;
311  ost << path << "/cap" << Z ;
312  G4PhysicsVector* v = RetrieveVector(ost, true);
313  data->InitialiseForElement(Z, v);
314 
315  // upload isotope data
316  if(amin[Z] > 0) {
317  size_t nmax = (size_t)(amax[Z]-amin[Z]+1);
318  data->InitialiseForComponent(Z, nmax);
319 
320  for(G4int A=amin[Z]; A<=amax[Z]; ++A) {
321  std::ostringstream ost1;
322  ost1 << path << "/cap" << Z << "_" << A;
323  v = RetrieveVector(ost1, false);
324  data->AddComponent(Z, A, v);
325  }
326  }
327 }
328 
330 G4NeutronCaptureXS::RetrieveVector(std::ostringstream& ost, G4bool warn)
331 {
332  G4PhysicsLogVector* v = 0;
333  std::ifstream filein(ost.str().c_str());
334  if (!(filein)) {
335  if(warn) {
337  ed << "Data file <" << ost.str().c_str()
338  << "> is not opened!";
339  G4Exception("G4NeutronCaptureXS::RetrieveVector(..)","had014",
340  FatalException, ed, "Check G4NEUTRONXSDATA");
341  }
342  } else {
343  if(verboseLevel > 1) {
344  G4cout << "File " << ost.str()
345  << " is opened by G4NeutronCaptureXS" << G4endl;
346  }
347  // retrieve data from DB
348  v = new G4PhysicsLogVector();
349  if(!v->Retrieve(filein, true)) {
351  ed << "Data file <" << ost.str().c_str()
352  << "> is not retrieved!";
353  G4Exception("G4NeutronCaptureXS::RetrieveVector(..)","had015",
354  FatalException, ed, "Check G4NEUTRONXSDATA");
355  }
356  }
357  return v;
358 }
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
static const G4int amin[MAXZCAPTURE]
static const double MeV
Definition: G4SIunits.hh:211
G4PhysicsVector * RetrieveVector(std::ostringstream &in, G4bool warn)
virtual G4bool Retrieve(std::ifstream &fIn, G4bool ascii)
std::vector< G4Isotope * > G4IsotopeVector
void AddComponent(G4int Z, G4int id, G4PhysicsVector *v)
virtual G4double GetElementCrossSection(const G4DynamicParticle *, G4int Z, const G4Material *mat=0)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetKineticEnergy() const
virtual G4double GetIsoCrossSection(const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *iso, const G4Element *elm, const G4Material *mat)
G4PhysicsVector * GetComponentDataByID(G4int Z, G4int id)
std::vector< G4double > temp
G4PhysicsVector * GetElementData(G4int Z)
G4double GetZ() const
Definition: G4Element.hh:131
virtual G4bool IsElementApplicable(const G4DynamicParticle *, G4int Z, const G4Material *)
const G4int MAXZCAPTURE
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
void InitialiseForElement(G4int Z, G4PhysicsVector *v)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
static size_t GetNumberOfElements()
Definition: G4Element.cc:402
bool G4bool
Definition: G4Types.hh:79
void Initialise(G4int Z, const char *=0)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
const G4int nmax
G4double Energy(size_t index) const
G4double Value(G4double theEnergy, size_t &lastidx) const
G4_DECLARE_XS_FACTORY(G4NeutronCaptureXS)
G4double IsoCrossSection(G4double ekin, G4int Z, G4int A)
virtual void CrossSectionDescription(std::ostream &) const
static const G4double e1
virtual G4Isotope * SelectIsotope(const G4Element *, G4double kinEnergy)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const G4double emax
virtual G4bool IsIsoApplicable(const G4DynamicParticle *, G4int Z, G4int A, const G4Element *, const G4Material *)
static const double eV
Definition: G4SIunits.hh:212
G4IsotopeVector * GetIsotopeVector() const
Definition: G4Element.hh:162
int G4lrint(double ad)
Definition: templates.hh:163
static const G4int amax[MAXZCAPTURE]
#define G4endl
Definition: G4ios.hh:61
static const double barn
Definition: G4SIunits.hh:104
void SetName(const G4String &nam)
std::vector< G4Element * > G4ElementTable
double G4double
Definition: G4Types.hh:76
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:395
void InitialiseForComponent(G4int Z, G4int nComponents=0)
static G4ElementData * data