source: trunk/source/processes/electromagnetic/lowenergy/test/fluoTest/src/XrayFluoRunAction.cc@ 1201

Last change on this file since 1201 was 1199, checked in by garnier, 16 years ago

nvx fichiers dans CVS

File size: 10.0 KB
Line 
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 <strstream>
48#include "XrayFluoNormalization.hh"
49#include "XrayFluoAnalysisManager.hh"
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52
53#ifdef G4ANALYSIS_USE
54
55XrayFluoRunAction::XrayFluoRunAction()
56 :dataSet(0),dataGammaSet(0),dataAlphaSet(0),efficiencySet(0)
57{
58 XrayFluoNormalization* normalization = new XrayFluoNormalization();
59
60 energies = new G4DataVector;
61 data = new G4DataVector;
62
63
64 ReadData(MeV, "/examples/advanced/xray_fluorescence/mercury_flx_solmin");
65 ReadResponse("/examples/advanced/xray_fluorescence/response");
66
67 G4double minGamma = 0.*keV;
68 G4double maxGamma = 10. *keV;
69 G4int nBinsGamma = 100;
70
71 dataGammaSet = normalization->Normalize(minGamma, maxGamma, nBinsGamma,
72 "/examples/advanced/xray_fluorescence/B_flare");
73
74 G4String fileName = "/examples/advanced/xray_fluorescence/efficienza";
75 G4VDataSetAlgorithm* interpolation4 = new G4LogLogInterpolation();
76 efficiencySet = new XrayFluoDataSet(1,fileName,interpolation4,keV,1);
77
78
79}
80#else
81XrayFluoRunAction::XrayFluoRunAction()
82{
83}
84#endif
85
86//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
87#ifdef G4ANALYSIS_USE
88
89XrayFluoRunAction::~XrayFluoRunAction()
90{
91 std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos;
92
93 for (pos = energyMap.begin(); pos != energyMap.end(); pos++)
94 {
95 G4DataVector* dataSet = (*pos).second;
96 delete dataSet;
97 dataSet = 0;
98 }
99 for (pos = dataMap.begin(); pos != dataMap.end(); pos++)
100 {
101 G4DataVector* dataSet = (*pos).second;
102 delete dataSet;
103 dataSet = 0;
104 }
105
106}
107#else
108XrayFluoRunAction::~XrayFluoRunAction()
109{
110
111}
112#endif
113
114//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
115
116void XrayFluoRunAction::BeginOfRunAction(const G4Run* aRun)
117{
118
119 G4cout << "### Run " << aRun << " start." << G4endl;
120
121 if (G4VVisManager::GetConcreteInstance())
122 {
123 G4UImanager* UI = G4UImanager::GetUIpointer();
124 UI->ApplyCommand("/vis/scene/notifyHandlers");
125 }
126#ifdef G4ANALYSIS_USE
127
128 // Book histograms and ntuples
129 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
130 analysis->book();
131#endif
132}
133
134//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
135
136void XrayFluoRunAction::EndOfRunAction(const G4Run* aRun )
137{
138#ifdef G4ANALYSIS_USE
139 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
140 analysis->finish();
141#endif
142 // Run ended, update the visualization
143 if (G4VVisManager::GetConcreteInstance()) {
144 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
145 }
146
147}
148
149//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
150
151
152const XrayFluoDataSet* XrayFluoRunAction::GetSet()
153{
154 return dataSet;
155}
156const XrayFluoDataSet* XrayFluoRunAction::GetGammaSet()
157{
158 return dataGammaSet;
159}
160const XrayFluoDataSet* XrayFluoRunAction::GetAlphaSet()
161{
162 return dataAlphaSet;
163}
164const XrayFluoDataSet* XrayFluoRunAction::GetEfficiencySet()
165{
166 return efficiencySet;
167}
168G4DataVector* XrayFluoRunAction::GetEnergies()
169{
170 return energies;
171}
172G4DataVector* XrayFluoRunAction::GetData()
173{
174 return data;
175}
176G4double XrayFluoRunAction::GetDataSum()
177{
178 G4double sum = 0;
179 size_t size = data->size();
180 for (size_t i = 0; i <size; i++)
181 {
182 sum+=(*data)[i];
183 }
184 return sum;
185}
186G4double XrayFluoRunAction::GetInfData(G4double energy, G4double random)
187{
188 G4double value = 0.;
189 G4int zMin = 1;
190 G4int zMax = 10;
191
192 G4int Z = ((G4int)(energy/keV));
193
194 if (Z<zMin) {Z=zMin;}
195 if (Z>zMax) {Z=zMax;}
196
197 if (Z >= zMin && Z <= zMax)
198 {
199 std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
200 pos = energyMap.find(Z);
201 std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posData;
202 posData = dataMap.find(Z);
203 if (pos!= energyMap.end())
204 {
205 G4DataVector energySet = *((*pos).second);
206 G4DataVector dataSet = *((*posData).second);
207 G4int nData = energySet.size();
208
209 G4double partSum = 0;
210 G4int index = 0;
211
212 while (random> partSum)
213 {
214 partSum += dataSet[index];
215 index++;
216 }
217
218
219 if (index >= 0 && index < nData)
220 {
221 value = energySet[index];
222
223 }
224
225 }
226 }
227 return value;
228}
229
230G4double XrayFluoRunAction::GetSupData(G4double energy, G4double random)
231{
232 G4double value = 0.;
233 G4int zMin = 1;
234 G4int zMax = 10;
235 G4int Z = ((G4int)(energy/keV)+1);
236
237 if (Z<zMin) {Z=zMin;}
238 if (Z>zMax) {Z=zMax;}
239 if (Z >= zMin && Z <= zMax)
240 {
241 std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
242 pos = energyMap.find(Z);
243 std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posData;
244 posData = dataMap.find(Z);
245 if (pos!= energyMap.end())
246 {
247 G4DataVector energySet = *((*pos).second);
248 G4DataVector dataSet = *((*posData).second);
249 G4int nData = energySet.size();
250 G4double partSum = 0;
251 G4int index = 0;
252
253 while (random> partSum)
254 {
255 partSum += dataSet[index];
256 index++;
257 }
258
259
260 if (index >= 0 && index < nData)
261 {
262 value = energySet[index];
263 }
264 }
265 }
266 return value;
267}
268
269
270
271void XrayFluoRunAction::ReadData(G4double unitE, G4String fileName)
272{
273 char nameChar[100] = {""};
274 std::ostrstream ost(nameChar, 100, std::ios::out);
275
276 ost << fileName <<".dat";
277
278 G4String name(nameChar);
279
280 char* path = getenv("G4INSTALL");
281
282 G4String pathString(path);
283 G4String dirFile = pathString + "/" + name;
284 std::ifstream file(dirFile);
285 std::filebuf* lsdp = file.rdbuf();
286
287 if (! (lsdp->is_open()) )
288 {
289 G4String excep = "XrayFluoRunAction - data file: " + dirFile + " not found";
290 G4Exception(excep);
291 }
292 G4double a = 0;
293 G4int k = 1;
294
295 do
296 {
297 file >> a;
298 G4int nColumns = 2;
299 // The file is organized into two columns:
300 // 1st column is the energy
301 // 2nd column is the corresponding value
302 // The file terminates with the pattern: -1 -1
303 // -2 -2
304 if (a == -1 || a == -2)
305 {
306
307 }
308 else
309 {
310 if (k%nColumns != 0)
311 {
312 G4double e = a * unitE;
313
314 energies->push_back(e);
315
316 k++;
317
318 }
319 else if (k%nColumns == 0)
320 {
321 G4double value = a;
322 data->push_back(value);
323
324 k = 1;
325 }
326 }
327
328 } while (a != -2); // end of file
329
330 file.close();
331}
332
333void XrayFluoRunAction::ReadResponse(const G4String& fileName)
334{
335 char nameChar[100] = {""};
336 std::ostrstream ost(nameChar, 100, std::ios::out);
337
338
339 ost << fileName<<".dat";
340
341 G4String name(nameChar);
342
343 char* path = getenv("G4INSTALL");
344
345 G4String pathString(path);
346 G4String dirFile = pathString + "/" + name;
347 std::ifstream file(dirFile);
348 std::filebuf* lsdp = file.rdbuf();
349
350 if (! (lsdp->is_open()) )
351 {
352 G4String excep = "XrayFluoRunAction - data file: " + dirFile + " not found";
353 G4Exception(excep);
354 }
355 G4double a = 0;
356 G4int k = 1;
357 G4int s = 0;
358
359 G4int Z = 1;
360 G4DataVector* energies = new G4DataVector;
361 G4DataVector* data = new G4DataVector;
362
363 do
364 {
365 file >> a;
366 G4int nColumns = 2;
367 if (a == -1)
368 {
369 if (s == 0)
370 {
371 // End of a data set
372 energyMap[Z] = energies;
373 dataMap[Z] = data;
374 // Start of new shell data set
375 energies = new G4DataVector;
376 data = new G4DataVector;
377 Z++;
378 }
379 s++;
380 if (s == nColumns)
381 {
382 s = 0;
383 }
384 }
385 else if (a == -2)
386 {
387 // End of file; delete the empty vectors
388 //created when encountering the last -1 -1 row
389 delete energies;
390 delete data;
391
392 }
393 else
394 {
395 // 1st column is energy
396 if(k%nColumns != 0)
397 {
398 G4double e = a * keV;
399 energies->push_back(e);
400 k++;
401 }
402 else if (k%nColumns == 0)
403 {
404 // 2nd column is data
405
406 data->push_back(a);
407 k = 1;
408 }
409 }
410 } while (a != -2); // end of file
411 file.close();
412}
413
414
415
416
Note: See TracBrowser for help on using the repository browser.