Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4CompositeEMDataSet.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//
27// $Id$
28//
29// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
30//
31// History:
32// -----------
33// 1 Aug 2001 MGP Created
34//
35// 15 Jul 2009 Nicolas A. Karakatsanis
36//
37// - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
38// dataset. It is essentially performing the data loading operations as in the past.
39//
40// - LoadData method was revised in order to calculate the logarithmic values of the data
41// It retrieves the data values from the G4EMLOW data files but, then, calculates the
42// respective log values and loads them to seperate data structures.
43//
44// - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
45// The EM data sets, initialized this way, contain both non-log and log values.
46// These initialized data sets can enhance the computing performance of data interpolation
47// operations
48//
49// -------------------------------------------------------------------
50
52#include "G4EMDataSet.hh"
54#include <fstream>
55#include <sstream>
56
58 G4double argUnitEnergies,
59 G4double argUnitData,
60 G4int argMinZ,
61 G4int argMaxZ)
62 :
63 algorithm(argAlgorithm),
64 unitEnergies(argUnitEnergies),
65 unitData(argUnitData),
66 minZ(argMinZ),
67 maxZ(argMaxZ)
68{
69 if (algorithm == 0)
70 G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet",
71 "em1003",FatalException,"interpolation == 0");
72
73}
74
75
76
78{
79 CleanUpComponents();
80 if (algorithm) delete algorithm;
81}
82
83
85{
86 const G4VEMDataSet* component(GetComponent(argComponentId));
87
88 if (component) return component->FindValue(argEnergy);
89
90 std::ostringstream message;
91 message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
92
93 G4Exception("G4CompositeEMDataSet::FindValue",
94 "em1004",FatalException,message.str().c_str());
95
96 return 0.;
97}
98
100{
101 const size_t n(NumberOfComponents());
102
103 G4cout << "The data set has " << n << " components" << G4endl;
104 G4cout << G4endl;
105
106 size_t i(0);
107
108 while (i<n)
109 {
110 G4cout << "--- Component " << i << " ---" << G4endl;
112 i++;
113 }
114}
115
116void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
117{
118 G4VEMDataSet * component(components[argComponentId]);
119
120 if (component)
121 {
122 component->SetEnergiesData(argEnergies, argData, 0);
123 return;
124 }
125
126 std::ostringstream message;
127 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
128
129 G4Exception("G4CompositeEMDataSet::SetEnergiesData",
130 "em1004",FatalException,message.str().c_str());
131}
132
134 G4DataVector* argData,
135 G4DataVector* argLogEnergies,
136 G4DataVector* argLogData,
137 G4int argComponentId)
138{
139 G4VEMDataSet * component(components[argComponentId]);
140
141 if (component)
142 {
143 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
144 return;
145 }
146
147 std::ostringstream message;
148 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
149
150 G4Exception("G4CompositeEMDataSet::SetLogEnergiesData",
151 "em1004",FatalException,message.str().c_str());
152}
153
154
156{
157 CleanUpComponents();
158
159 for (G4int z(minZ); z<maxZ; z++)
160 {
161 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
162 if (!component->LoadData(argFileName))
163 {
164 delete component;
165 return false;
166 }
167 AddComponent(component);
168 }
169 return true;
170}
171
172
174{
175 CleanUpComponents();
176
177 for (G4int z(minZ); z<maxZ; z++)
178 {
179 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
180 if (!component->LoadNonLogData(argFileName))
181 {
182 delete component;
183 return false;
184 }
185 AddComponent(component);
186 }
187 return true;
188}
189
190
192{
193 for (G4int z=minZ; z<maxZ; z++)
194 {
195 const G4VEMDataSet* component(GetComponent(z-minZ));
196
197 if (!component)
198 {
199 std::ostringstream message;
200 message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
201 G4Exception("G4CompositeEMDataSet::SaveData",
202 "em1004",FatalException,message.str().c_str());
203 return false;
204 }
205
206 if (!component->SaveData(argFileName))
207 return false;
208 }
209
210 return true;
211}
212
213void G4CompositeEMDataSet::CleanUpComponents(void)
214{
215 while (!components.empty())
216 {
217 if (components.back())
218 delete components.back();
219 components.pop_back();
220 }
221}
222
223
225{
226 G4double value = 0.;
227 if (componentId >= 0 && componentId < (G4int)components.size())
228 {
229 const G4VEMDataSet* dataSet = GetComponent(componentId);
230 value = dataSet->RandomSelect();
231 }
232 return value;
233}
@ FatalException
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
virtual void PrintData(void) const
virtual G4double RandomSelect(G4int componentId) const
virtual size_t NumberOfComponents() const
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int componentId)
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual void SetLogEnergiesData(G4DataVector *xData, G4DataVector *data, G4DataVector *xLogData, G4DataVector *Logdata, G4int componentId)
G4CompositeEMDataSet(G4VDataSetAlgorithm *argAlgorithm, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn, G4int zMin=1, G4int zMax=99)
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual G4bool LoadNonLogData(const G4String &fileName)
virtual G4bool LoadData(const G4String &fileName)
virtual G4bool SaveData(const G4String &fileName) const
virtual G4VDataSetAlgorithm * Clone() const =0
virtual G4bool SaveData(const G4String &fileName) const =0
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual G4bool LoadNonLogData(const G4String &fileName)=0
virtual G4double RandomSelect(G4int componentId=0) const =0
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
virtual G4double FindValue(G4double x, G4int componentId=0) const =0
virtual G4bool LoadData(const G4String &fileName)=0
virtual void PrintData(void) const =0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41