Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ShellEMDataSet Class Reference

#include <G4ShellEMDataSet.hh>

+ Inheritance diagram for G4ShellEMDataSet:

Public Member Functions

 G4ShellEMDataSet (G4int Z, G4VDataSetAlgorithm *algo, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
virtual ~G4ShellEMDataSet ()
 
virtual G4double FindValue (G4double energy, G4int componentId=0) const
 
virtual void PrintData (void) const
 
virtual const G4VEMDataSetGetComponent (G4int componentId) const
 
virtual void AddComponent (G4VEMDataSet *dataSet)
 
virtual size_t NumberOfComponents (void) const
 
virtual const G4DataVectorGetEnergies (G4int componentId) const
 
virtual const G4DataVectorGetData (G4int componentId) const
 
virtual const G4DataVectorGetLogEnergies (G4int componentId) const
 
virtual const G4DataVectorGetLogData (G4int componentId) const
 
virtual void SetEnergiesData (G4DataVector *energies, G4DataVector *data, G4int componentId)
 
virtual void SetLogEnergiesData (G4DataVector *energies, G4DataVector *data, G4DataVector *log_energies, G4DataVector *log_data, G4int componentId)
 
virtual G4bool LoadData (const G4String &fileName)
 
virtual G4bool LoadNonLogData (const G4String &fileName)
 
virtual G4bool SaveData (const G4String &fileName) const
 
virtual G4double RandomSelect (G4int) const
 
- Public Member Functions inherited from G4VEMDataSet
 G4VEMDataSet ()
 
virtual ~G4VEMDataSet ()
 
virtual G4double FindValue (G4double x, G4int componentId=0) const =0
 
virtual void PrintData (void) const =0
 
virtual const G4VEMDataSetGetComponent (G4int componentId) const =0
 
virtual void AddComponent (G4VEMDataSet *dataSet)=0
 
virtual size_t NumberOfComponents (void) const =0
 
virtual const G4DataVectorGetEnergies (G4int componentId) const =0
 
virtual const G4DataVectorGetData (G4int componentId) const =0
 
virtual const G4DataVectorGetLogEnergies (G4int componentId) const =0
 
virtual const G4DataVectorGetLogData (G4int componentId) const =0
 
virtual void SetEnergiesData (G4DataVector *x, G4DataVector *data, G4int component=0)=0
 
virtual void SetLogEnergiesData (G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
 
virtual G4bool LoadData (const G4String &fileName)=0
 
virtual G4bool LoadNonLogData (const G4String &fileName)=0
 
virtual G4bool SaveData (const G4String &fileName) const =0
 
virtual G4double RandomSelect (G4int componentId=0) const =0
 

Protected Member Functions

G4double GetUnitEnergies () const
 
G4double GetUnitData () const
 
const G4VDataSetAlgorithmGetAlgorithm () const
 
void CleanUpComponents (void)
 

Detailed Description

Definition at line 59 of file G4ShellEMDataSet.hh.

Constructor & Destructor Documentation

◆ G4ShellEMDataSet()

G4ShellEMDataSet::G4ShellEMDataSet ( G4int  Z,
G4VDataSetAlgorithm algo,
G4double  eUnit = CLHEP::MeV,
G4double  dataUnit = CLHEP::barn 
)

Definition at line 63 of file G4ShellEMDataSet.cc.

66 :
67 z(zeta),
68 algorithm(algo),
69 unitEnergies(eUnit),
70 unitData(dataUnit)
71{
72 if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet()","em0007",FatalErrorInArgument, "Interpolation == 0");
73}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35

Referenced by G4ShellEMDataSet().

◆ ~G4ShellEMDataSet()

G4ShellEMDataSet::~G4ShellEMDataSet ( )
virtual

Definition at line 76 of file G4ShellEMDataSet.cc.

77{
79 if (algorithm) delete algorithm;
80}
void CleanUpComponents(void)

Member Function Documentation

◆ AddComponent()

virtual void G4ShellEMDataSet::AddComponent ( G4VEMDataSet dataSet)
inlinevirtual

Implements G4VEMDataSet.

Definition at line 74 of file G4ShellEMDataSet.hh.

74{ components.push_back(dataSet); }

Referenced by LoadData(), and LoadNonLogData().

◆ CleanUpComponents()

void G4ShellEMDataSet::CleanUpComponents ( void  )
protected

Definition at line 388 of file G4ShellEMDataSet.cc.

389{
390 while (!components.empty())
391 {
392 if (components.back()) delete components.back();
393 components.pop_back();
394 }
395}

Referenced by LoadData(), LoadNonLogData(), and ~G4ShellEMDataSet().

◆ FindValue()

G4double G4ShellEMDataSet::FindValue ( G4double  energy,
G4int  componentId = 0 
) const
virtual

Implements G4VEMDataSet.

Definition at line 83 of file G4ShellEMDataSet.cc.

84{
85 // Returns the sum over the shells corresponding to e
86 G4double value = 0.;
87
88 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
89 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
90
91 while (i != end)
92 {
93 value += (*i)->FindValue(energy);
94 i++;
95 }
96
97 return value;
98}
double G4double
Definition: G4Types.hh:83

◆ GetAlgorithm()

const G4VDataSetAlgorithm * G4ShellEMDataSet::GetAlgorithm ( ) const
inlineprotected

Definition at line 100 of file G4ShellEMDataSet.hh.

100{ return algorithm; }

◆ GetComponent()

virtual const G4VEMDataSet * G4ShellEMDataSet::GetComponent ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 73 of file G4ShellEMDataSet.hh.

73{ return components[componentId]; }

Referenced by GetData(), GetEnergies(), GetLogData(), GetLogEnergies(), PrintData(), and SaveData().

◆ GetData()

virtual const G4DataVector & G4ShellEMDataSet::GetData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 78 of file G4ShellEMDataSet.hh.

78{ return GetComponent(componentId)->GetData(0); }
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual const G4DataVector & GetData(G4int componentId) const =0

◆ GetEnergies()

virtual const G4DataVector & G4ShellEMDataSet::GetEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 77 of file G4ShellEMDataSet.hh.

77{ return GetComponent(componentId)->GetEnergies(0); }
virtual const G4DataVector & GetEnergies(G4int componentId) const =0

◆ GetLogData()

virtual const G4DataVector & G4ShellEMDataSet::GetLogData ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 80 of file G4ShellEMDataSet.hh.

80{ return GetComponent(componentId)->GetLogData(0); }
virtual const G4DataVector & GetLogData(G4int componentId) const =0

◆ GetLogEnergies()

virtual const G4DataVector & G4ShellEMDataSet::GetLogEnergies ( G4int  componentId) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 79 of file G4ShellEMDataSet.hh.

79{ return GetComponent(componentId)->GetLogEnergies(0); }
virtual const G4DataVector & GetLogEnergies(G4int componentId) const =0

◆ GetUnitData()

G4double G4ShellEMDataSet::GetUnitData ( ) const
inlineprotected

Definition at line 99 of file G4ShellEMDataSet.hh.

99{ return unitData; }

◆ GetUnitEnergies()

G4double G4ShellEMDataSet::GetUnitEnergies ( ) const
inlineprotected

Definition at line 98 of file G4ShellEMDataSet.hh.

98{ return unitEnergies; }

◆ LoadData()

G4bool G4ShellEMDataSet::LoadData ( const G4String fileName)
virtual

Implements G4VEMDataSet.

Definition at line 159 of file G4ShellEMDataSet.cc.

160{
162
163 G4String fullFileName = FullFileName(file);
164 std::ifstream in(fullFileName);
165
166 if (!in.is_open())
167 {
168 G4String message("Data file \"");
169 message += fullFileName;
170 message += "\" not found";
171 G4Exception("G4ShellEMDataSet::LoadData()", "em0003",FatalException, message);
172 return 0;
173 }
174
175 G4DataVector* orig_shell_energies = 0;
176 G4DataVector* orig_shell_data = 0;
177 G4DataVector* log_shell_energies = 0;
178 G4DataVector* log_shell_data = 0;
179
180 G4double a = 0.;
181 G4int shellIndex = 0;
182 G4int k = 0;
183 G4int nColumns = 2;
184
185 do
186 {
187 in >> a;
188
189 if (a==0.) a=1e-300;
190
191 // The file is organized into four columns:
192 // 1st column contains the values of energy
193 // 2nd column contains the corresponding data value
194 // The file terminates with the pattern: -1 -1
195 // -2 -2
196 //
197 if (a == -1)
198 {
199 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
200 {
201 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData));
202 orig_shell_energies = 0;
203 orig_shell_data = 0;
204 log_shell_energies = 0;
205 log_shell_data = 0;
206 }
207 }
208 else if (a != -2)
209 {
210 if (orig_shell_energies == 0)
211 {
212 orig_shell_energies = new G4DataVector;
213 orig_shell_data = new G4DataVector;
214 log_shell_energies = new G4DataVector;
215 log_shell_data = new G4DataVector;
216 }
217 if (k%nColumns == 0)
218 {
219 orig_shell_energies->push_back(a*unitEnergies);
220 log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies));
221 }
222 else if (k%nColumns == 1)
223 {
224 orig_shell_data->push_back(a*unitData);
225 log_shell_data->push_back(std::log10(a) + std::log10(unitData));
226 }
227 k++;
228 }
229 else k = 1;
230 }
231 while (a != -2); // End of file
232
233
234 delete orig_shell_energies;
235 delete orig_shell_data;
236 delete log_shell_energies;
237 delete log_shell_data;
238
239 return true;
240}
@ FatalException
int G4int
Definition: G4Types.hh:85
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual G4VDataSetAlgorithm * Clone() const =0

