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: G4RDShellEMDataSet.cc 107396 2017-11-10 08:28:08Z gcosmo $ >> 28 // GEANT4 tag $Name: $ 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 // 09.10.01 V.Ivanchenko Add case z=0 35 // 09.10.01 V.Ivanchenko Add case z=0 34 // 9 Mar 2008 MGP Cleaned up unreada 36 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer 35 // (Further clean-up 37 // (Further clean-up needed) 36 // 38 // 37 // ------------------------------------------- 39 // ------------------------------------------------------------------- 38 40 39 #include "G4RDShellEMDataSet.hh" 41 #include "G4RDShellEMDataSet.hh" 40 #include "G4RDEMDataSet.hh" 42 #include "G4RDEMDataSet.hh" 41 #include "G4RDVDataSetAlgorithm.hh" 43 #include "G4RDVDataSetAlgorithm.hh" 42 #include <fstream> 44 #include <fstream> 43 #include <sstream> 45 #include <sstream> 44 46 45 47 46 G4RDShellEMDataSet::G4RDShellEMDataSet(G4int z 48 G4RDShellEMDataSet::G4RDShellEMDataSet(G4int zeta, G4RDVDataSetAlgorithm* algo, 47 G4double eUnit, 49 G4double eUnit, 48 G4double dataUnit) 50 G4double dataUnit) 49 : 51 : 50 z(zeta), 52 z(zeta), 51 algorithm(algo), 53 algorithm(algo), 52 unitEnergies(eUnit), 54 unitEnergies(eUnit), 53 unitData(dataUnit) 55 unitData(dataUnit) 54 { 56 { 55 if (algorithm == 0) 57 if (algorithm == 0) 56 G4Exception("G4RDShellEMDataSet::G4RDShell 58 G4Exception("G4RDShellEMDataSet::G4RDShellEMDataSet()", "InvalidSetup", 57 FatalException, "Interpolation 59 FatalException, "Interpolation == 0!"); 58 } 60 } 59 61 60 62 61 G4RDShellEMDataSet::~G4RDShellEMDataSet() 63 G4RDShellEMDataSet::~G4RDShellEMDataSet() 62 { 64 { 63 CleanUpComponents(); 65 CleanUpComponents(); 64 if (algorithm) delete algorithm; 66 if (algorithm) delete algorithm; 65 } 67 } 66 68 67 69 68 G4double G4RDShellEMDataSet::FindValue(G4doubl 70 G4double G4RDShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const 69 { 71 { 70 // Returns the sum over the shells correspon 72 // Returns the sum over the shells corresponding to e 71 G4double value = 0.; 73 G4double value = 0.; 72 74 73 std::vector<G4RDVEMDataSet *>::const_iterato 75 std::vector<G4RDVEMDataSet *>::const_iterator i(components.begin()); 74 std::vector<G4RDVEMDataSet *>::const_iterato 76 std::vector<G4RDVEMDataSet *>::const_iterator end(components.end()); 75 77 76 while (i != end) 78 while (i != end) 77 { 79 { 78 value += (*i)->FindValue(energy); 80 value += (*i)->FindValue(energy); 79 i++; 81 i++; 80 } 82 } 81 83 82 return value; 84 return value; 83 } 85 } 84 86 85 87 86 void G4RDShellEMDataSet::PrintData(void) const 88 void G4RDShellEMDataSet::PrintData(void) const 87 { 89 { 88 const size_t n = NumberOfComponents(); 90 const size_t n = NumberOfComponents(); 89 91 90 G4cout << "The data set has " << n << " comp 92 G4cout << "The data set has " << n << " components" << G4endl; 91 G4cout << G4endl; 93 G4cout << G4endl; 92 94 93 size_t i = 0; 95 size_t i = 0; 94 96 95 while (i < n) 97 while (i < n) 96 { 98 { 97 G4cout << "--- Component " << i << " --- 99 G4cout << "--- Component " << i << " ---" << G4endl; 98 GetComponent(i)->PrintData(); 100 GetComponent(i)->PrintData(); 99 i++; 101 i++; 100 } 102 } 101 } 103 } 102 104 103 105 104 void G4RDShellEMDataSet::SetEnergiesData(G4Dat 106 void G4RDShellEMDataSet::SetEnergiesData(G4DataVector* energies, 105 G4DataVector* data, 107 G4DataVector* data, 106 G4int componentId) 108 G4int componentId) 107 { 109 { 108 G4RDVEMDataSet* component = components[compo 110 G4RDVEMDataSet* component = components[componentId]; 109 111 110 if (component) 112 if (component) 111 { 113 { 112 component->SetEnergiesData(energies, dat 114 component->SetEnergiesData(energies, data, 0); 113 return; 115 return; 114 } 116 } 115 117 116 std::ostringstream message; 118 std::ostringstream message; 117 message << "Component " << componentId << " 119 message << "Component " << componentId << " not found"; 118 120 119 G4Exception("G4RDShellEMDataSet::SetEnergies 121 G4Exception("G4RDShellEMDataSet::SetEnergiesData()", "DataNotFound", 120 FatalException, message.str().c_ 122 FatalException, message.str().c_str()); 121 } 123 } 122 124 123 125 124 G4bool G4RDShellEMDataSet::LoadData(const G4St 126 G4bool G4RDShellEMDataSet::LoadData(const G4String& file) 125 { 127 { 126 CleanUpComponents(); 128 CleanUpComponents(); 127 129 128 G4String fullFileName = FullFileName(file); 130 G4String fullFileName = FullFileName(file); 129 std::ifstream in(fullFileName); 131 std::ifstream in(fullFileName); 130 132 131 if (!in.is_open()) 133 if (!in.is_open()) 132 { 134 { 133 G4String message("Data file \""); 135 G4String message("Data file \""); 134 message += fullFileName; 136 message += fullFileName; 135 message += "\" not found"; 137 message += "\" not found"; 136 G4Exception("G4RDShellEMDataSet::LoadDat 138 G4Exception("G4RDShellEMDataSet::LoadData()", "DataNotFound", 137 FatalException, message); 139 FatalException, message); 138 } 140 } 139 141 140 G4DataVector* energies = 0; 142 G4DataVector* energies = 0; 141 G4DataVector* data = 0; 143 G4DataVector* data = 0; 142 144 143 G4double a = 0.; 145 G4double a = 0.; 144 G4int shellIndex = 0; 146 G4int shellIndex = 0; 145 bool energyColumn = true; 147 bool energyColumn = true; 146 148 147 do 149 do 148 { 150 { 149 in >> a; 151 in >> a; 150 152 151 if (a == -1) 153 if (a == -1) 152 { 154 { 153 if (energyColumn && energies!=0) 155 if (energyColumn && energies!=0) 154 { 156 { 155 AddComponent(new G4RDEMDataSet(shellIn 157 AddComponent(new G4RDEMDataSet(shellIndex, energies, data, algorithm->Clone(), unitEnergies, unitData)); 156 energies = 0; 158 energies = 0; 157 data = 0; 159 data = 0; 158 } 160 } 159 161 160 energyColumn = (!energyColumn); 162 energyColumn = (!energyColumn); 161 } 163 } 162 else if (a != -2) 164 else if (a != -2) 163 { 165 { 164 if (energies == 0) 166 if (energies == 0) 165 { 167 { 166 energies = new G4DataVector; 168 energies = new G4DataVector; 167 data = new G4DataVector; 169 data = new G4DataVector; 168 } 170 } 169 171 170 if (energyColumn) 172 if (energyColumn) 171 energies->push_back(a * unitEnergies); 173 energies->push_back(a * unitEnergies); 172 else 174 else 173 data->push_back(a * unitData); 175 data->push_back(a * unitData); 174 176 175 energyColumn = (!energyColumn); 177 energyColumn = (!energyColumn); 176 } 178 } 177 } 179 } 178 while (a != -2); 180 while (a != -2); 179 181 180 return true; 182 return true; 181 } 183 } 182 184 183 185 184 G4bool G4RDShellEMDataSet::SaveData(const G4St 186 G4bool G4RDShellEMDataSet::SaveData(const G4String& file) const 185 { 187 { 186 G4String fullFileName = FullFileName(file); 188 G4String fullFileName = FullFileName(file); 187 std::ofstream out(fullFileName); 189 std::ofstream out(fullFileName); 188 190 189 if (!out.is_open()) 191 if (!out.is_open()) 190 { 192 { 191 G4String message("Cannot open \""); 193 G4String message("Cannot open \""); 192 message += fullFileName; 194 message += fullFileName; 193 message += "\""; 195 message += "\""; 194 G4Exception("G4RDEMDataSet::SaveData()", 196 G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile", 195 FatalException, message); 197 FatalException, message); 196 } 198 } 197 199 198 const size_t n = NumberOfComponents(); 200 const size_t n = NumberOfComponents(); 199 size_t k = 0; 201 size_t k = 0; 200 202 201 while (k < n) 203 while (k < n) 202 { 204 { 203 const G4RDVEMDataSet* component = GetCom 205 const G4RDVEMDataSet* component = GetComponent(k); 204 206 205 if (component) 207 if (component) 206 { 208 { 207 const G4DataVector& energies = component-> 209 const G4DataVector& energies = component->GetEnergies(0); 208 const G4DataVector& data = component->GetD 210 const G4DataVector& data = component->GetData(0); 209 211 210 G4DataVector::const_iterator i = energies. 212 G4DataVector::const_iterator i = energies.begin(); 211 G4DataVector::const_iterator endI = energi 213 G4DataVector::const_iterator endI = energies.end(); 212 G4DataVector::const_iterator j = data.begi 214 G4DataVector::const_iterator j = data.begin(); 213 215 214 while (i != endI) 216 while (i != endI) 215 { 217 { 216 out.precision(10); 218 out.precision(10); 217 out.width(15); 219 out.width(15); 218 out.setf(std::ofstream::left); 220 out.setf(std::ofstream::left); 219 out << ((*i)/unitEnergies) << ' '; 221 out << ((*i)/unitEnergies) << ' '; 220 222 221 out.precision(10); 223 out.precision(10); 222 out.width(15); 224 out.width(15); 223 out.setf(std::ofstream::left); 225 out.setf(std::ofstream::left); 224 out << ((*j)/unitData) << std::endl; 226 out << ((*j)/unitData) << std::endl; 225 i++; 227 i++; 226 j++; 228 j++; 227 } 229 } 228 } 230 } 229 231 230 out.precision(10); 232 out.precision(10); 231 out.width(15); 233 out.width(15); 232 out.setf(std::ofstream::left); 234 out.setf(std::ofstream::left); 233 out << -1.f << ' '; 235 out << -1.f << ' '; 234 236 235 out.precision(10); 237 out.precision(10); 236 out.width(15); 238 out.width(15); 237 out.setf(std::ofstream::left); 239 out.setf(std::ofstream::left); 238 out << -1.f << std::endl; 240 out << -1.f << std::endl; 239 241 240 k++; 242 k++; 241 } 243 } 242 244 243 out.precision(10); 245 out.precision(10); 244 out.width(15); 246 out.width(15); 245 out.setf(std::ofstream::left); 247 out.setf(std::ofstream::left); 246 out << -2.f << ' '; 248 out << -2.f << ' '; 247 249 248 out.precision(10); 250 out.precision(10); 249 out.width(15); 251 out.width(15); 250 out.setf(std::ofstream::left); 252 out.setf(std::ofstream::left); 251 out << -2.f << std::endl; 253 out << -2.f << std::endl; 252 254 253 return true; 255 return true; 254 } 256 } 255 257 256 258 257 void G4RDShellEMDataSet::CleanUpComponents(voi 259 void G4RDShellEMDataSet::CleanUpComponents(void) 258 { 260 { 259 while (!components.empty()) 261 while (!components.empty()) 260 { 262 { 261 if (components.back()) delete components 263 if (components.back()) delete components.back(); 262 components.pop_back(); 264 components.pop_back(); 263 } 265 } 264 } 266 } 265 267 266 268 267 G4String G4RDShellEMDataSet::FullFileName(cons 269 G4String G4RDShellEMDataSet::FullFileName(const G4String& fileName) const 268 { 270 { 269 const char* path = G4FindDataDir("G4LEDATA") << 271 char* path = getenv("G4LEDATA"); 270 if (!path) 272 if (!path) 271 G4Exception("G4RDShellEMDataSet::FullFileN 273 G4Exception("G4RDShellEMDataSet::FullFileName()", "InvalidSetup", 272 FatalException, "G4LEDATA envi 274 FatalException, "G4LEDATA environment variable not set!"); 273 275 274 std::ostringstream fullFileName; 276 std::ostringstream fullFileName; 275 277 276 fullFileName << path << '/' << fileName << z 278 fullFileName << path << '/' << fileName << z << ".dat"; 277 279 278 return G4String(fullFileName.str().c_str()); 280 return G4String(fullFileName.str().c_str()); 279 } 281 } 280 282