Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CompositeDataSet.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 ([email protected])
30//
31// History:
32// -----------
33// 1 Aug 2001 MGP Created
34// 31 Jul 2008 MGP Revised and renamed to G4CompositeDataSet
35//
36//
37// -------------------------------------------------------------------
38
39#include "G4CompositeDataSet.hh"
40#include "G4DataSet.hh"
41#include "G4IInterpolator.hh"
42#include <fstream>
43#include <sstream>
44
46 G4double eUnit,
47 G4double dataUnit,
48 G4int zMin,
49 G4int zMax)
50 :
51 algorithm(algo),
52 unitEnergies(eUnit),
53 unitData(dataUnit),
54 minZ(zMin),
55 maxZ(zMax)
56{
57 if (algorithm == 0)
58 G4Exception("G4CompositeDataSet::G4CompositeDataSet",
59 "pii00000001",
61 "Interpolation == 0");
62}
63
64
65
67{
68 CleanUpComponents();
69 if (algorithm) delete algorithm;
70}
71
72
74{
75 const G4IDataSet* component(GetComponent(componentId));
76
77 if (component) return component->FindValue(energy);
78
79 std::ostringstream message;
80 message << "G4CompositeDataSet::FindValue - component " << componentId << " not found";
81
82 G4Exception("G4CompositeDataSet::FindValue",
83 "pii00000010",
85 message.str().c_str());
86
87 return 0.;
88}
89
91{
92 const size_t n(NumberOfComponents());
93
94 G4cout << "The data set has " << n << " components" << G4endl;
95 G4cout << G4endl;
96
97 size_t i(0);
98
99 while (i<n)
100 {
101 G4cout << "--- Component " << i << " ---" << G4endl;
103 i++;
104 }
105}
106
108{
109 G4IDataSet * component(components[componentId]);
110
111 if (component)
112 {
113 component->SetEnergiesData(energies, data, 0);
114 return;
115 }
116
117 std::ostringstream message;
118 message << "G4CompositeDataSet::SetEnergiesData - component " << componentId << " not found";
119
120 G4Exception("G4CompositeDataSet::SetEnergiesData",
121 "pii00000020",
123 message.str().c_str());
124
125}
126
128{
129 CleanUpComponents();
130
131 for (G4int z(minZ); z<maxZ; z++)
132 {
133 G4IDataSet* component = new G4DataSet(z, algorithm->Clone(), unitEnergies, unitData);
134 if (!component->LoadData(argFileName))
135 {
136 delete component;
137 return false;
138 }
139 AddComponent(component);
140 }
141 return true;
142}
143
144
145
147{
148 for (G4int z=minZ; z<maxZ; z++)
149 {
150 const G4IDataSet* component(GetComponent(z-minZ));
151
152 if (!component)
153 {
154 std::ostringstream message;
155 message << "G4CompositeDataSet::SaveData - component " << (z-minZ) << " not found";
156 G4Exception("G4CompositeDataSet::SaveData",
157 "pii00000030",
159 message.str().c_str());
160 }
161
162 if (!component->SaveData(argFileName))
163 return false;
164 }
165
166 return true;
167}
168
169void G4CompositeDataSet::CleanUpComponents(void)
170{
171 while (!components.empty())
172 {
173 if (components.back())
174 delete components.back();
175 components.pop_back();
176 }
177}
178
179
181{
182 G4double value = 0.;
183 if (componentId >= 0 && componentId < (G4int)components.size())
184 {
185 const G4IDataSet* dataSet = GetComponent(componentId);
186 value = dataSet->RandomSelect();
187 }
188 return value;
189}
@ 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
G4CompositeDataSet(G4IInterpolator *argAlgorithm, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn, G4int zMin=1, G4int zMax=99)
virtual size_t NumberOfComponents() const
virtual G4bool SaveData(const G4String &fileName) const
virtual void AddComponent(G4IDataSet *dataSet)
virtual G4double RandomSelect(G4int componentId) const
virtual void PrintData(void) const
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int componentId)
virtual const G4IDataSet * GetComponent(G4int componentId) const
virtual G4bool LoadData(const G4String &fileName)
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual G4bool LoadData(const G4String &fileName)=0
virtual G4double RandomSelect(G4int componentId=0) const =0
virtual G4double FindValue(G4double x, G4int componentId=0) const =0
virtual void PrintData(void) const =0
virtual G4bool SaveData(const G4String &fileName) const =0
virtual G4IInterpolator * Clone() const =0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41