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