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