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