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