00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "G4CompositeEMDataSet.hh"
00052 #include "G4EMDataSet.hh"
00053 #include "G4VDataSetAlgorithm.hh"
00054 #include <fstream>
00055 #include <sstream>
00056
00057 G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm,
00058 G4double argUnitEnergies,
00059 G4double argUnitData,
00060 G4int argMinZ,
00061 G4int argMaxZ)
00062 :
00063 algorithm(argAlgorithm),
00064 unitEnergies(argUnitEnergies),
00065 unitData(argUnitData),
00066 minZ(argMinZ),
00067 maxZ(argMaxZ)
00068 {
00069 if (algorithm == 0)
00070 G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet",
00071 "em1003",FatalException,"interpolation == 0");
00072
00073 }
00074
00075
00076
00077 G4CompositeEMDataSet::~G4CompositeEMDataSet()
00078 {
00079 CleanUpComponents();
00080 if (algorithm) delete algorithm;
00081 }
00082
00083
00084 G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
00085 {
00086 const G4VEMDataSet* component(GetComponent(argComponentId));
00087
00088 if (component) return component->FindValue(argEnergy);
00089
00090 std::ostringstream message;
00091 message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
00092
00093 G4Exception("G4CompositeEMDataSet::FindValue",
00094 "em1004",FatalException,message.str().c_str());
00095
00096 return 0.;
00097 }
00098
00099 void G4CompositeEMDataSet::PrintData(void) const
00100 {
00101 const size_t n(NumberOfComponents());
00102
00103 G4cout << "The data set has " << n << " components" << G4endl;
00104 G4cout << G4endl;
00105
00106 size_t i(0);
00107
00108 while (i<n)
00109 {
00110 G4cout << "--- Component " << i << " ---" << G4endl;
00111 GetComponent(i)->PrintData();
00112 i++;
00113 }
00114 }
00115
00116 void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
00117 {
00118 G4VEMDataSet * component(components[argComponentId]);
00119
00120 if (component)
00121 {
00122 component->SetEnergiesData(argEnergies, argData, 0);
00123 return;
00124 }
00125
00126 std::ostringstream message;
00127 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
00128
00129 G4Exception("G4CompositeEMDataSet::SetEnergiesData",
00130 "em1004",FatalException,message.str().c_str());
00131 }
00132
00133 void G4CompositeEMDataSet::SetLogEnergiesData(G4DataVector* argEnergies,
00134 G4DataVector* argData,
00135 G4DataVector* argLogEnergies,
00136 G4DataVector* argLogData,
00137 G4int argComponentId)
00138 {
00139 G4VEMDataSet * component(components[argComponentId]);
00140
00141 if (component)
00142 {
00143 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
00144 return;
00145 }
00146
00147 std::ostringstream message;
00148 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
00149
00150 G4Exception("G4CompositeEMDataSet::SetLogEnergiesData",
00151 "em1004",FatalException,message.str().c_str());
00152 }
00153
00154
00155 G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
00156 {
00157 CleanUpComponents();
00158
00159 for (G4int z(minZ); z<maxZ; z++)
00160 {
00161 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
00162 if (!component->LoadData(argFileName))
00163 {
00164 delete component;
00165 return false;
00166 }
00167 AddComponent(component);
00168 }
00169 return true;
00170 }
00171
00172
00173 G4bool G4CompositeEMDataSet::LoadNonLogData(const G4String& argFileName)
00174 {
00175 CleanUpComponents();
00176
00177 for (G4int z(minZ); z<maxZ; z++)
00178 {
00179 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
00180 if (!component->LoadNonLogData(argFileName))
00181 {
00182 delete component;
00183 return false;
00184 }
00185 AddComponent(component);
00186 }
00187 return true;
00188 }
00189
00190
00191 G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
00192 {
00193 for (G4int z=minZ; z<maxZ; z++)
00194 {
00195 const G4VEMDataSet* component(GetComponent(z-minZ));
00196
00197 if (!component)
00198 {
00199 std::ostringstream message;
00200 message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
00201 G4Exception("G4CompositeEMDataSet::SaveData",
00202 "em1004",FatalException,message.str().c_str());
00203 return false;
00204 }
00205
00206 if (!component->SaveData(argFileName))
00207 return false;
00208 }
00209
00210 return true;
00211 }
00212
00213 void G4CompositeEMDataSet::CleanUpComponents(void)
00214 {
00215 while (!components.empty())
00216 {
00217 if (components.back())
00218 delete components.back();
00219 components.pop_back();
00220 }
00221 }
00222
00223
00224 G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
00225 {
00226 G4double value = 0.;
00227 if (componentId >= 0 && componentId < (G4int)components.size())
00228 {
00229 const G4VEMDataSet* dataSet = GetComponent(componentId);
00230 value = dataSet->RandomSelect();
00231 }
00232 return value;
00233 }