Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4CrossSectionDataStore Class Reference

#include <G4CrossSectionDataStore.hh>

Public Member Functions

void AddDataSet (G4VCrossSectionDataSet *)
 
void AddDataSet (G4VCrossSectionDataSet *, size_t)
 
void BuildPhysicsTable (const G4ParticleDefinition &)
 
G4double ComputeCrossSection (const G4DynamicParticle *, const G4Material *)
 
void DumpHtml (const G4ParticleDefinition &, std::ofstream &) const
 
void DumpPhysicsTable (const G4ParticleDefinition &)
 
 G4CrossSectionDataStore ()
 
G4double GetCrossSection (const G4DynamicParticle *, const G4Element *, const G4Material *)
 
G4double GetCrossSection (const G4DynamicParticle *, const G4Material *)
 
G4double GetCrossSection (const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *, const G4Element *, const G4Material *)
 
void PrintCrossSectionHtml (const G4VCrossSectionDataSet *cs) const
 
const G4ElementSampleZandA (const G4DynamicParticle *, const G4Material *, G4Nucleus &target)
 
void SetVerboseLevel (G4int value)
 
 ~G4CrossSectionDataStore ()
 

Private Member Functions

 G4CrossSectionDataStore (const G4CrossSectionDataStore &)
 
G4double GetIsoCrossSection (const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *, const G4Element *, const G4Material *aMaterial, G4int index)
 
G4String HtmlFileName (const G4String &in) const
 
G4CrossSectionDataStoreoperator= (const G4CrossSectionDataStore &right)
 

Private Attributes

const G4MaterialcurrentMaterial
 
std::vector< G4VCrossSectionDataSet * > dataSetList
 
G4double matCrossSection
 
G4double matKinEnergy
 
const G4ParticleDefinitionmatParticle
 
G4int nDataSetList
 
G4NistManagernist
 
G4int verboseLevel
 
std::vector< G4doublexsecelm
 
std::vector< G4doublexseciso
 

Detailed Description

Definition at line 61 of file G4CrossSectionDataStore.hh.

Constructor & Destructor Documentation

◆ G4CrossSectionDataStore() [1/2]

G4CrossSectionDataStore::G4CrossSectionDataStore ( )

Definition at line 60 of file G4CrossSectionDataStore.cc.

◆ ~G4CrossSectionDataStore()

G4CrossSectionDataStore::~G4CrossSectionDataStore ( )

Definition at line 72 of file G4CrossSectionDataStore.cc.

73{}

◆ G4CrossSectionDataStore() [2/2]

G4CrossSectionDataStore::G4CrossSectionDataStore ( const G4CrossSectionDataStore )
private

Member Function Documentation

◆ AddDataSet() [1/2]

void G4CrossSectionDataStore::AddDataSet ( G4VCrossSectionDataSet p)

◆ AddDataSet() [2/2]

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

Definition at line 437 of file G4CrossSectionDataStore.cc.

438{
439 if(p->ForAllAtomsAndEnergies()) {
440 dataSetList.clear();
441 dataSetList.push_back(p);
442 nDataSetList = 1;
443 } else {
444 if ( i > dataSetList.size() ) i = dataSetList.size();
445 std::vector< G4VCrossSectionDataSet* >::iterator it = dataSetList.end() - i;
446 dataSetList.insert(it , p);
447 ++nDataSetList;
448 }
449}

References dataSetList, G4VCrossSectionDataSet::ForAllAtomsAndEnergies(), and nDataSetList.

◆ BuildPhysicsTable()

void G4CrossSectionDataStore::BuildPhysicsTable ( const G4ParticleDefinition aParticleType)

Definition at line 310 of file G4CrossSectionDataStore.cc.

311{
312 if (nDataSetList == 0) {
314 ed << "No cross section is registered for "
315 << aParticleType.GetParticleName() << G4endl;
316 G4Exception("G4CrossSectionDataStore::BuildPhysicsTable", "had001",
317 FatalException, ed);
318 return;
319 }
320 for (G4int i=0; i<nDataSetList; ++i) {
321 dataSetList[i]->BuildPhysicsTable(aParticleType);
322 }
323}
@ 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
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
const G4String & GetParticleName() const

References dataSetList, FatalException, G4endl, G4Exception(), G4ParticleDefinition::GetParticleName(), and nDataSetList.

Referenced by G4HadronicProcess::BuildPhysicsTable().

◆ ComputeCrossSection()

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

Definition at line 106 of file G4CrossSectionDataStore.cc.

