#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=0) |
const G4Element * | SelectRandomAtom (G4double kineticEnergy) |
const G4Material * | GetMaterial () const |
Definition at line 63 of file G4EmElementSelector.hh.
G4EmElementSelector::G4EmElementSelector | ( | G4VEmModel * | , | |
const G4Material * | , | |||
G4int | bins, | |||
G4double | emin, | |||
G4double | emax, | |||
G4bool | spline = true | |||
) |
Definition at line 54 of file G4EmElementSelector.cc.
References G4Material::GetElementVector(), G4Material::GetNumberOfElements(), CLHEP::detail::n, and G4PhysicsVector::SetSpline().
00059 : 00060 model(mod), material(mat), nbins(bins), cutEnergy(-1.0), 00061 lowEnergy(emin), highEnergy(emax) 00062 { 00063 G4int n = material->GetNumberOfElements(); 00064 nElmMinusOne = n - 1; 00065 theElementVector = material->GetElementVector(); 00066 element = (*theElementVector)[0]; 00067 if(nElmMinusOne > 0) { 00068 xSections.reserve(n); 00069 G4PhysicsLogVector* v0 = new G4PhysicsLogVector(lowEnergy,highEnergy,nbins); 00070 xSections.push_back(v0); 00071 v0->SetSpline(spline); 00072 for(G4int i=1; i<n; ++i) { 00073 G4PhysicsLogVector* v = new G4PhysicsLogVector(*v0); 00074 xSections.push_back(v); 00075 } 00076 } 00077 //G4cout << "G4EmElementSelector for " << mat->GetName() << " n= " << n << G4endl; 00078 }
G4EmElementSelector::~G4EmElementSelector | ( | ) |
Definition at line 82 of file G4EmElementSelector.cc.
00083 { 00084 if(nElmMinusOne > 0) { 00085 for(G4int i=0; i<=nElmMinusOne; ++i) { 00086 delete xSections[i]; 00087 } 00088 } 00089 }
void G4EmElementSelector::Dump | ( | const G4ParticleDefinition * | p = 0 |
) |
Definition at line 147 of file G4EmElementSelector.cc.
References G4cout, G4endl, G4Material::GetName(), G4VEmModel::GetName(), and G4ParticleDefinition::GetParticleName().
00148 { 00149 G4cout << "======== G4EmElementSelector for the " << model->GetName(); 00150 if(part) G4cout << " and " << part->GetParticleName(); 00151 G4cout << " for " << material->GetName() << " ========" << G4endl; 00152 if(0 < nElmMinusOne) { 00153 for(G4int i=0; i<nElmMinusOne; i++) { 00154 G4cout << " " << (*theElementVector)[i]->GetName() << " : " << G4endl; 00155 G4cout << *(xSections[i]) << G4endl; 00156 } 00157 } 00158 G4cout << "Last Element in element vector " 00159 << (*theElementVector)[nElmMinusOne]->GetName() 00160 << G4endl; 00161 G4cout << G4endl; 00162 }
const G4Material * G4EmElementSelector::GetMaterial | ( | ) | const [inline] |
void G4EmElementSelector::Initialise | ( | const G4ParticleDefinition * | , | |
G4double | cut = 0.0 | |||
) |
Definition at line 93 of file G4EmElementSelector.cc.
References G4VEmModel::ComputeCrossSectionPerAtom(), G4Material::GetVecNbOfAtomsPerVolume(), and G4VEmModel::SetupForMaterial().
00095 { 00096 //G4cout << "G4EmElementSelector initialise for " << material->GetName() << G4endl; 00097 if(0 == nElmMinusOne || cut == cutEnergy) { return; } 00098 00099 cutEnergy = cut; 00100 //G4cout << "cut(keV)= " << cut/keV << G4endl; 00101 G4double cross; 00102 00103 const G4double* theAtomNumDensityVector = material->GetVecNbOfAtomsPerVolume(); 00104 00105 // loop over bins 00106 for(G4int j=0; j<=nbins; ++j) { 00107 G4double e = (xSections[0])->Energy(j); 00108 model->SetupForMaterial(part, material, e); 00109 cross = 0.0; 00110 //G4cout << "j= " << j << " e(MeV)= " << e/MeV << G4endl; 00111 for (G4int i=0; i<=nElmMinusOne; ++i) { 00112 cross += theAtomNumDensityVector[i]* 00113 model->ComputeCrossSectionPerAtom(part, (*theElementVector)[i], e, 00114 cutEnergy, e); 00115 xSections[i]->PutValue(j, cross); 00116 } 00117 } 00118 00119 // xSections start from null, so use probabilities from the next bin 00120 if(0.0 == (*xSections[nElmMinusOne])[0]) { 00121 for (G4int i=0; i<=nElmMinusOne; ++i) { 00122 xSections[i]->PutValue(0, (*xSections[i])[1]); 00123 } 00124 } 00125 // xSections ends with null, so use probabilities from the previous bin 00126 if(0.0 == (*xSections[nElmMinusOne])[nbins]) { 00127 for (G4int i=0; i<=nElmMinusOne; ++i) { 00128 xSections[i]->PutValue(nbins, (*xSections[i])[nbins-1]); 00129 } 00130 } 00131 // perform normalization 00132 for(G4int j=0; j<=nbins; ++j) { 00133 cross = (*xSections[nElmMinusOne])[j]; 00134 // only for positive X-section 00135 if(cross > 0.0) { 00136 for (G4int i=0; i<nElmMinusOne; ++i) { 00137 G4double x = (*xSections[i])[j]/cross; 00138 xSections[i]->PutValue(j, x); 00139 } 00140 } 00141 } 00142 //G4cout << "======== G4EmElementSelector for the " << model->GetName(); 00143 }
Definition at line 107 of file G4EmElementSelector.hh.
References G4UniformRand.
00108 { 00109 if (nElmMinusOne > 0) { 00110 G4double x = G4UniformRand(); 00111 element = (*theElementVector)[nElmMinusOne]; 00112 for(G4int i=0; i<nElmMinusOne; ++i) { 00113 if (x <= (xSections[i])->Value(e)) { 00114 element = (*theElementVector)[i]; 00115 break; 00116 } 00117 } 00118 } 00119 return element; 00120 }