Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
XrayFluoSiLiDetectorType.cc
이 파일의 문서화 페이지로 가기
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 // $Id: XrayFluoVdetectorType.cc
28 // GEANT4 tag $Name:
29 //
30 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
31 //
32 // History:
33 // -----------
34 // 19 Jun 2003 Alfonso Mantero Created
35 //
36 // -------------------------------------------------------------------
37 
38 #include <fstream>
39 #include <sstream>
40 
42 #include "XrayFluoDataSet.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "G4UnitsTable.hh"
45 #include "G4DataVector.hh"
46 #include "G4LogLogInterpolation.hh"
47 #include "G4ios.hh"
48 #include "Randomize.hh"
49 
51  detectorMaterial("SiLi"),efficiencySet(0)
52 {
53  LoadResponseData("SILIresponse");
54 
55  LoadEfficiencyData("SILIefficiency");
56 
57 
58 }
60 {
61  std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos;
62 
63  for (pos = energyMap.begin(); pos != energyMap.end(); pos++)
64  {
65  G4DataVector* dataSet = (*pos).second;
66  delete dataSet;
67  dataSet = 0;
68  }
69  for (pos = dataMap.begin(); pos != dataMap.end(); pos++)
70  {
71  G4DataVector* dataSet = (*pos).second;
72  delete dataSet;
73  dataSet = 0;
74  }
75 
76  delete interpolation4;
77 
78 }
80 {
81  return detectorMaterial;
82 }
83 
85 
87 
88 {
89  if (instance == 0)
90  {
92 
93  }
94  return instance;
95 }
96 
97 
99 {
100 
101  G4double eMin = 1.500 *keV;
102  G4double eMax = 6.403 *keV;
103  G4double value = 0.;
104  G4double efficiency = 1.;
105 
106  const XrayFluoDataSet* dataSet = efficiencySet;
107  G4int id = 0;
108  G4DataVector energyVector;
109  energyVector.push_back(1.486* keV);
110  energyVector.push_back(1.740* keV);
111  energyVector.push_back(3.688* keV);
112  energyVector.push_back(4.510* keV);
113  energyVector.push_back(5.414* keV);
114  energyVector.push_back(6.404* keV);
115 
116  G4double infEnergy = 0 *keV;
117  G4double supEnergy = 10* keV;
118  G4int energyNumber = 0;
119  G4double random = G4UniformRand();
120 
121  if (energy>=eMin && energy <=eMax)
122  {
123 
124  for (G4int i=0; i<(G4int)energyVector.size(); i++){
125  if (energyVector[i]/keV < energy/keV){
126 
127  infEnergy = energyVector[i];
128  supEnergy = energyVector[i+1];
129 
130  energyNumber = i+1;
131 
132  }
133  }
134 
135 
136  G4double infData = GetInfData(energy, random, energyNumber);
137 
138  G4double supData = GetSupData(energy,random, energyNumber);
139 
140  value = (std::log10(infData)*std::log10(supEnergy/energy) +
141  std::log10(supData)*std::log10(energy/infEnergy)) /
142  std::log10(supEnergy/infEnergy);
143  value = std::pow(10,value);
144 
145 
146  }
147 // else if (energy<eMin || energy>eMax)
148 // {
149 // G4double infEnergy = eMin;
150 // G4double supEnergy = eMin/keV +1*keV;
151 
152 // G4double infData = GetInfData(eMin, random);
153 // G4double supData = GetSupData(eMin,random);
154 // value = (std::log10(infData)*std::log10(supEnergy/eMin) +
155 // std::log10(supData)*std::log10(eMin/infEnergy)) /
156 // std::log10(supEnergy/infEnergy);
157 // value = std::pow(10,value);
158 // value = value-eMin+ energy;
159 
160 
161 // }
162 
163 
164  else if (energy > eMax)
165  {
166 
167  energyNumber = 5;
168 
169  value = (GetSupData(energy, random, energyNumber))+(energy - 6.404* keV);
170 
171  }
172 
173 
174 
175  else
176  {
177 
178  energyNumber = 1;
179 
180  value = (GetInfData(energy, random, energyNumber))+(energy - 1.486* keV);
181 
182 
183  // G4double mean = -14.03 * eV + 1.0047*energy/eV;
184  // G4double stdDev = 35.38 * eV + 0.004385*energy/eV;
185 
186 
187  // value = (G4RandGauss::shoot(mean,stdDev))*eV;
188 
189  }
190  G4double RandomNum = G4UniformRand();
191 
192  efficiency = dataSet->FindValue(value,id);
193  if ( RandomNum>efficiency )
194  {
195  value = 0.;
196  }
197 
198  // G4cout << value << G4endl;
199  return value;
200 
201 }
203 {
204  G4double value = 0.;
205  G4int zMin = 1;
206  G4int zMax = 6;
207 
208  G4int Z = posIndex;
209 
210  if (Z<zMin) {Z=zMin;}
211  if (Z>zMax) {Z=zMax;}
212 
213  if (Z >= zMin && Z <= zMax)
214  {
215  std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
216  pos = energyMap.find(Z);
217  std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posData;
218  posData = dataMap.find(Z);
219 
220 
221  if (pos!= energyMap.end())
222  {
223  G4DataVector energySet = *((*pos).second);
224  G4DataVector dataSet = *((*posData).second);
225  G4int nData = energySet.size();
226 
227 
228  G4double dataSum = 0;
229  G4double partSum = 0;
230  G4int index = 0;
231 
232  // if data is not perfectly normalized (it may happen)
233  // rnadom number is renormalized, in case it is higer
234  //than the sum of all energies => segmentation fault.
235 
236  for (G4int i = 0; i<nData; i++){
237  dataSum += dataSet[i];
238  }
239 
240  G4double normRandom = random*dataSum;
241 
242 
243  while (normRandom> partSum)
244  {
245 
246  partSum += dataSet[index];
247  index++;
248  }
249 
250 
251  if (index >= 0 && index < nData)
252  {
253  value = energySet[index];
254 
255  }
256 
257  }
258  }
259  return value;
260 }
262 {
263  G4double value = 0.;
264  G4int zMin = 1;
265  G4int zMax = 6;
266  G4int Z = (posIndex+1);
267 
268  if (Z<zMin) {Z=zMin;}
269  if (Z>zMax) {Z=zMax;}
270  if (Z >= zMin && Z <= zMax)
271  {
272  std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
273  pos = energyMap.find(Z);
274  std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posData;
275  posData = dataMap.find(Z);
276  if (pos!= energyMap.end())
277  {
278  G4DataVector energySet = *((*pos).second);
279  G4DataVector dataSet = *((*posData).second);
280  G4int nData = energySet.size();
281  G4double dataSum = 0;
282  G4double partSum = 0;
283  G4int index = 0;
284 
285  // if data is not perfectly normalized (it may happen)
286  // rnadom number is renormalized, in case it is higer
287  //than the sum of all energies => segmentation fault.
288 
289  for (G4int i = 0; i<nData; i++){
290  dataSum += dataSet[i];
291  }
292 
293  G4double normRandom = random*dataSum;
294 
295 
296  while (normRandom> partSum)
297  {
298  partSum += dataSet[index];
299  index++;
300  }
301 
302 
303  if (index >= 0 && index < nData)
304  {
305  value = energySet[index];
306  }
307  }
308  }
309  return value;
310 }
312 {
313  std::ostringstream ost;
314  ost << fileName<<".dat";
315  G4String name = ost.str();
316 
317  char* path = getenv("XRAYDATA");
318  G4String dirFile;
319  if (path) {
320  G4String pathString(path);
321  pathString += "\0";
322  dirFile = pathString + "/" + name;
323  }
324  else{
325  path = getenv("PWD");
326  G4String pathString(path);
327  pathString += "\0";
328  dirFile = pathString + "/" + name;
329  }
330 
331  std::ifstream file(dirFile);
332  std::filebuf* lsdp = file.rdbuf();
333 
334  if (! (lsdp->is_open()) )
335  {
337  execp << "XrayFluoSiLiDetectorType - data file: " + dirFile + " not found";
338  G4Exception("XrayFluoSiLiDetectorType::LoadResponseData()","example-xray_fluorescence07",
339  FatalException, execp);
340  }
341  G4double a = 0;
342  G4int k = 1;
343  G4int q = 0;
344 
345  G4int Z = 1;
346  G4DataVector* energies = new G4DataVector;
348 
349  do
350  {
351  file >> a;
352  G4int nColumns = 2;
353  if (a == -1)
354  {
355  if (q == 0)
356  {
357  // End of a data set
358  energyMap[Z] = energies;
359  dataMap[Z] = data;
360  // Start of new shell data set
361  energies = new G4DataVector;
362  data = new G4DataVector;
363  Z++;
364  }
365  q++;
366  if (q == nColumns)
367  {
368  q = 0;
369  }
370  }
371  else if (a == -2)
372  {
373  // End of file; delete the empty vectors
374  //created when encountering the last -1 -1 row
375  delete energies;
376  delete data;
377 
378  }
379  else
380  {
381  // 1st column is energy
382  if(k%nColumns != 0)
383  {
384  G4double e = a * keV;
385  energies->push_back(e);
386  k++;
387  }
388  else if (k%nColumns == 0)
389  {
390  // 2nd column is data
391 
392  data->push_back(a);
393  k = 1;
394  }
395  }
396  } while (a != -2); // end of file
397  file.close();
398 }
399 
401 {
402  char* path = getenv("XRAYDATA");
403  G4String dirFile;
404  if (path) {
405  G4String pathString(path);
406  dirFile = pathString + "/" + fileName;
407  }
408  else{
409  path = getenv("PWD");
410  G4String pathString(path);
411  dirFile = pathString + "/" + fileName;
412  }
413 
415  efficiencySet = new XrayFluoDataSet(1,fileName,interpolation4,keV,1);
416 }
417 
const XML_Char * name
Definition: expat.h:151
G4double GetInfData(G4double, G4double, G4int)
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static const G4double pos
std::map< G4int, G4DataVector *, std::less< G4int > > energyMap
static constexpr double keV
Definition: G4SIunits.hh:216
static XrayFluoSiLiDetectorType * GetInstance()
const XrayFluoDataSet * efficiencySet
const XML_Char const XML_Char * data
Definition: expat.h:268
Float_t Z
static XrayFluoSiLiDetectorType * instance
double G4double
Definition: G4Types.hh:76
G4VDataSetAlgorithm * interpolation4
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4UniformRand()
Definition: Randomize.hh:53
double energy
Definition: plottest35.C:25
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4double FindValue(G4double e, G4int) const
G4double GetSupData(G4double, G4double, G4int)
TFile * file
std::map< G4int, G4DataVector *, std::less< G4int > > dataMap