ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XrayFluoRunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file XrayFluoRunAction.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: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
29 //
30 // History:
31 // -----------
32 // 28 Nov 2001 Elena Guardincerri Created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "XrayFluoRunAction.hh"
37 #include "G4Run.hh"
38 #include "G4UImanager.hh"
39 #include "G4VVisManager.hh"
40 #include "G4ios.hh"
41 #include "XrayFluoDataSet.hh"
42 #include "G4DataVector.hh"
43 #include "G4LogLogInterpolation.hh"
44 #include <fstream>
45 #include <sstream>
46 #include "XrayFluoNormalization.hh"
48 #include "G4SystemOfUnits.hh"
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51 
53  : isInitialized(false), dataSet(0), dataGammaSet(0),
54  dataAlphaSet(0)
55 {;}
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
58 
60 {;}
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
63 
65 {
66  //Only the master is initialized and keeps the data
67  //(or in sequential mode)
68  if (!IsMaster())
69  return;
70 
71  XrayFluoNormalization normalization;
72 
73  energies = new G4DataVector;
74  data = new G4DataVector;
75 
76 
77  ReadData(keV,"M_flare");
78  //ReadResponse("SILIresponse");
79 
80  G4double minGamma = 0.*keV;
81  G4double maxGamma = 10. *keV;
82  G4int nBinsGamma = 6;
83 
84 
85  dataGammaSet = normalization.Normalize(minGamma, maxGamma, nBinsGamma,
86  "M_flare");
87  isInitialized = true;
88  G4cout << "XrayFluoRunAction initialized" << G4endl;
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
92 
94 {
95 
96  //Master mode or sequential
97  if (IsMaster())
98  {
99  G4cout << "### Run " << aRun->GetRunID() << " starts (master)." << G4endl;
100  if (!isInitialized)
101  Initialise();
102  }
103  else
104  G4cout << "### Run " << aRun->GetRunID() << " starts (worker)." << G4endl;
105 
107  {
109  UI->ApplyCommand("/vis/scene/notifyHandlers");
110  }
111 
112  // Book histograms and ntuples
114  analysis->book();
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
118 
120 {
122  analysis->finish();
123  // Run ended, update the visualization
125  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
126  }
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130 
131 
133 {
134  return dataSet;
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
138 
140 {
141  return dataGammaSet;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
145 
147 {
148  return dataAlphaSet;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
152 
154 {
155  return energies;
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
159 
161 {
162  return data;
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
166 
168 {
169 
170  G4double sum = 0;
171  for (size_t i = 0; i < data->size(); i++)
172  {
173  sum+=(*data)[i];
174  }
175  return sum;
176 }
177 
178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
179 
181 {
182  G4cout << "Reading data...";
183  std::ostringstream ost;
184 
185  ost << fileName <<".dat";
186 
187  G4String name = ost.str();
188  char* path;
189 
190  if (!(std::getenv("XRAYDATA"))) {
191 
192  path = std::getenv("PWD");
193  }
194 
195  else {
196  path = std::getenv("XRAYDATA");
197  }
198 
199 
200  G4String pathString(path);
201  name = pathString + "/" + name;
202 
203 
204  std::ifstream file(name);
205  std::filebuf* lsdp = file.rdbuf();
206 
207  if (! (lsdp->is_open()) )
208  {
210  execp << "XrayFluoRunAction - data file: " + name + " not found";
211  G4Exception("XrayFluoRunAction::ReadData()","example-xray_fluorescence04",
212  FatalException, execp);
213  }
214  G4double a = 0;
215  G4int k = 1;
216 
217  do
218  {
219  file >> a;
220  G4int nColumns = 2;
221  // The file is organized into two columns:
222  // 1st column is the energy
223  // 2nd column is the corresponding value
224  // The file terminates with the pattern: -1 -1
225  // -2 -2
226  if (a == -1 || a == -2)
227  {
228 
229  }
230  else
231  {
232  if (k%nColumns != 0)
233  {
234  G4double e = a * unitE;
235 
236  energies->push_back(e);
237 
238  k++;
239 
240  }
241  else if (k%nColumns == 0)
242  {
243  G4double value = a;
244  data->push_back(value);
245 
246  k = 1;
247  }
248  }
249 
250  } while (a != -2); // end of file
251 
252  file.close();
253  G4cout << " done" << G4endl;
254 }
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268