Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CrossSectionDataStore Class Reference

#include <G4CrossSectionDataStore.hh>

Public Member Functions

 G4CrossSectionDataStore ()
 
 ~G4CrossSectionDataStore ()=default
 
G4double GetCrossSection (const G4DynamicParticle *, const G4Material *)
 
G4double ComputeCrossSection (const G4DynamicParticle *, const G4Material *)
 
G4double GetCrossSection (const G4DynamicParticle *, const G4Element *, const G4Material *)
 
G4double GetCrossSection (const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *, const G4Element *, const G4Material *)
 
const G4ElementSampleZandA (const G4DynamicParticle *, const G4Material *, G4Nucleus &target)
 
void BuildPhysicsTable (const G4ParticleDefinition &)
 
void DumpPhysicsTable (const G4ParticleDefinition &)
 
void DumpHtml (const G4ParticleDefinition &, std::ofstream &) const
 
void PrintCrossSectionHtml (const G4VCrossSectionDataSet *cs, const G4String &, const G4String &) const
 
void AddDataSet (G4VCrossSectionDataSet *)
 
void AddDataSet (G4VCrossSectionDataSet *, std::size_t)
 
const std::vector< G4VCrossSectionDataSet * > & GetDataSetList () const
 
void SetVerboseLevel (G4int value)
 
void SetForcedElement (const G4Element *)
 
G4CrossSectionDataStoreoperator= (const G4CrossSectionDataStore &right)=delete
 
 G4CrossSectionDataStore (const G4CrossSectionDataStore &)=delete
 

Detailed Description

Definition at line 61 of file G4CrossSectionDataStore.hh.

Constructor & Destructor Documentation

◆ G4CrossSectionDataStore() [1/2]

G4CrossSectionDataStore::G4CrossSectionDataStore ( )

Definition at line 62 of file G4CrossSectionDataStore.cc.

64{}
static G4NistManager * Instance()

◆ ~G4CrossSectionDataStore()

G4CrossSectionDataStore::~G4CrossSectionDataStore ( )
default

◆ G4CrossSectionDataStore() [2/2]

G4CrossSectionDataStore::G4CrossSectionDataStore ( const G4CrossSectionDataStore & )
delete

Member Function Documentation

◆ AddDataSet() [1/2]

void G4CrossSectionDataStore::AddDataSet ( G4VCrossSectionDataSet * p)

Definition at line 402 of file G4CrossSectionDataStore.cc.

403{
404 if(p->ForAllAtomsAndEnergies()) {
405 dataSetList.clear();
406 nDataSetList = 0;
407 }
408 dataSetList.push_back(p);
409 ++nDataSetList;
410}

Referenced by G4HadronicProcess::AddDataSet(), G4ElectronNuclearProcess::G4ElectronNuclearProcess(), G4PositronNuclearProcess::G4PositronNuclearProcess(), and G4HadronPhysicsShielding::Neutron().

◆ AddDataSet() [2/2]

void G4CrossSectionDataStore::AddDataSet ( G4VCrossSectionDataSet * p,
std::size_t i )

Definition at line 414 of file G4CrossSectionDataStore.cc.

415{
416 if(p->ForAllAtomsAndEnergies()) {
417 dataSetList.clear();
418 dataSetList.push_back(p);
419 nDataSetList = 1;
420 } else if ( i >= dataSetList.size() ) {
421 dataSetList.push_back(p);
422 ++nDataSetList;
423 } else {
424 std::vector< G4VCrossSectionDataSet* >::iterator it = dataSetList.end() - i;
425 dataSetList.insert(it , p);
426 ++nDataSetList;
427 }
428}

◆ BuildPhysicsTable()

void G4CrossSectionDataStore::BuildPhysicsTable ( const G4ParticleDefinition & part)

Definition at line 273 of file G4CrossSectionDataStore.cc.

