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: G4NeutronCaptureXS.cc,v 1.3 2010/06/03 11:50:21 vnivanch Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ |
---|
28 | // |
---|
29 | // ------------------------------------------------------------------- |
---|
30 | // |
---|
31 | // GEANT4 Class file |
---|
32 | // |
---|
33 | // |
---|
34 | // File name: G4NeutronCaptureXS |
---|
35 | // |
---|
36 | // Author Ivantchenko, Geant4, 3-Aug-09 |
---|
37 | // |
---|
38 | // Modifications: |
---|
39 | // |
---|
40 | |
---|
41 | #include "G4NeutronCaptureXS.hh" |
---|
42 | #include "G4Element.hh" |
---|
43 | #include "G4ElementTable.hh" |
---|
44 | #include "G4PhysicsLogVector.hh" |
---|
45 | #include "G4PhysicsVector.hh" |
---|
46 | |
---|
47 | #include <iostream> |
---|
48 | #include <fstream> |
---|
49 | #include <sstream> |
---|
50 | using namespace std; |
---|
51 | |
---|
52 | G4NeutronCaptureXS::G4NeutronCaptureXS() |
---|
53 | { |
---|
54 | verboseLevel = 0; |
---|
55 | emax = 20.*MeV; |
---|
56 | G4cout << "G4NeutronCaptureXS::G4NeutronCaptureXS: Initialise " << G4endl; |
---|
57 | for(G4int i=0; i<93; ++i) { |
---|
58 | data[i] = 0; |
---|
59 | } |
---|
60 | isInitialized = false; |
---|
61 | } |
---|
62 | |
---|
63 | G4NeutronCaptureXS::~G4NeutronCaptureXS() |
---|
64 | { |
---|
65 | for(G4int i=0; i<92; ++i) { |
---|
66 | delete data[i]; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | G4bool |
---|
71 | G4NeutronCaptureXS::IsApplicable(const G4DynamicParticle*, |
---|
72 | const G4Element*) |
---|
73 | { |
---|
74 | return true; |
---|
75 | } |
---|
76 | |
---|
77 | G4bool |
---|
78 | G4NeutronCaptureXS::IsZAApplicable(const G4DynamicParticle*, |
---|
79 | G4double /*ZZ*/, G4double /*AA*/) |
---|
80 | { |
---|
81 | return false; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | G4double |
---|
86 | G4NeutronCaptureXS::GetCrossSection(const G4DynamicParticle* aParticle, |
---|
87 | const G4Element* elm, |
---|
88 | G4double) |
---|
89 | { |
---|
90 | G4double xs = 0.0; |
---|
91 | G4double ekin = aParticle->GetKineticEnergy(); |
---|
92 | if(ekin > emax) return xs; |
---|
93 | |
---|
94 | G4int Z = G4int(elm->GetZ()); |
---|
95 | G4PhysicsVector* pv = data[Z]; |
---|
96 | |
---|
97 | // element was not initialised |
---|
98 | if(!pv) { |
---|
99 | Initialise(Z); |
---|
100 | pv = data[Z]; |
---|
101 | if(!pv) return xs; |
---|
102 | } |
---|
103 | |
---|
104 | G4int n = pv->GetVectorLength() - 1; |
---|
105 | G4double e1 = pv->Energy(0); |
---|
106 | G4double e2 = pv->Energy(n); |
---|
107 | if(ekin < e1) { xs = (*pv)[0]*std::sqrt(e1/ekin); } |
---|
108 | else if(ekin <= e2) { xs = pv->Value(ekin); } |
---|
109 | |
---|
110 | if(verboseLevel > 0){ |
---|
111 | G4cout << "ekin= " << ekin << ", xs= " << xs << G4endl; |
---|
112 | } |
---|
113 | return xs; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | void |
---|
118 | G4NeutronCaptureXS::BuildPhysicsTable(const G4ParticleDefinition& p) |
---|
119 | { |
---|
120 | G4cout << "G4NeutronCaptureXS::BuildPhysicsTable: " << G4endl; |
---|
121 | G4cout << p.GetParticleName() << G4endl; |
---|
122 | if(p.GetParticleName() != "neutron") { |
---|
123 | return; |
---|
124 | } |
---|
125 | if(isInitialized) return; |
---|
126 | isInitialized = true; |
---|
127 | |
---|
128 | |
---|
129 | // check environment variable |
---|
130 | // Build the complete string identifying the file with the data set |
---|
131 | char* path = getenv("G4NEUTRONXSDATA"); |
---|
132 | if (!path){ |
---|
133 | G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl; |
---|
134 | } |
---|
135 | |
---|
136 | // Access to elements |
---|
137 | const G4ElementTable* theElmTable = G4Element::GetElementTable(); |
---|
138 | size_t numOfElm = G4Element::GetNumberOfElements(); |
---|
139 | if(numOfElm > 0) { |
---|
140 | for(size_t i=0; i<numOfElm; ++i) { |
---|
141 | G4int Z = G4int(((*theElmTable)[i])->GetZ()); |
---|
142 | if(Z < 1) Z = 1; |
---|
143 | else if(Z > 92) Z = 92; |
---|
144 | //G4cout << "Z= " << Z << G4endl; |
---|
145 | // Initialisation |
---|
146 | if(!data[Z]) { Initialise(Z, path); } |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | void |
---|
152 | G4NeutronCaptureXS::DumpPhysicsTable(const G4ParticleDefinition&) |
---|
153 | { |
---|
154 | } |
---|
155 | |
---|
156 | void |
---|
157 | G4NeutronCaptureXS::Initialise(G4int Z, const char* p) |
---|
158 | { |
---|
159 | if(data[Z]) return; |
---|
160 | const char* path = p; |
---|
161 | if(!p) { |
---|
162 | // check environment variable |
---|
163 | // Build the complete string identifying the file with the data set |
---|
164 | path = getenv("G4NEUTRONXSDATA"); |
---|
165 | if (!path) { |
---|
166 | if(verboseLevel > 1) { |
---|
167 | G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl; |
---|
168 | } |
---|
169 | return; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | // upload data from file |
---|
174 | data[Z] = new G4PhysicsLogVector(); |
---|
175 | |
---|
176 | std::ostringstream ost; |
---|
177 | ost << path << "/cap" << Z ; |
---|
178 | std::ifstream filein(ost.str().c_str()); |
---|
179 | if (!(filein)) { |
---|
180 | G4cout << " file " << ost << " is not opened" << G4endl; |
---|
181 | }else{ |
---|
182 | if(verboseLevel > 1) { |
---|
183 | G4cout << ost << " is opened" << G4endl; |
---|
184 | } |
---|
185 | // retrieve data from DB |
---|
186 | data[Z]->Retrieve(filein, true); |
---|
187 | } |
---|
188 | } |
---|