Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4ShellEMDataSet.cc,v 1.18 2009/09/25 07:41:34 sincerti Exp $ >> 28 // GEANT4 tag $Name: geant4-09-03-patch-02 $ 27 // 29 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@ 30 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // 31 // 30 // History: 32 // History: 31 // ----------- 33 // ----------- 32 // 1 Aug 2001 MGP Created 34 // 1 Aug 2001 MGP Created 33 // 35 // 34 // 09.10.01 V.Ivanchenko Add case z=0 36 // 09.10.01 V.Ivanchenko Add case z=0 35 // 37 // 36 // 9 Mar 2008 MGP Cleaned up unread 38 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer 37 // (Further clean-up 39 // (Further clean-up needed) 38 // 40 // 39 // 15 Jul 2009 Nicolas A. Karakatsanis 41 // 15 Jul 2009 Nicolas A. Karakatsanis 40 // 42 // 41 // - LoadNonLogData 43 // - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW 42 // dataset. It is 44 // dataset. It is essentially performing the data loading operations as in the past. 43 // 45 // 44 // - LoadData method 46 // - LoadData method was revised in order to calculate the logarithmic values of the data 45 // It retrieves th 47 // It retrieves the data values from the G4EMLOW data files but, then, calculates the 46 // respective log 48 // respective log values and loads them to seperate data structures. 47 // 49 // 48 // - SetLogEnergiesD 50 // - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors. 49 // The EM data set 51 // The EM data sets, initialized this way, contain both non-log and log values. 50 // These initializ 52 // These initialized data sets can enhance the computing performance of data interpolation 51 // operations 53 // operations 52 // 54 // 53 // 55 // 54 // ------------------------------------------- 56 // ------------------------------------------------------------------- 55 57 56 #include "G4ShellEMDataSet.hh" 58 #include "G4ShellEMDataSet.hh" 57 #include "G4EMDataSet.hh" 59 #include "G4EMDataSet.hh" 58 #include "G4VDataSetAlgorithm.hh" 60 #include "G4VDataSetAlgorithm.hh" 59 #include <fstream> 61 #include <fstream> 60 #include <sstream> 62 #include <sstream> 61 63 62 //....oooOO0OOooo........oooOO0OOooo........oo << 64 63 G4ShellEMDataSet::G4ShellEMDataSet(G4int zeta, 65 G4ShellEMDataSet::G4ShellEMDataSet(G4int zeta, G4VDataSetAlgorithm* algo, 64 G4double eUnit, 66 G4double eUnit, 65 G4double dataUnit) 67 G4double dataUnit) 66 : << 68 : >> 69 z(zeta), 67 algorithm(algo), 70 algorithm(algo), 68 unitEnergies(eUnit), 71 unitEnergies(eUnit), 69 unitData(dataUnit), << 72 unitData(dataUnit) 70 z(zeta) << 71 { 73 { 72 if (algorithm == nullptr) << 74 if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet - interpolation == 0"); 73 G4Exception("G4ShellEMDataSet::G4ShellEMDa << 74 FatalErrorInArgument, "Interpolation == 0" << 75 } 75 } 76 76 77 //....oooOO0OOooo........oooOO0OOooo........oo << 77 78 G4ShellEMDataSet::~G4ShellEMDataSet() 78 G4ShellEMDataSet::~G4ShellEMDataSet() 79 { 79 { 80 CleanUpComponents(); 80 CleanUpComponents(); 81 if (algorithm) delete algorithm; 81 if (algorithm) delete algorithm; 82 } 82 } 83 83 84 //....oooOO0OOooo........oooOO0OOooo........oo << 84 85 G4double G4ShellEMDataSet::FindValue(G4double 85 G4double G4ShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const 86 { 86 { 87 // Returns the sum over the shells correspon 87 // Returns the sum over the shells corresponding to e 88 G4double value = 0.; 88 G4double value = 0.; 89 89 90 std::vector<G4VEMDataSet *>::const_iterator 90 std::vector<G4VEMDataSet *>::const_iterator i(components.begin()); 91 std::vector<G4VEMDataSet *>::const_iterator 91 std::vector<G4VEMDataSet *>::const_iterator end(components.end()); 92 92 93 while (i != end) 93 while (i != end) 94 { 94 { 95 value += (*i)->FindValue(energy); 95 value += (*i)->FindValue(energy); 96 i++; 96 i++; 97 } 97 } 98 98 99 return value; 99 return value; 100 } 100 } 101 101 102 //....oooOO0OOooo........oooOO0OOooo........oo << 103 102 104 void G4ShellEMDataSet::PrintData() const << 103 void G4ShellEMDataSet::PrintData(void) const 105 { 104 { 106 const G4int n = (G4int)NumberOfComponents(); << 105 const size_t n = NumberOfComponents(); 107 106 108 G4cout << "The data set has " << n << " comp 107 G4cout << "The data set has " << n << " components" << G4endl; 109 G4cout << G4endl; 108 G4cout << G4endl; 110 109 111 G4int i = 0; << 110 size_t i = 0; 112 111 113 while (i < n) 112 while (i < n) 114 { 113 { 115 G4cout << "--- Component " << i << " --- 114 G4cout << "--- Component " << i << " ---" << G4endl; 116 GetComponent(i)->PrintData(); 115 GetComponent(i)->PrintData(); 117 ++i; << 116 i++; 118 } 117 } 119 } 118 } 120 119 121 //....oooOO0OOooo........oooOO0OOooo........oo << 122 120 123 void G4ShellEMDataSet::SetEnergiesData(G4DataV 121 void G4ShellEMDataSet::SetEnergiesData(G4DataVector* energies, 124 G4DataVector* data, 122 G4DataVector* data, 125 G4int componentId) 123 G4int componentId) 126 { 124 { 127 G4VEMDataSet* component = components[compone << 125 G4VEMDataSet* component = components[componentId]; >> 126 128 if (component) 127 if (component) 129 { 128 { 130 component->SetEnergiesData(energies, dat 129 component->SetEnergiesData(energies, data, 0); 131 return; 130 return; 132 } 131 } 133 132 134 G4String msg = "component "; << 133 std::ostringstream message; 135 msg += static_cast<char>(componentId); << 134 message << "G4ShellEMDataSet::SetEnergiesData - component " << componentId << " not found"; 136 msg += " not found"; << 137 135 138 G4Exception("G4ShellEMDataSet::SetEnergiesDa << 136 G4Exception(message.str().c_str()); 139 } 137 } 140 138 141 //....oooOO0OOooo........oooOO0OOooo........oo << 142 139 143 void G4ShellEMDataSet::SetLogEnergiesData(G4Da 140 void G4ShellEMDataSet::SetLogEnergiesData(G4DataVector* energies, 144 G4Da 141 G4DataVector* data, 145 G4Da 142 G4DataVector* log_energies, 146 G4Da 143 G4DataVector* log_data, 147 G4in 144 G4int componentId) 148 { 145 { 149 G4VEMDataSet* component = components[compone << 146 G4VEMDataSet* component = components[componentId]; >> 147 150 if (component) 148 if (component) 151 { 149 { 152 component->SetLogEnergiesData(energies, 150 component->SetLogEnergiesData(energies, data, log_energies, log_data, 0); 153 return; 151 return; 154 } 152 } 155 153 156 G4String msg = "component "; << 154 std::ostringstream message; 157 msg += static_cast<char>(componentId); << 155 message << "G4ShellEMDataSet::SetLogEnergiesData - component " << componentId << " not found"; 158 msg += " not found"; << 156 159 G4Exception("G4ShellEMDataSet::SetLogEnergie << 157 G4Exception(message.str().c_str()); 160 FatalErrorInArgument ,msg); << 161 } 158 } 162 159 163 //....oooOO0OOooo........oooOO0OOooo........oo << 160 164 161 165 G4bool G4ShellEMDataSet::LoadData(const G4Stri 162 G4bool G4ShellEMDataSet::LoadData(const G4String& file) 166 { 163 { 167 CleanUpComponents(); 164 CleanUpComponents(); 168 165 169 G4String fullFileName = FullFileName(file); 166 G4String fullFileName = FullFileName(file); 170 std::ifstream in(fullFileName); 167 std::ifstream in(fullFileName); 171 168 172 if (!in.is_open()) 169 if (!in.is_open()) 173 { 170 { 174 G4String message("Data file \""); << 171 G4String message("G4ShellEMDataSet::LoadData - data file \""); 175 message += fullFileName; 172 message += fullFileName; 176 message += "\" not found"; 173 message += "\" not found"; 177 G4Exception("G4ShellEMDataSet::LoadData( << 174 G4Exception(message); 178 return 0; << 179 } 175 } 180 << 176 181 G4DataVector* orig_shell_energies = 0; 177 G4DataVector* orig_shell_energies = 0; 182 G4DataVector* orig_shell_data = 0; 178 G4DataVector* orig_shell_data = 0; 183 G4DataVector* log_shell_energies = 0; 179 G4DataVector* log_shell_energies = 0; 184 G4DataVector* log_shell_data = 0; 180 G4DataVector* log_shell_data = 0; 185 181 186 G4double a = 0.; 182 G4double a = 0.; 187 G4int shellIndex = 0; 183 G4int shellIndex = 0; 188 G4int k = 0; 184 G4int k = 0; 189 G4int nColumns = 2; 185 G4int nColumns = 2; 190 186 191 do 187 do 192 { 188 { 193 in >> a; 189 in >> a; 194 190 195 if (a==0.) a=1e-300; 191 if (a==0.) a=1e-300; 196 192 197 // The file is organized into four colum 193 // The file is organized into four columns: 198 // 1st column contains the values of ene 194 // 1st column contains the values of energy 199 // 2nd column contains the corresponding 195 // 2nd column contains the corresponding data value 200 // The file terminates with the pattern: 196 // The file terminates with the pattern: -1 -1 201 // 197 // -2 -2 202 // 198 // 203 if (a == -1) 199 if (a == -1) 204 { 200 { 205 if ((k%nColumns == 0) && (orig_shell_energ 201 if ((k%nColumns == 0) && (orig_shell_energies != 0) ) 206 { 202 { 207 AddComponent(new G4EMDataSet(shellIndex << 203 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData)); 208 orig_shell_data, log_shell_energie << 209 log_shell_data, algorithm->Clone() << 210 unitEnergies, unitData)); << 211 orig_shell_energies = 0; 204 orig_shell_energies = 0; 212 orig_shell_data = 0; 205 orig_shell_data = 0; 213 log_shell_energies = 0; 206 log_shell_energies = 0; 214 log_shell_data = 0; 207 log_shell_data = 0; 215 } 208 } 216 } 209 } 217 else if (a != -2) 210 else if (a != -2) 218 { 211 { 219 if (orig_shell_energies == 0) 212 if (orig_shell_energies == 0) 220 { 213 { 221 orig_shell_energies = new G4DataVector; 214 orig_shell_energies = new G4DataVector; 222 orig_shell_data = new G4DataVector; 215 orig_shell_data = new G4DataVector; 223 log_shell_energies = new G4DataVe 216 log_shell_energies = new G4DataVector; 224 log_shell_data = new G4DataVector 217 log_shell_data = new G4DataVector; 225 } 218 } 226 if (k%nColumns == 0) 219 if (k%nColumns == 0) 227 { 220 { 228 orig_shell_energies->push_back(a*unitEn 221 orig_shell_energies->push_back(a*unitEnergies); 229 log_shell_energies->push_back(std::log1 222 log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies)); 230 } 223 } 231 else if (k%nColumns == 1) 224 else if (k%nColumns == 1) 232 { 225 { 233 orig_shell_data->push_back(a*unitData); 226 orig_shell_data->push_back(a*unitData); 234 log_shell_data->push_back(std::lo 227 log_shell_data->push_back(std::log10(a) + std::log10(unitData)); 235 } 228 } 236 k++; 229 k++; 237 } 230 } 238 else k = 1; 231 else k = 1; 239 } 232 } 240 while (a != -2); // End of file 233 while (a != -2); // End of file 241 234 242 delete orig_shell_energies; << 243 delete orig_shell_data; << 244 delete log_shell_energies; << 245 delete log_shell_data; << 246 << 247 return true; 235 return true; 248 } 236 } 249 237 250 //....oooOO0OOooo........oooOO0OOooo........oo << 251 238 252 G4bool G4ShellEMDataSet::LoadNonLogData(const 239 G4bool G4ShellEMDataSet::LoadNonLogData(const G4String& file) 253 { 240 { 254 CleanUpComponents(); 241 CleanUpComponents(); 255 242 256 G4String fullFileName = FullFileName(file); 243 G4String fullFileName = FullFileName(file); 257 std::ifstream in(fullFileName); 244 std::ifstream in(fullFileName); 258 245 259 if (!in.is_open()) 246 if (!in.is_open()) 260 { 247 { 261 G4String message("G4ShellEMDataSet::Load 248 G4String message("G4ShellEMDataSet::LoadData - data file \""); 262 message += fullFileName; 249 message += fullFileName; 263 message += "\" not found"; 250 message += "\" not found"; 264 G4Exception("G4ShellEMDataSet::LoadNonLo << 251 G4Exception(message); 265 return 0; << 266 } 252 } 267 253 268 G4DataVector* orig_shell_energies = 0; 254 G4DataVector* orig_shell_energies = 0; 269 G4DataVector* orig_shell_data = 0; 255 G4DataVector* orig_shell_data = 0; 270 256 271 G4double a = 0.; 257 G4double a = 0.; 272 G4int shellIndex = 0; 258 G4int shellIndex = 0; 273 G4int k = 0; 259 G4int k = 0; 274 G4int nColumns = 2; 260 G4int nColumns = 2; 275 261 276 do 262 do 277 { 263 { 278 in >> a; 264 in >> a; >> 265 279 // The file is organized into four colum 266 // The file is organized into four columns: 280 // 1st column contains the values of ene 267 // 1st column contains the values of energy 281 // 2nd column contains the corresponding 268 // 2nd column contains the corresponding data value 282 // The file terminates with the pattern: 269 // The file terminates with the pattern: -1 -1 283 // 270 // -2 -2 284 // 271 // 285 if (a == -1) 272 if (a == -1) 286 { 273 { 287 if ((k%nColumns == 0) && (orig_shell_energ 274 if ((k%nColumns == 0) && (orig_shell_energies != 0) ) 288 { 275 { 289 AddComponent(new G4EMDataSet(shellIndex << 276 AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData)); 290 orig_shell_data, algorithm->Clone( << 291 unitEnergies, unitData)); << 292 orig_shell_energies = 0; 277 orig_shell_energies = 0; 293 orig_shell_data = 0; 278 orig_shell_data = 0; 294 } 279 } 295 } 280 } 296 else if (a != -2) 281 else if (a != -2) 297 { 282 { 298 if (orig_shell_energies == 0) 283 if (orig_shell_energies == 0) 299 { 284 { 300 orig_shell_energies = new G4DataVector; 285 orig_shell_energies = new G4DataVector; 301 orig_shell_data = new G4DataVector; 286 orig_shell_data = new G4DataVector; 302 } 287 } 303 if (k%nColumns == 0) 288 if (k%nColumns == 0) 304 { 289 { 305 orig_shell_energies->push_back(a*unitEn 290 orig_shell_energies->push_back(a*unitEnergies); 306 } 291 } 307 else if (k%nColumns == 1) 292 else if (k%nColumns == 1) 308 { 293 { 309 orig_shell_data->push_back(a*unitData); 294 orig_shell_data->push_back(a*unitData); 310 } 295 } 311 k++; 296 k++; 312 } 297 } 313 else k = 1; 298 else k = 1; 314 } 299 } 315 while (a != -2); // End of file 300 while (a != -2); // End of file 316 301 317 << 318 delete orig_shell_energies; << 319 delete orig_shell_data; << 320 << 321 return true; 302 return true; 322 } 303 } 323 304 324 //....oooOO0OOooo........oooOO0OOooo........oo << 305 325 306 326 G4bool G4ShellEMDataSet::SaveData(const G4Stri 307 G4bool G4ShellEMDataSet::SaveData(const G4String& file) const 327 { 308 { 328 G4String fullFileName = FullFileName(file); 309 G4String fullFileName = FullFileName(file); 329 std::ofstream out(fullFileName); 310 std::ofstream out(fullFileName); 330 311 331 if (!out.is_open()) 312 if (!out.is_open()) 332 { 313 { 333 G4String message("Cannot open \""); << 314 G4String message("G4EMDataSet::SaveData - cannot open \""); 334 message += fullFileName; 315 message += fullFileName; 335 message += "\""; 316 message += "\""; 336 G4Exception("G4EMDataSet::SaveData()","e << 317 G4Exception(message); 337 } 318 } 338 319 339 const G4int n = (G4int)NumberOfComponents(); << 320 const size_t n = NumberOfComponents(); 340 G4int k = 0; << 321 size_t k = 0; 341 322 342 while (k < n) 323 while (k < n) 343 { 324 { 344 const G4VEMDataSet* component = GetCompo 325 const G4VEMDataSet* component = GetComponent(k); 345 326 346 if (component) 327 if (component) 347 { 328 { 348 const G4DataVector& energies = component-> 329 const G4DataVector& energies = component->GetEnergies(0); 349 const G4DataVector& data = component->GetD 330 const G4DataVector& data = component->GetData(0); 350 331 351 G4DataVector::const_iterator i = energies. << 332 G4DataVector::const_iterator i = energies.begin(); 352 G4DataVector::const_iterator endI = energi << 333 G4DataVector::const_iterator endI = energies.end(); 353 G4DataVector::const_iterator j = data.cbeg << 334 G4DataVector::const_iterator j = data.begin(); 354 335 355 while (i != endI) 336 while (i != endI) 356 { 337 { 357 out.precision(10); 338 out.precision(10); 358 out.width(15); 339 out.width(15); 359 out.setf(std::ofstream::left); 340 out.setf(std::ofstream::left); 360 out << ((*i)/unitEnergies) << ' '; 341 out << ((*i)/unitEnergies) << ' '; 361 342 362 out.precision(10); 343 out.precision(10); 363 out.width(15); 344 out.width(15); 364 out.setf(std::ofstream::left); 345 out.setf(std::ofstream::left); 365 out << ((*j)/unitData) << std::endl; 346 out << ((*j)/unitData) << std::endl; 366 i++; 347 i++; 367 j++; 348 j++; 368 } 349 } 369 } 350 } 370 351 371 out.precision(10); 352 out.precision(10); 372 out.width(15); 353 out.width(15); 373 out.setf(std::ofstream::left); 354 out.setf(std::ofstream::left); 374 out << -1.f << ' '; 355 out << -1.f << ' '; 375 356 376 out.precision(10); 357 out.precision(10); 377 out.width(15); 358 out.width(15); 378 out.setf(std::ofstream::left); 359 out.setf(std::ofstream::left); 379 out << -1.f << std::endl; 360 out << -1.f << std::endl; 380 361 381 k++; 362 k++; 382 } 363 } 383 364 384 out.precision(10); 365 out.precision(10); 385 out.width(15); 366 out.width(15); 386 out.setf(std::ofstream::left); 367 out.setf(std::ofstream::left); 387 out << -2.f << ' '; 368 out << -2.f << ' '; 388 369 389 out.precision(10); 370 out.precision(10); 390 out.width(15); 371 out.width(15); 391 out.setf(std::ofstream::left); 372 out.setf(std::ofstream::left); 392 out << -2.f << std::endl; 373 out << -2.f << std::endl; 393 374 394 return true; 375 return true; 395 } 376 } 396 377 397 //....oooOO0OOooo........oooOO0OOooo........oo << 398 378 399 void G4ShellEMDataSet::CleanUpComponents() << 379 void G4ShellEMDataSet::CleanUpComponents(void) 400 { 380 { 401 while (!components.empty()) 381 while (!components.empty()) 402 { 382 { 403 if (components.back()) delete components 383 if (components.back()) delete components.back(); 404 components.pop_back(); 384 components.pop_back(); 405 } 385 } 406 } 386 } 407 387 408 //....oooOO0OOooo........oooOO0OOooo........oo << 409 388 410 G4String G4ShellEMDataSet::FullFileName(const 389 G4String G4ShellEMDataSet::FullFileName(const G4String& fileName) const 411 { 390 { 412 const char* path = G4FindDataDir("G4LEDATA") << 391 char* path = getenv("G4LEDATA"); 413 << 414 if (!path) 392 if (!path) 415 { << 393 G4Exception("G4ShellEMDataSet::FullFileName - G4LEDATA environment variable not set"); 416 G4Exception("G4ShellEMDataSet::FullFileNam << 417 return ""; << 418 } << 419 394 420 std::ostringstream fullFileName; 395 std::ostringstream fullFileName; 421 396 422 fullFileName << path << '/' << fileName << z 397 fullFileName << path << '/' << fileName << z << ".dat"; 423 398 424 return G4String(fullFileName.str().c_str()); 399 return G4String(fullFileName.str().c_str()); 425 } 400 } 426 401