274{
275 if (nDataSetList == 0) {
277 ed << "No cross section is registered for "
278 << part.GetParticleName() << G4endl;
279 G4Exception("G4CrossSectionDataStore::BuildPhysicsTable", "had001",
280 FatalException, ed);
281 return;
282 }
283 matParticle = &part;
284 for (G4int i=0; i<nDataSetList; ++i) {
285 dataSetList[i]->BuildPhysicsTable(part);
286 }
287 const G4MaterialTable* theMatTable = G4Material::GetMaterialTable();
288 std::size_t nelm = 0;
289 std::size_t niso = 0;
290 for(auto mat : *theMatTable) {
291 std::size_t nElements = mat->GetNumberOfElements();
292 nelm = std::max(nelm, nElements);
293 for(G4int j=0; j<(G4int)nElements; ++j) {
294 niso = std::max(niso, mat->GetElement(j)->GetNumberOfIsotopes());
295 }
296 }
297 // define vectors for a run
298 xsecelm.resize(nelm, 0.0);
299 xseciso.resize(niso, 0.0);
300}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::vector< G4Material * > G4MaterialTable
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
static G4MaterialTable * GetMaterialTable()
const G4String & GetParticleName() const

Referenced by G4HadronicProcess::BuildPhysicsTable().

◆ ComputeCrossSection()

G4double G4CrossSectionDataStore::ComputeCrossSection ( const G4DynamicParticle * dp,
const G4Material * mat )

Definition at line 69 of file G4CrossSectionDataStore.cc.

71{
72 currentMaterial = mat;
73 matParticle = dp->GetDefinition();
74 matKinEnergy = dp->GetKineticEnergy();
75 matCrossSection = 0.0;
76
77 std::size_t nElements = mat->GetNumberOfElements();
78 const G4double* nAtomsPerVolume = mat->GetVecNbOfAtomsPerVolume();
79
80 if(xsecelm.size() < nElements) { xsecelm.resize(nElements); }
81
82 for(G4int i=0; i<(G4int)nElements; ++i) {
83 G4double xs =
84 nAtomsPerVolume[i]*GetCrossSection(dp, mat->GetElement(i), mat);
85 matCrossSection += std::max(xs, 0.0);
86 xsecelm[i] = matCrossSection;
87 }
88 return matCrossSection;
89}
double G4double
Definition G4Types.hh:83
G4double GetCrossSection(const G4DynamicParticle *, const G4Material *)
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
const G4Element * GetElement(G4int iel) const
const G4double * GetVecNbOfAtomsPerVolume() const
std::size_t GetNumberOfElements() const

Referenced by G4GammaGeneralProcess::BuildPhysicsTable(), G4HadronicProcess::ComputeCrossSection(), GetCrossSection(), G4ElNeutrinoNucleusProcess::GetMeanFreePath(), G4HadronicProcess::GetMeanFreePath(), G4MuNeutrinoNucleusProcess::GetMeanFreePath(), G4NeutrinoElectronProcess::GetMeanFreePath(), G4TauNeutrinoNucleusProcess::GetMeanFreePath(), G4HadronXSDataTable::Initialise(), G4HadronElasticProcess::PostStepDoIt(), G4HadronicProcess::PostStepDoIt(), G4NeutronGeneralProcess::PostStepDoIt(), and G4GammaGeneralProcess::SelectHadProcess().

◆ DumpHtml()

void G4CrossSectionDataStore::DumpHtml ( const G4ParticleDefinition & ,
std::ofstream & outFile ) const

Definition at line 332 of file G4CrossSectionDataStore.cc.

