Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RDCompositeEMDataSet.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 // GEANT4 tag $Name: $
29 //
30 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31 //
32 // History:
33 // -----------
34 // 1 Aug 2001 MGP Created
35 //
36 // -------------------------------------------------------------------
37 
39 #include "G4RDEMDataSet.hh"
40 #include "G4RDVDataSetAlgorithm.hh"
41 #include <fstream>
42 #include <sstream>
43 
45  G4double argUnitEnergies,
46  G4double argUnitData,
47  G4int argMinZ,
48  G4int argMaxZ)
49  :
50  algorithm(argAlgorithm),
51  unitEnergies(argUnitEnergies),
52  unitData(argUnitData),
53  minZ(argMinZ),
54  maxZ(argMaxZ)
55 {
56  if (algorithm == 0)
57  G4Exception("G4RDCompositeEMDataSet::G4RDCompositeEMDataSet()",
58  "InvalidSetup", FatalException, "Interpolation == 0!");
59 }
60 
61 
62 
64 {
65  CleanUpComponents();
66  if (algorithm) delete algorithm;
67 }
68 
69 
70 G4double G4RDCompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
71 {
72  const G4RDVEMDataSet* component(GetComponent(argComponentId));
73 
74  if (component) return component->FindValue(argEnergy);
75 
76  std::ostringstream message;
77  message << "Component " << argComponentId << " not found";
78 
79  G4Exception("G4RDCompositeEMDataSet::FindValue()",
80  "DataNotFound", FatalException, message.str().c_str());
81 
82  return 0.;
83 }
84 
86 {
87  const size_t n(NumberOfComponents());
88 
89  G4cout << "The data set has " << n << " components" << G4endl;
90  G4cout << G4endl;
91 
92  size_t i(0);
93 
94  while (i<n)
95  {
96  G4cout << "--- Component " << i << " ---" << G4endl;
97  GetComponent(i)->PrintData();
98  i++;
99  }
100 }
101 
102 void G4RDCompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
103 {
104  G4RDVEMDataSet * component(components[argComponentId]);
105 
106  if (component)
107  {
108  component->SetEnergiesData(argEnergies, argData, 0);
109  return;
110  }
111 
112  std::ostringstream message;
113  message << "Component " << argComponentId << " not found";
114 
115  G4Exception("G4RDCompositeEMDataSet::SetEnergiesData()",
116  "DataNotFound", FatalException, message.str().c_str());
117 }
118 
120 {
121  CleanUpComponents();
122 
123  for (G4int z(minZ); z<maxZ; z++)
124  {
125  G4RDVEMDataSet* component = new G4RDEMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
126  if (!component->LoadData(argFileName))
127  {
128  delete component;
129  return false;
130  }
131  AddComponent(component);
132  }
133  return true;
134 }
135 
136 
137 
139 {
140  for (G4int z=minZ; z<maxZ; z++)
141  {
142  const G4RDVEMDataSet* component(GetComponent(z-minZ));
143 
144  if (!component)
145  {
146  std::ostringstream message;
147  message << "Component " << (z-minZ) << " not found";
148  G4Exception("G4RDCompositeEMDataSet::SaveData()",
149  "DataNotFound", FatalException, message.str().c_str());
150  }
151 
152  if (!component->SaveData(argFileName))
153  return false;
154  }
155 
156  return true;
157 }
158 
159 void G4RDCompositeEMDataSet::CleanUpComponents(void)
160 {
161  while (!components.empty())
162  {
163  if (components.back())
164  delete components.back();
165  components.pop_back();
166  }
167 }
168 
169 
171 {
172  G4double value = 0.;
173  if (componentId >= 0 && componentId < (G4int)components.size())
174  {
175  const G4RDVEMDataSet* dataSet = GetComponent(componentId);
176  value = dataSet->RandomSelect();
177  }
178  return value;
179 }
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual G4RDVDataSetAlgorithm * Clone() const =0
G4double z
Definition: TRTMaterials.hh:39
virtual const G4RDVEMDataSet * GetComponent(G4int componentId) const
virtual G4bool SaveData(const G4String &fileName) const =0
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
virtual void PrintData(void) const
virtual void AddComponent(G4RDVEMDataSet *dataSet)
bool G4bool
Definition: G4Types.hh:79
virtual G4double RandomSelect(G4int componentId) const
const G4int n
virtual G4double FindValue(G4double x, G4int componentId=0) const =0
virtual void PrintData(void) const =0
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual G4bool SaveData(const G4String &fileName) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual size_t NumberOfComponents() const
G4RDCompositeEMDataSet(G4RDVDataSetAlgorithm *argAlgorithm, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn, G4int zMin=1, G4int zMax=99)
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
virtual G4double RandomSelect(G4int componentId=0) const =0
virtual G4bool LoadData(const G4String &fileName)=0
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int componentId)
virtual G4bool LoadData(const G4String &fileName)