| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | // $Id: G4EmElementSelector.cc,v 1.10 2009/05/26 16:59:35 vnivanch Exp $
|
|---|
| 27 | // GEANT4 tag $Name: geant4-09-03-beta-cand-01 $
|
|---|
| 28 | //
|
|---|
| 29 | // -------------------------------------------------------------------
|
|---|
| 30 | //
|
|---|
| 31 | // GEANT4 Class file
|
|---|
| 32 | //
|
|---|
| 33 | //
|
|---|
| 34 | // File name: G4EmElementSelector
|
|---|
| 35 | //
|
|---|
| 36 | // Author: Vladimir Ivanchenko
|
|---|
| 37 | //
|
|---|
| 38 | // Creation date: 29.05.2008
|
|---|
| 39 | //
|
|---|
| 40 | // Modifications:
|
|---|
| 41 | //
|
|---|
| 42 | // Class Description:
|
|---|
| 43 | //
|
|---|
| 44 | // Generic helper class for the random selection of an element
|
|---|
| 45 |
|
|---|
| 46 | // -------------------------------------------------------------------
|
|---|
| 47 | //
|
|---|
| 48 |
|
|---|
| 49 | #include "G4EmElementSelector.hh"
|
|---|
| 50 | #include "G4VEmModel.hh"
|
|---|
| 51 |
|
|---|
| 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 53 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 54 |
|
|---|
| 55 | G4EmElementSelector::G4EmElementSelector(G4VEmModel* mod,
|
|---|
| 56 | const G4Material* mat,
|
|---|
| 57 | G4int bins,
|
|---|
| 58 | G4double emin,
|
|---|
| 59 | G4double emax,
|
|---|
| 60 | G4bool /*spline*/):
|
|---|
| 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 | element = (*theElementVector)[0];
|
|---|
| 68 | if(nElmMinusOne > 0) {
|
|---|
| 69 | xSections.reserve(n);
|
|---|
| 70 | for(G4int i=0; i<n; i++) {
|
|---|
| 71 | G4PhysicsLogVector* v = new G4PhysicsLogVector(lowEnergy,highEnergy,nbins);
|
|---|
| 72 | //v->SetSpline(spline);
|
|---|
| 73 | xSections.push_back(v);
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | //G4cout << "G4EmElementSelector for " << mat->GetName() << " n= " << n << G4endl;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 80 |
|
|---|
| 81 | G4EmElementSelector::~G4EmElementSelector()
|
|---|
| 82 | {
|
|---|
| 83 | if(nElmMinusOne > 0) {
|
|---|
| 84 | for(G4int i=0; i<=nElmMinusOne; i++) {
|
|---|
| 85 | delete xSections[i];
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 91 |
|
|---|
| 92 | void G4EmElementSelector::Initialise(const G4ParticleDefinition* part,
|
|---|
| 93 | G4double cut)
|
|---|
| 94 | {
|
|---|
| 95 | //G4cout << "G4EmElementSelector initialise for " << material->GetName() << G4endl;
|
|---|
| 96 | if(0 == nElmMinusOne || cut == cutEnergy) return;
|
|---|
| 97 |
|
|---|
| 98 | cutEnergy = cut;
|
|---|
| 99 | //G4cout << "cut(keV)= " << cut/keV << G4endl;
|
|---|
| 100 | G4double cross;
|
|---|
| 101 |
|
|---|
| 102 | const G4double* theAtomNumDensityVector = material->GetVecNbOfAtomsPerVolume();
|
|---|
| 103 |
|
|---|
| 104 | G4int i;
|
|---|
| 105 |
|
|---|
| 106 | // loop over bins
|
|---|
| 107 | for(G4int j=0; j<nbins; j++) {
|
|---|
| 108 | G4double e = (xSections[0])->GetLowEdgeEnergy(j);
|
|---|
| 109 | model->SetupForMaterial(part, material, e);
|
|---|
| 110 | cross = 0.0;
|
|---|
| 111 | //G4cout << "j= " << j << " e(MeV)= " << e/MeV << G4endl;
|
|---|
| 112 | for (i=0; i<=nElmMinusOne; i++) {
|
|---|
| 113 | cross += theAtomNumDensityVector[i]*
|
|---|
| 114 | model->ComputeCrossSectionPerAtom(part, (*theElementVector)[i], e,
|
|---|
| 115 | cutEnergy, e);
|
|---|
| 116 | xSections[i]->PutValue(j, cross);
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // xSections start from null, so use probabilities from the next bin
|
|---|
| 121 | if(DBL_MIN >= (*xSections[nElmMinusOne])[0]) {
|
|---|
| 122 | for (i=0; i<=nElmMinusOne; i++) {
|
|---|
| 123 | xSections[i]->PutValue(0, (*xSections[i])[1]);
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 | // xSections ends with null, so use probabilities from the previous bin
|
|---|
| 127 | if(DBL_MIN >= (*xSections[nElmMinusOne])[nbins-1]) {
|
|---|
| 128 | for (i=0; i<=nElmMinusOne; i++) {
|
|---|
| 129 | xSections[i]->PutValue(nbins-1, (*xSections[i])[nbins-2]);
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | // perform normalization
|
|---|
| 133 | for(G4int j=0; j<nbins; j++) {
|
|---|
| 134 | cross = (*xSections[nElmMinusOne])[j];
|
|---|
| 135 | // only for positive X-section
|
|---|
| 136 | if(cross > DBL_MIN) {
|
|---|
| 137 | for (i=0; i<nElmMinusOne; i++) {
|
|---|
| 138 | xSections[i]->PutValue(j, (*xSections[i])[j]/cross);
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 145 |
|
|---|
| 146 | void G4EmElementSelector::Dump(const G4ParticleDefinition* part)
|
|---|
| 147 | {
|
|---|
| 148 | G4cout << "======== G4EmElementSelector for the " << model->GetName();
|
|---|
| 149 | if(part) G4cout << " and " << part->GetParticleName();
|
|---|
| 150 | G4cout << " for " << material->GetName() << " ========" << G4endl;
|
|---|
| 151 | if(0 < nElmMinusOne) {
|
|---|
| 152 | for(G4int i=0; i<nElmMinusOne; i++) {
|
|---|
| 153 | G4cout << " " << (*theElementVector)[i]->GetName() << " : " << G4endl;
|
|---|
| 154 | G4cout << *(xSections[i]) << G4endl;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | G4cout << "Last Element in element vector "
|
|---|
| 158 | << (*theElementVector)[nElmMinusOne]->GetName()
|
|---|
| 159 | << G4endl;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|