334{
335 // Write cross section data set info to html physics list
336 // documentation page
337
338 G4double ehi = 0;
339 G4double elo = 0;
340 auto param = G4HadronicParameters::Instance();
341 G4String physListName = param->GetPhysListName();
342 G4String dirName = param->GetPhysListDocDir();
343
344 for (G4int i = nDataSetList-1; i > 0; i--) {
345 elo = dataSetList[i]->GetMinKinEnergy()/GeV;
346 ehi = dataSetList[i]->GetMaxKinEnergy()/GeV;
347 outFile << " <li><b><a href=\"" << physListName << "_"
348 << dataSetList[i]->GetName() << ".html\"> "
349 << dataSetList[i]->GetName() << "</a> from "
350 << elo << " GeV to " << ehi << " GeV </b></li>\n";
351 PrintCrossSectionHtml(dataSetList[i], physListName, dirName);
352 }
353
354 G4double defaultHi = dataSetList[0]->GetMaxKinEnergy()/GeV;
355 if (ehi < defaultHi) {
356 outFile << " <li><b><a href=\"" << dataSetList[0]->GetName()
357 << ".html\"> "
358 << dataSetList[0]->GetName() << "</a> from "
359 << ehi << " GeV to " << defaultHi << " GeV </b></li>\n";
360 PrintCrossSectionHtml(dataSetList[0], physListName, dirName);
361 }
362}
void PrintCrossSectionHtml(const G4VCrossSectionDataSet *cs, const G4String &, const G4String &) const
static G4HadronicParameters * Instance()

Referenced by G4HadronicProcessStore::PrintHtml().

◆ DumpPhysicsTable()

void G4CrossSectionDataStore::DumpPhysicsTable ( const G4ParticleDefinition & part)

Definition at line 305 of file G4CrossSectionDataStore.cc.

306{
307 // Print out all cross section data sets used and the energies at
308 // which they apply
309
310 if (nDataSetList == 0) {
311 G4cout << "WARNING - G4CrossSectionDataStore::DumpPhysicsTable: "
312 << " no data sets registered" << G4endl;
313 return;
314 }
315
316 for (G4int i = nDataSetList-1; i >= 0; --i) {
317 G4double e1 = dataSetList[i]->GetMinKinEnergy();
318 G4double e2 = dataSetList[i]->GetMaxKinEnergy();
319 G4cout
320 << " Cr_sctns: " << std::setw(25) << dataSetList[i]->GetName() << ": "
321 << G4BestUnit(e1, "Energy") << " ---> "
322 << G4BestUnit(e2, "Energy") << "\n";
323 if (dataSetList[i]->GetName() == "G4CrossSectionPairGG") {
324 dataSetList[i]->DumpPhysicsTable(part);
325 G4cout << G4endl;
326 }
327 }
328}
#define G4BestUnit(a, b)
G4GLOB_DLL std::ostream G4cout

Referenced by G4ChargeExchangeProcess::DumpPhysicsTable(), and G4HadronicProcess::DumpPhysicsTable().

◆ GetCrossSection() [1/3]

G4double G4CrossSectionDataStore::GetCrossSection ( const G4DynamicParticle * dp,
const G4Element * elm,
const G4Material * mat )

Definition at line 93 of file G4CrossSectionDataStore.cc.

96{
97 // first check the most last cross section
98 G4int i = nDataSetList-1;
99 G4int Z = elm->GetZasInt();
100
101 if(elm->GetNaturalAbundanceFlag() &&
102 dataSetList[i]->IsElementApplicable(dp, Z, mat))
103 {
104 // element wise cross section
105 return dataSetList[i]->GetElementCrossSection(dp, Z, mat);
106 }
107
108 // isotope wise cross section
109 G4int nIso = (G4int)elm->GetNumberOfIsotopes();
110
111 // user-defined isotope abundances
112 const G4double* abundVector = elm->GetRelativeAbundanceVector();
113
114 G4double sigma = 0.0;
115
116 // isotope and element wise cross sections
117 for(G4int j = 0; j < nIso; ++j)
118 {
119 const G4Isotope* iso = elm->GetIsotope(j);
120 sigma += abundVector[j] *
121 GetIsoCrossSection(dp, Z, iso->GetN(), iso, elm, mat, i);
122 }
123 return sigma;
124}
G4double * GetRelativeAbundanceVector() const
Definition G4Element.hh:149
G4bool GetNaturalAbundanceFlag() const
Definition G4Element.hh:221
const G4Isotope * GetIsotope(G4int iso) const
Definition G4Element.hh:151
size_t GetNumberOfIsotopes() const
Definition G4Element.hh:143
G4int GetZasInt() const
Definition G4Element.hh:120
G4int GetN() const
Definition G4Isotope.hh:83

