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