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
00052
00053
00054
00055
00056
00057 #include "G4ShellEMDataSet.hh"
00058 #include "G4EMDataSet.hh"
00059 #include "G4VDataSetAlgorithm.hh"
00060 #include <fstream>
00061 #include <sstream>
00062
00063
00064 G4ShellEMDataSet::G4ShellEMDataSet(G4int zeta, G4VDataSetAlgorithm* algo,
00065 G4double eUnit,
00066 G4double dataUnit)
00067 :
00068 z(zeta),
00069 algorithm(algo),
00070 unitEnergies(eUnit),
00071 unitData(dataUnit)
00072 {
00073 if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet()","em0007",FatalErrorInArgument, "Interpolation == 0");
00074 }
00075
00076
00077 G4ShellEMDataSet::~G4ShellEMDataSet()
00078 {
00079 CleanUpComponents();
00080 if (algorithm) delete algorithm;
00081 }
00082
00083
00084 G4double G4ShellEMDataSet::FindValue(G4double energy, G4int ) const
00085 {
00086
00087 G4double value = 0.;
00088
00089 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
00090 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
00091
00092 while (i != end)
00093 {
00094 value += (*i)->FindValue(energy);
00095 i++;
00096 }
00097
00098 return value;
00099 }
00100
00101
00102 void G4ShellEMDataSet::PrintData(void) const
00103 {
00104 const size_t n = NumberOfComponents();
00105
00106 G4cout << "The data set has " << n << " components" << G4endl;
00107 G4cout << G4endl;
00108
00109 size_t i = 0;
00110
00111 while (i < n)
00112 {
00113 G4cout << "--- Component " << i << " ---" << G4endl;
00114 GetComponent(i)->PrintData();
00115 i++;
00116 }
00117 }
00118
00119
00120 void G4ShellEMDataSet::SetEnergiesData(G4DataVector* energies,
00121 G4DataVector* data,
00122 G4int componentId)
00123 {
00124 G4VEMDataSet* component = components[componentId];
00125
00126 if (component)
00127 {
00128 component->SetEnergiesData(energies, data, 0);
00129 return;
00130 }
00131
00132 G4String msg = "component " + (G4String)componentId + " not found";
00133
00134 G4Exception("G4ShellEMDataSet::SetEnergiesData()","em0008", FatalErrorInArgument ,msg);
00135 }
00136
00137
00138 void G4ShellEMDataSet::SetLogEnergiesData(G4DataVector* energies,
00139 G4DataVector* data,
00140 G4DataVector* log_energies,
00141 G4DataVector* log_data,
00142 G4int componentId)
00143 {
00144 G4VEMDataSet* component = components[componentId];
00145
00146 if (component)
00147 {
00148 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
00149 return;
00150 }
00151
00152 G4String msg = "component " + (G4String)componentId + " not found";
00153
00154 G4Exception("G4ShellEMDataSet::SetLogEnergiesData()","em0008", FatalErrorInArgument ,msg);
00155
00156 }
00157
00158
00159
00160 G4bool G4ShellEMDataSet::LoadData(const G4String& file)
00161 {
00162 CleanUpComponents();
00163
00164 G4String fullFileName = FullFileName(file);
00165 std::ifstream in(fullFileName);
00166
00167 if (!in.is_open())
00168 {
00169 G4String message("Data file \"");
00170 message += fullFileName;
00171 message += "\" not found";
00172 G4Exception("G4ShellEMDataSet::LoadData()", "em0003",FatalException, message);
00173 return 0;
00174 }
00175
00176 G4DataVector* orig_shell_energies = 0;
00177 G4DataVector* orig_shell_data = 0;
00178 G4DataVector* log_shell_energies = 0;
00179 G4DataVector* log_shell_data = 0;
00180
00181 G4double a = 0.;
00182 G4int shellIndex = 0;
00183 G4int k = 0;
00184 G4int nColumns = 2;
00185
00186 do
00187 {
00188 in >> a;
00189
00190 if (a==0.) a=1e-300;
00191
00192
00193
00194
00195
00196
00197
00198 if (a == -1)
00199 {
00200 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
00201 {
00202 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData));
00203 orig_shell_energies = 0;
00204 orig_shell_data = 0;
00205 log_shell_energies = 0;
00206 log_shell_data = 0;
00207 }
00208 }
00209 else if (a != -2)
00210 {
00211 if (orig_shell_energies == 0)
00212 {
00213 orig_shell_energies = new G4DataVector;
00214 orig_shell_data = new G4DataVector;
00215 log_shell_energies = new G4DataVector;
00216 log_shell_data = new G4DataVector;
00217 }
00218 if (k%nColumns == 0)
00219 {
00220 orig_shell_energies->push_back(a*unitEnergies);
00221 log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies));
00222 }
00223 else if (k%nColumns == 1)
00224 {
00225 orig_shell_data->push_back(a*unitData);
00226 log_shell_data->push_back(std::log10(a) + std::log10(unitData));
00227 }
00228 k++;
00229 }
00230 else k = 1;
00231 }
00232 while (a != -2);
00233
00234
00235 delete orig_shell_energies;
00236 delete orig_shell_data;
00237 delete log_shell_energies;
00238 delete log_shell_data;
00239
00240 return true;
00241 }
00242
00243
00244 G4bool G4ShellEMDataSet::LoadNonLogData(const G4String& file)
00245 {
00246 CleanUpComponents();
00247
00248 G4String fullFileName = FullFileName(file);
00249 std::ifstream in(fullFileName);
00250
00251 if (!in.is_open())
00252 {
00253 G4String message("G4ShellEMDataSet::LoadData - data file \"");
00254 message += fullFileName;
00255 message += "\" not found";
00256 G4Exception("G4ShellEMDataSet::LoadNonLogData()", "em0003",FatalException, message);
00257 return 0;
00258 }
00259
00260 G4DataVector* orig_shell_energies = 0;
00261 G4DataVector* orig_shell_data = 0;
00262
00263 G4double a = 0.;
00264 G4int shellIndex = 0;
00265 G4int k = 0;
00266 G4int nColumns = 2;
00267
00268 do
00269 {
00270 in >> a;
00271
00272
00273
00274
00275
00276
00277
00278 if (a == -1)
00279 {
00280 if ((k%nColumns == 0) && (orig_shell_energies != 0) )
00281 {
00282 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData));
00283 orig_shell_energies = 0;
00284 orig_shell_data = 0;
00285 }
00286 }
00287 else if (a != -2)
00288 {
00289 if (orig_shell_energies == 0)
00290 {
00291 orig_shell_energies = new G4DataVector;
00292 orig_shell_data = new G4DataVector;
00293 }
00294 if (k%nColumns == 0)
00295 {
00296 orig_shell_energies->push_back(a*unitEnergies);
00297 }
00298 else if (k%nColumns == 1)
00299 {
00300 orig_shell_data->push_back(a*unitData);
00301 }
00302 k++;
00303 }
00304 else k = 1;
00305 }
00306 while (a != -2);
00307
00308
00309 delete orig_shell_energies;
00310 delete orig_shell_data;
00311
00312 return true;
00313 }
00314
00315
00316
00317 G4bool G4ShellEMDataSet::SaveData(const G4String& file) const
00318 {
00319 G4String fullFileName = FullFileName(file);
00320 std::ofstream out(fullFileName);
00321
00322 if (!out.is_open())
00323 {
00324 G4String message("Cannot open \"");
00325 message += fullFileName;
00326 message += "\"";
00327 G4Exception("G4EMDataSet::SaveData()","em0005",FatalException,message);
00328 }
00329
00330 const size_t n = NumberOfComponents();
00331 size_t k = 0;
00332
00333 while (k < n)
00334 {
00335 const G4VEMDataSet* component = GetComponent(k);
00336
00337 if (component)
00338 {
00339 const G4DataVector& energies = component->GetEnergies(0);
00340 const G4DataVector& data = component->GetData(0);
00341
00342 G4DataVector::const_iterator i = energies.begin();
00343 G4DataVector::const_iterator endI = energies.end();
00344 G4DataVector::const_iterator j = data.begin();
00345
00346 while (i != endI)
00347 {
00348 out.precision(10);
00349 out.width(15);
00350 out.setf(std::ofstream::left);
00351 out << ((*i)/unitEnergies) << ' ';
00352
00353 out.precision(10);
00354 out.width(15);
00355 out.setf(std::ofstream::left);
00356 out << ((*j)/unitData) << std::endl;
00357 i++;
00358 j++;
00359 }
00360 }
00361
00362 out.precision(10);
00363 out.width(15);
00364 out.setf(std::ofstream::left);
00365 out << -1.f << ' ';
00366
00367 out.precision(10);
00368 out.width(15);
00369 out.setf(std::ofstream::left);
00370 out << -1.f << std::endl;
00371
00372 k++;
00373 }
00374
00375 out.precision(10);
00376 out.width(15);
00377 out.setf(std::ofstream::left);
00378 out << -2.f << ' ';
00379
00380 out.precision(10);
00381 out.width(15);
00382 out.setf(std::ofstream::left);
00383 out << -2.f << std::endl;
00384
00385 return true;
00386 }
00387
00388
00389 void G4ShellEMDataSet::CleanUpComponents(void)
00390 {
00391 while (!components.empty())
00392 {
00393 if (components.back()) delete components.back();
00394 components.pop_back();
00395 }
00396 }
00397
00398
00399 G4String G4ShellEMDataSet::FullFileName(const G4String& fileName) const
00400 {
00401 char* path = getenv("G4LEDATA");
00402
00403 if (!path)
00404 {
00405 G4Exception("G4ShellEMDataSet::FullFileName()","em0006",JustWarning,"Please set G4LEDATA");
00406 return "";
00407 }
00408
00409 std::ostringstream fullFileName;
00410
00411 fullFileName << path << '/' << fileName << z << ".dat";
00412
00413 return G4String(fullFileName.str().c_str());
00414 }