Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4FluoData.cc
Go to the documentation of this file.
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....
45{
46 fluoDirectory = dir;
47}
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
50
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
75{
76 return numberOfVacancies;
77}
78
79//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
80
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
103std::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
124G4int G4FluoData::StartShellId(G4int initIndex, G4int vacancyIndex) const
125{
126 G4int n = -1;
127
128 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
129 {
130 G4Exception("G4FluoData::StartShellId()","de0002",FatalErrorInArgument,
131 "vacancyIndex outside boundaries");
132 }
133 else
134 {
135 auto pos = idMap.find(vacancyIndex);
136
137 G4DataVector dataSet = *((*pos).second);
138
139 G4int nData = (G4int)dataSet.size();
140 // The first Element of idMap's dataSets is the original shell of
141 // the vacancy, so we must start from the first element of dataSet
142 if (initIndex >= 0 && initIndex < nData)
143 {
144 n = dataSet[initIndex+1];
145 }
146 }
147 return n;
148}
149
150//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
151
152G4double G4FluoData::StartShellEnergy(G4int initIndex, G4int vacancyIndex) const
153{
154 G4double n = -1;
155
156 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
157 {
158 G4Exception("G4FluoData::StartShellEnergy()","de0002",FatalErrorInArgument,
159 "vacancyIndex outside boundaries");}
160 else
161 {
162 auto pos = energyMap.find(vacancyIndex);
163
164 G4DataVector dataSet = *((*pos).second);
165
166 G4int nData = (G4int)dataSet.size();
167 if (initIndex >= 0 && initIndex < nData)
168 {
169 n = dataSet[initIndex];
170 }
171 }
172 return n;
173}
174
175//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
176
177G4double G4FluoData::StartShellProb(G4int initIndex, G4int vacancyIndex) const
178{
179 G4double n = -1;
180
181 if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
182 {
183 G4Exception("G4FluoData::StartShellEnergy()","de0002",JustWarning,
184 "vacancyIndex outside boundaries, energy deposited locally");
185 return 0;
186 }
187 else
188 {
189 auto pos = probabilityMap.find(vacancyIndex);
190
191 G4DataVector dataSet = *((*pos).second);
192
193 G4int nData = (G4int)dataSet.size();
194 if (initIndex >= 0 && initIndex < nData)
195 {
196 n = dataSet[initIndex];
197 }
198 }
199 return n;
200}
201
202//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
203
205{
206 // Build the complete string identifying the file with the data set
207 std::ostringstream ost;
208 if(Z != 0){
209 ost << "/fl-tr-pr-"<< Z << ".dat";
210 }
211 else{
212 ost << "/fl-tr-pr-"<<".dat";
213 }
214 G4String name(ost.str());
215
216
217 const char* path = G4FindDataDir("G4LEDATA");
218 if (!path)
219 {
220 G4String excep("G4FluoData::LoadData()");
221 G4Exception(excep,"em0006",FatalException,"Please set G4LEDATA");
222 return;
223 }
224
225 G4String pathString(path);
226
227 G4String dirFile = pathString + fluoDirectory + name;
228
229 //G4cout << "G4FluoData:: LoadData() name: " << dirFile << G4endl;
230
231
232 std::ifstream file(dirFile);
233 std::filebuf* lsdp = file.rdbuf();
234
235 if (! (lsdp->is_open()) )
236 {
237 G4String excep = "G4FluoData::LoadData()";
238 G4String msg = "data file: " + dirFile + " not found";
239 G4Exception(excep, "em0003",FatalException, msg );
240 return;
241 }
242
243 G4double a = 0;
244 G4int k = 1;
245 G4int sLocal = 0;
246
247 G4int vacIndex = 0;
248 G4DataVector* initIds = new G4DataVector;
249 G4DataVector* transEnergies = new G4DataVector;
250 G4DataVector* transProbabilities = new G4DataVector;
251
252 do {
253 file >> a;
254 G4int nColumns = 3;
255 if (a == -1)
256 {
257 if (sLocal == 0)
258 {
259 // End of a shell data set
260 idMap[vacIndex] = initIds;
261 energyMap[vacIndex] = transEnergies;
262 probabilityMap[vacIndex] = transProbabilities;
263 G4int n = (G4int)initIds->size();
264
265 nInitShells.push_back(n);
266 numberOfVacancies++;
267 // Start of new shell data set
268 initIds = new G4DataVector;
269 transEnergies = new G4DataVector;
270 transProbabilities = new G4DataVector;
271 vacIndex++;
272 }
273 sLocal++;
274 if (sLocal == nColumns)
275 {
276 sLocal = 0;
277 }
278 }
279 // moved to the end in order to avoid possible leak
280 /* else if (a == -2)
281 {
282 // End of file; delete the empty vectors created
283 //when encountering the last -1 -1 row
284 delete initIds;
285 delete transEnergies;
286 delete transProbabilities;
287 }*/
288 else
289 {
290 if(k%nColumns == 2)
291 {
292 // 2nd column is transition probabilities
293
294 if (a != -1) transProbabilities->push_back(a);
295
296 k++;
297 }
298 else if (k%nColumns == 1)
299 {
300 // 1st column is shell id
301 // if this is the first data of the shell, all the colums are equal
302 // to the shell Id; so we skip the next colums ang go to the next row
303 if(initIds->size() == 0) {
304 if (a != -1) initIds->push_back((G4int)a);
305 file >> a;
306 file >> a;
307 k=k+2;
308 }
309 else{
310 if (a != -1) initIds->push_back(a);
311 }
312 k++;
313 }
314 else if (k%nColumns == 0)
315
316 {//third column is transition energies
317
318 if (a != -1)
319 {G4double e = a * MeV;
320 transEnergies->push_back(e);}
321
322 k=1;
323 }
324 }
325 }
326 while (a != -2); // end of file
327 file.close();
328 delete initIds;
329 delete transEnergies;
330 delete transProbabilities;
331}
332
333//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
334
336{
337 for (G4int i = 0; i <numberOfVacancies; ++i)
338 {
339 G4cout << "---- TransitionData for the vacancy nb "
340 << i
341 << " ----- "
342 << G4endl;
343
344 for (G4int k = 0; k<(G4int)NumberOfTransitions(i); ++k)
345 {
346 G4int id = StartShellId(k,i);
347 // let's start from 1 because the first (index = 0) element of the vector
348 // is the id of the initial vacancy
349 G4double e = StartShellEnergy(k,i) /MeV;
350 G4double p = StartShellProb(k,i);
351 G4cout << k <<") Shell id: " << id <<G4endl;
352 G4cout << " - Transition energy = " << e << " MeV "<<G4endl;
353 G4cout << " - Transition probability = " << p <<G4endl;
354
355 }
356 G4cout << "-------------------------------------------------"
357 << G4endl;
358 }
359}
const char * G4FindDataDir(const char *)
@ JustWarning
@ FatalException
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
std::size_t NumberOfTransitions(G4int vacancyIndex) const
Definition: G4FluoData.cc:103
G4double StartShellEnergy(G4int initIndex, G4int vacancyIndex) const
Definition: G4FluoData.cc:152
G4int VacancyId(G4int vacancyIndex) const
Given the index of the vacancy returns its identity.
Definition: G4FluoData.cc:81
std::size_t NumberOfVacancies() const
Definition: G4FluoData.cc:74
void PrintData()
Definition: G4FluoData.cc:335
void LoadData(G4int Z)
Definition: G4FluoData.cc:204
G4FluoData(const G4String &dir)
Definition: G4FluoData.cc:44
G4int StartShellId(G4int initIndex, G4int vacancyIndex) const
Definition: G4FluoData.cc:124
G4double StartShellProb(G4int initIndex, G4int vacancyIndex) const
Definition: G4FluoData.cc:177