108{
109 if(part->GetKineticEnergy() == matKinEnergy && mat == currentMaterial &&
110 part->GetDefinition() == matParticle)
111 return matCrossSection;
112
113 currentMaterial = mat;
114 matParticle = part->GetDefinition();
116 matCrossSection = 0.0;
117
118 size_t nElements = mat->GetNumberOfElements();
119 const G4double* nAtomsPerVolume = mat->GetVecNbOfAtomsPerVolume();
120
121 if(xsecelm.size() < nElements) { xsecelm.resize(nElements); }
122
123 for(size_t i=0; i<nElements; ++i) {
124 matCrossSection += nAtomsPerVolume[i] *
125 GetCrossSection(part, mat->GetElement(i), mat);
127 }
128 return matCrossSection;
129}
double G4double
Definition: G4Types.hh:83
G4double GetCrossSection(const G4DynamicParticle *, const G4Material *)
std::vector< G4double > xsecelm
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
const G4Element * GetElement(G4int iel) const
Definition: G4Material.hh:198
size_t GetNumberOfElements() const
Definition: G4Material.hh:182
const G4double * GetVecNbOfAtomsPerVolume() const
Definition: G4Material.hh:202

References currentMaterial, GetCrossSection(), G4DynamicParticle::GetDefinition(), G4Material::GetElement(), G4DynamicParticle::GetKineticEnergy(), G4Material::GetNumberOfElements(), G4Material::GetVecNbOfAtomsPerVolume(), matCrossSection, matKinEnergy, matParticle, and xsecelm.

Referenced by G4GammaGeneralProcess::BuildPhysicsTable(), G4NeutrinoElectronProcess::GetMeanFreePath(), G4HadronicProcess::GetMeanFreePath(), G4ElNeutrinoNucleusProcess::GetMeanFreePath(), G4MuNeutrinoNucleusProcess::GetMeanFreePath(), G4HadronXSDataTable::Initialise(), G4HadronicProcess::PostStepDoIt(), and G4GammaGeneralProcess::SelectHadProcess().

◆ DumpHtml()

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

Definition at line 355 of file G4CrossSectionDataStore.cc.

357{
358 // Write cross section data set info to html physics list
359 // documentation page
360
361 G4double ehi = 0;
362 G4double elo = 0;
363 G4String physListName(std::getenv("G4PhysListName"));
364 for (G4int i = nDataSetList-1; i > 0; i--) {
365 elo = dataSetList[i]->GetMinKinEnergy()/GeV;
366 ehi = dataSetList[i]->GetMaxKinEnergy()/GeV;
367 outFile << " <li><b><a href=\"" << physListName << "_"
368 << dataSetList[i]->GetName() << ".html\"> "
369 << dataSetList[i]->GetName() << "</a> from "
370 << elo << " GeV to " << ehi << " GeV </b></li>\n";
371 //G4cerr << i << ": XS for " << pD.GetParticleName() << " : " << dataSetList[i]->GetName()
372 // << " typeid : " << typeid(dataSetList[i]).name()<< G4endl;
374 }
375
376 G4double defaultHi = dataSetList[0]->GetMaxKinEnergy()/GeV;
377 if (ehi < defaultHi) {
378 outFile << " <li><b><a href=\"" << dataSetList[0]->GetName() << ".html\"> "
379 << dataSetList[0]->GetName() << "</a> from "
380 << ehi << " GeV to " << defaultHi << " GeV </b></li>\n";
382 }
383}
static constexpr double GeV
Definition: G4SIunits.hh:203
void PrintCrossSectionHtml(const G4VCrossSectionDataSet *cs) const

References dataSetList, GeV, nDataSetList, and PrintCrossSectionHtml().

Referenced by G4HadronicProcessStore::PrintHtml().

◆ DumpPhysicsTable()

void G4CrossSectionDataStore::DumpPhysicsTable ( const G4ParticleDefinition aParticleType)

Definition at line 328 of file G4CrossSectionDataStore.cc.

