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 // 27 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@ 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // 29 // 30 // History: 30 // History: 31 // ----------- 31 // ----------- 32 // 1 Aug 2001 MGP Created 32 // 1 Aug 2001 MGP Created 33 // 09.10.01 V.Ivanchenko Add case z=0 33 // 09.10.01 V.Ivanchenko Add case z=0 34 // 9 Mar 2008 MGP Cleaned up unreada 34 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer 35 // (Further clean-up 35 // (Further clean-up needed) 36 // 31 Jul 2008 MGP Revised 36 // 31 Jul 2008 MGP Revised 37 // 37 // 38 // ------------------------------------------- 38 // ------------------------------------------------------------------- 39 39 40 #include "G4PixeShellDataSet.hh" 40 #include "G4PixeShellDataSet.hh" 41 #include "G4DataSet.hh" 41 #include "G4DataSet.hh" 42 #include "G4IInterpolator.hh" 42 #include "G4IInterpolator.hh" 43 #include <fstream> 43 #include <fstream> 44 #include <sstream> 44 #include <sstream> 45 45 46 46 47 G4PixeShellDataSet::G4PixeShellDataSet(G4int z 47 G4PixeShellDataSet::G4PixeShellDataSet(G4int zeta, 48 G4IInterpolator* algo, 48 G4IInterpolator* algo, 49 const G4String& modelK, 49 const G4String& modelK, 50 const G4String& modelL, 50 const G4String& modelL, 51 const G4String& modelM, 51 const G4String& modelM, 52 G4double eUnit, 52 G4double eUnit, 53 G4double dataUnit): 53 G4double dataUnit): 54 z(zeta), 54 z(zeta), 55 algorithm(algo), 55 algorithm(algo), 56 unitEnergies(eUnit), 56 unitEnergies(eUnit), 57 unitData(dataUnit) 57 unitData(dataUnit) 58 { 58 { 59 if (algorithm == 0) G4Exception("G4PixeShell 59 if (algorithm == 0) G4Exception("G4PixeShellDataSet::G4PixeShellDataSet", 60 "pii00000301", 60 "pii00000301", 61 FatalException, 61 FatalException, 62 "interpolation == 0"); 62 "interpolation == 0"); 63 63 64 crossModel.push_back(modelK); 64 crossModel.push_back(modelK); 65 crossModel.push_back(modelL); 65 crossModel.push_back(modelL); 66 crossModel.push_back(modelM); 66 crossModel.push_back(modelM); 67 67 68 shellName.push_back("k"); 68 shellName.push_back("k"); 69 shellName.push_back("l"); 69 shellName.push_back("l"); 70 shellName.push_back("m"); 70 shellName.push_back("m"); 71 71 72 std::size_t sizeK = modelK.size(); 72 std::size_t sizeK = modelK.size(); 73 std::size_t sizeL = modelL.size(); 73 std::size_t sizeL = modelL.size(); 74 std::size_t sizeM = modelM.size(); 74 std::size_t sizeM = modelM.size(); 75 75 76 if (sizeK > 0) subShellName.push_back("k"); 76 if (sizeK > 0) subShellName.push_back("k"); 77 77 78 if (sizeK > 0 && sizeL > 0) 78 if (sizeK > 0 && sizeL > 0) 79 { 79 { 80 subShellName.push_back("l1"); 80 subShellName.push_back("l1"); 81 subShellName.push_back("l2"); 81 subShellName.push_back("l2"); 82 subShellName.push_back("l3"); 82 subShellName.push_back("l3"); 83 } 83 } 84 if (sizeK > 0 && sizeL > 0 && sizeM >0) 84 if (sizeK > 0 && sizeL > 0 && sizeM >0) 85 { 85 { 86 subShellName.push_back("m1"); 86 subShellName.push_back("m1"); 87 subShellName.push_back("m2"); 87 subShellName.push_back("m2"); 88 subShellName.push_back("m3"); 88 subShellName.push_back("m3"); 89 subShellName.push_back("m4"); 89 subShellName.push_back("m4"); 90 subShellName.push_back("m5"); 90 subShellName.push_back("m5"); 91 } 91 } 92 } 92 } 93 93 94 94 95 G4PixeShellDataSet::~G4PixeShellDataSet() 95 G4PixeShellDataSet::~G4PixeShellDataSet() 96 { 96 { 97 CleanUpComponents(); 97 CleanUpComponents(); 98 if (algorithm) delete algorithm; 98 if (algorithm) delete algorithm; 99 } 99 } 100 100 101 101 102 G4double G4PixeShellDataSet::FindValue(G4doubl 102 G4double G4PixeShellDataSet::FindValue(G4double energy, G4int /* componentId */) const 103 { 103 { 104 // Returns the sum over the shells correspon 104 // Returns the sum over the shells corresponding to e 105 G4double value = 0.; 105 G4double value = 0.; 106 106 107 std::vector<G4IDataSet *>::const_iterator i( 107 std::vector<G4IDataSet *>::const_iterator i(components.begin()); 108 std::vector<G4IDataSet *>::const_iterator en 108 std::vector<G4IDataSet *>::const_iterator end(components.end()); 109 109 110 while (i != end) 110 while (i != end) 111 { 111 { 112 value += (*i)->FindValue(energy); 112 value += (*i)->FindValue(energy); 113 i++; 113 i++; 114 } 114 } 115 return value; 115 return value; 116 } 116 } 117 117 118 118 119 void G4PixeShellDataSet::PrintData(void) const 119 void G4PixeShellDataSet::PrintData(void) const 120 { 120 { 121 const G4int n = (G4int)NumberOfComponents(); 121 const G4int n = (G4int)NumberOfComponents(); 122 122 123 G4cout << "The data set has " << n << " comp 123 G4cout << "The data set has " << n << " components" << G4endl; 124 G4cout << G4endl; 124 G4cout << G4endl; 125 125 126 G4int i = 0; 126 G4int i = 0; 127 127 128 while (i < n) 128 while (i < n) 129 { 129 { 130 G4cout << "--- Component " << i << " --- 130 G4cout << "--- Component " << i << " ---" << G4endl; 131 GetComponent(i)->PrintData(); 131 GetComponent(i)->PrintData(); 132 ++i; 132 ++i; 133 } 133 } 134 } 134 } 135 135 136 136 137 void G4PixeShellDataSet::SetEnergiesData(G4Dat 137 void G4PixeShellDataSet::SetEnergiesData(G4DataVector* energies, 138 G4DataVector* data, 138 G4DataVector* data, 139 G4int componentId) 139 G4int componentId) 140 { 140 { 141 G4IDataSet* component = components[component 141 G4IDataSet* component = components[componentId]; 142 142 143 if (component) 143 if (component) 144 { 144 { 145 component->SetEnergiesData(energies, dat 145 component->SetEnergiesData(energies, data, 0); 146 return; 146 return; 147 } 147 } 148 148 149 std::ostringstream message; 149 std::ostringstream message; 150 message << "G4PixeShellDataSet::SetEnergiesD 150 message << "G4PixeShellDataSet::SetEnergiesData - component " << componentId << " not found"; 151 151 152 G4Exception("G4PixeShellDataSet::SetEnergies 152 G4Exception("G4PixeShellDataSet::SetEnergiesData", 153 "pii000000310", 153 "pii000000310", 154 FatalException, 154 FatalException, 155 message.str().c_str()); 155 message.str().c_str()); 156 } 156 } 157 157 158 158 159 G4bool G4PixeShellDataSet::LoadData(const G4St 159 G4bool G4PixeShellDataSet::LoadData(const G4String& file) 160 { 160 { 161 CleanUpComponents(); 161 CleanUpComponents(); 162 162 163 // Load shell cross sections 163 // Load shell cross sections 164 164 165 std::size_t nShells = subShellName.size(); 165 std::size_t nShells = subShellName.size(); 166 166 167 for (std::size_t subShellIndex=0; subShellIn 167 for (std::size_t subShellIndex=0; subShellIndex<nShells; ++subShellIndex) 168 { 168 { 169 G4String subName = subShellName[subShell 169 G4String subName = subShellName[subShellIndex]; 170 G4String fullFileName = FullFileName(fil 170 G4String fullFileName = FullFileName(file,subName); 171 171 172 // Create component DataSet with the dat 172 // Create component DataSet with the data from the current subshell 173 G4IDataSet* dataSet = new G4DataSet(z,al 173 G4IDataSet* dataSet = new G4DataSet(z,algorithm); 174 dataSet->LoadData(fullFileName); 174 dataSet->LoadData(fullFileName); 175 175 176 // Add component to the ShellDataSet 176 // Add component to the ShellDataSet 177 AddComponent(dataSet); 177 AddComponent(dataSet); 178 } 178 } 179 179 180 return true; 180 return true; 181 } 181 } 182 182 183 183 184 G4bool G4PixeShellDataSet::SaveData(const G4St 184 G4bool G4PixeShellDataSet::SaveData(const G4String& /* file */) const 185 { 185 { 186 // Dummy implementation 186 // Dummy implementation 187 return true; 187 return true; 188 } 188 } 189 189 190 190 191 void G4PixeShellDataSet::CleanUpComponents(voi 191 void G4PixeShellDataSet::CleanUpComponents(void) 192 { 192 { 193 while (!components.empty()) 193 while (!components.empty()) 194 { 194 { 195 if (components.back()) delete components 195 if (components.back()) delete components.back(); 196 components.pop_back(); 196 components.pop_back(); 197 } 197 } 198 } 198 } 199 199 200 200 201 G4String G4PixeShellDataSet::FullFileName(cons 201 G4String G4PixeShellDataSet::FullFileName(const G4String& file, 202 const G4String& subShell) const 202 const G4String& subShell) const 203 { 203 { 204 const char* path = G4FindDataDir("G4PIIDATA" 204 const char* path = G4FindDataDir("G4PIIDATA"); 205 if (!path) 205 if (!path) 206 G4Exception("G4PixeShellDataSet::FullFileN 206 G4Exception("G4PixeShellDataSet::FullFileName", 207 "pii00000320", 207 "pii00000320", 208 FatalException, 208 FatalException, 209 "G4PIIDATA environment variable not 209 "G4PIIDATA environment variable not set"); 210 210 211 // Identify the shell this subshell belongs 211 // Identify the shell this subshell belongs to 212 G4int shellIndex = TranslateShell(subShell); 212 G4int shellIndex = TranslateShell(subShell); 213 G4String shellString = shellName[shellIndex] 213 G4String shellString = shellName[shellIndex]; 214 G4String shellModel = crossModel[shellIndex] 214 G4String shellModel = crossModel[shellIndex]; 215 215 216 std::ostringstream fullFileName; 216 std::ostringstream fullFileName; 217 217 218 fullFileName 218 fullFileName 219 //<< path 219 //<< path 220 << "pixe/" 220 << "pixe/" 221 << file 221 << file 222 << '/' 222 << '/' 223 << shellString 223 << shellString 224 << '/' 224 << '/' 225 << shellModel 225 << shellModel 226 << '/' 226 << '/' 227 << subShell 227 << subShell 228 << '-' ; 228 << '-' ; 229 // << z 229 // << z 230 // << ".dat"; 230 // << ".dat"; 231 231 232 G4String test(fullFileName.str().c_str()); 232 G4String test(fullFileName.str().c_str()); 233 // std::cout << "PixeShellDataSet - Reading 233 // std::cout << "PixeShellDataSet - Reading data from file " << test << std::endl; 234 234 235 return G4String(fullFileName.str().c_str()); 235 return G4String(fullFileName.str().c_str()); 236 } 236 } 237 237 238 G4int G4PixeShellDataSet::TranslateShell(const 238 G4int G4PixeShellDataSet::TranslateShell(const G4String& subShell) const 239 { 239 { 240 // By default return K shell 240 // By default return K shell 241 G4int index = 0; 241 G4int index = 0; 242 242 243 if (subShell == "l1" || subShell == "l2" || 243 if (subShell == "l1" || subShell == "l2" || subShell == "l3" ) index = 1; 244 if (subShell == "m1" || 244 if (subShell == "m1" || 245 subShell == "m2" || 245 subShell == "m2" || 246 subShell == "m3" || 246 subShell == "m3" || 247 subShell == "m4" || 247 subShell == "m4" || 248 subShell == "m5" ) index = 2; 248 subShell == "m5" ) index = 2; 249 return index; 249 return index; 250 } 250 } 251 251