◆ GetCrossSection() [2/3]

G4double G4CrossSectionDataStore::GetCrossSection ( const G4DynamicParticle * dp,
const G4Material * mat )
inline

Definition at line 150 of file G4CrossSectionDataStore.hh.

152{
153 if(dp->GetKineticEnergy() != matKinEnergy || mat != currentMaterial ||
154 dp->GetDefinition() != matParticle) {
155 ComputeCrossSection(dp, mat);
156 }
157 return matCrossSection;
158}
G4double ComputeCrossSection(const G4DynamicParticle *, const G4Material *)

Referenced by ComputeCrossSection(), G4HadElementSelector::G4HadElementSelector(), G4ChargeExchangeProcess::GetElementCrossSection(), and G4HadronicProcess::GetElementCrossSection().

◆ GetCrossSection() [3/3]

G4double G4CrossSectionDataStore::GetCrossSection ( const G4DynamicParticle * dp,
G4int Z,
G4int A,
const G4Isotope * iso,
const G4Element * elm,
const G4Material * mat )

Definition at line 165 of file G4CrossSectionDataStore.cc.

170{
171 for (G4int i = nDataSetList-1; i >= 0; --i) {
172 if (dataSetList[i]->IsIsoApplicable(dp, Z, A, elm, mat) ) {
173 return dataSetList[i]->GetIsoCrossSection(dp, Z, A, iso, elm, mat);
174 } else if(dataSetList[i]->IsElementApplicable(dp, Z, mat)) {
175 return dataSetList[i]->GetElementCrossSection(dp, Z, mat);
176 }
177 }
179 ed << "No isotope cross section found for "
181 << " off target Element " << elm->GetName()
182 << " Z= " << Z << " A= " << A;
183 if(nullptr != mat) ed << " from " << mat->GetName();
184 ed << " E(MeV)=" << dp->GetKineticEnergy()/MeV << G4endl;
185 G4Exception("G4CrossSectionDataStore::GetCrossSection", "had001",
186 FatalException, ed);
187 return 0.0;
188}
const G4double A[17]
const G4String & GetName() const
Definition G4Element.hh:115
const G4String & GetName() const

◆ GetDataSetList()

const std::vector< G4VCrossSectionDataSet * > & G4CrossSectionDataStore::GetDataSetList ( ) const
inline

Definition at line 144 of file G4CrossSectionDataStore.hh.

145{
146 return dataSetList;
147}

◆ operator=()

G4CrossSectionDataStore & G4CrossSectionDataStore::operator= ( const G4CrossSectionDataStore & right)
delete

◆ PrintCrossSectionHtml()

void G4CrossSectionDataStore::PrintCrossSectionHtml ( const G4VCrossSectionDataSet * cs,
const G4String & physListName,
const G4String & dirName ) const

Definition at line 366 of file G4CrossSectionDataStore.cc.

369{
370
371 G4String pathName = dirName + "/" + physListName + "_" + HtmlFileName(cs->GetName());
372 std::ofstream outCS;
373 outCS.open(pathName);
374 outCS << "<html>\n";
375 outCS << "<head>\n";
376 outCS << "<title>Description of " << cs->GetName()
377 << "</title>\n";
378 outCS << "</head>\n";
379 outCS << "<body>\n";
380
381 cs->CrossSectionDescription(outCS);
382
383 outCS << "</body>\n";
384 outCS << "</html>\n";
385}
const G4String & GetName() const
virtual void CrossSectionDescription(std::ostream &) const

Referenced by DumpHtml().

