G4EmElementSelector.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:     G4EmElementSelector
00034 //
00035 // Author:        Vladimir Ivanchenko
00036 //
00037 // Creation date: 29.05.2008
00038 //
00039 // Modifications:
00040 //
00041 // Class Description:
00042 //
00043 // Generic helper class for the random selection of an element
00044 
00045 // -------------------------------------------------------------------
00046 //
00047 
00048 #include "G4EmElementSelector.hh"
00049 #include "G4VEmModel.hh"
00050 
00051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   //G4cout << "G4EmElementSelector for " << mat->GetName() << " n= " << n << G4endl;
00078 }
00079 
00080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00092 
00093 void G4EmElementSelector::Initialise(const G4ParticleDefinition* part, 
00094                                      G4double cut)
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 }
00144 
00145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00165 
00166 

Generated on Mon May 27 17:48:08 2013 for Geant4 by  doxygen 1.4.7