Geant4_10
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53 
54 #ifdef G4ANALYSIS_USE
55 
57  :dataSet(0),dataGammaSet(0),dataAlphaSet(0)
58 {
59  XrayFluoNormalization normalization;
60 
61  energies = new G4DataVector;
62  data = new G4DataVector;
63 
64 
65  ReadData(keV,"spec10");
66  //ReadResponse("SILIresponse");
67 
68  G4double minGamma = 0.*keV;
69  G4double maxGamma = 10. *keV;
70  G4int nBinsGamma = 6;
71 
72 
73  dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma,
74  "M_flare");
75 
76 
77  //G4String fileName = "SILIefficiency";
78  //G4VDataSetAlgorithm* interpolation4 = new G4LogLogInterpolation();
79  //efficiencySet = new XrayFluoDataSet(1,fileName,interpolation4,keV,1);
80  //delete interpolation4;
81  G4cout << "XrayFluoRunAction created" << G4endl;
82 }
83 #else
85 {
86  G4cout << "XrayFluoRunAction created" << G4endl;
87 }
88 #endif
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91 #ifdef G4ANALYSIS_USE
92 
94 {
95 
96  //std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos;
97 
98  // delete energies;
99  // delete data;
100  // G4cout << "energies and data deleted " << G4endl;
101 
102  //for (pos = energyMap.begin(); pos != energyMap.end(); pos++)
103  //{
104  // G4DataVector* dataSet = (*pos).second;
105  // delete dataSet;
106  // dataSet = 0;
107  // }
108  //for (pos = dataMap.begin(); pos != dataMap.end(); pos++)
109  // {
110  // G4DataVector* dataSet = (*pos).second;
111  // delete dataSet;
112  // dataSet = 0;
113  // }
114 
115 
116  G4cout << "XrayFluoRunAction deleted" << G4endl;
117 
118 }
119 
120 #else
122 {
123  G4cout << "XrayFluoRunAction deleted" << G4endl;
124 }
125 #endif
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
128 
130 {
131 
132  G4cout << "### Run " << aRun << " start." << G4endl;
134  {
136  UI->ApplyCommand("/vis/scene/notifyHandlers");
137  }
138 #ifdef G4ANALYSIS_USE
139 
140  // Book histograms and ntuples
141  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
142  analysis->book();
143  analysis->InitializePlotter();
144 #endif
145 }
146 
147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
148 
150 {
151 #ifdef G4ANALYSIS_USE
152  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
153 #endif
154  // Run ended, update the visualization
156  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
157  }
158 #ifdef G4ANALYSIS_USE
159  analysis->finish();
160 #endif
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
164 
165 
167 {
168  return dataSet;
169 }
171 {
172  return dataGammaSet;
173 }
175 {
176  return dataAlphaSet;
177 }
178 //const XrayFluoDataSet* XrayFluoRunAction::GetEfficiencySet()
179 //{
180 // return efficiencySet;
181 //}
183 {
184  return energies;
185 }
187 {
188  return data;
189 }
191 {
192  G4double sum = 0;
193  size_t size = data->size();
194  for (size_t i = 0; i <size; i++)
195  {
196  sum+=(*data)[i];
197  }
198  return sum;
199 }
200 
201 
202 void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName)
203 {
204  std::ostringstream ost;
205 
206  ost << fileName <<".dat";
207 
208  G4String name = ost.str();
209  char* path;
210 
211  if (!(getenv("XRAYDATA"))) {
212 
213  path = getenv("PWD");
214  }
215 
216  else {
217  path = getenv("XRAYDATA");
218  }
219 
220 
221  G4String pathString(path);
222  name = pathString + "/" + name;
223 
224 
225  std::ifstream file(name);
226  std::filebuf* lsdp = file.rdbuf();
227 
228  if (! (lsdp->is_open()) )
229  {
231  execp << "XrayFluoRunAction - data file: " + name + " not found";
232  G4Exception("XrayFluoRunAction::ReadData()","example-xray_fluorescence04",
233  FatalException, execp);
234  }
235  G4double a = 0;
236  G4int k = 1;
237 
238  do
239  {
240  file >> a;
241  G4int nColumns = 2;
242  // The file is organized into two columns:
243  // 1st column is the energy
244  // 2nd column is the corresponding value
245  // The file terminates with the pattern: -1 -1
246  // -2 -2
247  if (a == -1 || a == -2)
248  {
249 
250  }
251  else
252  {
253  if (k%nColumns != 0)
254  {
255  G4double e = a * unitE;
256 
257  energies->push_back(e);
258 
259  k++;
260 
261  }
262  else if (k%nColumns == 0)
263  {
264  G4double value = a;
265  data->push_back(value);
266 
267  k = 1;
268  }
269  }
270 
271  } while (a != -2); // end of file
272 
273  file.close();
274 }
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286 
287 
288 
tuple a
Definition: test.py:11
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static G4VVisManager * GetConcreteInstance()
void EndOfRunAction(const G4Run *)
void BeginOfRunAction(const G4Run *)
const XrayFluoDataSet * GetGammaSet()
const XML_Char * name
Definition: expat.h:151
TFile * file
int G4int
Definition: G4Types.hh:78
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()
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
const XrayFluoDataSet * GetAlphaSet()
G4DataVector * GetEnergies()
const XML_Char const XML_Char * data
Definition: expat.h:268
const XrayFluoDataSet * Normalize(G4double, G4double, G4int, G4String)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
const XrayFluoDataSet * GetSet()