Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
50 #include "G4SystemOfUnits.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53 
55  : isInitialized(false), dataSet(0), dataGammaSet(0),
56  dataAlphaSet(0)
57 {;}
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
60 
62 {;}
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
65 
66 void XrayFluoRunAction::Initialise()
67 {
68  //Only the master is initialized and keeps the data
69  //(or in sequential mode)
70  if (!IsMaster())
71  return;
72 
73  XrayFluoNormalization normalization;
74 
75  energies = new G4DataVector;
76  data = new G4DataVector;
77 
78 
79  ReadData(keV,"M_flare");
80  //ReadResponse("SILIresponse");
81 
82  G4double minGamma = 0.*keV;
83  G4double maxGamma = 10. *keV;
84  G4int nBinsGamma = 6;
85 
86 
87  dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma,
88  "M_flare");
89  isInitialized = true;
90  G4cout << "XrayFluoRunAction initialized" << G4endl;
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94 
96 {
97 
98  //Master mode or sequential
99  if (IsMaster())
100  {
101  G4cout << "### Run " << aRun->GetRunID() << " starts (master)." << G4endl;
102  if (!isInitialized)
103  Initialise();
104  }
105  else
106  G4cout << "### Run " << aRun->GetRunID() << " starts (worker)." << G4endl;
107 
109  {
111  UI->ApplyCommand("/vis/scene/notifyHandlers");
112  }
113 
114  // Book histograms and ntuples
116  analysis->book();
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
120 
122 {
124  analysis->finish();
125  // Run ended, update the visualization
127  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
128  }
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
132 
133 
135 {
136  return dataSet;
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
140 
142 {
143  return dataGammaSet;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
147 
149 {
150  return dataAlphaSet;
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
154 
156 {
157  return energies;
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
161 
163 {
164  return data;
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
168 
170 {
171 
172  G4double sum = 0;
173  for (size_t i = 0; i < data->size(); i++)
174  {
175  sum+=(*data)[i];
176  }
177  return sum;
178 }
179 
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
181 
182 void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName)
183 {
184  G4cout << "Reading data...";
185  std::ostringstream ost;
186 
187  ost << fileName <<".dat";
188 
189  G4String name = ost.str();
190  char* path;
191 
192  if (!(getenv("XRAYDATA"))) {
193 
194  path = getenv("PWD");
195  }
196 
197  else {
198  path = getenv("XRAYDATA");
199  }
200 
201 
202  G4String pathString(path);
203  name = pathString + "/" + name;
204 
205 
206  std::ifstream file(name);
207  std::filebuf* lsdp = file.rdbuf();
208 
209  if (! (lsdp->is_open()) )
210  {
212  execp << "XrayFluoRunAction - data file: " + name + " not found";
213  G4Exception("XrayFluoRunAction::ReadData()","example-xray_fluorescence04",
214  FatalException, execp);
215  }
216  G4double a = 0;
217  G4int k = 1;
218 
219  do
220  {
221  file >> a;
222  G4int nColumns = 2;
223  // The file is organized into two columns:
224  // 1st column is the energy
225  // 2nd column is the corresponding value
226  // The file terminates with the pattern: -1 -1
227  // -2 -2
228  if (a == -1 || a == -2)
229  {
230 
231  }
232  else
233  {
234  if (k%nColumns != 0)
235  {
236  G4double e = a * unitE;
237 
238  energies->push_back(e);
239 
240  k++;
241 
242  }
243  else if (k%nColumns == 0)
244  {
245  G4double value = a;
246  data->push_back(value);
247 
248  k = 1;
249  }
250  }
251 
252  } while (a != -2); // end of file
253 
254  file.close();
255  G4cout << " done" << G4endl;
256 }
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
const XML_Char * name
Definition: expat.h:151
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const XrayFluoDataSet * GetSet() const
static G4VVisManager * GetConcreteInstance()
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
void EndOfRunAction(const G4Run *)
void BeginOfRunAction(const G4Run *)
const XrayFluoDataSet * GetAlphaSet() const
int G4int
Definition: G4Types.hh:78
const XML_Char const XML_Char * data
Definition: expat.h:268
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4DataVector * GetEnergies() const
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
static XrayFluoAnalysisManager * getInstance()
G4bool IsMaster() const
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
const XrayFluoDataSet * GetGammaSet() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4DataVector * GetData() const
G4double GetDataSum() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static constexpr double keV
Definition: G4SIunits.hh:216
G4bool isInitialized()
const XrayFluoDataSet * Normalize(G4double, G4double, G4int, G4String)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447