Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
G4ShellEMDataSet Class Reference

#include <G4ShellEMDataSet.hh>

Inheritance diagram for G4ShellEMDataSet:
G4VEMDataSet

Public Member Functions

void AddComponent (G4VEMDataSet *dataSet) override
 
G4double FindValue (G4double energy, G4int componentId=0) const override
 
 G4ShellEMDataSet (const G4ShellEMDataSet &copy)=delete
 
 G4ShellEMDataSet (G4int Z, G4VDataSetAlgorithm *algo, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
 
const G4VEMDataSetGetComponent (G4int componentId) const override
 
const G4DataVectorGetData (G4int componentId) const override
 
const G4DataVectorGetEnergies (G4int componentId) const override
 
const G4DataVectorGetLogData (G4int componentId) const override
 
const G4DataVectorGetLogEnergies (G4int componentId) const override
 
G4bool LoadData (const G4String &fileName) override
 
G4bool LoadNonLogData (const G4String &fileName) override
 
size_t NumberOfComponents (void) const override
 
G4ShellEMDataSetoperator= (const G4ShellEMDataSet &right)=delete
 
void PrintData (void) const override
 
G4double RandomSelect (G4int) const override
 
G4bool SaveData (const G4String &fileName) const override
 
void SetEnergiesData (G4DataVector *energies, G4DataVector *data, G4int componentId) override
 
void SetLogEnergiesData (G4DataVector *energies, G4DataVector *data, G4DataVector *log_energies, G4DataVector *log_data, G4int componentId) override
 
virtual ~G4ShellEMDataSet ()
 

Protected Member Functions

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

Private Member Functions

G4String FullFileName (const G4String &fileName) const
 

Private Attributes

G4VDataSetAlgorithmalgorithm
 
std::vector< G4VEMDataSet * > components
 
G4double unitData
 
G4double unitEnergies
 
G4int z
 

Detailed Description

Definition at line 59 of file G4ShellEMDataSet.hh.

Constructor & Destructor Documentation

◆ G4ShellEMDataSet() [1/2]

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

Definition at line 63 of file G4ShellEMDataSet.cc.

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

References algorithm, FatalErrorInArgument, and G4Exception().

◆ ~G4ShellEMDataSet()

G4ShellEMDataSet::~G4ShellEMDataSet ( )
virtual

Definition at line 78 of file G4ShellEMDataSet.cc.

79{
81 if (algorithm) delete algorithm;
82}

References algorithm, and CleanUpComponents().

◆ G4ShellEMDataSet() [2/2]

G4ShellEMDataSet::G4ShellEMDataSet ( const G4ShellEMDataSet copy)
delete

Member Function Documentation

◆ AddComponent()

void G4ShellEMDataSet::AddComponent ( G4VEMDataSet dataSet)
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 73 of file G4ShellEMDataSet.hh.

73{ components.push_back(dataSet); }
std::vector< G4VEMDataSet * > components

References components.

Referenced by LoadData(), and LoadNonLogData().

◆ CleanUpComponents()

void G4ShellEMDataSet::CleanUpComponents ( void  )
protected

Definition at line 399 of file G4ShellEMDataSet.cc.

400{
401 while (!components.empty())
402 {
403 if (components.back()) delete components.back();
404 components.pop_back();
405 }
406}

References components.

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

◆ FindValue()

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

Implements G4VEMDataSet.

Definition at line 85 of file G4ShellEMDataSet.cc.

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}
double G4double
Definition: G4Types.hh:83
G4double energy(const ThreeVector &p, const G4double m)

References components, and G4INCL::KinematicsUtils::energy().

◆ FullFileName()

G4String G4ShellEMDataSet::FullFileName ( const G4String fileName) const
private

Definition at line 410 of file G4ShellEMDataSet.cc.

411{
412 char* path = std::getenv("G4LEDATA");
413
414 if (!path)
415 {
416 G4Exception("G4ShellEMDataSet::FullFileName()","em0006",JustWarning,"Please set G4LEDATA");
417 return "";
418 }
419
420 std::ostringstream fullFileName;
421
422 fullFileName << path << '/' << fileName << z << ".dat";
423
424 return G4String(fullFileName.str().c_str());
425}
@ JustWarning

References G4Exception(), JustWarning, and z.

Referenced by LoadData(), LoadNonLogData(), and SaveData().

◆ GetAlgorithm()

const G4VDataSetAlgorithm * G4ShellEMDataSet::GetAlgorithm ( ) const
inlineprotected

Definition at line 100 of file G4ShellEMDataSet.hh.

100{ return algorithm; }

References algorithm.

◆ GetComponent()

const G4VEMDataSet * G4ShellEMDataSet::GetComponent ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 72 of file G4ShellEMDataSet.hh.

72{ return components[componentId]; }

References components.

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

◆ GetData()

const G4DataVector & G4ShellEMDataSet::GetData ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 77 of file G4ShellEMDataSet.hh.

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

References GetComponent(), and G4VEMDataSet::GetData().

◆ GetEnergies()

const G4DataVector & G4ShellEMDataSet::GetEnergies ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 76 of file G4ShellEMDataSet.hh.

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

References GetComponent(), and G4VEMDataSet::GetEnergies().

