Geant4  10.00.p03
G4ElementSelector.cc
Go to the documentation of this file.
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: G4ElementSelector.cc 66367 2012-12-18 09:18:08Z gcosmo $
27 //
28 // File: G4ElementSelector
29 //
30 // Author: V.Ivanchenko (Vladimir.Ivanchenko@cern.ch)
31 //
32 // Creation date: 2 April 2000
33 //
34 // Modifications:
35 // 18/08/2000 V.Ivanchenko Update description
36 // 17/05/2006 V.Ivanchenko Cleanup
37 // 02/10/2007 V.Ivanchenko Fixed typo in computation of Lambda-factor
38 // proposed by Victor Pec
39 //
40 //---------------------------------------------------------------------
41 
42 #include "G4ElementSelector.hh"
43 #include "Randomize.hh"
44 #include "G4Material.hh"
45 #include "G4Nucleus.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
48 
50 {}
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53 
55 {}
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
58 
59 G4Element*
61 {
62  // Fermi-Teller Z-low of mu- capture and exceptions
63  // for halogens and oxigen.
64  // N.C.Mukhopadhyay Phys. Rep. 30 (1977) 1.
65 
66  size_t i = 0;
67  const G4Material* mat = track.GetMaterial();
68  size_t numberOfElements = mat->GetNumberOfElements();
69  const G4ElementVector* theElementVector = mat->GetElementVector();
70 
71  if(1 < numberOfElements) {
72  if(numberOfElements > prob.size()) { prob.resize(numberOfElements, 0.0); }
73 
74  const G4double* theAtomNumDensity = mat->GetAtomicNumDensityVector();
75 
76  G4double sum = 0.0;
77  for (i=0; i < numberOfElements; ++i) {
78 
79  G4int Z = G4lrint((*theElementVector)[i]->GetZ());
80 
81  // Halogens
82  if( (9 == Z) || (17 == Z) || (35 == Z) || (53 == Z) || (85 == Z) ) {
83  sum += 0.66 * Z * theAtomNumDensity[i];
84 
85  // Oxigen
86  } else if( 8 == Z ) {
87  sum += 0.56 * Z * theAtomNumDensity[i];
88 
89  // Others
90  } else {
91  sum += Z * theAtomNumDensity[i];
92  }
93  prob[i] = sum;
94  }
95 
96  sum *= G4UniformRand();
97  for (i=0; i < numberOfElements; ++i) {
98  if(sum <= prob[i]) { break; }
99  }
100  }
101 
102  G4Element* elm = (*theElementVector)[i];
103  G4int Z = G4lrint(elm->GetZ());
104 
105  // select isotope
106  const G4IsotopeVector* isv = elm->GetIsotopeVector();
107  size_t ni = isv->size();
108  i = 0;
109 
110  if(1 < ni) {
111 
112  const G4double* ab = elm->GetRelativeAbundanceVector();
113  G4double y = G4UniformRand();
114  for(i=0; i<ni; ++i) {
115  y -= ab[i];
116  if(y <= 0.0) { break; }
117  }
118  }
119 
120  G4int A = elm->GetIsotope(i)->GetN();
121  target->SetParameters(A, Z);
122 
123  return elm;
124 }
125 
virtual G4Element * SelectZandA(const G4Track &track, G4Nucleus *)
std::vector< G4Isotope * > G4IsotopeVector
std::vector< G4Element * > G4ElementVector
G4double GetZ() const
Definition: G4Element.hh:131
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:188
int G4int
Definition: G4Types.hh:78
G4int GetN() const
Definition: G4Isotope.hh:94
#define G4UniformRand()
Definition: Randomize.hh:87
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
static const G4double A[nN]
std::vector< G4double > prob
const G4double * GetAtomicNumDensityVector() const
Definition: G4Material.hh:214
G4Material * GetMaterial() const
G4IsotopeVector * GetIsotopeVector() const
Definition: G4Element.hh:162
static const G4double ab
int G4lrint(double ad)
Definition: templates.hh:163
virtual ~G4ElementSelector()
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:169
size_t GetNumberOfElements() const
Definition: G4Material.hh:184
double G4double
Definition: G4Types.hh:76
void SetParameters(const G4double A, const G4double Z)
Definition: G4Nucleus.cc:198