source: trunk/source/processes/electromagnetic/lowenergy/src/G4ShellEMDataSet.cc@ 1199

Last change on this file since 1199 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 11.1 KB
Line 
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: G4ShellEMDataSet.cc,v 1.18 2009/09/25 07:41:34 sincerti Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001 MGP Created
35//
36// 09.10.01 V.Ivanchenko Add case z=0
37//
38// 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
39// (Further clean-up needed)
40//
41// 15 Jul 2009 Nicolas A. Karakatsanis
42//
43// - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
44// dataset. It is essentially performing the data loading operations as in the past.
45//
46// - LoadData method was revised in order to calculate the logarithmic values of the data
47// It retrieves the data values from the G4EMLOW data files but, then, calculates the
48// respective log values and loads them to seperate data structures.
49//
50// - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
51// The EM data sets, initialized this way, contain both non-log and log values.
52// These initialized data sets can enhance the computing performance of data interpolation
53// operations
54//
55//
56// -------------------------------------------------------------------
57
58#include "G4ShellEMDataSet.hh"
59#include "G4EMDataSet.hh"
60#include "G4VDataSetAlgorithm.hh"
61#include <fstream>
62#include <sstream>
63
64
65G4ShellEMDataSet::G4ShellEMDataSet(G4int zeta, G4VDataSetAlgorithm* algo,
66 G4double eUnit,
67 G4double dataUnit)
68 :
69 z(zeta),
70 algorithm(algo),
71 unitEnergies(eUnit),
72 unitData(dataUnit)
73{
74 if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet - interpolation == 0");
75}
76
77
78G4ShellEMDataSet::~G4ShellEMDataSet()
79{
80 CleanUpComponents();
81 if (algorithm) delete algorithm;
82}
83
84
85G4double G4ShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const
86{
87 // Returns the sum over the shells corresponding to e
88 G4double value = 0.;
89
90 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
91 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
92
93 while (i != end)
94 {
95 value += (*i)->FindValue(energy);
96 i++;
97 }
98
99 return value;
100}
101
102
103void G4ShellEMDataSet::PrintData(void) const
104{
105 const size_t n = NumberOfComponents();
106
107 G4cout << "The data set has " << n << " components" << G4endl;
108 G4cout << G4endl;
109
110 size_t i = 0;
111
112 while (i < n)
113 {
114 G4cout << "--- Component " << i << " ---" << G4endl;
115 GetComponent(i)->PrintData();
116 i++;
117 }
118}
119
120
121void G4ShellEMDataSet::SetEnergiesData(G4DataVector* energies,
122 G4DataVector* data,
123 G4int componentId)
124{
125 G4VEMDataSet* component = components[componentId];
126
127 if (component)
128 {
129 component->SetEnergiesData(energies, data, 0);
130 return;
131 }
132
133 std::ostringstream message;
134 message << "G4ShellEMDataSet::SetEnergiesData - component " << componentId << " not found";
135
136 G4Exception(message.str().c_str());
137}
138
139
140void G4ShellEMDataSet::SetLogEnergiesData(G4DataVector* energies,
141 G4DataVector* data,
142 G4DataVector* log_energies,
143 G4DataVector* log_data,
144 G4int componentId)
145{
146 G4VEMDataSet* component = components[componentId];
147
148 if (component)
149 {
150 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
151 return;
152 }
153
154 std::ostringstream message;
155 message << "G4ShellEMDataSet::SetLogEnergiesData - component " << componentId << " not found";
156
157 G4Exception(message.str().c_str());
158}
159
160
161
162G4bool G4ShellEMDataSet::LoadData(const G4String& file)
163{
164 CleanUpComponents();
165
166 G4String fullFileName = FullFileName(file);
167 std::ifstream in(fullFileName);
168
169 if (!in.is_open())
170 {
171 G4String message("G4ShellEMDataSet::LoadData - data file \"");
172 message += fullFileName;
173 message += "\" not found";
174 G4Exception(message);
175 }
176
177 G4DataVector* orig_shell_energies = 0;
178 G4DataVector* orig_shell_data = 0;
179 G4DataVector* log_shell_energies = 0;
180 G4DataVector* log_shell_data = 0;
181
182 G4double a = 0.;
183 G4int shellIndex = 0;
184 G4int k = 0;
185 G4int nColumns = 2;
186
187 do
188 {
189 in >> a;
190
191 if (a==0.) a=1e-300;
192
193 // The file is organized into four columns:
194 // 1st column contains the values of energy
195 // 2nd column contains the corresponding data value
196 // The file terminates with the pattern: -1 -1
197 // -2 -2
198 //
199 if (a == -1)
200 {
201 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
202 {
203 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData));
204 orig_shell_energies = 0;
205 orig_shell_data = 0;
206 log_shell_energies = 0;
207 log_shell_data = 0;
208 }
209 }
210 else if (a != -2)
211 {
212 if (orig_shell_energies == 0)
213 {
214 orig_shell_energies = new G4DataVector;
215 orig_shell_data = new G4DataVector;
216 log_shell_energies = new G4DataVector;
217 log_shell_data = new G4DataVector;
218 }
219 if (k%nColumns == 0)
220 {
221 orig_shell_energies->push_back(a*unitEnergies);
222 log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies));
223 }
224 else if (k%nColumns == 1)
225 {
226 orig_shell_data->push_back(a*unitData);
227 log_shell_data->push_back(std::log10(a) + std::log10(unitData));
228 }
229 k++;
230 }
231 else k = 1;
232 }
233 while (a != -2); // End of file
234
235 return true;
236}
237
238
239G4bool G4ShellEMDataSet::LoadNonLogData(const G4String& file)
240{
241 CleanUpComponents();
242
243 G4String fullFileName = FullFileName(file);
244 std::ifstream in(fullFileName);
245
246 if (!in.is_open())
247 {
248 G4String message("G4ShellEMDataSet::LoadData - data file \"");
249 message += fullFileName;
250 message += "\" not found";
251 G4Exception(message);
252 }
253
254 G4DataVector* orig_shell_energies = 0;
255 G4DataVector* orig_shell_data = 0;
256
257 G4double a = 0.;
258 G4int shellIndex = 0;
259 G4int k = 0;
260 G4int nColumns = 2;
261
262 do
263 {
264 in >> a;
265
266 // The file is organized into four columns:
267 // 1st column contains the values of energy
268 // 2nd column contains the corresponding data value
269 // The file terminates with the pattern: -1 -1
270 // -2 -2
271 //
272 if (a == -1)
273 {
274 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
275 {
276 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData));
277 orig_shell_energies = 0;
278 orig_shell_data = 0;
279 }
280 }
281 else if (a != -2)
282 {
283 if (orig_shell_energies == 0)
284 {
285 orig_shell_energies = new G4DataVector;
286 orig_shell_data = new G4DataVector;
287 }
288 if (k%nColumns == 0)
289 {
290 orig_shell_energies->push_back(a*unitEnergies);
291 }
292 else if (k%nColumns == 1)
293 {
294 orig_shell_data->push_back(a*unitData);
295 }
296 k++;
297 }
298 else k = 1;
299 }
300 while (a != -2); // End of file
301
302 return true;
303}
304
305
306
307G4bool G4ShellEMDataSet::SaveData(const G4String& file) const
308{
309 G4String fullFileName = FullFileName(file);
310 std::ofstream out(fullFileName);
311
312 if (!out.is_open())
313 {
314 G4String message("G4EMDataSet::SaveData - cannot open \"");
315 message += fullFileName;
316 message += "\"";
317 G4Exception(message);
318 }
319
320 const size_t n = NumberOfComponents();
321 size_t k = 0;
322
323 while (k < n)
324 {
325 const G4VEMDataSet* component = GetComponent(k);
326
327 if (component)
328 {
329 const G4DataVector& energies = component->GetEnergies(0);
330 const G4DataVector& data = component->GetData(0);
331
332 G4DataVector::const_iterator i = energies.begin();
333 G4DataVector::const_iterator endI = energies.end();
334 G4DataVector::const_iterator j = data.begin();
335
336 while (i != endI)
337 {
338 out.precision(10);
339 out.width(15);
340 out.setf(std::ofstream::left);
341 out << ((*i)/unitEnergies) << ' ';
342
343 out.precision(10);
344 out.width(15);
345 out.setf(std::ofstream::left);
346 out << ((*j)/unitData) << std::endl;
347 i++;
348 j++;
349 }
350 }
351
352 out.precision(10);
353 out.width(15);
354 out.setf(std::ofstream::left);
355 out << -1.f << ' ';
356
357 out.precision(10);
358 out.width(15);
359 out.setf(std::ofstream::left);
360 out << -1.f << std::endl;
361
362 k++;
363 }
364
365 out.precision(10);
366 out.width(15);
367 out.setf(std::ofstream::left);
368 out << -2.f << ' ';
369
370 out.precision(10);
371 out.width(15);
372 out.setf(std::ofstream::left);
373 out << -2.f << std::endl;
374
375 return true;
376}
377
378
379void G4ShellEMDataSet::CleanUpComponents(void)
380{
381 while (!components.empty())
382 {
383 if (components.back()) delete components.back();
384 components.pop_back();
385 }
386}
387
388
389G4String G4ShellEMDataSet::FullFileName(const G4String& fileName) const
390{
391 char* path = getenv("G4LEDATA");
392 if (!path)
393 G4Exception("G4ShellEMDataSet::FullFileName - G4LEDATA environment variable not set");
394
395 std::ostringstream fullFileName;
396
397 fullFileName << path << '/' << fileName << z << ".dat";
398
399 return G4String(fullFileName.str().c_str());
400}
Note: See TracBrowser for help on using the repository browser.