Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 // 28 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) 29 // 30 // History: 31 // ----------- 32 // 16 Sept 2001 First committed to cvs 33 // 34 // ------------------------------------------------------------------- 35 36 #include <fstream> 37 #include <sstream> 38 39 #include "G4FluoData.hh" 40 #include "G4SystemOfUnits.hh" 41 #include "G4DataVector.hh" 42 #include "G4FluoTransition.hh" 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 44 G4FluoData::G4FluoData(const G4String& dir) 45 { 46 fluoDirectory = dir; 47 } 48 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 51 G4FluoData::~G4FluoData() 52 { 53 for (auto& pos : idMap) 54 { 55 G4DataVector* dataSet = pos.second; 56 delete dataSet; 57 } 58 59 for (auto& pos : energyMap) 60 { 61 G4DataVector* dataSet = pos.second; 62 delete dataSet; 63 } 64 65 for (auto& pos: probabilityMap) 66 { 67 G4DataVector* dataSet = pos.second; 68 delete dataSet; 69 } 70 } 71 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 73 74 std::size_t G4FluoData::NumberOfVacancies() const 75 { 76 return numberOfVacancies; 77 } 78 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 80 81 G4int G4FluoData::VacancyId(G4int vacancyIndex) const 82 { 83 G4int n = -1; 84 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 85 { 86 G4Exception("G4FluoData::vacancyId()","de0002",FatalErrorInArgument, 87 "vacancyIndex outside boundaries"); 88 } 89 else 90 { 91 auto pos = idMap.find(vacancyIndex); 92 if (pos!= idMap.end()) 93 { G4DataVector dataSet = (*(*pos).second); 94 n = (G4int) dataSet[0]; 95 96 } 97 } 98 return n; 99 } 100 101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 102 103 std::size_t G4FluoData::NumberOfTransitions(G4int vacancyIndex) const 104 { 105 G4int n = 0; 106 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 107 { 108 G4Exception("G4FluoData::NumberOfTransitions()","de0002",JustWarning, 109 "vacancyIndex outside boundaries, energy deposited locally"); 110 return 0; 111 } 112 else 113 { 114 n = nInitShells[vacancyIndex]-1; 115 //-1 is necessary because the elements of the vector nInitShells 116 //include also the vacancy shell: 117 // -1 subtracts this last one 118 } 119 return n; 120 } 121 122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 123 124 G4int G4FluoData::StartShellId(G4int initIndex, G4int vacancyIndex) const 125 { 126 G4int n = -1; 127 128 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) { 129 G4Exception("G4FluoData::StartShellId()","de0002",FatalErrorInArgument, 130 "vacancyIndex outside boundaries"); 131 } else { 132 auto pos = idMap.find(vacancyIndex); 133 if (pos != idMap.end()) { 134 G4DataVector* dataSet = (*pos).second; 135 136 G4int nData = (G4int)dataSet->size(); 137 // The first Element of idMap's dataSets is the original shell of 138 // the vacancy, so we must start from the first element of dataSet 139 if (initIndex >= 0 && initIndex < nData) { 140 n = (*dataSet)[initIndex+1]; 141 } 142 } 143 } 144 return n; 145 } 146 147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 148 149 G4double G4FluoData::StartShellEnergy(G4int initIndex, G4int vacancyIndex) const 150 { 151 G4double n = -1; 152 153 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 154 { 155 G4Exception("G4FluoData::StartShellEnergy()","de0002",FatalErrorInArgument, 156 "vacancyIndex outside boundaries");} 157 else 158 { 159 auto pos = energyMap.find(vacancyIndex); 160 161 G4DataVector dataSet = *((*pos).second); 162 163 G4int nData = (G4int)dataSet.size(); 164 if (initIndex >= 0 && initIndex < nData) 165 { 166 n = dataSet[initIndex]; 167 } 168 } 169 return n; 170 } 171 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 173 174 G4double G4FluoData::StartShellProb(G4int initIndex, G4int vacancyIndex) const 175 { 176 G4double n = -1; 177 178 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies) 179 { 180 G4Exception("G4FluoData::StartShellEnergy()","de0002",JustWarning, 181 "vacancyIndex outside boundaries, energy deposited locally"); 182 return 0; 183 } 184 else 185 { 186 auto pos = probabilityMap.find(vacancyIndex); 187 188 G4DataVector dataSet = *((*pos).second); 189 190 G4int nData = (G4int)dataSet.size(); 191 if (initIndex >= 0 && initIndex < nData) 192 { 193 n = dataSet[initIndex]; 194 } 195 } 196 return n; 197 } 198 199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 200 201 void G4FluoData::LoadData(G4int Z) 202 { 203 // Build the complete string identifying the file with the data set 204 std::ostringstream ost; 205 if(Z != 0){ 206 ost << "/fl-tr-pr-"<< Z << ".dat"; 207 } 208 else{ 209 ost << "/fl-tr-pr-"<<".dat"; 210 } 211 G4String name(ost.str()); 212 213 214 const char* path = G4FindDataDir("G4LEDATA"); 215 if (!path) 216 { 217 G4String excep("G4FluoData::LoadData()"); 218 G4Exception(excep,"em0006",FatalException,"Please set G4LEDATA"); 219 return; 220 } 221 222 G4String pathString(path); 223 224 G4String dirFile = pathString + fluoDirectory + name; 225 226 //G4cout << "G4FluoData:: LoadData() name: " << dirFile << G4endl; 227 228 229 std::ifstream file(dirFile); 230 std::filebuf* lsdp = file.rdbuf(); 231 232 if (! (lsdp->is_open()) ) 233 { 234 G4String excep = "G4FluoData::LoadData()"; 235 G4String msg = "data file: " + dirFile + " not found"; 236 G4Exception(excep, "em0003",FatalException, msg ); 237 return; 238 } 239 240 G4double a = 0; 241 G4int k = 1; 242 G4int sLocal = 0; 243 244 G4int vacIndex = 0; 245 G4DataVector* initIds = new G4DataVector; 246 G4DataVector* transEnergies = new G4DataVector; 247 G4DataVector* transProbabilities = new G4DataVector; 248 249 do { 250 file >> a; 251 G4int nColumns = 3; 252 if (a == -1) 253 { 254 if (sLocal == 0) 255 { 256 // End of a shell data set 257 idMap[vacIndex] = initIds; 258 energyMap[vacIndex] = transEnergies; 259 probabilityMap[vacIndex] = transProbabilities; 260 G4int n = (G4int)initIds->size(); 261 262 nInitShells.push_back(n); 263 numberOfVacancies++; 264 // Start of new shell data set 265 initIds = new G4DataVector; 266 transEnergies = new G4DataVector; 267 transProbabilities = new G4DataVector; 268 vacIndex++; 269 } 270 sLocal++; 271 if (sLocal == nColumns) 272 { 273 sLocal = 0; 274 } 275 } 276 // moved to the end in order to avoid possible leak 277 /* else if (a == -2) 278 { 279 // End of file; delete the empty vectors created 280 //when encountering the last -1 -1 row 281 delete initIds; 282 delete transEnergies; 283 delete transProbabilities; 284 }*/ 285 else 286 { 287 if(k%nColumns == 2) 288 { 289 // 2nd column is transition probabilities 290 291 if (a != -1) transProbabilities->push_back(a); 292 293 k++; 294 } 295 else if (k%nColumns == 1) 296 { 297 // 1st column is shell id 298 // if this is the first data of the shell, all the colums are equal 299 // to the shell Id; so we skip the next colums ang go to the next row 300 if(initIds->size() == 0) { 301 if (a != -1) initIds->push_back((G4int)a); 302 file >> a; 303 file >> a; 304 k=k+2; 305 } 306 else{ 307 if (a != -1) initIds->push_back(a); 308 } 309 k++; 310 } 311 else if (k%nColumns == 0) 312 313 {//third column is transition energies 314 315 if (a != -1) 316 {G4double e = a * MeV; 317 transEnergies->push_back(e);} 318 319 k=1; 320 } 321 } 322 } 323 while (a != -2); // end of file 324 file.close(); 325 delete initIds; 326 delete transEnergies; 327 delete transProbabilities; 328 } 329 330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 331 332 void G4FluoData::PrintData() 333 { 334 for (G4int i = 0; i <numberOfVacancies; ++i) 335 { 336 G4cout << "---- TransitionData for the vacancy nb " 337 << i 338 << " ----- " 339 << G4endl; 340 341 for (G4int k = 0; k<(G4int)NumberOfTransitions(i); ++k) 342 { 343 G4int id = StartShellId(k,i); 344 // let's start from 1 because the first (index = 0) element of the vector 345 // is the id of the initial vacancy 346 G4double e = StartShellEnergy(k,i) /MeV; 347 G4double p = StartShellProb(k,i); 348 G4cout << k <<") Shell id: " << id <<G4endl; 349 G4cout << " - Transition energy = " << e << " MeV "<<G4endl; 350 G4cout << " - Transition probability = " << p <<G4endl; 351 352 } 353 G4cout << "-------------------------------------------------" 354 << G4endl; 355 } 356 } 357