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