Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NeutronElasticXS.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// GEANT4 Class file
29//
30//
31// File name: G4NeutronElasticXS
32//
33// Author Ivantchenko, Geant4, 3-Aug-09
34//
35// Modifications:
36//
37
38#include "G4NeutronElasticXS.hh"
39#include "G4Neutron.hh"
40#include "G4DynamicParticle.hh"
42#include "G4Material.hh"
43#include "G4Element.hh"
44#include "G4PhysicsLogVector.hh"
47#include "Randomize.hh"
48#include "G4SystemOfUnits.hh"
49#include "G4IsotopeList.hh"
50
51#include <fstream>
52#include <sstream>
53
54// factory
56//
58
59G4PhysicsVector* G4NeutronElasticXS::data[] = {nullptr};
60G4double G4NeutronElasticXS::coeff[] = {0.0};
61G4String G4NeutronElasticXS::gDataDirectory = "";
62
63#ifdef G4MULTITHREADED
64 G4Mutex G4NeutronElasticXS::neutronElasticXSMutex = G4MUTEX_INITIALIZER;
65#endif
66
68 : G4VCrossSectionDataSet(Default_Name()),
69 ggXsection(nullptr),
70 neutron(G4Neutron::Neutron()),
71 isMaster(false)
72{
73 // verboseLevel = 0;
74 if(verboseLevel > 0){
75 G4cout << "G4NeutronElasticXS::G4NeutronElasticXS Initialise for Z < "
76 << MAXZEL << G4endl;
77 }
79 if(ggXsection == nullptr) ggXsection = new G4ComponentGGHadronNucleusXsc();
81}
82
84{
85 if(isMaster) {
86 for(G4int i=0; i<MAXZEL; ++i) {
87 delete data[i];
88 data[i] = nullptr;
89 }
90 }
91}
92
93void G4NeutronElasticXS::CrossSectionDescription(std::ostream& outFile) const
94{
95 outFile << "G4NeutronElasticXS calculates the neutron elastic scattering\n"
96 << "cross section on nuclei using data from the high precision\n"
97 << "neutron database. These data are simplified and smoothed over\n"
98 << "the resonance region in order to reduce CPU time.\n"
99 << "For high energies Glauber-Gribiv cross section is used.\n";
100}
101
102G4bool
104 G4int, const G4Material*)
105{
106 return true;
107}
108
110 G4int, G4int,
111 const G4Element*, const G4Material*)
112{
113 return true;
114}
115
118 G4int ZZ, const G4Material*)
119{
120 G4double xs = 0.0;
121 G4double ekin = aParticle->GetKineticEnergy();
122
123 G4int Z = (ZZ >= MAXZEL) ? MAXZEL - 1 : ZZ;
124
125 auto pv = GetPhysicsVector(Z);
126 if(pv == nullptr) { return xs; }
127 // G4cout << "G4NeutronElasticXS::GetCrossSection e= " << ekin
128 // << " Z= " << Z << G4endl;
129
130 if(ekin <= pv->Energy(1)) {
131 xs = (*pv)[1];
132 } else if(ekin <= pv->GetMaxEnergy()) {
133 xs = pv->LogVectorValue(ekin, aParticle->GetLogKineticEnergy());
134 } else {
135 xs = coeff[Z]*ggXsection->GetElasticElementCrossSection(neutron,
136 ekin, Z, aeff[Z]);
137 }
138
139#ifdef G4VERBOSE
140 if(verboseLevel > 1) {
141 G4cout << "Z= " << Z << " Ekin(MeV)= " << ekin/CLHEP::MeV
142 << ", nElmXSel(b)= " << xs/CLHEP::barn
143 << G4endl;
144 }
145#endif
146 return xs;
147}
148
150 const G4DynamicParticle* aParticle,
151 G4int Z, G4int A,
152 const G4Isotope*, const G4Element*,
153 const G4Material* mat)
154{
155 return GetElementCrossSection(aParticle, Z, mat) * A/aeff[Z];
156}
157
159 const G4Element* anElement, G4double, G4double)
160{
161 size_t nIso = anElement->GetNumberOfIsotopes();
162 const G4Isotope* iso = anElement->GetIsotope(0);
163
164 //G4cout << "SelectIsotope NIso= " << nIso << G4endl;
165 if(1 == nIso) { return iso; }
166
167 const G4double* abundVector = anElement->GetRelativeAbundanceVector();
169 G4double sum = 0.0;
170 size_t j;
171
172 // isotope wise cross section not used
173 for (j=0; j<nIso; ++j) {
174 sum += abundVector[j];
175 if(q <= sum) {
176 iso = anElement->GetIsotope(j);
177 break;
178 }
179 }
180 return iso;
181}
182
183void
185{
186 if(verboseLevel > 0){
187 G4cout << "G4NeutronElasticXS::BuildPhysicsTable for "
188 << p.GetParticleName() << G4endl;
189 }
190 if(p.GetParticleName() != "neutron") {
192 ed << p.GetParticleName() << " is a wrong particle type -"
193 << " only neutron is allowed";
194 G4Exception("G4NeutronElasticXS::BuildPhysicsTable(..)","had012",
195 FatalException, ed, "");
196 return;
197 }
198 if(0. == coeff[0]) {
199#ifdef G4MULTITHREADED
200 G4MUTEXLOCK(&neutronElasticXSMutex);
201 if(0. == coeff[0]) {
202#endif
203 coeff[0] = 1.0;
204 isMaster = true;
205 FindDirectoryPath();
206#ifdef G4MULTITHREADED
207 }
208 G4MUTEXUNLOCK(&neutronElasticXSMutex);
209#endif
210 }
211
212 // it is possible re-initialisation for the second run
213 if(isMaster) {
214
215 // Access to elements
216 auto theCoupleTable = G4ProductionCutsTable::GetProductionCutsTable();
217 size_t numOfCouples = theCoupleTable->GetTableSize();
218 for(size_t j=0; j<numOfCouples; ++j) {
219 auto mat = theCoupleTable->GetMaterialCutsCouple(j)->GetMaterial();
220 auto elmVec = mat->GetElementVector();
221 size_t numOfElem = mat->GetNumberOfElements();
222 for (size_t ie = 0; ie < numOfElem; ++ie) {
223 G4int Z = std::max(1,std::min(((*elmVec)[ie])->GetZasInt(), MAXZEL-1));
224 if(data[Z] == nullptr) { Initialise(Z); }
225 }
226 }
227 }
228}
229
230const G4String& G4NeutronElasticXS::FindDirectoryPath()
231{
232 // check environment variable
233 // build the complete string identifying the file with the data set
234 if(gDataDirectory.empty()) {
235 char* path = std::getenv("G4PARTICLEXSDATA");
236 if (path) {
237 std::ostringstream ost;
238 ost << path << "/neutron/el";
239 gDataDirectory = ost.str();
240 } else {
241 G4Exception("G4NeutronElasticXS::Initialise(..)","had013",
243 "Environment variable G4PARTICLEXSDATA is not defined");
244 }
245 }
246 return gDataDirectory;
247}
248
249void G4NeutronElasticXS::InitialiseOnFly(G4int Z)
250{
251#ifdef G4MULTITHREADED
252 G4MUTEXLOCK(&neutronElasticXSMutex);
253 if(data[Z] == nullptr) {
254#endif
255 Initialise(Z);
256#ifdef G4MULTITHREADED
257 }
258 G4MUTEXUNLOCK(&neutronElasticXSMutex);
259#endif
260}
261
262void G4NeutronElasticXS::Initialise(G4int Z)
263{
264 if(data[Z] != nullptr) { return; }
265
266 // upload data from file
267 data[Z] = new G4PhysicsLogVector();
268
269 std::ostringstream ost;
270 ost << FindDirectoryPath() << Z ;
271 std::ifstream filein(ost.str().c_str());
272 if (!(filein)) {
274 ed << "Data file <" << ost.str().c_str()
275 << "> is not opened!";
276 G4Exception("G4NeutronElasticXS::Initialise(..)","had014",
277 FatalException, ed, "Check G4PARTICLEXSDATA");
278 return;
279 }
280 if(verboseLevel > 1) {
281 G4cout << "file " << ost.str()
282 << " is opened by G4NeutronElasticXS" << G4endl;
283 }
284
285 // retrieve data from DB
286 if(!data[Z]->Retrieve(filein, true)) {
288 ed << "Data file <" << ost.str().c_str()
289 << "> is not retrieved!";
290 G4Exception("G4NeutronElasticXS::Initialise(..)","had015",
291 FatalException, ed, "Check G4PARTICLEXSDATA");
292 return;
293 }
294 // smooth transition
295 G4double sig1 = (*(data[Z]))[data[Z]->GetVectorLength()-1];
296 G4double ehigh = data[Z]->GetMaxEnergy();
297 G4double sig2 = ggXsection->GetElasticElementCrossSection(neutron,
298 ehigh, Z, aeff[Z]);
299 coeff[Z] = (sig2 > 0.) ? sig1/sig2 : 1.0;
300}
#define G4_DECLARE_XS_FACTORY(cross_section)
double A(double temperature)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
const G4int MAXZEL
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:52
G4VComponentCrossSection * GetComponentCrossSection(const G4String &name)
static G4CrossSectionDataSetRegistry * Instance()
G4double GetLogKineticEnergy() const
G4double GetKineticEnergy() const
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:169
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
G4bool IsElementApplicable(const G4DynamicParticle *, G4int Z, const G4Material *) final
G4double GetIsoCrossSection(const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *iso, const G4Element *elm, const G4Material *mat) final
void BuildPhysicsTable(const G4ParticleDefinition &) final
G4bool IsIsoApplicable(const G4DynamicParticle *, G4int Z, G4int A, const G4Element *, const G4Material *) final
const G4Isotope * SelectIsotope(const G4Element *, G4double kinEnergy, G4double logE) final
void CrossSectionDescription(std::ostream &) const final
G4double GetElementCrossSection(const G4DynamicParticle *, G4int Z, const G4Material *) final
const G4String & GetParticleName() const
G4double GetMaxEnergy() const
std::size_t GetVectorLength() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4double GetElasticElementCrossSection(const G4ParticleDefinition *, G4double kinEnergy, const G4Element *)
void SetForAllAtomsAndEnergies(G4bool val)