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$ 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 // 15 Jul 2009 Nicolas A. Karakatsanis 35 // 15 Jul 2009 Nicolas A. Karakatsanis 35 // 36 // 36 // - LoadNonLogData 37 // - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW 37 // dataset. It is 38 // dataset. It is essentially performing the data loading operations as in the past. 38 // 39 // 39 // - LoadData method 40 // - LoadData method was revised in order to calculate the logarithmic values of the data 40 // It retrieves th 41 // It retrieves the data values from the G4EMLOW data files but, then, calculates the 41 // respective log 42 // respective log values and loads them to seperate data structures. 42 // 43 // 43 // - SetLogEnergiesD 44 // - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors. 44 // The EM data set 45 // The EM data sets, initialized this way, contain both non-log and log values. 45 // These initializ 46 // These initialized data sets can enhance the computing performance of data interpolation 46 // operations 47 // operations 47 // 48 // 48 // ------------------------------------------- 49 // ------------------------------------------------------------------- 49 50 50 #include "G4CompositeEMDataSet.hh" 51 #include "G4CompositeEMDataSet.hh" 51 #include "G4EMDataSet.hh" 52 #include "G4EMDataSet.hh" 52 #include "G4VDataSetAlgorithm.hh" 53 #include "G4VDataSetAlgorithm.hh" 53 #include <fstream> 54 #include <fstream> 54 #include <sstream> 55 #include <sstream> 55 56 56 //....oooOO0OOooo........oooOO0OOooo........oo << 57 << 58 G4CompositeEMDataSet::G4CompositeEMDataSet(G4V 57 G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm, 59 G4double argUnitEnergies, 58 G4double argUnitEnergies, 60 G4double argUnitData, 59 G4double argUnitData, 61 G4int argMinZ, 60 G4int argMinZ, 62 G4int argMaxZ) 61 G4int argMaxZ) 63 : 62 : 64 algorithm(argAlgorithm), 63 algorithm(argAlgorithm), 65 unitEnergies(argUnitEnergies), 64 unitEnergies(argUnitEnergies), 66 unitData(argUnitData), 65 unitData(argUnitData), 67 minZ(argMinZ), 66 minZ(argMinZ), 68 maxZ(argMaxZ) 67 maxZ(argMaxZ) 69 { 68 { 70 if (algorithm == nullptr) << 69 if (algorithm == 0) 71 G4Exception("G4CompositeEMDataSet::G4Composi 70 G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet", 72 "em1003",FatalException,"interpolation 71 "em1003",FatalException,"interpolation == 0"); 73 72 74 } 73 } 75 74 76 //....oooOO0OOooo........oooOO0OOooo........oo << 75 77 76 78 G4CompositeEMDataSet::~G4CompositeEMDataSet() 77 G4CompositeEMDataSet::~G4CompositeEMDataSet() 79 { 78 { 80 CleanUpComponents(); 79 CleanUpComponents(); 81 if (algorithm) delete algorithm; 80 if (algorithm) delete algorithm; 82 } 81 } 83 //....oooOO0OOooo........oooOO0OOooo........oo << 82 84 83 85 G4double G4CompositeEMDataSet::FindValue(G4dou 84 G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const 86 { 85 { 87 const G4VEMDataSet* component(GetComponent(a 86 const G4VEMDataSet* component(GetComponent(argComponentId)); 88 87 89 if (component) return component->FindValue(a 88 if (component) return component->FindValue(argEnergy); 90 89 91 std::ostringstream message; 90 std::ostringstream message; 92 message << "G4CompositeEMDataSet::FindValue 91 message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found"; 93 92 94 G4Exception("G4CompositeEMDataSet::FindValue 93 G4Exception("G4CompositeEMDataSet::FindValue", 95 "em1004",FatalException,message.str(). 94 "em1004",FatalException,message.str().c_str()); 96 95 97 return 0.; 96 return 0.; 98 } 97 } 99 98 100 //....oooOO0OOooo........oooOO0OOooo........oo << 101 << 102 void G4CompositeEMDataSet::PrintData(void) con 99 void G4CompositeEMDataSet::PrintData(void) const 103 { 100 { 104 const G4int n = (G4int)NumberOfComponents(); << 101 const size_t n(NumberOfComponents()); 105 102 106 G4cout << "The data set has " << n << " comp 103 G4cout << "The data set has " << n << " components" << G4endl; 107 G4cout << G4endl; 104 G4cout << G4endl; 108 105 109 G4int i(0); << 106 size_t i(0); 110 107 111 while (i<n) 108 while (i<n) 112 { 109 { 113 G4cout << "--- Component " << i << " --- 110 G4cout << "--- Component " << i << " ---" << G4endl; 114 GetComponent(i)->PrintData(); 111 GetComponent(i)->PrintData(); 115 ++i; << 112 i++; 116 } 113 } 117 } 114 } 118 115 119 //....oooOO0OOooo........oooOO0OOooo........oo << 120 << 121 void G4CompositeEMDataSet::SetEnergiesData(G4D 116 void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId) 122 { 117 { 123 G4VEMDataSet * component(components[argCompo 118 G4VEMDataSet * component(components[argComponentId]); 124 119 125 if (component) 120 if (component) 126 { 121 { 127 component->SetEnergiesData(argEnergies, 122 component->SetEnergiesData(argEnergies, argData, 0); 128 return; 123 return; 129 } 124 } 130 125 131 std::ostringstream message; 126 std::ostringstream message; 132 message << "G4CompositeEMDataSet::SetEnergie 127 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found"; 133 128 134 G4Exception("G4CompositeEMDataSet::SetEnergi 129 G4Exception("G4CompositeEMDataSet::SetEnergiesData", 135 "em1004",FatalException,message.str(). 130 "em1004",FatalException,message.str().c_str()); 136 } 131 } 137 132 138 //....oooOO0OOooo........oooOO0OOooo........oo << 139 << 140 void G4CompositeEMDataSet::SetLogEnergiesData( 133 void G4CompositeEMDataSet::SetLogEnergiesData(G4DataVector* argEnergies, 141 134 G4DataVector* argData, 142 135 G4DataVector* argLogEnergies, 143 136 G4DataVector* argLogData, 144 137 G4int argComponentId) 145 { 138 { 146 G4VEMDataSet * component(components[argCompo 139 G4VEMDataSet * component(components[argComponentId]); 147 140 148 if (component) 141 if (component) 149 { 142 { 150 component->SetLogEnergiesData(argEnergie 143 component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0); 151 return; 144 return; 152 } 145 } 153 146 154 std::ostringstream message; 147 std::ostringstream message; 155 message << "G4CompositeEMDataSet::SetEnergie 148 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found"; 156 149 157 G4Exception("G4CompositeEMDataSet::SetLogEne 150 G4Exception("G4CompositeEMDataSet::SetLogEnergiesData", 158 "em1004",FatalException,message.str(). 151 "em1004",FatalException,message.str().c_str()); 159 } 152 } 160 153 161 //....oooOO0OOooo........oooOO0OOooo........oo << 162 154 163 G4bool G4CompositeEMDataSet::LoadData(const G4 155 G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName) 164 { 156 { 165 CleanUpComponents(); 157 CleanUpComponents(); 166 158 167 for (G4int z(minZ); z<maxZ; ++z) << 159 for (G4int z(minZ); z<maxZ; z++) 168 { 160 { 169 G4VEMDataSet* component = new G4EMDataSe 161 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData); 170 if (!component->LoadData(argFileName)) 162 if (!component->LoadData(argFileName)) 171 { 163 { 172 delete component; 164 delete component; 173 return false; 165 return false; 174 } 166 } 175 AddComponent(component); 167 AddComponent(component); 176 } 168 } 177 return true; 169 return true; 178 } 170 } 179 171 180 //....oooOO0OOooo........oooOO0OOooo........oo << 181 172 182 G4bool G4CompositeEMDataSet::LoadNonLogData(co 173 G4bool G4CompositeEMDataSet::LoadNonLogData(const G4String& argFileName) 183 { 174 { 184 CleanUpComponents(); 175 CleanUpComponents(); 185 176 186 for (G4int z(minZ); z<maxZ; ++z) << 177 for (G4int z(minZ); z<maxZ; z++) 187 { 178 { 188 G4VEMDataSet* component = new G4EMDataSe 179 G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData); 189 if (!component->LoadNonLogData(argFileNa 180 if (!component->LoadNonLogData(argFileName)) 190 { 181 { 191 delete component; 182 delete component; 192 return false; 183 return false; 193 } 184 } 194 AddComponent(component); 185 AddComponent(component); 195 } 186 } 196 return true; 187 return true; 197 } 188 } 198 189 199 //....oooOO0OOooo........oooOO0OOooo........oo << 200 190 201 G4bool G4CompositeEMDataSet::SaveData(const G4 191 G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const 202 { 192 { 203 for (G4int z=minZ; z<maxZ; ++z) << 193 for (G4int z=minZ; z<maxZ; z++) 204 { 194 { 205 const G4VEMDataSet* component(GetCompone 195 const G4VEMDataSet* component(GetComponent(z-minZ)); 206 196 207 if (!component) 197 if (!component) 208 { 198 { 209 std::ostringstream message; 199 std::ostringstream message; 210 message << "G4CompositeEMDataSet::SaveData 200 message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found"; 211 G4Exception("G4CompositeEMDataSet::S 201 G4Exception("G4CompositeEMDataSet::SaveData", 212 "em1004",FatalException,message.str(). 202 "em1004",FatalException,message.str().c_str()); 213 return false; 203 return false; 214 } 204 } 215 205 216 if (!component->SaveData(argFileName)) 206 if (!component->SaveData(argFileName)) 217 return false; 207 return false; 218 } 208 } 219 209 220 return true; 210 return true; 221 } 211 } 222 212 223 //....oooOO0OOooo........oooOO0OOooo........oo << 224 << 225 void G4CompositeEMDataSet::CleanUpComponents(v 213 void G4CompositeEMDataSet::CleanUpComponents(void) 226 { 214 { 227 while (!components.empty()) 215 while (!components.empty()) 228 { 216 { 229 if (components.back()) 217 if (components.back()) 230 delete components.back(); 218 delete components.back(); 231 components.pop_back(); 219 components.pop_back(); 232 } 220 } 233 } 221 } 234 222 235 //....oooOO0OOooo........oooOO0OOooo........oo << 236 223 237 G4double G4CompositeEMDataSet::RandomSelect(G4 224 G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const 238 { 225 { 239 G4double value = 0.; 226 G4double value = 0.; 240 if (componentId >= 0 && componentId < (G4int 227 if (componentId >= 0 && componentId < (G4int)components.size()) 241 { 228 { 242 const G4VEMDataSet* dataSet = GetCompone 229 const G4VEMDataSet* dataSet = GetComponent(componentId); 243 value = dataSet->RandomSelect(); 230 value = dataSet->RandomSelect(); 244 } 231 } 245 return value; 232 return value; 246 } 233 } 247 234