Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4EmElementSelector Class Reference

#include <G4EmElementSelector.hh>

Public Member Functions

 G4EmElementSelector (G4VEmModel *, const G4Material *, G4int bins, G4double emin, G4double emax, G4bool spline=true)
 
 ~G4EmElementSelector ()
 
void Initialise (const G4ParticleDefinition *, G4double cut=0.0)
 
void Dump (const G4ParticleDefinition *p=nullptr)
 
const G4ElementSelectRandomAtom (G4double kineticEnergy) const
 
const G4MaterialGetMaterial () const
 

Detailed Description

Definition at line 63 of file G4EmElementSelector.hh.

Constructor & Destructor Documentation

G4EmElementSelector::G4EmElementSelector ( G4VEmModel mod,
const G4Material mat,
G4int  bins,
G4double  emin,
G4double  emax,
G4bool  spline = true 
)

Definition at line 55 of file G4EmElementSelector.cc.

60  :
61  model(mod), material(mat), nbins(bins), cutEnergy(-1.0),
62  lowEnergy(emin), highEnergy(emax)
63 {
64  G4int n = material->GetNumberOfElements();
65  nElmMinusOne = n - 1;
66  theElementVector = material->GetElementVector();
67  if(nElmMinusOne > 0) {
68  xSections.reserve(n);
69  G4PhysicsLogVector* v0 = new G4PhysicsLogVector(lowEnergy,highEnergy,nbins);
70  xSections.push_back(v0);
71  v0->SetSpline(false);
72  for(G4int i=1; i<n; ++i) {
74  xSections.push_back(v);
75  }
76  }
77  /*
78  G4cout << "G4EmElementSelector for " << mat->GetName() << " n= " << n
79  << " nbins= " << nbins << " Emin= " << lowEnergy
80  << " Emax= " << highEnergy << G4endl;
81  */
82 }
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:190
int G4int
Definition: G4Types.hh:78
void SetSpline(G4bool)
static const G4double emax
size_t GetNumberOfElements() const
Definition: G4Material.hh:186
const XML_Char XML_Content * model
Definition: expat.h:151

Here is the call graph for this function:

G4EmElementSelector::~G4EmElementSelector ( )

Definition at line 86 of file G4EmElementSelector.cc.

87 {
88  if(nElmMinusOne > 0) {
89  for(G4int i=0; i<=nElmMinusOne; ++i) { delete xSections[i]; }
90  }
91 }
int G4int
Definition: G4Types.hh:78

Member Function Documentation

void G4EmElementSelector::Dump ( const G4ParticleDefinition p = nullptr)

Definition at line 152 of file G4EmElementSelector.cc.

153 {
154  G4cout << "======== G4EmElementSelector for the " << model->GetName();
155  if(part) G4cout << " and " << part->GetParticleName();
156  G4cout << " for " << material->GetName() << " ========" << G4endl;
157  if(0 < nElmMinusOne) {
158  for(G4int i=0; i<nElmMinusOne; i++) {
159  G4cout << " " << (*theElementVector)[i]->GetName() << " : " << G4endl;
160  G4cout << *(xSections[i]) << G4endl;
161  }
162  }
163  G4cout << "Last Element in element vector "
164  << (*theElementVector)[nElmMinusOne]->GetName()
165  << G4endl;
166  G4cout << G4endl;
167 }
const G4String & GetName() const
Definition: G4Material.hh:178
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
const XML_Char XML_Content * model
Definition: expat.h:151

Here is the call graph for this function:

const G4Material * G4EmElementSelector::GetMaterial ( ) const
inline

Definition at line 121 of file G4EmElementSelector.hh.

122 {
123  return material;
124 }
void G4EmElementSelector::Initialise ( const G4ParticleDefinition part,
G4double  cut = 0.0 
)

Definition at line 95 of file G4EmElementSelector.cc.

97 {
98  //G4cout << "G4EmElementSelector initialise for " << material->GetName()
99  // << G4endl;
100  if(0 == nElmMinusOne || cut == cutEnergy) { return; }
101 
102  cutEnergy = cut;
103  //G4cout << "cut(keV)= " << cut/keV << G4endl;
104  G4double cross;
105 
106  const G4double* theAtomNumDensityVector =
107  material->GetVecNbOfAtomsPerVolume();
108 
109  // loop over bins
110  for(G4int j=0; j<=nbins; ++j) {
111  G4double e = (xSections[0])->Energy(j);
112  model->SetupForMaterial(part, material, e);
113  cross = 0.0;
114  //G4cout << "j= " << j << " e(MeV)= " << e/MeV << G4endl;
115  for (G4int i=0; i<=nElmMinusOne; ++i) {
116  cross += theAtomNumDensityVector[i]*
117  model->ComputeCrossSectionPerAtom(part, (*theElementVector)[i], e,
118  cutEnergy, e);
119  xSections[i]->PutValue(j, cross);
120  }
121  }
122 
123  // xSections start from null, so use probabilities from the next bin
124  if(0.0 == (*xSections[nElmMinusOne])[0]) {
125  for (G4int i=0; i<=nElmMinusOne; ++i) {
126  xSections[i]->PutValue(0, (*xSections[i])[1]);
127  }
128  }
129  // xSections ends with null, so use probabilities from the previous bin
130  if(0.0 == (*xSections[nElmMinusOne])[nbins]) {
131  for (G4int i=0; i<=nElmMinusOne; ++i) {
132  xSections[i]->PutValue(nbins, (*xSections[i])[nbins-1]);
133  }
134  }
135  // perform normalization
136  for(G4int j=0; j<=nbins; ++j) {
137  cross = (*xSections[nElmMinusOne])[j];
138  // only for positive X-section
139  if(cross > 0.0) {
140  for (G4int i=0; i<nElmMinusOne; ++i) {
141  G4double x = (*xSections[i])[j]/cross;
142  xSections[i]->PutValue(j, x);
143  }
144  }
145  }
146  //G4cout << "======== G4EmElementSelector for the " << model->GetName()
147  // << G4endl;
148 }
int G4int
Definition: G4Types.hh:78
const G4double * GetVecNbOfAtomsPerVolume() const
Definition: G4Material.hh:206
double G4double
Definition: G4Types.hh:76
const XML_Char XML_Content * model
Definition: expat.h:151

Here is the call graph for this function:

const G4Element * G4EmElementSelector::SelectRandomAtom ( G4double  kineticEnergy) const
inline

Definition at line 106 of file G4EmElementSelector.hh.

107 {
108  const G4Element* element = (*theElementVector)[nElmMinusOne];
109  if (nElmMinusOne > 0) {
110  G4double x = G4UniformRand();
111  for(G4int i=0; i<nElmMinusOne; ++i) {
112  if (x <= (xSections[i])->Value(e)) {
113  element = (*theElementVector)[i];
114  break;
115  }
116  }
117  }
118  return element;
119 }
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:97
double G4double
Definition: G4Types.hh:76

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