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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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"
 47 #include "XrayFluoAnalysisManager.hh"
 48 #include "G4SystemOfUnits.hh"
 49 
 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 51 
 52 XrayFluoRunAction::XrayFluoRunAction()
 53   : isInitialized(false), dataSet(0), dataGammaSet(0), 
 54     dataAlphaSet(0)
 55 {;}
 56 
 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 58 
 59 XrayFluoRunAction::~XrayFluoRunAction()
 60 {;}
 61 
 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 63 
 64 void XrayFluoRunAction::Initialise()
 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 
 93 void XrayFluoRunAction::BeginOfRunAction(const G4Run* aRun)
 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 
106   if (G4VVisManager::GetConcreteInstance())
107     {
108       G4UImanager* UI = G4UImanager::GetUIpointer(); 
109       UI->ApplyCommand("/vis/scene/notifyHandlers");
110     } 
111 
112   // Book histograms and ntuples
113   XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
114   analysis->book();
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
118 
119 void XrayFluoRunAction::EndOfRunAction(const G4Run*)
120 {
121   XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
122   analysis->finish();
123   // Run ended, update the visualization
124   if (G4VVisManager::GetConcreteInstance()) {
125     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
126   }
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130 
131 
132 const XrayFluoDataSet* XrayFluoRunAction::GetSet() const
133 {
134   return  dataSet;
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
138 
139 const XrayFluoDataSet* XrayFluoRunAction::GetGammaSet() const
140 {
141   return  dataGammaSet;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
145 
146 const XrayFluoDataSet* XrayFluoRunAction::GetAlphaSet() const
147 {
148   return  dataAlphaSet;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
152 
153 G4DataVector* XrayFluoRunAction::GetEnergies() const
154 {
155   return energies;
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
159 
160 G4DataVector* XrayFluoRunAction::GetData() const
161 {
162   return data;
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
166 
167 G4double XrayFluoRunAction::GetDataSum() const
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 
180 void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName)
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     {
209       G4ExceptionDescription execp;
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 
269