◆ GetLogData()

const G4DataVector & G4ShellEMDataSet::GetLogData ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 80 of file G4ShellEMDataSet.hh.

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

References GetComponent(), and G4VEMDataSet::GetLogData().

◆ GetLogEnergies()

const G4DataVector & G4ShellEMDataSet::GetLogEnergies ( G4int  componentId) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 78 of file G4ShellEMDataSet.hh.

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

References GetComponent(), and G4VEMDataSet::GetLogEnergies().

◆ GetUnitData()

G4double G4ShellEMDataSet::GetUnitData ( ) const
inlineprotected

Definition at line 99 of file G4ShellEMDataSet.hh.

99{ return unitData; }

References unitData.

◆ GetUnitEnergies()

G4double G4ShellEMDataSet::GetUnitEnergies ( ) const
inlineprotected

Definition at line 98 of file G4ShellEMDataSet.hh.

98{ return unitEnergies; }

References unitEnergies.

◆ LoadData()

G4bool G4ShellEMDataSet::LoadData ( const G4String fileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 165 of file G4ShellEMDataSet.cc.

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

References AddComponent(), algorithm, CleanUpComponents(), G4VDataSetAlgorithm::Clone(), FatalException, geant4_check_module_cycles::file, FullFileName(), G4Exception(), unitData, and unitEnergies.

◆ LoadNonLogData()

G4bool G4ShellEMDataSet::LoadNonLogData ( const G4String fileName)
overridevirtual

Implements G4VEMDataSet.

Definition at line 252 of file G4ShellEMDataSet.cc.

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

References AddComponent(), algorithm, CleanUpComponents(), G4VDataSetAlgorithm::Clone(), FatalException, geant4_check_module_cycles::file, FullFileName(), G4Exception(), unitData, and unitEnergies.

◆ NumberOfComponents()

size_t G4ShellEMDataSet::NumberOfComponents ( void  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 74 of file G4ShellEMDataSet.hh.

74{ return components.size(); }

References components.

Referenced by PrintData(), and SaveData().

◆ operator=()

G4ShellEMDataSet & G4ShellEMDataSet::operator= ( const G4ShellEMDataSet right)
delete

◆ PrintData()

void G4ShellEMDataSet::PrintData ( void  ) const
overridevirtual

Implements G4VEMDataSet.

Definition at line 104 of file G4ShellEMDataSet.cc.

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

References G4cout, G4endl, GetComponent(), CLHEP::detail::n, NumberOfComponents(), and G4VEMDataSet::PrintData().

◆ RandomSelect()

G4double G4ShellEMDataSet::RandomSelect ( G4int  ) const
inlineoverridevirtual

Implements G4VEMDataSet.

Definition at line 92 of file G4ShellEMDataSet.hh.

92{ return -1.; };

◆ SaveData()

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

Implements G4VEMDataSet.

Definition at line 326 of file G4ShellEMDataSet.cc.

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

References FatalException, geant4_check_module_cycles::file, FullFileName(), G4Exception(), GetComponent(), G4VEMDataSet::GetData(), G4VEMDataSet::GetEnergies(), CLHEP::detail::n, NumberOfComponents(), unitData, and unitEnergies.

◆ SetEnergiesData()

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

Implements G4VEMDataSet.

Definition at line 123 of file G4ShellEMDataSet.cc.

126{
127 G4VEMDataSet* component = components[componentId];
128 if (component)
129 {
130 component->SetEnergiesData(energies, data, 0);
131 return;
132 }
133
134 G4String msg = "component ";
135 msg += static_cast<char>(componentId);
136 msg += " not found";
137
138 G4Exception("G4ShellEMDataSet::SetEnergiesData()","em0008", FatalErrorInArgument ,msg);
139}
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0

References components, FatalErrorInArgument, G4Exception(), and G4VEMDataSet::SetEnergiesData().

◆ SetLogEnergiesData()

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

Implements G4VEMDataSet.

Definition at line 143 of file G4ShellEMDataSet.cc.

148{
149 G4VEMDataSet* component = components[componentId];
150 if (component)
151 {
152 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
153 return;
154 }
155
156 G4String msg = "component ";
157 msg += static_cast<char>(componentId);
158 msg += " not found";
159 G4Exception("G4ShellEMDataSet::SetLogEnergiesData()","em0008",
161}
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0

References components, FatalErrorInArgument, G4Exception(), and G4VEMDataSet::SetLogEnergiesData().

Field Documentation

◆ algorithm

G4VDataSetAlgorithm* G4ShellEMDataSet::algorithm
private

◆ components

std::vector<G4VEMDataSet*> G4ShellEMDataSet::components
private

◆ unitData

G4double G4ShellEMDataSet::unitData
private

Definition at line 110 of file G4ShellEMDataSet.hh.

Referenced by GetUnitData(), LoadData(), LoadNonLogData(), and SaveData().

◆ unitEnergies

G4double G4ShellEMDataSet::unitEnergies
private

Definition at line 109 of file G4ShellEMDataSet.hh.

Referenced by GetUnitEnergies(), LoadData(), LoadNonLogData(), and SaveData().

◆ z

G4int G4ShellEMDataSet::z
private

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