◆ LoadNonLogData()

G4bool G4ShellEMDataSet::LoadNonLogData ( const G4String fileName)
virtual

Implements G4VEMDataSet.

Definition at line 243 of file G4ShellEMDataSet.cc.

244{
246
247 G4String fullFileName = FullFileName(file);
248 std::ifstream in(fullFileName);
249
250 if (!in.is_open())
251 {
252 G4String message("G4ShellEMDataSet::LoadData - data file \"");
253 message += fullFileName;
254 message += "\" not found";
255 G4Exception("G4ShellEMDataSet::LoadNonLogData()", "em0003",FatalException, message);
256 return 0;
257 }
258
259 G4DataVector* orig_shell_energies = 0;
260 G4DataVector* orig_shell_data = 0;
261
262 G4double a = 0.;
263 G4int shellIndex = 0;
264 G4int k = 0;
265 G4int nColumns = 2;
266
267 do
268 {
269 in >> a;
270
271 // The file is organized into four columns:
272 // 1st column contains the values of energy
273 // 2nd column contains the corresponding data value
274 // The file terminates with the pattern: -1 -1
275 // -2 -2
276 //
277 if (a == -1)
278 {
279 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
280 {
281 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData));
282 orig_shell_energies = 0;
283 orig_shell_data = 0;
284 }
285 }
286 else if (a != -2)
287 {
288 if (orig_shell_energies == 0)
289 {
290 orig_shell_energies = new G4DataVector;
291 orig_shell_data = new G4DataVector;
292 }
293 if (k%nColumns == 0)
294 {
295 orig_shell_energies->push_back(a*unitEnergies);
296 }
297 else if (k%nColumns == 1)
298 {
299 orig_shell_data->push_back(a*unitData);
300 }
301 k++;
302 }
303 else k = 1;
304 }
305 while (a != -2); // End of file
306
307
308 delete orig_shell_energies;
309 delete orig_shell_data;
310
311 return true;
312}

