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 | // |
---|
27 | // $Id: G4BremsstrahlungParameters.cc,v 1.20 2009/06/10 13:32:36 mantero Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) |
---|
31 | // V.Ivanchenko (Vladimir.Ivantchenko@cern.ch) |
---|
32 | // |
---|
33 | // History: |
---|
34 | // ----------- |
---|
35 | // 31 Jul 2001 MGP Created |
---|
36 | // 12.09.01 V.Ivanchenko Add activeZ and paramA |
---|
37 | // 25.09.01 V.Ivanchenko Add parameter C and change interface to B |
---|
38 | // 29.11.01 V.Ivanchenko Update parametrisation |
---|
39 | // 18.11.02 V.Ivanchenko Fix problem of load |
---|
40 | // 21.02.03 V.Ivanchenko Number of parameters is defined in the constructor |
---|
41 | // 28.02.03 V.Ivanchenko Filename is defined in the constructor |
---|
42 | // |
---|
43 | // ------------------------------------------------------------------- |
---|
44 | |
---|
45 | #include "G4BremsstrahlungParameters.hh" |
---|
46 | #include "G4VEMDataSet.hh" |
---|
47 | #include "G4EMDataSet.hh" |
---|
48 | #include "G4LogLogInterpolation.hh" |
---|
49 | #include "G4Material.hh" |
---|
50 | #include <fstream> |
---|
51 | |
---|
52 | |
---|
53 | G4BremsstrahlungParameters:: G4BremsstrahlungParameters(const G4String& name, |
---|
54 | size_t num, G4int minZ, G4int maxZ) |
---|
55 | : zMin(minZ), |
---|
56 | zMax(maxZ), |
---|
57 | length(num) |
---|
58 | { |
---|
59 | LoadData(name); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | G4BremsstrahlungParameters::~G4BremsstrahlungParameters() |
---|
64 | { |
---|
65 | // Reset the map of data sets: remove the data sets from the map |
---|
66 | std::map<G4int,G4VEMDataSet*,std::less<G4int> >::iterator pos; |
---|
67 | |
---|
68 | for (pos = param.begin(); pos != param.end(); ++pos) |
---|
69 | { |
---|
70 | G4VEMDataSet* dataSet = (*pos).second; |
---|
71 | delete dataSet; |
---|
72 | } |
---|
73 | |
---|
74 | activeZ.clear(); |
---|
75 | paramC.clear(); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | G4double G4BremsstrahlungParameters::Parameter(G4int parameterIndex, |
---|
80 | G4int Z, |
---|
81 | G4double energy) const |
---|
82 | { |
---|
83 | G4double value = 0.; |
---|
84 | G4int id = Z*length + parameterIndex; |
---|
85 | std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos; |
---|
86 | |
---|
87 | pos = param.find(id); |
---|
88 | if (pos!= param.end()) { |
---|
89 | |
---|
90 | G4VEMDataSet* dataSet = (*pos).second; |
---|
91 | const G4DataVector ener = dataSet->GetEnergies(0); |
---|
92 | G4double ee = std::max(ener.front(),std::min(ener.back(),energy)); |
---|
93 | value = dataSet->FindValue(ee); |
---|
94 | |
---|
95 | } else { |
---|
96 | G4cout << "WARNING: G4BremsstrahlungParameters::FindValue " |
---|
97 | << "did not find ID = " |
---|
98 | << id << G4endl; |
---|
99 | } |
---|
100 | |
---|
101 | return value; |
---|
102 | } |
---|
103 | |
---|
104 | void G4BremsstrahlungParameters::LoadData(const G4String& name) |
---|
105 | { |
---|
106 | // Build the complete string identifying the file with the data set |
---|
107 | |
---|
108 | // define active elements |
---|
109 | |
---|
110 | const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); |
---|
111 | if (materialTable == 0) |
---|
112 | G4Exception("G4CrossSectionHandler: no MaterialTable found)"); |
---|
113 | |
---|
114 | G4int nMaterials = G4Material::GetNumberOfMaterials(); |
---|
115 | |
---|
116 | G4double x = 1.e-9; |
---|
117 | for (G4int mm=0; mm<100; mm++) { |
---|
118 | paramC.push_back(x); |
---|
119 | } |
---|
120 | |
---|
121 | for (G4int m=0; m<nMaterials; m++) { |
---|
122 | |
---|
123 | const G4Material* material= (*materialTable)[m]; |
---|
124 | const G4ElementVector* elementVector = material->GetElementVector(); |
---|
125 | const G4int nElements = material->GetNumberOfElements(); |
---|
126 | |
---|
127 | for (G4int iEl=0; iEl<nElements; iEl++) { |
---|
128 | G4Element* element = (*elementVector)[iEl]; |
---|
129 | G4double Z = element->GetZ(); |
---|
130 | G4int iz = (G4int)Z; |
---|
131 | if(iz < 100) |
---|
132 | paramC[iz] = 0.217635e-33*(material->GetTotNbOfElectPerVolume()); |
---|
133 | if (!(activeZ.contains(Z))) { |
---|
134 | activeZ.push_back(Z); |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | // Read parameters |
---|
140 | |
---|
141 | char* path = getenv("G4LEDATA"); |
---|
142 | if (path == 0) |
---|
143 | { |
---|
144 | G4String excep("G4BremsstrahlungParameters - G4LEDATA environment variable not set"); |
---|
145 | G4Exception(excep); |
---|
146 | } |
---|
147 | |
---|
148 | G4String pathString_a(path); |
---|
149 | G4String name_a = pathString_a + name; |
---|
150 | std::ifstream file_a(name_a); |
---|
151 | std::filebuf* lsdp_a = file_a.rdbuf(); |
---|
152 | |
---|
153 | if (! (lsdp_a->is_open()) ) |
---|
154 | { |
---|
155 | G4String stringConversion2("G4BremsstrahlungParameters: cannot open file "); |
---|
156 | G4String excep = stringConversion2 + name_a; |
---|
157 | G4Exception(excep); |
---|
158 | } |
---|
159 | |
---|
160 | // The file is organized into two columns: |
---|
161 | // 1st column is the energy |
---|
162 | // 2nd column is the corresponding value |
---|
163 | // The file terminates with the pattern: -1 -1 |
---|
164 | // -2 -2 |
---|
165 | |
---|
166 | G4DataVector* energies; |
---|
167 | G4DataVector* data; |
---|
168 | G4double ener = 0.0; |
---|
169 | G4double sum = 0.0; |
---|
170 | energies = new G4DataVector(); |
---|
171 | data = new G4DataVector(); |
---|
172 | G4int z = 0; |
---|
173 | |
---|
174 | std::vector<G4DataVector*> a; |
---|
175 | for (size_t j=0; j<length; j++) { |
---|
176 | G4DataVector* aa = new G4DataVector(); |
---|
177 | a.push_back(aa); |
---|
178 | } |
---|
179 | G4DataVector e; |
---|
180 | e.clear(); |
---|
181 | |
---|
182 | do { |
---|
183 | file_a >> ener >> sum; |
---|
184 | |
---|
185 | // End of file |
---|
186 | if (ener == (G4double)(-2)) { |
---|
187 | break; |
---|
188 | |
---|
189 | // End of next element |
---|
190 | } else if (ener == (G4double)(-1)) { |
---|
191 | |
---|
192 | z++; |
---|
193 | G4double Z = (G4double)z; |
---|
194 | |
---|
195 | // fill map if Z is used |
---|
196 | if (activeZ.contains(Z)) { |
---|
197 | |
---|
198 | for (size_t k=0; k<length; k++) { |
---|
199 | |
---|
200 | G4int id = z*length + k; |
---|
201 | G4VDataSetAlgorithm* inter = new G4LogLogInterpolation(); |
---|
202 | G4DataVector* eVector = new G4DataVector; |
---|
203 | size_t eSize = e.size(); |
---|
204 | for (size_t s=0; s<eSize; s++) { |
---|
205 | eVector->push_back(e[s]); |
---|
206 | } |
---|
207 | G4VEMDataSet* set = new G4EMDataSet(id,eVector,a[k],inter,1.,1.); |
---|
208 | param[id] = set; |
---|
209 | } |
---|
210 | a.clear(); |
---|
211 | for (size_t j=0; j<length; j++) { |
---|
212 | G4DataVector* aa = new G4DataVector(); |
---|
213 | a.push_back(aa); |
---|
214 | } |
---|
215 | } else { |
---|
216 | for (size_t j=0; j<length; j++) { |
---|
217 | a[j]->clear(); |
---|
218 | } |
---|
219 | } |
---|
220 | e.clear(); |
---|
221 | |
---|
222 | } else { |
---|
223 | |
---|
224 | if(ener > 1000.) ener = 1000.; |
---|
225 | e.push_back(ener); |
---|
226 | a[length-1]->push_back(sum); |
---|
227 | |
---|
228 | for (size_t j=0; j<length-1; j++) { |
---|
229 | G4double qRead; |
---|
230 | file_a >> qRead; |
---|
231 | a[j]->push_back(qRead); |
---|
232 | } |
---|
233 | |
---|
234 | } |
---|
235 | } while (ener != (G4double)(-2)); |
---|
236 | |
---|
237 | file_a.close(); |
---|
238 | |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | G4double G4BremsstrahlungParameters::ParameterC(G4int id) const |
---|
243 | { |
---|
244 | G4int n = paramC.size(); |
---|
245 | if (id < 0 || id >= n) |
---|
246 | { |
---|
247 | G4String stringConversion1("G4BremsstrahlungParameters::ParameterC - wrong id = "); |
---|
248 | G4String stringConversion2(id); |
---|
249 | G4String ex = stringConversion1 + stringConversion2; |
---|
250 | G4Exception(ex); |
---|
251 | } |
---|
252 | |
---|
253 | return paramC[id]; |
---|
254 | } |
---|
255 | |
---|
256 | |
---|
257 | void G4BremsstrahlungParameters::PrintData() const |
---|
258 | { |
---|
259 | |
---|
260 | G4cout << G4endl; |
---|
261 | G4cout << "===== G4BremsstrahlungParameters =====" << G4endl; |
---|
262 | G4cout << G4endl; |
---|
263 | G4cout << "===== Parameters =====" << G4endl; |
---|
264 | G4cout << G4endl; |
---|
265 | |
---|
266 | size_t nZ = activeZ.size(); |
---|
267 | std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos; |
---|
268 | |
---|
269 | for (size_t j=0; j<nZ; j++) { |
---|
270 | G4int Z = (G4int)activeZ[j]; |
---|
271 | |
---|
272 | for (size_t i=0; i<length; i++) { |
---|
273 | |
---|
274 | pos = param.find(Z*length + i); |
---|
275 | if (pos!= param.end()) { |
---|
276 | |
---|
277 | G4cout << "===== Z= " << Z |
---|
278 | << " parameter[" << i << "] =====" |
---|
279 | << G4endl; |
---|
280 | G4VEMDataSet* dataSet = (*pos).second; |
---|
281 | dataSet->PrintData(); |
---|
282 | } |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | G4cout << "==========================================" << G4endl; |
---|
287 | } |
---|
288 | |
---|