Geant4 11.1.1
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
 
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 61 of file G4CrossSectionDataStore.cc.

63{}
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 398 of file G4CrossSectionDataStore.cc.

399{
400 if(p->ForAllAtomsAndEnergies()) {
401 dataSetList.clear();
402 nDataSetList = 0;
403 }
404 dataSetList.push_back(p);
405 ++nDataSetList;
406}

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 410 of file G4CrossSectionDataStore.cc.

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

◆ BuildPhysicsTable()

void G4CrossSectionDataStore::BuildPhysicsTable ( const G4ParticleDefinition part)

Definition at line 272 of file G4CrossSectionDataStore.cc.

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

Referenced by G4HadronicProcess::BuildPhysicsTable().

◆ ComputeCrossSection()

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

Definition at line 68 of file G4CrossSectionDataStore.cc.

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

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

◆ DumpHtml()

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

Definition at line 331 of file G4CrossSectionDataStore.cc.

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

Referenced by G4HadronicProcessStore::PrintHtml().

◆ DumpPhysicsTable()

void G4CrossSectionDataStore::DumpPhysicsTable ( const G4ParticleDefinition part)

Definition at line 304 of file G4CrossSectionDataStore.cc.

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

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

◆ GetCrossSection() [2/3]

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

Definition at line 149 of file G4CrossSectionDataStore.hh.

151{
152 if(dp->GetKineticEnergy() != matKinEnergy || mat != currentMaterial ||
153 dp->GetDefinition() != matParticle) {
154 ComputeCrossSection(dp, mat);
155 }
156 return matCrossSection;
157}
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 164 of file G4CrossSectionDataStore.cc.

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

◆ GetDataSetList()

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

Definition at line 143 of file G4CrossSectionDataStore.hh.

144{
145 return dataSetList;
146}

◆ operator=()

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

◆ PrintCrossSectionHtml()

void G4CrossSectionDataStore::PrintCrossSectionHtml ( const G4VCrossSectionDataSet cs) const

Definition at line 362 of file G4CrossSectionDataStore.cc.

363{
364 G4String dirName(std::getenv("G4PhysListDocDir"));
365 G4String physListName(std::getenv("G4PhysListName"));
366
367 G4String pathName = dirName + "/" + physListName + "_" + HtmlFileName(cs->GetName());
368 std::ofstream outCS;
369 outCS.open(pathName);
370 outCS << "<html>\n";
371 outCS << "<head>\n";
372 outCS << "<title>Description of " << cs->GetName()
373 << "</title>\n";
374 outCS << "</head>\n";
375 outCS << "<body>\n";
376
377 cs->CrossSectionDescription(outCS);
378
379 outCS << "</body>\n";
380 outCS << "</html>\n";
381}
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 192 of file G4CrossSectionDataStore.cc.

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

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

◆ SetForcedElement()

void G4CrossSectionDataStore::SetForcedElement ( const G4Element ptr)
inline

Definition at line 137 of file G4CrossSectionDataStore.hh.

138{
139 forcedElement = ptr;
140}

◆ SetVerboseLevel()

void G4CrossSectionDataStore::SetVerboseLevel ( G4int  value)
inline

Definition at line 132 of file G4CrossSectionDataStore.hh.

133{
134 verboseLevel = value;
135}

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