Geant4  10.00.p01
XrayFluoRunAction.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 // $Id: XrayFluoRunAction.cc
28 // GEANT4 tag $Name: xray_fluo-V03-02-00
29 //
30 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
31 //
32 // History:
33 // -----------
34 // 28 Nov 2001 Elena Guardincerri Created
35 //
36 // -------------------------------------------------------------------
37 
38 #include "XrayFluoRunAction.hh"
39 #include "G4Run.hh"
40 #include "G4UImanager.hh"
41 #include "G4VVisManager.hh"
42 #include "G4ios.hh"
43 #include "XrayFluoDataSet.hh"
44 #include "G4DataVector.hh"
45 #include "G4LogLogInterpolation.hh"
46 #include <fstream>
47 #include <sstream>
48 #include "XrayFluoNormalization.hh"
49 #ifdef G4ANALYSIS_USE
51 #endif
52 #include "G4SystemOfUnits.hh"
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55 
56 #ifdef G4ANALYSIS_USE
57 
59  :dataSet(0),dataGammaSet(0),dataAlphaSet(0)
60 {
61  XrayFluoNormalization normalization;
62 
63  energies = new G4DataVector;
64  data = new G4DataVector;
65 
66 
67  ReadData(keV,"spec10");
68  //ReadResponse("SILIresponse");
69 
70  G4double minGamma = 0.*keV;
71  G4double maxGamma = 10. *keV;
72  G4int nBinsGamma = 6;
73 
74 
75  dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma,
76  "M_flare");
77 
78 
79  //G4String fileName = "SILIefficiency";
80  //G4VDataSetAlgorithm* interpolation4 = new G4LogLogInterpolation();
81  //efficiencySet = new XrayFluoDataSet(1,fileName,interpolation4,keV,1);
82  //delete interpolation4;
83  G4cout << "XrayFluoRunAction created" << G4endl;
84 }
85 #else
87 {
88  G4cout << "XrayFluoRunAction created" << G4endl;
89 }
90 #endif
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93 #ifdef G4ANALYSIS_USE
94 
96 {
97 
98  G4cout << "XrayFluoRunAction deleted" << G4endl;
99 
100 }
101 
102 #else
104 {
105  G4cout << "XrayFluoRunAction deleted" << G4endl;
106 }
107 #endif
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
110 
112 {
113 
114  G4cout << "### Run " << aRun << " start." << G4endl;
116  {
118  UI->ApplyCommand("/vis/scene/notifyHandlers");
119  }
120 #ifdef G4ANALYSIS_USE
121 
122  // Book histograms and ntuples
123  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
124  analysis->book();
125  analysis->InitializePlotter();
126 #endif
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130 
132 {
133 #ifdef G4ANALYSIS_USE
134  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
135 #endif
136  // Run ended, update the visualization
138  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
139  }
140 #ifdef G4ANALYSIS_USE
141  analysis->finish();
142 #endif
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
146 
147 
149 {
150  return dataSet;
151 }
153 {
154  return dataGammaSet;
155 }
157 {
158  return dataAlphaSet;
159 }
160 //const XrayFluoDataSet* XrayFluoRunAction::GetEfficiencySet()
161 //{
162 // return efficiencySet;
163 //}
165 {
166  return energies;
167 }
169 {
170  return data;
171 }
173 {
174  G4double sum = 0;
175  size_t size = data->size();
176  for (size_t i = 0; i <size; i++)
177  {
178  sum+=(*data)[i];
179  }
180  return sum;
181 }
182 
183 
185 {
186  std::ostringstream ost;
187 
188  ost << fileName <<".dat";
189 
190  G4String name = ost.str();
191  char* path;
192 
193  if (!(getenv("XRAYDATA"))) {
194 
195  path = getenv("PWD");
196  }
197 
198  else {
199  path = getenv("XRAYDATA");
200  }
201 
202 
203  G4String pathString(path);
204  name = pathString + "/" + name;
205 
206 
207  std::ifstream file(name);
208  std::filebuf* lsdp = file.rdbuf();
209 
210  if (! (lsdp->is_open()) )
211  {
213  execp << "XrayFluoRunAction - data file: " + name + " not found";
214  G4Exception("XrayFluoRunAction::ReadData()","example-xray_fluorescence04",
215  FatalException, execp);
216  }
217  G4double a = 0;
218  G4int k = 1;
219 
220  do
221  {
222  file >> a;
223  G4int nColumns = 2;
224  // The file is organized into two columns:
225  // 1st column is the energy
226  // 2nd column is the corresponding value
227  // The file terminates with the pattern: -1 -1
228  // -2 -2
229  if (a == -1 || a == -2)
230  {
231 
232  }
233  else
234  {
235  if (k%nColumns != 0)
236  {
237  G4double e = a * unitE;
238 
239  energies->push_back(e);
240 
241  k++;
242 
243  }
244  else if (k%nColumns == 0)
245  {
246  G4double value = a;
247  data->push_back(value);
248 
249  k = 1;
250  }
251  }
252 
253  } while (a != -2); // end of file
254 
255  file.close();
256 }
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const XrayFluoDataSet * dataAlphaSet
static G4VVisManager * GetConcreteInstance()
void EndOfRunAction(const G4Run *)
G4String name
Definition: TRTMaterials.hh:40
void BeginOfRunAction(const G4Run *)
const XrayFluoDataSet * GetGammaSet()
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
G4DataVector * energies
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
Definition: G4Run.hh:46
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4DataVector * GetData()
void ReadData(G4double, G4String)
#define G4endl
Definition: G4ios.hh:61
static const double keV
Definition: G4SIunits.hh:195
const XrayFluoDataSet * dataSet
double G4double
Definition: G4Types.hh:76
const XrayFluoDataSet * GetAlphaSet()
G4DataVector * GetEnergies()
const XrayFluoDataSet * dataGammaSet
const XrayFluoDataSet * Normalize(G4double, G4double, G4int, G4String)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
const XrayFluoDataSet * GetSet()