329{
330 // Print out all cross section data sets used and the energies at
331 // which they apply
332
333 if (nDataSetList == 0) {
334 G4cout << "WARNING - G4CrossSectionDataStore::DumpPhysicsTable: "
335 << " no data sets registered" << G4endl;
336 return;
337 }
338
339 for (G4int i = nDataSetList-1; i >= 0; --i) {
340 G4double e1 = dataSetList[i]->GetMinKinEnergy();
341 G4double e2 = dataSetList[i]->GetMaxKinEnergy();
342 G4cout
343 << " Cr_sctns: " << std::setw(25) << dataSetList[i]->GetName() << ": "
344 << G4BestUnit(e1, "Energy")
345 << " ---> "
346 << G4BestUnit(e2, "Energy") << "\n";
347 if (dataSetList[i]->GetName() == "G4CrossSectionPairGG") {
348 dataSetList[i]->DumpPhysicsTable(aParticleType);
349 }
350 }
351}
static const G4double e1[44]
static const G4double e2[44]
#define G4BestUnit(a, b)
G4GLOB_DLL std::ostream G4cout

References dataSetList, e1, e2, G4BestUnit, G4cout, G4endl, and nDataSetList.

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

◆ GetCrossSection() [1/3]

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

Definition at line 133 of file G4CrossSectionDataStore.cc.

136{
137 G4int i = nDataSetList - 1;
138 G4int Z = elm->GetZasInt();
139
140 if(elm->GetNaturalAbundanceFlag() &&
141 dataSetList[i]->IsElementApplicable(part, Z, mat))
142 {
143 // element wise cross section
144 return dataSetList[i]->GetElementCrossSection(part, Z, mat);
145 }
146
147 // isotope wise cross section
148 size_t nIso = elm->GetNumberOfIsotopes();
149
150 // user-defined isotope abundances
151 const G4double* abundVector = elm->GetRelativeAbundanceVector();
152
153 G4double sigma = 0.0;
154
155 for(size_t j = 0; j < nIso; ++j)
156 {
157 const G4Isotope* iso = elm->GetIsotope(j);
158 sigma += abundVector[j] *
159 GetIsoCrossSection(part, Z, iso->GetN(), iso, elm, mat, i);
160 }
161
162 return sigma;
163}
const G4int Z[17]
G4double GetIsoCrossSection(const G4DynamicParticle *, G4int Z, G4int A, const G4Isotope *, const G4Element *, const G4Material *aMaterial, G4int index)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:167
G4bool GetNaturalAbundanceFlag() const
Definition: G4Element.hh:263
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

References dataSetList, GetIsoCrossSection(), G4Element::GetIsotope(), G4Isotope::GetN(), G4Element::GetNaturalAbundanceFlag(), G4Element::GetNumberOfIsotopes(), G4Element::GetRelativeAbundanceVector(), G4Element::GetZasInt(), nDataSetList, and Z.

◆ GetCrossSection() [2/3]

G4double G4CrossSectionDataStore::GetCrossSection ( const G4DynamicParticle part,
const G4Material mat 
)

◆ GetCrossSection() [3/3]

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

Definition at line 206 of file G4CrossSectionDataStore.cc.

211{
212 for (G4int i = nDataSetList-1; i >= 0; --i) {
213 if (dataSetList[i]->IsIsoApplicable(part, Z, A, elm, mat) ) {
214 return dataSetList[i]->GetIsoCrossSection(part, Z, A, iso, elm, mat);
215 }
216 }
218 ed << "No isotope cross section found for "
219 << part->GetDefinition()->GetParticleName()
220 << " off Element " << elm->GetName()
221 << " in " << mat->GetName() << " Z= " << Z << " A= " << A
222 << " E(MeV)= " << part->GetKineticEnergy()/MeV << G4endl;
223 G4Exception("G4CrossSectionDataStore::GetCrossSection", "had001",
224 FatalException, ed);
225 return 0.0;
226}
static constexpr double MeV
Definition: G4SIunits.hh:200
const G4double A[17]
const G4String & GetName() const
Definition: G4Element.hh:127
const G4String & GetName() const
Definition: G4Material.hh:173

References A, dataSetList, FatalException, G4endl, G4Exception(), G4DynamicParticle::GetDefinition(), G4DynamicParticle::GetKineticEnergy(), G4Element::GetName(), G4Material::GetName(), G4ParticleDefinition::GetParticleName(), MeV, nDataSetList, and Z.

◆ GetIsoCrossSection()

G4double G4CrossSectionDataStore::GetIsoCrossSection ( const G4DynamicParticle part,
G4int  Z,
G4int  A,
const G4Isotope iso,
const G4Element elm,
const G4Material aMaterial,
G4int  index 
)
private

Definition at line 168 of file G4CrossSectionDataStore.cc.

