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