[819] | 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 | // |
---|
[1192] | 27 | // $Id: G4ShellEMDataSet.cc,v 1.18 2009/09/25 07:41:34 sincerti Exp $ |
---|
[1337] | 28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
[819] | 29 | // |
---|
| 30 | // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) |
---|
| 31 | // |
---|
| 32 | // History: |
---|
| 33 | // ----------- |
---|
[1192] | 34 | // 1 Aug 2001 MGP Created |
---|
[819] | 35 | // |
---|
[1192] | 36 | // 09.10.01 V.Ivanchenko Add case z=0 |
---|
| 37 | // |
---|
| 38 | // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer |
---|
| 39 | // (Further clean-up needed) |
---|
| 40 | // |
---|
| 41 | // 15 Jul 2009 Nicolas A. Karakatsanis |
---|
| 42 | // |
---|
| 43 | // - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW |
---|
| 44 | // dataset. It is essentially performing the data loading operations as in the past. |
---|
| 45 | // |
---|
| 46 | // - LoadData method was revised in order to calculate the logarithmic values of the data |
---|
| 47 | // It retrieves the data values from the G4EMLOW data files but, then, calculates the |
---|
| 48 | // respective log values and loads them to seperate data structures. |
---|
| 49 | // |
---|
| 50 | // - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors. |
---|
| 51 | // The EM data sets, initialized this way, contain both non-log and log values. |
---|
| 52 | // These initialized data sets can enhance the computing performance of data interpolation |
---|
| 53 | // operations |
---|
| 54 | // |
---|
| 55 | // |
---|
[819] | 56 | // ------------------------------------------------------------------- |
---|
| 57 | |
---|
| 58 | #include "G4ShellEMDataSet.hh" |
---|
| 59 | #include "G4EMDataSet.hh" |
---|
| 60 | #include "G4VDataSetAlgorithm.hh" |
---|
| 61 | #include <fstream> |
---|
| 62 | #include <sstream> |
---|
| 63 | |
---|
| 64 | |
---|
[961] | 65 | G4ShellEMDataSet::G4ShellEMDataSet(G4int zeta, G4VDataSetAlgorithm* algo, |
---|
| 66 | G4double eUnit, |
---|
| 67 | G4double dataUnit) |
---|
[819] | 68 | : |
---|
[961] | 69 | z(zeta), |
---|
| 70 | algorithm(algo), |
---|
| 71 | unitEnergies(eUnit), |
---|
| 72 | unitData(dataUnit) |
---|
[819] | 73 | { |
---|
[961] | 74 | if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet - interpolation == 0"); |
---|
[819] | 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | G4ShellEMDataSet::~G4ShellEMDataSet() |
---|
| 79 | { |
---|
| 80 | CleanUpComponents(); |
---|
[961] | 81 | if (algorithm) delete algorithm; |
---|
[819] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
[961] | 85 | G4double G4ShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const |
---|
[819] | 86 | { |
---|
| 87 | // Returns the sum over the shells corresponding to e |
---|
| 88 | G4double value = 0.; |
---|
| 89 | |
---|
| 90 | std::vector<G4VEMDataSet *>::const_iterator i(components.begin()); |
---|
| 91 | std::vector<G4VEMDataSet *>::const_iterator end(components.end()); |
---|
| 92 | |
---|
[961] | 93 | while (i != end) |
---|
[819] | 94 | { |
---|
[961] | 95 | value += (*i)->FindValue(energy); |
---|
[819] | 96 | i++; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return value; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | void G4ShellEMDataSet::PrintData(void) const |
---|
| 104 | { |
---|
[961] | 105 | const size_t n = NumberOfComponents(); |
---|
[819] | 106 | |
---|
| 107 | G4cout << "The data set has " << n << " components" << G4endl; |
---|
| 108 | G4cout << G4endl; |
---|
| 109 | |
---|
[961] | 110 | size_t i = 0; |
---|
[819] | 111 | |
---|
[961] | 112 | while (i < n) |
---|
[819] | 113 | { |
---|
| 114 | G4cout << "--- Component " << i << " ---" << G4endl; |
---|
| 115 | GetComponent(i)->PrintData(); |
---|
| 116 | i++; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
[961] | 121 | void G4ShellEMDataSet::SetEnergiesData(G4DataVector* energies, |
---|
| 122 | G4DataVector* data, |
---|
| 123 | G4int componentId) |
---|
[819] | 124 | { |
---|
[961] | 125 | G4VEMDataSet* component = components[componentId]; |
---|
[819] | 126 | |
---|
| 127 | if (component) |
---|
| 128 | { |
---|
[961] | 129 | component->SetEnergiesData(energies, data, 0); |
---|
[819] | 130 | return; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | std::ostringstream message; |
---|
[961] | 134 | message << "G4ShellEMDataSet::SetEnergiesData - component " << componentId << " not found"; |
---|
[819] | 135 | |
---|
| 136 | G4Exception(message.str().c_str()); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[1192] | 140 | void G4ShellEMDataSet::SetLogEnergiesData(G4DataVector* energies, |
---|
| 141 | G4DataVector* data, |
---|
| 142 | G4DataVector* log_energies, |
---|
| 143 | G4DataVector* log_data, |
---|
| 144 | G4int componentId) |
---|
| 145 | { |
---|
| 146 | G4VEMDataSet* component = components[componentId]; |
---|
| 147 | |
---|
| 148 | if (component) |
---|
| 149 | { |
---|
| 150 | component->SetLogEnergiesData(energies, data, log_energies, log_data, 0); |
---|
| 151 | return; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | std::ostringstream message; |
---|
| 155 | message << "G4ShellEMDataSet::SetLogEnergiesData - component " << componentId << " not found"; |
---|
| 156 | |
---|
| 157 | G4Exception(message.str().c_str()); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | |
---|
[961] | 162 | G4bool G4ShellEMDataSet::LoadData(const G4String& file) |
---|
[819] | 163 | { |
---|
| 164 | CleanUpComponents(); |
---|
| 165 | |
---|
[961] | 166 | G4String fullFileName = FullFileName(file); |
---|
[819] | 167 | std::ifstream in(fullFileName); |
---|
| 168 | |
---|
| 169 | if (!in.is_open()) |
---|
| 170 | { |
---|
| 171 | G4String message("G4ShellEMDataSet::LoadData - data file \""); |
---|
[961] | 172 | message += fullFileName; |
---|
| 173 | message += "\" not found"; |
---|
[819] | 174 | G4Exception(message); |
---|
| 175 | } |
---|
| 176 | |
---|
[1192] | 177 | G4DataVector* orig_shell_energies = 0; |
---|
| 178 | G4DataVector* orig_shell_data = 0; |
---|
| 179 | G4DataVector* log_shell_energies = 0; |
---|
| 180 | G4DataVector* log_shell_data = 0; |
---|
[819] | 181 | |
---|
[961] | 182 | G4double a = 0.; |
---|
| 183 | G4int shellIndex = 0; |
---|
[1192] | 184 | G4int k = 0; |
---|
| 185 | G4int nColumns = 2; |
---|
[819] | 186 | |
---|
| 187 | do |
---|
| 188 | { |
---|
| 189 | in >> a; |
---|
[1192] | 190 | |
---|
| 191 | if (a==0.) a=1e-300; |
---|
| 192 | |
---|
| 193 | // The file is organized into four columns: |
---|
| 194 | // 1st column contains the values of energy |
---|
| 195 | // 2nd column contains the corresponding data value |
---|
| 196 | // The file terminates with the pattern: -1 -1 |
---|
| 197 | // -2 -2 |
---|
| 198 | // |
---|
[819] | 199 | if (a == -1) |
---|
| 200 | { |
---|
[1192] | 201 | if ((k%nColumns == 0) && (orig_shell_energies != 0) ) |
---|
[819] | 202 | { |
---|
[1192] | 203 | AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData)); |
---|
| 204 | orig_shell_energies = 0; |
---|
| 205 | orig_shell_data = 0; |
---|
| 206 | log_shell_energies = 0; |
---|
| 207 | log_shell_data = 0; |
---|
[819] | 208 | } |
---|
| 209 | } |
---|
[961] | 210 | else if (a != -2) |
---|
[819] | 211 | { |
---|
[1192] | 212 | if (orig_shell_energies == 0) |
---|
[819] | 213 | { |
---|
[1192] | 214 | orig_shell_energies = new G4DataVector; |
---|
| 215 | orig_shell_data = new G4DataVector; |
---|
| 216 | log_shell_energies = new G4DataVector; |
---|
| 217 | log_shell_data = new G4DataVector; |
---|
[819] | 218 | } |
---|
[1192] | 219 | if (k%nColumns == 0) |
---|
| 220 | { |
---|
| 221 | orig_shell_energies->push_back(a*unitEnergies); |
---|
| 222 | log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies)); |
---|
| 223 | } |
---|
| 224 | else if (k%nColumns == 1) |
---|
| 225 | { |
---|
| 226 | orig_shell_data->push_back(a*unitData); |
---|
| 227 | log_shell_data->push_back(std::log10(a) + std::log10(unitData)); |
---|
| 228 | } |
---|
| 229 | k++; |
---|
| 230 | } |
---|
| 231 | else k = 1; |
---|
| 232 | } |
---|
| 233 | while (a != -2); // End of file |
---|
[819] | 234 | |
---|
[1192] | 235 | return true; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | G4bool G4ShellEMDataSet::LoadNonLogData(const G4String& file) |
---|
| 240 | { |
---|
| 241 | CleanUpComponents(); |
---|
| 242 | |
---|
| 243 | G4String fullFileName = FullFileName(file); |
---|
| 244 | std::ifstream in(fullFileName); |
---|
| 245 | |
---|
| 246 | if (!in.is_open()) |
---|
| 247 | { |
---|
| 248 | G4String message("G4ShellEMDataSet::LoadData - data file \""); |
---|
| 249 | message += fullFileName; |
---|
| 250 | message += "\" not found"; |
---|
| 251 | G4Exception(message); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | G4DataVector* orig_shell_energies = 0; |
---|
| 255 | G4DataVector* orig_shell_data = 0; |
---|
| 256 | |
---|
| 257 | G4double a = 0.; |
---|
| 258 | G4int shellIndex = 0; |
---|
| 259 | G4int k = 0; |
---|
| 260 | G4int nColumns = 2; |
---|
| 261 | |
---|
| 262 | do |
---|
| 263 | { |
---|
| 264 | in >> a; |
---|
| 265 | |
---|
| 266 | // The file is organized into four columns: |
---|
| 267 | // 1st column contains the values of energy |
---|
| 268 | // 2nd column contains the corresponding data value |
---|
| 269 | // The file terminates with the pattern: -1 -1 |
---|
| 270 | // -2 -2 |
---|
| 271 | // |
---|
| 272 | if (a == -1) |
---|
| 273 | { |
---|
| 274 | if ((k%nColumns == 0) && (orig_shell_energies != 0) ) |
---|
| 275 | { |
---|
| 276 | AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData)); |
---|
| 277 | orig_shell_energies = 0; |
---|
| 278 | orig_shell_data = 0; |
---|
| 279 | } |
---|
[819] | 280 | } |
---|
[1192] | 281 | else if (a != -2) |
---|
| 282 | { |
---|
| 283 | if (orig_shell_energies == 0) |
---|
| 284 | { |
---|
| 285 | orig_shell_energies = new G4DataVector; |
---|
| 286 | orig_shell_data = new G4DataVector; |
---|
| 287 | } |
---|
| 288 | if (k%nColumns == 0) |
---|
| 289 | { |
---|
| 290 | orig_shell_energies->push_back(a*unitEnergies); |
---|
| 291 | } |
---|
| 292 | else if (k%nColumns == 1) |
---|
| 293 | { |
---|
| 294 | orig_shell_data->push_back(a*unitData); |
---|
| 295 | } |
---|
| 296 | k++; |
---|
| 297 | } |
---|
| 298 | else k = 1; |
---|
[819] | 299 | } |
---|
[1192] | 300 | while (a != -2); // End of file |
---|
[819] | 301 | |
---|
| 302 | return true; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | |
---|
[1192] | 306 | |
---|
[961] | 307 | G4bool G4ShellEMDataSet::SaveData(const G4String& file) const |
---|
[819] | 308 | { |
---|
[961] | 309 | G4String fullFileName = FullFileName(file); |
---|
[819] | 310 | std::ofstream out(fullFileName); |
---|
| 311 | |
---|
| 312 | if (!out.is_open()) |
---|
| 313 | { |
---|
| 314 | G4String message("G4EMDataSet::SaveData - cannot open \""); |
---|
[961] | 315 | message += fullFileName; |
---|
| 316 | message += "\""; |
---|
[819] | 317 | G4Exception(message); |
---|
| 318 | } |
---|
| 319 | |
---|
[961] | 320 | const size_t n = NumberOfComponents(); |
---|
| 321 | size_t k = 0; |
---|
[819] | 322 | |
---|
[961] | 323 | while (k < n) |
---|
[819] | 324 | { |
---|
[961] | 325 | const G4VEMDataSet* component = GetComponent(k); |
---|
[819] | 326 | |
---|
| 327 | if (component) |
---|
| 328 | { |
---|
[961] | 329 | const G4DataVector& energies = component->GetEnergies(0); |
---|
| 330 | const G4DataVector& data = component->GetData(0); |
---|
[819] | 331 | |
---|
[961] | 332 | G4DataVector::const_iterator i = energies.begin(); |
---|
| 333 | G4DataVector::const_iterator endI = energies.end(); |
---|
| 334 | G4DataVector::const_iterator j = data.begin(); |
---|
[819] | 335 | |
---|
[961] | 336 | while (i != endI) |
---|
[819] | 337 | { |
---|
| 338 | out.precision(10); |
---|
| 339 | out.width(15); |
---|
| 340 | out.setf(std::ofstream::left); |
---|
| 341 | out << ((*i)/unitEnergies) << ' '; |
---|
| 342 | |
---|
| 343 | out.precision(10); |
---|
| 344 | out.width(15); |
---|
| 345 | out.setf(std::ofstream::left); |
---|
| 346 | out << ((*j)/unitData) << std::endl; |
---|
| 347 | i++; |
---|
| 348 | j++; |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | out.precision(10); |
---|
| 353 | out.width(15); |
---|
| 354 | out.setf(std::ofstream::left); |
---|
| 355 | out << -1.f << ' '; |
---|
| 356 | |
---|
| 357 | out.precision(10); |
---|
| 358 | out.width(15); |
---|
| 359 | out.setf(std::ofstream::left); |
---|
| 360 | out << -1.f << std::endl; |
---|
| 361 | |
---|
| 362 | k++; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | out.precision(10); |
---|
| 366 | out.width(15); |
---|
| 367 | out.setf(std::ofstream::left); |
---|
| 368 | out << -2.f << ' '; |
---|
| 369 | |
---|
| 370 | out.precision(10); |
---|
| 371 | out.width(15); |
---|
| 372 | out.setf(std::ofstream::left); |
---|
| 373 | out << -2.f << std::endl; |
---|
| 374 | |
---|
| 375 | return true; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | void G4ShellEMDataSet::CleanUpComponents(void) |
---|
| 380 | { |
---|
| 381 | while (!components.empty()) |
---|
| 382 | { |
---|
[961] | 383 | if (components.back()) delete components.back(); |
---|
[819] | 384 | components.pop_back(); |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | |
---|
[961] | 389 | G4String G4ShellEMDataSet::FullFileName(const G4String& fileName) const |
---|
[819] | 390 | { |
---|
| 391 | char* path = getenv("G4LEDATA"); |
---|
| 392 | if (!path) |
---|
| 393 | G4Exception("G4ShellEMDataSet::FullFileName - G4LEDATA environment variable not set"); |
---|
| 394 | |
---|
| 395 | std::ostringstream fullFileName; |
---|
| 396 | |
---|
[961] | 397 | fullFileName << path << '/' << fileName << z << ".dat"; |
---|
[819] | 398 | |
---|
| 399 | return G4String(fullFileName.str().c_str()); |
---|
| 400 | } |
---|