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