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