174{
175 // this methods is called after the check that dataSetList[idx]
176 // depend on isotopes, so for this DataSet only isotopes are checked
177
178 // isotope-wise cross section does exist
179 if(dataSetList[idx]->IsIsoApplicable(part, Z, A, elm, mat) ) {
180 return dataSetList[idx]->GetIsoCrossSection(part, Z, A, iso, elm, mat);
181
182 } else {
183 // seach for other dataSet
184 for (G4int j = nDataSetList-1; j >= 0; --j) {
185 if (dataSetList[j]->IsElementApplicable(part, Z, mat)) {
186 return dataSetList[j]->GetElementCrossSection(part, Z, mat);
187 } else if (dataSetList[j]->IsIsoApplicable(part, Z, A, elm, mat)) {
188 return dataSetList[j]->GetIsoCrossSection(part, Z, A, iso, elm, mat);
189 }
190 }
191 }
193 ed << "No isotope cross section found for "
194 << part->GetDefinition()->GetParticleName()
195 << " off Element " << elm->GetName()
196 << " in " << mat->GetName() << " Z= " << Z << " A= " << A
197 << " E(MeV)= " << part->GetKineticEnergy()/MeV << G4endl;
198 G4Exception("G4CrossSectionDataStore::GetIsoCrossSection", "had001",
199 FatalException, ed);
200 return 0.0;
201}

References A, dataSetList, FatalException, G4endl, G4Exception(), G4DynamicParticle::GetDefinition(), G4DynamicParticle::GetKineticEnergy(), G4Element::GetName(), G4Material::GetName(), G4ParticleDefinition::GetParticleName(), MeV, nDataSetList, and Z.

Referenced by GetCrossSection(), and SampleZandA().

◆ HtmlFileName()

G4String G4CrossSectionDataStore::HtmlFileName ( const G4String in) const
private

Definition at line 410 of file G4CrossSectionDataStore.cc.

411{
412 G4String str(in);
413 // replace blanks by _ C++11 version:
414 std::transform(str.begin(), str.end(), str.begin(), [](char ch) {
415 return ch == ' ' ? '_' : ch;
416 });
417 str=str + ".html";
418 return str;
419}
G4bool transform(G4String &input, const G4String &type)

References G4coutFormatters::anonymous_namespace{G4coutFormatters.cc}::transform().

Referenced by PrintCrossSectionHtml().

◆ operator=()

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

◆ PrintCrossSectionHtml()

void G4CrossSectionDataStore::PrintCrossSectionHtml ( const G4VCrossSectionDataSet cs) const

Definition at line 387 of file G4CrossSectionDataStore.cc.

388{
389 G4String dirName(std::getenv("G4PhysListDocDir"));
390 G4String physListName(std::getenv("G4PhysListName"));
391
392 G4String pathName = dirName + "/" + physListName + "_" + HtmlFileName(cs->GetName());
393 std::ofstream outCS;
394 outCS.open(pathName);
395 outCS << "<html>\n";
396 outCS << "<head>\n";
397 outCS << "<title>Description of " << cs->GetName()
398 << "</title>\n";
399 outCS << "</head>\n";
400 outCS << "<body>\n";
401
402 cs->CrossSectionDescription(outCS);
403
404 outCS << "</body>\n";
405 outCS << "</html>\n";
406
407}
G4String HtmlFileName(const G4String &in) const
const G4String & GetName() const
virtual void CrossSectionDescription(std::ostream &) const

References G4VCrossSectionDataSet::CrossSectionDescription(), G4VCrossSectionDataSet::GetName(), and HtmlFileName().

Referenced by DumpHtml().

◆ SampleZandA()

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

Definition at line 231 of file G4CrossSectionDataStore.cc.

