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: Elena Guardincerri (Elena.Guardince 28 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) 29 // 29 // 30 // History: 30 // History: 31 // ----------- 31 // ----------- 32 // 16 Sept 2001 First committed to cvs 32 // 16 Sept 2001 First committed to cvs 33 // 33 // 34 // ------------------------------------------- 34 // ------------------------------------------------------------------- 35 35 36 #include <fstream> 36 #include <fstream> 37 #include <sstream> 37 #include <sstream> 38 38 39 #include "G4FluoData.hh" 39 #include "G4FluoData.hh" 40 #include "G4SystemOfUnits.hh" 40 #include "G4SystemOfUnits.hh" 41 #include "G4DataVector.hh" 41 #include "G4DataVector.hh" 42 #include "G4FluoTransition.hh" 42 #include "G4FluoTransition.hh" 43 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 44 G4FluoData::G4FluoData(const G4String& dir) 44 G4FluoData::G4FluoData(const G4String& dir) 45 { 45 { 46 fluoDirectory = dir; 46 fluoDirectory = dir; 47 } 47 } 48 48 49 //....oooOO0OOooo........oooOO0OOooo........oo 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 50 51 G4FluoData::~G4FluoData() 51 G4FluoData::~G4FluoData() 52 { 52 { 53 for (auto& pos : idMap) 53 for (auto& pos : idMap) 54 { 54 { 55 G4DataVector* dataSet = pos.second; 55 G4DataVector* dataSet = pos.second; 56 delete dataSet; 56 delete dataSet; 57 } 57 } 58 58 59 for (auto& pos : energyMap) 59 for (auto& pos : energyMap) 60 { 60 { 61 G4DataVector* dataSet = pos.second; 61 G4DataVector* dataSet = pos.second; 62 delete dataSet; 62 delete dataSet; 63 } 63 } 64 64 65 for (auto& pos: probabilityMap) 65 for (auto& pos: probabilityMap) 66 { 66 { 67 G4DataVector* dataSet = pos.second; 67 G4DataVector* dataSet = pos.second; 68 delete dataSet; 68 delete dataSet; 69 } 69 } 70 } 70 } 71 71 72 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 73 73 74 std::size_t G4FluoData::NumberOfVacancies() co << 74 size_t G4FluoData::NumberOfVacancies() const 75 { 75 { 76 return numberOfVacancies; 76 return numberOfVacancies; 77 } 77 } 78 78 79 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 80 80 81 G4int G4FluoData::VacancyId(G4int vacancyIndex 81 G4int G4FluoData::VacancyId(G4int vacancyIndex) const 82 { 82 { 83 G4int n = -1; 83 G4int n = -1; 84 if (vacancyIndex<0 || vacancyIndex>=numberOf 84 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 85 { 85 { 86 G4Exception("G4FluoData::vacancyId()","d 86 G4Exception("G4FluoData::vacancyId()","de0002",FatalErrorInArgument, 87 "vacancyIndex outside boundaries"); 87 "vacancyIndex outside boundaries"); 88 } 88 } 89 else 89 else 90 { 90 { 91 auto pos = idMap.find(vacancyIndex); 91 auto pos = idMap.find(vacancyIndex); 92 if (pos!= idMap.end()) 92 if (pos!= idMap.end()) 93 { G4DataVector dataSet = (*(*pos).second); 93 { G4DataVector dataSet = (*(*pos).second); 94 n = (G4int) dataSet[0]; 94 n = (G4int) dataSet[0]; 95 95 96 } 96 } 97 } 97 } 98 return n; 98 return n; 99 } 99 } 100 100 101 //....oooOO0OOooo........oooOO0OOooo........oo 101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 102 102 103 std::size_t G4FluoData::NumberOfTransitions(G4 << 103 size_t G4FluoData::NumberOfTransitions(G4int vacancyIndex) const 104 { 104 { 105 G4int n = 0; 105 G4int n = 0; 106 if (vacancyIndex<0 || vacancyIndex>=numberOf 106 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 107 { 107 { 108 G4Exception("G4FluoData::NumberOfTransit 108 G4Exception("G4FluoData::NumberOfTransitions()","de0002",JustWarning, 109 "vacancyIndex outside boundaries, energy 109 "vacancyIndex outside boundaries, energy deposited locally"); 110 return 0; 110 return 0; 111 } 111 } 112 else 112 else 113 { 113 { 114 n = nInitShells[vacancyIndex]-1; 114 n = nInitShells[vacancyIndex]-1; 115 //-1 is necessary because the elements o 115 //-1 is necessary because the elements of the vector nInitShells 116 //include also the vacancy shell: 116 //include also the vacancy shell: 117 // -1 subtracts this last one 117 // -1 subtracts this last one 118 } 118 } 119 return n; 119 return n; 120 } 120 } 121 121 122 //....oooOO0OOooo........oooOO0OOooo........oo 122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 123 123 124 G4int G4FluoData::StartShellId(G4int initIndex 124 G4int G4FluoData::StartShellId(G4int initIndex, G4int vacancyIndex) const 125 { 125 { 126 G4int n = -1; 126 G4int n = -1; 127 127 128 if (vacancyIndex<0 || vacancyIndex>=numberOfV << 128 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 129 G4Exception("G4FluoData::StartShellId()","d << 129 { 130 "vacancyIndex outside boundaries"); << 130 G4Exception("G4FluoData::StartShellId()","de0002",FatalErrorInArgument, 131 } else { << 131 "vacancyIndex outside boundaries"); 132 auto pos = idMap.find(vacancyIndex); << 132 } 133 if (pos != idMap.end()) { << 133 else 134 G4DataVector* dataSet = (*pos).second; << 134 { >> 135 auto pos = idMap.find(vacancyIndex); >> 136 >> 137 G4DataVector dataSet = *((*pos).second); 135 138 136 G4int nData = (G4int)dataSet->size(); << 139 G4int nData = dataSet.size(); 137 // The first Element of idMap's dataSets 140 // The first Element of idMap's dataSets is the original shell of 138 // the vacancy, so we must start from the 141 // the vacancy, so we must start from the first element of dataSet 139 if (initIndex >= 0 && initIndex < nData) << 142 if (initIndex >= 0 && initIndex < nData) 140 n = (*dataSet)[initIndex+1]; << 143 { 141 } << 144 n = (G4int) dataSet[initIndex+1]; >> 145 } 142 } 146 } 143 } << 144 return n; 147 return n; 145 } 148 } 146 149 147 //....oooOO0OOooo........oooOO0OOooo........oo 150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 148 151 149 G4double G4FluoData::StartShellEnergy(G4int in 152 G4double G4FluoData::StartShellEnergy(G4int initIndex, G4int vacancyIndex) const 150 { 153 { 151 G4double n = -1; 154 G4double n = -1; 152 155 153 if (vacancyIndex<0 || vacancyIndex>=numberOf 156 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 154 { 157 { 155 G4Exception("G4FluoData::StartShellEnerg 158 G4Exception("G4FluoData::StartShellEnergy()","de0002",FatalErrorInArgument, 156 "vacancyIndex outside boundaries");} 159 "vacancyIndex outside boundaries");} 157 else 160 else 158 { 161 { 159 auto pos = energyMap.find(vacancyIndex); 162 auto pos = energyMap.find(vacancyIndex); 160 163 161 G4DataVector dataSet = *((*pos).second); 164 G4DataVector dataSet = *((*pos).second); 162 165 163 G4int nData = (G4int)dataSet.size(); << 166 G4int nData = dataSet.size(); 164 if (initIndex >= 0 && initIndex < nData) 167 if (initIndex >= 0 && initIndex < nData) 165 { 168 { 166 n = dataSet[initIndex]; << 169 n = dataSet[initIndex]; 167 } 170 } 168 } 171 } 169 return n; 172 return n; 170 } 173 } 171 174 172 //....oooOO0OOooo........oooOO0OOooo........oo 175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 173 176 174 G4double G4FluoData::StartShellProb(G4int init 177 G4double G4FluoData::StartShellProb(G4int initIndex, G4int vacancyIndex) const 175 { 178 { 176 G4double n = -1; 179 G4double n = -1; 177 180 178 if (vacancyIndex<0 || vacancyIndex>=numberOf 181 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 179 { 182 { 180 G4Exception("G4FluoData::StartShellEnerg 183 G4Exception("G4FluoData::StartShellEnergy()","de0002",JustWarning, 181 "vacancyIndex outside boundaries, energy 184 "vacancyIndex outside boundaries, energy deposited locally"); 182 return 0; 185 return 0; 183 } 186 } 184 else 187 else 185 { 188 { 186 auto pos = probabilityMap.find(vacancyIn 189 auto pos = probabilityMap.find(vacancyIndex); 187 190 188 G4DataVector dataSet = *((*pos).second); 191 G4DataVector dataSet = *((*pos).second); 189 192 190 G4int nData = (G4int)dataSet.size(); << 193 G4int nData = dataSet.size(); 191 if (initIndex >= 0 && initIndex < nData) 194 if (initIndex >= 0 && initIndex < nData) 192 { 195 { 193 n = dataSet[initIndex]; << 196 n = dataSet[initIndex]; 194 } 197 } 195 } 198 } 196 return n; 199 return n; 197 } 200 } 198 201 199 //....oooOO0OOooo........oooOO0OOooo........oo 202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 200 203 201 void G4FluoData::LoadData(G4int Z) 204 void G4FluoData::LoadData(G4int Z) 202 { 205 { 203 // Build the complete string identifying the 206 // Build the complete string identifying the file with the data set 204 std::ostringstream ost; 207 std::ostringstream ost; 205 if(Z != 0){ 208 if(Z != 0){ 206 ost << "/fl-tr-pr-"<< Z << ".dat"; 209 ost << "/fl-tr-pr-"<< Z << ".dat"; 207 } 210 } 208 else{ 211 else{ 209 ost << "/fl-tr-pr-"<<".dat"; 212 ost << "/fl-tr-pr-"<<".dat"; 210 } 213 } 211 G4String name(ost.str()); 214 G4String name(ost.str()); 212 215 213 216 214 const char* path = G4FindDataDir("G4LEDATA") << 217 char* path = std::getenv("G4LEDATA"); 215 if (!path) 218 if (!path) 216 { 219 { 217 G4String excep("G4FluoData::LoadData()") 220 G4String excep("G4FluoData::LoadData()"); 218 G4Exception(excep,"em0006",FatalExceptio 221 G4Exception(excep,"em0006",FatalException,"Please set G4LEDATA"); 219 return; 222 return; 220 } 223 } 221 224 222 G4String pathString(path); 225 G4String pathString(path); 223 226 224 G4String dirFile = pathString + fluoDirector 227 G4String dirFile = pathString + fluoDirectory + name; 225 228 226 //G4cout << "G4FluoData:: LoadData() name: " 229 //G4cout << "G4FluoData:: LoadData() name: " << dirFile << G4endl; 227 230 228 231 229 std::ifstream file(dirFile); 232 std::ifstream file(dirFile); 230 std::filebuf* lsdp = file.rdbuf(); 233 std::filebuf* lsdp = file.rdbuf(); 231 234 232 if (! (lsdp->is_open()) ) 235 if (! (lsdp->is_open()) ) 233 { 236 { 234 G4String excep = "G4FluoData::LoadData() 237 G4String excep = "G4FluoData::LoadData()"; 235 G4String msg = "data file: " + dirFile + 238 G4String msg = "data file: " + dirFile + " not found"; 236 G4Exception(excep, "em0003",FatalExcepti 239 G4Exception(excep, "em0003",FatalException, msg ); 237 return; 240 return; 238 } 241 } 239 242 240 G4double a = 0; 243 G4double a = 0; 241 G4int k = 1; 244 G4int k = 1; 242 G4int sLocal = 0; 245 G4int sLocal = 0; 243 246 244 G4int vacIndex = 0; 247 G4int vacIndex = 0; 245 G4DataVector* initIds = new G4DataVector; 248 G4DataVector* initIds = new G4DataVector; 246 G4DataVector* transEnergies = new G4DataVect 249 G4DataVector* transEnergies = new G4DataVector; 247 G4DataVector* transProbabilities = new G4Dat 250 G4DataVector* transProbabilities = new G4DataVector; 248 251 249 do { 252 do { 250 file >> a; 253 file >> a; 251 G4int nColumns = 3; 254 G4int nColumns = 3; 252 if (a == -1) 255 if (a == -1) 253 { 256 { 254 if (sLocal == 0) 257 if (sLocal == 0) 255 { 258 { 256 // End of a shell data set 259 // End of a shell data set 257 idMap[vacIndex] = initIds; << 260 idMap[vacIndex] = initIds; 258 energyMap[vacIndex] = transEnergie 261 energyMap[vacIndex] = transEnergies; 259 probabilityMap[vacIndex] = transPr << 262 probabilityMap[vacIndex] = transProbabilities; 260 G4int n = (G4int)initIds->size(); << 263 // G4double size=transProbabilities->size(); >> 264 G4int n = initIds->size(); 261 265 262 nInitShells.push_back(n); 266 nInitShells.push_back(n); 263 numberOfVacancies++; 267 numberOfVacancies++; 264 // Start of new shell data set 268 // Start of new shell data set 265 initIds = new G4DataVector; 269 initIds = new G4DataVector; 266 transEnergies = new G4DataVector; 270 transEnergies = new G4DataVector; 267 transProbabilities = new G4DataVector; 271 transProbabilities = new G4DataVector; 268 vacIndex++; 272 vacIndex++; 269 } 273 } 270 sLocal++; 274 sLocal++; 271 if (sLocal == nColumns) 275 if (sLocal == nColumns) 272 { 276 { 273 sLocal = 0; 277 sLocal = 0; 274 } 278 } 275 } 279 } 276 // moved to the end in order to avoid poss 280 // moved to the end in order to avoid possible leak 277 /* else if (a == -2) 281 /* else if (a == -2) 278 { 282 { 279 // End of file; delete the empty vectors cre 283 // End of file; delete the empty vectors created 280 //when encountering the last -1 -1 row 284 //when encountering the last -1 -1 row 281 delete initIds; 285 delete initIds; 282 delete transEnergies; 286 delete transEnergies; 283 delete transProbabilities; 287 delete transProbabilities; 284 }*/ 288 }*/ 285 else 289 else 286 { 290 { 287 if(k%nColumns == 2) 291 if(k%nColumns == 2) 288 { 292 { 289 // 2nd column is transition probabiliti 293 // 2nd column is transition probabilities 290 294 291 if (a != -1) transProbabilities->push_bac 295 if (a != -1) transProbabilities->push_back(a); 292 296 293 k++; 297 k++; 294 } 298 } 295 else if (k%nColumns == 1) 299 else if (k%nColumns == 1) 296 { 300 { 297 // 1st column is shell id 301 // 1st column is shell id 298 // if this is the first data of the shel 302 // if this is the first data of the shell, all the colums are equal 299 // to the shell Id; so we skip the next 303 // to the shell Id; so we skip the next colums ang go to the next row 300 if(initIds->size() == 0) { 304 if(initIds->size() == 0) { 301 if (a != -1) initIds->push_back((G4int 305 if (a != -1) initIds->push_back((G4int)a); 302 file >> a; 306 file >> a; 303 file >> a; 307 file >> a; 304 k=k+2; 308 k=k+2; 305 } 309 } 306 else{ 310 else{ 307 if (a != -1) initIds->push_back(a); 311 if (a != -1) initIds->push_back(a); 308 } 312 } 309 k++; 313 k++; 310 } 314 } 311 else if (k%nColumns == 0) 315 else if (k%nColumns == 0) 312 316 313 {//third column is transition energies 317 {//third column is transition energies 314 318 315 if (a != -1) 319 if (a != -1) 316 {G4double e = a * MeV; 320 {G4double e = a * MeV; 317 transEnergies->push_back(e);} 321 transEnergies->push_back(e);} 318 322 319 k=1; 323 k=1; 320 } 324 } 321 } 325 } 322 } 326 } 323 while (a != -2); // end of file 327 while (a != -2); // end of file 324 file.close(); 328 file.close(); 325 delete initIds; 329 delete initIds; 326 delete transEnergies; 330 delete transEnergies; 327 delete transProbabilities; 331 delete transProbabilities; 328 } 332 } 329 333 330 //....oooOO0OOooo........oooOO0OOooo........oo 334 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 331 335 332 void G4FluoData::PrintData() 336 void G4FluoData::PrintData() 333 { 337 { 334 for (G4int i = 0; i <numberOfVacancies; ++i) << 338 for (G4int i = 0; i <numberOfVacancies; i++) 335 { 339 { 336 G4cout << "---- TransitionData for the v 340 G4cout << "---- TransitionData for the vacancy nb " 337 << i << 341 <<i 338 << " ----- " << 342 <<" ----- " 339 << G4endl; << 343 <<G4endl; 340 344 341 for (G4int k = 0; k<(G4int)NumberOfTrans << 345 for (size_t k = 0; k<NumberOfTransitions(i); k++) 342 { 346 { 343 G4int id = StartShellId(k,i); 347 G4int id = StartShellId(k,i); 344 // let's start from 1 because the first (ind 348 // let's start from 1 because the first (index = 0) element of the vector 345 // is the id of the initial vacancy 349 // is the id of the initial vacancy 346 G4double e = StartShellEnergy(k,i) /MeV; 350 G4double e = StartShellEnergy(k,i) /MeV; 347 G4double p = StartShellProb(k,i); 351 G4double p = StartShellProb(k,i); 348 G4cout << k <<") Shell id: " << id <<G4end 352 G4cout << k <<") Shell id: " << id <<G4endl; 349 G4cout << " - Transition energy = " << e < 353 G4cout << " - Transition energy = " << e << " MeV "<<G4endl; 350 G4cout << " - Transition probability = " 354 G4cout << " - Transition probability = " << p <<G4endl; 351 355 352 } 356 } 353 G4cout << "----------------------------- 357 G4cout << "-------------------------------------------------" 354 << G4endl; 358 << G4endl; 355 } 359 } 356 } 360 } 357 361