◆ SampleZandA()

const G4Element * G4CrossSectionDataStore::SampleZandA ( const G4DynamicParticle * dp,
const G4Material * mat,
G4Nucleus & target )

Definition at line 193 of file G4CrossSectionDataStore.cc.

196{
197 if(nullptr != forcedElement) { return forcedElement; }
198 std::size_t nElements = mat->GetNumberOfElements();
199 const G4Element* anElement = mat->GetElement(0);
200
201 // select element from a compound
202 if(1 < nElements) {
203 G4double cross = matCrossSection*G4UniformRand();
204 for(G4int i=0; i<(G4int)nElements; ++i) {
205 if(cross <= xsecelm[i]) {
206 anElement = mat->GetElement(i);
207 break;
208 }
209 }
210 }
211
212 G4int Z = anElement->GetZasInt();
213 const G4Isotope* iso = nullptr;
214
215 G4int i = nDataSetList-1;
216 if (dataSetList[i]->IsElementApplicable(dp, Z, mat)) {
217
218 //----------------------------------------------------------------
219 // element-wise cross section
220 // isotope cross section is not computed
221 //----------------------------------------------------------------
222 std::size_t nIso = anElement->GetNumberOfIsotopes();
223 iso = anElement->GetIsotope(0);
224
225 // more than 1 isotope
226 if(1 < nIso) {
227 iso = dataSetList[i]->SelectIsotope(anElement,
228 dp->GetKineticEnergy(),
229 dp->GetLogKineticEnergy());
230 }
231 } else {
232
233 //----------------------------------------------------------------
234 // isotope-wise cross section
235 // isotope cross section is computed
236 //----------------------------------------------------------------
237 std::size_t nIso = anElement->GetNumberOfIsotopes();
238 iso = anElement->GetIsotope(0);
239
240 // more than 1 isotope
241 if(1 < nIso) {
242 const G4double* abundVector = anElement->GetRelativeAbundanceVector();
243 if(xseciso.size() < nIso) { xseciso.resize(nIso); }
244
245 G4double cross = 0.0;
246 G4int j;
247 for (j = 0; j<(G4int)nIso; ++j) {
248 G4double xsec = 0.0;
249 if(abundVector[j] > 0.0) {
250 iso = anElement->GetIsotope(j);
251 xsec = abundVector[j]*
252 GetIsoCrossSection(dp, Z, iso->GetN(), iso, anElement, mat, i);
253 }
254 cross += xsec;
255 xseciso[j] = cross;
256 }
257 cross *= G4UniformRand();
258 for (j = 0; j<(G4int)nIso; ++j) {
259 if(cross <= xseciso[j]) {
260 iso = anElement->GetIsotope(j);
261 break;
262 }
263 }
264 }
265 }
266 target.SetIsotope(iso);
267 return anElement;
268}
#define G4UniformRand()
Definition Randomize.hh:52
G4double GetLogKineticEnergy() const
void SetIsotope(const G4Isotope *iso)
Definition G4Nucleus.hh:114

Referenced by G4ElNeutrinoNucleusProcess::PostStepDoIt(), G4HadronElasticProcess::PostStepDoIt(), G4HadronicProcess::PostStepDoIt(), G4MuNeutrinoNucleusProcess::PostStepDoIt(), G4NeutrinoElectronProcess::PostStepDoIt(), and G4TauNeutrinoNucleusProcess::PostStepDoIt().

◆ SetForcedElement()

void G4CrossSectionDataStore::SetForcedElement ( const G4Element * ptr)
inline

Definition at line 138 of file G4CrossSectionDataStore.hh.

139{
140 forcedElement = ptr;
141}

◆ SetVerboseLevel()

void G4CrossSectionDataStore::SetVerboseLevel ( G4int value)
inline

Definition at line 133 of file G4CrossSectionDataStore.hh.

134{
135 verboseLevel = value;
136}

The documentation for this class was generated from the following files: