00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "G4EmElementSelector.hh"
00049 #include "G4VEmModel.hh"
00050
00051
00052
00053
00054 G4EmElementSelector::G4EmElementSelector(G4VEmModel* mod,
00055 const G4Material* mat,
00056 G4int bins,
00057 G4double emin,
00058 G4double emax,
00059 G4bool spline):
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
00078 }
00079
00080
00081
00082 G4EmElementSelector::~G4EmElementSelector()
00083 {
00084 if(nElmMinusOne > 0) {
00085 for(G4int i=0; i<=nElmMinusOne; ++i) {
00086 delete xSections[i];
00087 }
00088 }
00089 }
00090
00091
00092
00093 void G4EmElementSelector::Initialise(const G4ParticleDefinition* part,
00094 G4double cut)
00095 {
00096
00097 if(0 == nElmMinusOne || cut == cutEnergy) { return; }
00098
00099 cutEnergy = cut;
00100
00101 G4double cross;
00102
00103 const G4double* theAtomNumDensityVector = material->GetVecNbOfAtomsPerVolume();
00104
00105
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
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
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
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
00132 for(G4int j=0; j<=nbins; ++j) {
00133 cross = (*xSections[nElmMinusOne])[j];
00134
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
00143 }
00144
00145
00146
00147 void G4EmElementSelector::Dump(const G4ParticleDefinition* part)
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 }
00163
00164
00165
00166