234{
235 size_t nElements = mat->GetNumberOfElements();
236 const G4Element* anElement = mat->GetElement(0);
237
238 // select element from a compound
239 if(1 < nElements) {
241 for(size_t i=0; i<nElements; ++i) {
242 if(cross <= xsecelm[i]) {
243 anElement = mat->GetElement(i);
244 break;
245 }
246 }
247 }
248
249 G4int Z = anElement->GetZasInt();
250 const G4Isotope* iso = nullptr;
251
252 G4int i = nDataSetList-1;
253 if (dataSetList[i]->IsElementApplicable(part, Z, mat)) {
254
255 //----------------------------------------------------------------
256 // element-wise cross section
257 // isotope cross section is not computed
258 //----------------------------------------------------------------
259 size_t nIso = anElement->GetNumberOfIsotopes();
260 iso = anElement->GetIsotope(0);
261
262 // more than 1 isotope
263 if(1 < nIso) {
264 iso = dataSetList[i]->SelectIsotope(anElement,
265 part->GetKineticEnergy(),
266 part->GetLogKineticEnergy());
267 }
268 } else {
269
270 //----------------------------------------------------------------
271 // isotope-wise cross section
272 // isotope cross section is computed
273 //----------------------------------------------------------------
274 size_t nIso = anElement->GetNumberOfIsotopes();
275 iso = anElement->GetIsotope(0);
276
277 // more than 1 isotope
278 if(1 < nIso) {
279 const G4double* abundVector = anElement->GetRelativeAbundanceVector();
280 if(xseciso.size() < nIso) { xseciso.resize(nIso); }
281
282 G4double cross = 0.0;
283 size_t j;
284 for (j = 0; j<nIso; ++j) {
285 G4double xsec = 0.0;
286 if(abundVector[j] > 0.0) {
287 iso = anElement->GetIsotope(j);
288 xsec = abundVector[j]*
289 GetIsoCrossSection(part, Z, iso->GetN(), iso, anElement, mat, i);
290 }
291 cross += xsec;
292 xseciso[j] = cross;
293 }
294 cross *= G4UniformRand();
295 for (j = 0; j<nIso; ++j) {
296 if(cross <= xseciso[j]) {
297 iso = anElement->GetIsotope(j);
298 break;
299 }
300 }
301 }
302 }
303 target.SetIsotope(iso);
304 return anElement;
305}
#define G4UniformRand()
Definition: Randomize.hh:52
std::vector< G4double > xseciso
G4double GetLogKineticEnergy() const
void SetIsotope(const G4Isotope *iso)
Definition: G4Nucleus.hh:114

References dataSetList, G4UniformRand, G4Material::GetElement(), GetIsoCrossSection(), G4Element::GetIsotope(), G4DynamicParticle::GetKineticEnergy(), G4DynamicParticle::GetLogKineticEnergy(), G4Isotope::GetN(), G4Material::GetNumberOfElements(), G4Element::GetNumberOfIsotopes(), G4Element::GetRelativeAbundanceVector(), G4Element::GetZasInt(), matCrossSection, nDataSetList, G4Nucleus::SetIsotope(), xsecelm, xseciso, and Z.

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

◆ SetVerboseLevel()

void G4CrossSectionDataStore::SetVerboseLevel ( G4int  value)
inline

Definition at line 128 of file G4CrossSectionDataStore.hh.

129{
130 verboseLevel = value;
131}

References verboseLevel.

Field Documentation

◆ currentMaterial

const G4Material* G4CrossSectionDataStore::currentMaterial
private

Definition at line 119 of file G4CrossSectionDataStore.hh.

Referenced by ComputeCrossSection(), and GetCrossSection().

◆ dataSetList

std::vector<G4VCrossSectionDataSet*> G4CrossSectionDataStore::dataSetList
private

◆ matCrossSection

G4double G4CrossSectionDataStore::matCrossSection
private

Definition at line 122 of file G4CrossSectionDataStore.hh.

Referenced by ComputeCrossSection(), GetCrossSection(), and SampleZandA().

◆ matKinEnergy

G4double G4CrossSectionDataStore::matKinEnergy
private

Definition at line 121 of file G4CrossSectionDataStore.hh.

Referenced by ComputeCrossSection(), and GetCrossSection().

◆ matParticle

const G4ParticleDefinition* G4CrossSectionDataStore::matParticle
private

Definition at line 120 of file G4CrossSectionDataStore.hh.

Referenced by ComputeCrossSection(), and GetCrossSection().

◆ nDataSetList

G4int G4CrossSectionDataStore::nDataSetList
private

◆ nist

G4NistManager* G4CrossSectionDataStore::nist
private

Definition at line 113 of file G4CrossSectionDataStore.hh.

◆ verboseLevel

G4int G4CrossSectionDataStore::verboseLevel
private

Definition at line 125 of file G4CrossSectionDataStore.hh.

Referenced by SetVerboseLevel().

◆ xsecelm

std::vector<G4double> G4CrossSectionDataStore::xsecelm
private

Definition at line 116 of file G4CrossSectionDataStore.hh.

Referenced by ComputeCrossSection(), GetCrossSection(), and SampleZandA().

◆ xseciso

std::vector<G4double> G4CrossSectionDataStore::xseciso
private

Definition at line 117 of file G4CrossSectionDataStore.hh.

Referenced by SampleZandA().


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