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 | #include "G4ElementIsoCrossSections.hh" |
---|
27 | |
---|
28 | template <class IsoIsoCrossSectionType> |
---|
29 | G4ElementIsoCrossSections<IsoIsoCrossSectionType>:: |
---|
30 | G4ElementIsoCrossSections() |
---|
31 | { |
---|
32 | nIsotopes = 0; |
---|
33 | theData = NULL; |
---|
34 | } |
---|
35 | |
---|
36 | template <class IsoIsoCrossSectionType> |
---|
37 | G4ElementIsoCrossSections<IsoIsoCrossSectionType>:: |
---|
38 | ~G4ElementIsoCrossSections() |
---|
39 | { |
---|
40 | for(G4int i=0; i<nIsotopes; i++) |
---|
41 | { |
---|
42 | delete theData[i]; |
---|
43 | } |
---|
44 | delete theData; |
---|
45 | } |
---|
46 | |
---|
47 | template <class IsoIsoCrossSectionType> |
---|
48 | void G4ElementIsoCrossSections<IsoIsoCrossSectionType>:: |
---|
49 | Init(const G4Element * anElement) |
---|
50 | { |
---|
51 | G4int Z = G4int(anElement->GetZ()+0.001); |
---|
52 | nIsotopes = anElement->GetNumberOfIsotopes(); |
---|
53 | G4bool useIsotopesFromElement = true; |
---|
54 | if( nIsotopes == 0 ) |
---|
55 | { |
---|
56 | nIsotopes += theStableOnes.GetNumberOfIsotopes(Z); |
---|
57 | useIsotopesFromElement = false; |
---|
58 | } |
---|
59 | theData = new IsoIsoCrossSectionType * [nIsotopes]; |
---|
60 | if(useIsotopesFromElement) |
---|
61 | { |
---|
62 | for (G4int i=0; i<nIsotopes; i++) |
---|
63 | { |
---|
64 | G4int A = anElement->GetIsotope(i)->GetN(); |
---|
65 | G4double frac = anElement->GetRelativeAbundanceVector()[i]/perCent; |
---|
66 | theData[i] = new IsoIsoCrossSectionType; |
---|
67 | theData[i]->Init(A, Z, frac); |
---|
68 | } |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | G4int first = theStableOnes.GetFirstIsotope(Z); |
---|
73 | for(G4int i=0; i<theStableOnes.GetNumberOfIsotopes(Z); i++) |
---|
74 | { |
---|
75 | G4int A = theStableOnes.GetIsotopeNucleonCount(first+i); |
---|
76 | G4double frac = theStableOnes.GetAbundance(first+i); |
---|
77 | theData[i] = new IsoIsoCrossSectionType; |
---|
78 | theData[i]->Init(A, Z, frac); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | template <class IsoIsoCrossSectionType> |
---|
84 | G4double G4ElementIsoCrossSections<IsoIsoCrossSectionType>:: |
---|
85 | GetCrossSection(G4double anEnergy) |
---|
86 | { |
---|
87 | G4double result = 0; |
---|
88 | for(G4int i=0; i<nIsotopes; i++) |
---|
89 | { |
---|
90 | result += theData[i]->GetCrossSection(anEnergy); // this is already weighted with relative abundance |
---|
91 | } |
---|
92 | crossSectionBuffer = result; |
---|
93 | return result; |
---|
94 | } |
---|
95 | |
---|
96 | template <class IsoIsoCrossSectionType> |
---|
97 | G4IsoResult * G4ElementIsoCrossSections<IsoIsoCrossSectionType>:: |
---|
98 | GetProductIsotope(G4double anEnergy) |
---|
99 | { |
---|
100 | G4double running = 0; |
---|
101 | G4int index(0); |
---|
102 | G4double random = G4UniformRand(); |
---|
103 | for(G4int i=0; i<nIsotopes; i++) |
---|
104 | { |
---|
105 | running += theData[i]->GetCrossSection(anEnergy); |
---|
106 | index = i; |
---|
107 | if(running/crossSectionBuffer > random) break; |
---|
108 | } |
---|
109 | G4String result = theData[index]->GetProductIsotope(anEnergy); |
---|
110 | G4Nucleus nucleus(theData[index]->GetA(), theData[index]->GetZ()); |
---|
111 | G4IsoResult * theResult = new G4IsoResult(result, nucleus); |
---|
112 | return theResult; |
---|
113 | } |
---|
114 | |
---|
115 | |
---|