◆ NumberOfComponents()

virtual size_t G4ShellEMDataSet::NumberOfComponents ( void  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 75 of file G4ShellEMDataSet.hh.

75{ return components.size(); }

Referenced by PrintData(), and SaveData().

◆ PrintData()

void G4ShellEMDataSet::PrintData ( void  ) const
virtual

Implements G4VEMDataSet.

Definition at line 101 of file G4ShellEMDataSet.cc.

102{
103 const size_t n = NumberOfComponents();
104
105 G4cout << "The data set has " << n << " components" << G4endl;
106 G4cout << G4endl;
107
108 size_t i = 0;
109
110 while (i < n)
111 {
112 G4cout << "--- Component " << i << " ---" << G4endl;
114 i++;
115 }
116}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual size_t NumberOfComponents(void) const
virtual void PrintData(void) const =0

◆ RandomSelect()

virtual G4double G4ShellEMDataSet::RandomSelect ( G4int  ) const
inlinevirtual

Implements G4VEMDataSet.

Definition at line 94 of file G4ShellEMDataSet.hh.

94{ return -1.; };

◆ SaveData()

G4bool G4ShellEMDataSet::SaveData ( const G4String fileName) const
virtual

Implements G4VEMDataSet.

Definition at line 316 of file G4ShellEMDataSet.cc.

317{
318 G4String fullFileName = FullFileName(file);
319 std::ofstream out(fullFileName);
320
321 if (!out.is_open())
322 {
323 G4String message("Cannot open \"");
324 message += fullFileName;
325 message += "\"";
326 G4Exception("G4EMDataSet::SaveData()","em0005",FatalException,message);
327 }
328
329 const size_t n = NumberOfComponents();
330 size_t k = 0;
331
332 while (k < n)
333 {
334 const G4VEMDataSet* component = GetComponent(k);
335
336 if (component)
337 {
338 const G4DataVector& energies = component->GetEnergies(0);
339 const G4DataVector& data = component->GetData(0);
340
341 G4DataVector::const_iterator i = energies.begin();
342 G4DataVector::const_iterator endI = energies.end();
343 G4DataVector::const_iterator j = data.begin();
344
345 while (i != endI)
346 {
347 out.precision(10);
348 out.width(15);
349 out.setf(std::ofstream::left);
350 out << ((*i)/unitEnergies) << ' ';
351
352 out.precision(10);
353 out.width(15);
354 out.setf(std::ofstream::left);
355 out << ((*j)/unitData) << std::endl;
356 i++;
357 j++;
358 }
359 }
360
361 out.precision(10);
362 out.width(15);
363 out.setf(std::ofstream::left);
364 out << -1.f << ' ';
365
366 out.precision(10);
367 out.width(15);
368 out.setf(std::ofstream::left);
369 out << -1.f << std::endl;
370
371 k++;
372 }
373
374 out.precision(10);
375 out.width(15);
376 out.setf(std::ofstream::left);
377 out << -2.f << ' ';
378
379 out.precision(10);
380 out.width(15);
381 out.setf(std::ofstream::left);
382 out << -2.f << std::endl;
383
384 return true;
385}

◆ SetEnergiesData()

void G4ShellEMDataSet::SetEnergiesData ( G4DataVector energies,
G4DataVector data,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 119 of file G4ShellEMDataSet.cc.

122{
123 G4VEMDataSet* component = components[componentId];
124
125 if (component)
126 {
127 component->SetEnergiesData(energies, data, 0);
128 return;
129 }
130
131 G4String msg = "component " + (G4String)componentId + " not found";
132
133 G4Exception("G4ShellEMDataSet::SetEnergiesData()","em0008", FatalErrorInArgument ,msg);
134}
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0

◆ SetLogEnergiesData()

void G4ShellEMDataSet::SetLogEnergiesData ( G4DataVector energies,
G4DataVector data,
G4DataVector log_energies,
G4DataVector log_data,
G4int  componentId 
)
virtual

Implements G4VEMDataSet.

Definition at line 137 of file G4ShellEMDataSet.cc.

142{
143 G4VEMDataSet* component = components[componentId];
144
145 if (component)
146 {
147 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
148 return;
149 }
150
151 G4String msg = "component " + (G4String)componentId + " not found";
152
153 G4Exception("G4ShellEMDataSet::SetLogEnergiesData()","em0008", FatalErrorInArgument ,msg);
154
155}
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0

The documentation for this class was generated from the following files: