Geant4  10.01.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 83697 2014-09-10 07:15:29Z 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 
137 
138  // element was not initialised
139  if(!pv) {
140  Initialise(Z);
141  pv = data->GetElementData(Z);
142  if(!pv) { return xs; }
143  }
144 
145  G4double e1 = pv->Energy(0);
146  if(ekin < e1) { xs = (*pv)[0]*std::sqrt(e1/ekin); }
147  else if(ekin <= pv->GetMaxEnergy()) { xs = pv->Value(ekin); }
148 
149  if(verboseLevel > 0){
150  G4cout << "ekin= " << ekin << ", xs= " << xs << G4endl;
151  }
152  return xs;
153 }
154 
155 G4double
157  G4int Z, G4int A,
158  const G4Isotope*, const G4Element*,
159  const G4Material*)
160 {
161  G4double xs = 0.0;
162  G4double ekin = aParticle->GetKineticEnergy();
163  if(ekin <= emax && Z > 0 && Z < MAXZCAPTURE) {
164  xs = IsoCrossSection(ekin, Z, A);
165  }
166  return xs;
167 }
168 
170 {
171  G4double xs = 0.0;
172  if(ekin < elimit) { ekin = elimit; }
173 
175 
176  // element was not initialised
177  if(!pv) {
178  Initialise(Z);
179  pv = data->GetElementData(Z);
180  if(!pv) { return xs; }
181  }
182  G4PhysicsVector* pviso = data->GetComponentDataByID(Z, A);
183  if(pviso) { pv = pviso; }
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  if(verboseLevel > 0){
190  G4cout << "G4NeutronCaptureXS::IsoCrossSection: Ekin(MeV)= " << ekin/MeV
191  << " xs(b)= " << xs/barn
192  << " Z= " << Z << " A= " << A << " " << pv->GetVectorLength()
193  << G4endl;
194  }
195  return xs;
196 }
197 
199  G4double kinEnergy)
200 {
201  G4int 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  if(Z >= MAXZCAPTURE) { Z = MAXZCAPTURE-1; }
209  G4double* abundVector = anElement->GetRelativeAbundanceVector();
210  G4double q = G4UniformRand();
211  G4double sum = 0.0;
212 
213  // is there isotope wise cross section?
214  if(0 == amin[Z]) {
215  for (G4int j = 0; j<nIso; ++j) {
216  sum += abundVector[j];
217  if(q <= sum) {
218  iso = (*isoVector)[j];
219  break;
220  }
221  }
222  } else {
223  size_t nmax = data->GetNumberOfComponents(Z);
224  if(temp.size() < nmax) { temp.resize(nmax,0.0); }
225  for (size_t i=0; i<nmax; ++i) {
226  G4int A = (*isoVector)[i]->GetN();
227  sum += abundVector[i]*IsoCrossSection(kinEnergy, Z, A);
228  temp[i] = sum;
229  }
230  sum *= q;
231  for (size_t j = 0; j<nmax; ++j) {
232  if(temp[j] >= sum) {
233  iso = (*isoVector)[j];
234  break;
235  }
236  }
237  }
238  }
239  return iso;
240 }
241 
242 void
244 {
245  if(verboseLevel > 0){
246  G4cout << "G4NeutronCaptureXS::BuildPhysicsTable for "
247  << p.GetParticleName() << G4endl;
248  }
249  if(p.GetParticleName() != "neutron") {
251  ed << p.GetParticleName() << " is a wrong particle type -"
252  << " only neutron is allowed";
253  G4Exception("G4NeutronCaptureXS::BuildPhysicsTable(..)","had012",
254  FatalException, ed, "");
255  return;
256  }
257 
258  if(!data) {
259  isMaster = true;
260  data = new G4ElementData();
261  data->SetName("NeutronCapture");
262  work.resize(13,0);
263  temp.resize(13,0.0);
264  }
265 
266  // it is possible re-initialisation for the second run
267  if(isMaster) {
268 
269  // check environment variable
270  // Build the complete string identifying the file with the data set
271  char* path = getenv("G4NEUTRONXSDATA");
272 
273  // Access to elements
274  const G4ElementTable* theElmTable = G4Element::GetElementTable();
275  size_t numOfElm = G4Element::GetNumberOfElements();
276  if(numOfElm > 0) {
277  for(size_t i=0; i<numOfElm; ++i) {
278  G4int Z = G4int(((*theElmTable)[i])->GetZ());
279  if(Z < 1) { Z = 1; }
280  else if(Z >= MAXZCAPTURE) { Z = MAXZCAPTURE-1; }
281  //G4cout << "Z= " << Z << G4endl;
282  // Initialisation
283  if(!data->GetElementData(Z)) { Initialise(Z, path); }
284  }
285  }
286  }
287 }
288 
289 void
291 {
292  if(data->GetElementData(Z)) { return; }
293  const char* path = p;
294 
295  // check environment variable
296  if(!p) {
297  path = getenv("G4NEUTRONXSDATA");
298  if (!path) {
299  G4Exception("G4NeutronCaptureXS::Initialise(..)","had013",FatalException,
300  "Environment variable G4NEUTRONXSDATA is not defined");
301  return;
302  }
303  }
304 
305  // upload element data
306  std::ostringstream ost;
307  ost << path << "/cap" << Z ;
308  G4PhysicsVector* v = RetrieveVector(ost, true);
309  data->InitialiseForElement(Z, v);
310 
311  // upload isotope data
312  if(amin[Z] > 0) {
313  size_t n = 0;
314  size_t i = 0;
315  size_t nmax = (size_t)(amax[Z]-amin[Z]+1);
316  if(work.size() < nmax) { work.resize(nmax,0); }
317  for(G4int A=amin[Z]; A<=amax[Z]; ++A) {
318  std::ostringstream ost1;
319  ost1 << path << "/cap" << Z << "_" << A;
320  v = RetrieveVector(ost1, false);
321  if(v) { ++n; }
322  work[i] = v;
323  ++i;
324  }
326  for(size_t j=0; j<i; ++j) {
327  if(work[j]) { data->AddComponent(Z, amin[Z]+j, work[j]); }
328  }
329  }
330 }
331 
333 G4NeutronCaptureXS::RetrieveVector(std::ostringstream& ost, G4bool warn)
334 {
335  G4PhysicsLogVector* v = 0;
336  std::ifstream filein(ost.str().c_str());
337  if (!(filein)) {
338  if(!warn) { return v; }
340  ed << "Data file <" << ost.str().c_str()
341  << "> is not opened!";
342  G4Exception("G4NeutronCaptureXS::RetrieveVector(..)","had014",
343  FatalException, ed, "Check G4NEUTRONXSDATA");
344  }else{
345  if(verboseLevel > 1) {
346  G4cout << "File " << ost.str()
347  << " is opened by G4NeutronCaptureXS" << G4endl;
348  }
349  // retrieve data from DB
350  v = new G4PhysicsLogVector();
351  if(!v->Retrieve(filein, true)) {
353  ed << "Data file <" << ost.str().c_str()
354  << "> is not retrieved!";
355  G4Exception("G4NeutronCaptureXS::RetrieveVector(..)","had015",
356  FatalException, ed, "Check G4NEUTRONXSDATA");
357  }
358  }
359  return v;
360 }
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
static const G4int amin[MAXZCAPTURE]
static const double MeV
Definition: G4SIunits.hh:193
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
size_t GetVectorLength() const
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:93
G4GLOB_DLL std::ostream G4cout
static size_t GetNumberOfElements()
Definition: G4Element.cc:410
bool G4bool
Definition: G4Types.hh:79
std::vector< G4PhysicsVector * > work
void Initialise(G4int Z, const char *=0)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
const G4int nmax
const G4int n
G4double Energy(size_t index) const
size_t GetNumberOfComponents(G4int Z)
G4double Value(G4double theEnergy, size_t &lastidx) const
static const G4double A[nN]
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
virtual G4bool IsIsoApplicable(const G4DynamicParticle *, G4int Z, G4int A, const G4Element *, const G4Material *)
static const double eV
Definition: G4SIunits.hh:194
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:95
void SetName(const G4String &nam)
std::vector< G4Element * > G4ElementTable
double G4double
Definition: G4Types.hh:76
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:403
void InitialiseForComponent(G4int Z, G4int nComponents=0)
static G4ElementData * data