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: XrayFluoDAtaSet.cc >> 28 // GEANT4 tag $Name: xray_fluo-V03-02-00 27 // 29 // 28 // Author: Elena Guardincerri (Elena.Guardince 30 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) 29 // 31 // 30 // History: 32 // History: 31 // ----------- 33 // ----------- 32 // 28 Nov 2001 Elena Guardincerri Created 34 // 28 Nov 2001 Elena Guardincerri Created 33 // 35 // 34 // ------------------------------------------- 36 // ------------------------------------------------------------------- 35 37 36 #include "XrayFluoDataSet.hh" 38 #include "XrayFluoDataSet.hh" 37 #include <fstream> 39 #include <fstream> 38 #include "G4VDataSetAlgorithm.hh" 40 #include "G4VDataSetAlgorithm.hh" 39 41 40 XrayFluoDataSet::XrayFluoDataSet(G4int /*Z*/, << 42 XrayFluoDataSet::XrayFluoDataSet(G4int Z, 41 G4DataVector* points, 43 G4DataVector* points, 42 G4DataVector* values, 44 G4DataVector* values, 43 const G4VDataSetAlgorithm* interpolatio 45 const G4VDataSetAlgorithm* interpolation, 44 G4double unitE, G4double unitData) 46 G4double unitE, G4double unitData) 45 :energies(points), data(values), algorithm(i << 47 :z(Z), energies(points), data(values), algorithm(interpolation) 46 { 48 { 47 numberOfBins = energies->size(); 49 numberOfBins = energies->size(); 48 unit1 = unitE; 50 unit1 = unitE; 49 unit2 = unitData; 51 unit2 = unitData; 50 } << 51 52 52 //....oooOO0OOooo........oooOO0OOooo........oo << 53 G4cout << "XrayFluo FluoDataSet created" << G4endl; >> 54 } 53 55 54 XrayFluoDataSet:: XrayFluoDataSet(G4int /*Z*/, << 56 XrayFluoDataSet:: XrayFluoDataSet(G4int Z, 55 const G4String& dataFile, 57 const G4String& dataFile, 56 const G4VDataSetAlgorithm* interpolati 58 const G4VDataSetAlgorithm* interpolation, 57 G4double unitE, G4double unitData) 59 G4double unitE, G4double unitData) 58 : algorithm(interpolation) << 60 :z(Z), algorithm(interpolation) 59 { 61 { 60 energies = new G4DataVector; 62 energies = new G4DataVector; 61 data = new G4DataVector; 63 data = new G4DataVector; 62 unit1 = unitE; 64 unit1 = unitE; 63 unit2 = unitData; 65 unit2 = unitData; 64 LoadData(dataFile); 66 LoadData(dataFile); 65 numberOfBins = energies->size(); 67 numberOfBins = energies->size(); >> 68 >> 69 G4cout << "XrayFluo FluoDataSet created" << G4endl; >> 70 66 } 71 } 67 72 68 //....oooOO0OOooo........oooOO0OOooo........oo << 69 73 70 // Destructor 74 // Destructor >> 75 71 XrayFluoDataSet::~XrayFluoDataSet() 76 XrayFluoDataSet::~XrayFluoDataSet() 72 { 77 { 73 delete energies; 78 delete energies; 74 delete data; 79 delete data; >> 80 G4cout << "XrayFluo FluoDataSet deleted" << G4endl; 75 } 81 } 76 82 77 //....oooOO0OOooo........oooOO0OOooo........oo << 78 83 79 G4double XrayFluoDataSet::FindValue(G4double e 84 G4double XrayFluoDataSet::FindValue(G4double e, G4int) const 80 { 85 { 81 G4double value; 86 G4double value; 82 G4double e0 = (*energies)[0]; 87 G4double e0 = (*energies)[0]; 83 // Protections 88 // Protections 84 size_t bin = FindBinLocation(e); 89 size_t bin = FindBinLocation(e); 85 if (bin == numberOfBins) 90 if (bin == numberOfBins) 86 { 91 { 87 92 88 value = (*data)[bin]; 93 value = (*data)[bin]; 89 } 94 } 90 else if (e <= e0) 95 else if (e <= e0) 91 { 96 { 92 97 93 value = (*data)[0]; 98 value = (*data)[0]; 94 } 99 } 95 else 100 else 96 { 101 { 97 value = algorithm->Calculate(e,bin,*ener 102 value = algorithm->Calculate(e,bin,*energies,*data); 98 } 103 } 99 104 100 return value; 105 return value; 101 } 106 } 102 107 103 //....oooOO0OOooo........oooOO0OOooo........oo << 104 << 105 G4int XrayFluoDataSet::FindBinLocation(G4doubl 108 G4int XrayFluoDataSet::FindBinLocation(G4double energy) const 106 { 109 { 107 // Protection against call outside allowed r 110 // Protection against call outside allowed range 108 G4double e0 = (*energies)[0]; 111 G4double e0 = (*energies)[0]; 109 if (energy < e0) 112 if (energy < e0) 110 { 113 { 111 114 112 energy = e0; 115 energy = e0; 113 } 116 } 114 117 115 size_t lowerBound = 0; 118 size_t lowerBound = 0; 116 size_t upperBound = numberOfBins - 1; 119 size_t upperBound = numberOfBins - 1; 117 120 118 // Binary search 121 // Binary search 119 while (lowerBound <= upperBound) 122 while (lowerBound <= upperBound) 120 { 123 { 121 size_t midBin = (lowerBound + upperBound 124 size_t midBin = (lowerBound + upperBound)/2; 122 if ( energy < (*energies)[midBin] ) uppe 125 if ( energy < (*energies)[midBin] ) upperBound = midBin-1; 123 else lowerBound = midBin+1; 126 else lowerBound = midBin+1; 124 } 127 } 125 128 126 return upperBound; 129 return upperBound; 127 } 130 } 128 131 129 //....oooOO0OOooo........oooOO0OOooo........oo << 130 132 131 G4bool XrayFluoDataSet::LoadData(const G4Strin << 133 void XrayFluoDataSet::LoadData(const G4String& fileName) 132 { 134 { 133 // Build the complete string identifying the 135 // Build the complete string identifying the file with the data set 134 G4String dirFile = ""; << 135 136 >> 137 >> 138 G4String dirFile = ""; >> 139 136 char* path; 140 char* path; 137 141 138 path = std::getenv("XRAYDATA"); << 142 #ifndef XRAYDATA 139 if (!path) << 143 #define XRAYDATA PWD 140 path = std::getenv("PWD"); << 144 #endif >> 145 >> 146 path = getenv("XRAYDATA"); 141 147 142 //G4cout << path << G4endl; << 148 G4cout << path << G4endl; 143 //G4cout << fileName << G4endl; << 149 G4cout << fileName << G4endl; 144 150 145 151 146 G4String pathString(path); << 152 G4String pathString(path); 147 pathString += "\0"; << 153 dirFile = pathString + "/" + fileName + ".dat"; 148 dirFile = pathString + "/" + fileName + ".da << 154 149 << 150 std::ifstream file(dirFile); 155 std::ifstream file(dirFile); 151 std::filebuf* lsdp = file.rdbuf(); 156 std::filebuf* lsdp = file.rdbuf(); 152 157 153 if (! (lsdp->is_open()) ) 158 if (! (lsdp->is_open()) ) 154 { 159 { 155 G4ExceptionDescription execp; << 160 G4String excep = "XrayFluoDataSet - data file: " + dirFile + " not found"; 156 execp << "XrayFluoDataSet - data file: " + << 161 G4Exception(excep); 157 G4Exception("XrayFluoDataSet::LoadData()", << 158 FatalException, execp); << 159 } 162 } 160 G4double a = 0; 163 G4double a = 0; 161 G4int k = 1; 164 G4int k = 1; 162 165 163 do 166 do 164 { 167 { 165 file >> a; 168 file >> a; 166 G4int nColumns = 2; 169 G4int nColumns = 2; 167 // The file is organized into two column 170 // The file is organized into two columns: 168 // 1st column is the energy 171 // 1st column is the energy 169 // 2nd column is the corresponding value 172 // 2nd column is the corresponding value 170 // The file terminates with the pattern: 173 // The file terminates with the pattern: -1 -1 171 // 174 // -2 -2 172 if (a == -1 || a == -2) 175 if (a == -1 || a == -2) 173 { 176 { 174 177 175 } 178 } 176 else 179 else 177 { 180 { 178 if (k%nColumns != 0) 181 if (k%nColumns != 0) 179 { 182 { 180 G4double e = a * unit1; 183 G4double e = a * unit1; 181 energies->push_back(e); 184 energies->push_back(e); 182 185 183 k++; 186 k++; 184 187 185 } 188 } 186 else if (k%nColumns == 0) 189 else if (k%nColumns == 0) 187 { 190 { 188 G4double value = a * unit2; 191 G4double value = a * unit2; 189 data->push_back(value); 192 data->push_back(value); 190 193 191 k = 1; 194 k = 1; 192 } 195 } 193 } 196 } 194 197 195 } while (a != -2); // end of file 198 } while (a != -2); // end of file 196 199 197 file.close(); 200 file.close(); 198 return true; << 199 << 200 } 201 } 201 << 202 //....oooOO0OOooo........oooOO0OOooo........oo << 203 << 204 void XrayFluoDataSet::PrintData() const 202 void XrayFluoDataSet::PrintData() const 205 { 203 { 206 size_t size = numberOfBins; 204 size_t size = numberOfBins; 207 for (size_t i=0; i<size; i++) 205 for (size_t i=0; i<size; i++) 208 { 206 { 209 G4double e = (*energies)[i] / unit1; 207 G4double e = (*energies)[i] / unit1; 210 G4double sigma = (*data)[i] / unit2 ; 208 G4double sigma = (*data)[i] / unit2 ; 211 G4cout << "Point: " 209 G4cout << "Point: " 212 << e 210 << e 213 << " - Data value : " 211 << " - Data value : " 214 << sigma 212 << sigma 215 << G4endl; 213 << G4endl; 216 } 214 } 217 } 215 } >> 216 >> 217 >> 218 >> 219 >> 220 >> 221 >> 222 >> 223 >> 224 >> 225 >> 226 >> 227 218 228 219 229 220 230 221 231