File indexing completed on 2025-01-31 09:22:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include "G4RDCompositeEMDataSet.hh"
0037 #include "G4RDEMDataSet.hh"
0038 #include "G4RDVDataSetAlgorithm.hh"
0039 #include <fstream>
0040 #include <sstream>
0041
0042 G4RDCompositeEMDataSet::G4RDCompositeEMDataSet(G4RDVDataSetAlgorithm* argAlgorithm,
0043 G4double argUnitEnergies,
0044 G4double argUnitData,
0045 G4int argMinZ,
0046 G4int argMaxZ)
0047 :
0048 algorithm(argAlgorithm),
0049 unitEnergies(argUnitEnergies),
0050 unitData(argUnitData),
0051 minZ(argMinZ),
0052 maxZ(argMaxZ)
0053 {
0054 if (algorithm == 0)
0055 G4Exception("G4RDCompositeEMDataSet::G4RDCompositeEMDataSet()",
0056 "InvalidSetup", FatalException, "Interpolation == 0!");
0057 }
0058
0059
0060
0061 G4RDCompositeEMDataSet::~G4RDCompositeEMDataSet()
0062 {
0063 CleanUpComponents();
0064 if (algorithm) delete algorithm;
0065 }
0066
0067
0068 G4double G4RDCompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
0069 {
0070 const G4RDVEMDataSet* component(GetComponent(argComponentId));
0071
0072 if (component) return component->FindValue(argEnergy);
0073
0074 std::ostringstream message;
0075 message << "Component " << argComponentId << " not found";
0076
0077 G4Exception("G4RDCompositeEMDataSet::FindValue()",
0078 "DataNotFound", FatalException, message.str().c_str());
0079
0080 return 0.;
0081 }
0082
0083 void G4RDCompositeEMDataSet::PrintData(void) const
0084 {
0085 const size_t n(NumberOfComponents());
0086
0087 G4cout << "The data set has " << n << " components" << G4endl;
0088 G4cout << G4endl;
0089
0090 size_t i(0);
0091
0092 while (i<n)
0093 {
0094 G4cout << "--- Component " << i << " ---" << G4endl;
0095 GetComponent(i)->PrintData();
0096 i++;
0097 }
0098 }
0099
0100 void G4RDCompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
0101 {
0102 G4RDVEMDataSet * component(components[argComponentId]);
0103
0104 if (component)
0105 {
0106 component->SetEnergiesData(argEnergies, argData, 0);
0107 return;
0108 }
0109
0110 std::ostringstream message;
0111 message << "Component " << argComponentId << " not found";
0112
0113 G4Exception("G4RDCompositeEMDataSet::SetEnergiesData()",
0114 "DataNotFound", FatalException, message.str().c_str());
0115 }
0116
0117 G4bool G4RDCompositeEMDataSet::LoadData(const G4String& argFileName)
0118 {
0119 CleanUpComponents();
0120
0121 for (G4int z(minZ); z<maxZ; z++)
0122 {
0123 G4RDVEMDataSet* component = new G4RDEMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
0124 if (!component->LoadData(argFileName))
0125 {
0126 delete component;
0127 return false;
0128 }
0129 AddComponent(component);
0130 }
0131 return true;
0132 }
0133
0134
0135
0136 G4bool G4RDCompositeEMDataSet::SaveData(const G4String& argFileName) const
0137 {
0138 for (G4int z=minZ; z<maxZ; z++)
0139 {
0140 const G4RDVEMDataSet* component(GetComponent(z-minZ));
0141
0142 if (!component)
0143 {
0144 std::ostringstream message;
0145 message << "Component " << (z-minZ) << " not found";
0146 G4Exception("G4RDCompositeEMDataSet::SaveData()",
0147 "DataNotFound", FatalException, message.str().c_str());
0148 }
0149
0150 if (!component->SaveData(argFileName))
0151 return false;
0152 }
0153
0154 return true;
0155 }
0156
0157 void G4RDCompositeEMDataSet::CleanUpComponents(void)
0158 {
0159 while (!components.empty())
0160 {
0161 if (components.back())
0162 delete components.back();
0163 components.pop_back();
0164 }
0165 }
0166
0167
0168 G4double G4RDCompositeEMDataSet::RandomSelect(G4int componentId) const
0169 {
0170 G4double value = 0.;
0171 if (componentId >= 0 && componentId < (G4int)components.size())
0172 {
0173 const G4RDVEMDataSet* dataSet = GetComponent(componentId);
0174 value = dataSet->RandomSelect();
0175 }
0176 return value;
0177 }