source: trunk/examples/advanced/xray_fluorescence/src/XrayFluoEventAction.cc@ 1270

Last change on this file since 1270 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

File size: 7.8 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: XrayFluoEventAction.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// 15 Jul 2003 Alfonso Mantero "DetectorType" use integration
36// 23 Sep 2003 Alfonso Mantero differnt geometries integration
37//
38// -------------------------------------------------------------------
39
40#include "XrayFluoEventAction.hh"
41#include "XrayFluoSensorHit.hh"
42#include "XrayFluoEventActionMessenger.hh"
43
44//#include "XrayFluoRunAction.hh"
45#include "XrayFluoDataSet.hh"
46
47#include "XrayFluoAnalysisManager.hh"
48
49#include "G4Event.hh"
50#include "G4EventManager.hh"
51#include "G4HCofThisEvent.hh"
52#include "G4VHitsCollection.hh"
53#include "G4TrajectoryContainer.hh"
54#include "G4Trajectory.hh"
55#include "G4VVisManager.hh"
56#include "G4SDManager.hh"
57#include "G4UImanager.hh"
58#include "G4ios.hh"
59#include "G4UnitsTable.hh"
60#include "Randomize.hh"
61#include <fstream>
62//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
63
64XrayFluoEventAction::XrayFluoEventAction(XrayFluoDetectorConstruction* det)
65 :drawFlag("all"),
66 HPGeCollID(0),
67 eventMessenger(0),
68 printModulo(1),
69 detectorType(0)
70{
71 eventMessenger = new XrayFluoEventActionMessenger(this);
72
73 if (!(det->GetPhaseSpaceFlag()) ){
74 detectorType = det->GetDetectorType();
75 HPGeCollID=-1;
76 }
77
78 //runManager = new XrayFluoRunAction();
79 G4cout << "XrayFluoEventAction created" << G4endl;
80}
81
82//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
83
84XrayFluoEventAction::XrayFluoEventAction(XrayFluoPlaneDetectorConstruction* det)
85 :drawFlag("all"),
86 HPGeCollID(-1),
87 eventMessenger(0),
88 printModulo(1),
89 detectorType(0)
90{
91 eventMessenger = new XrayFluoEventActionMessenger(this);
92 detectorType = det->GetDetectorType();
93
94 //runManager = new XrayFluoRunAction();
95 G4cout << "XrayFluoEventAction created" << G4endl;
96}
97
98//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
99
100XrayFluoEventAction::XrayFluoEventAction(XrayFluoMercuryDetectorConstruction* det)
101 :drawFlag("all"),
102 HPGeCollID(-1),
103 eventMessenger(0),
104 printModulo(1),
105 detectorType(0)
106{
107 eventMessenger = new XrayFluoEventActionMessenger(this);
108 detectorType = det->GetDetectorType();
109
110 //runManager = new XrayFluoRunAction();
111 G4cout << "XrayFluoEventAction created" << G4endl;
112}
113
114//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
115
116
117
118//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
119
120XrayFluoEventAction::~XrayFluoEventAction()
121{
122 delete eventMessenger;
123 eventMessenger = 0;
124 //delete runManager;
125 //runManager = 0;
126 G4cout << "XrayFluoEventAction deleted" << G4endl;
127}
128
129//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130
131void XrayFluoEventAction::BeginOfEventAction(const G4Event* evt)
132{
133
134 G4int eventNumber = (evt->GetEventID())+1;
135 if ( eventNumber == 1){
136
137 G4cout << "# = 100000 events" << G4endl;
138 G4cout << "1--------+---------+---------+---------+---------5e6"<<G4endl;
139 }
140
141 if ( ((eventNumber) % 100000) == 0 ) {
142
143 if ( eventNumber % (G4int)5e6 != 0 ) G4cout << "#" << std::flush;
144 else G4cout << "#"<< G4endl;
145 // if ( eventNumber % 5e6 == 0 ) G4cout << "#"<< G4endl;
146#ifdef G4ANALYSIS_USE
147 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
148 analysis->PlotCurrentResults();
149#endif
150 }
151
152 if (HPGeCollID==-1)
153
154 {
155 G4SDManager * SDman = G4SDManager::GetSDMpointer();
156 HPGeCollID = SDman->GetCollectionID("HPGeCollection");
157 //the pointer points to the ID number of the sensitive detector
158 }
159}
160
161//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
162
163void XrayFluoEventAction::EndOfEventAction(const G4Event* evt)
164{
165
166 if (detectorType) {
167
168 // extracted from hits, compute the total energy deposit (and total charged
169 // track length)
170 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
171
172 XrayFluoSensorHitsCollection* HPGeHC = 0;
173 G4int n_hit = 0;
174 G4double totEnergyDetect=0., totEnergy=0., energyD=0.;
175
176 if (HCE) HPGeHC = (XrayFluoSensorHitsCollection*)(HCE->GetHC(HPGeCollID));
177 if(HPGeHC)
178
179
180 {
181 n_hit = HPGeHC->entries();
182
183 // if (n_hit) {G4cout << "Ecco quante hit ho nel detector "<< n_hit << G4endl;}
184
185 for (G4int i=0;i<n_hit;i++)
186 {
187
188 totEnergy += (*HPGeHC)[i]->GetEdepTot();
189
190
191
192 energyD = detectorType->ResponseFunction(totEnergy);
193 // energyD = totEnergy;
194 // G4cout << "energy deposit: "<< totEnergy << G4endl;
195#ifdef G4ANALYSIS_USE
196 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
197 analysis->analyseEnergyDep(energyD);
198#endif
199 totEnergyDetect += energyD;
200
201
202 }
203 }
204 }
205
206 // extract the trajectories and draw them
207
208 if (G4VVisManager::GetConcreteInstance())
209 {
210
211 G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
212 G4int n_trajectories = 0;
213 if (trajectoryContainer) n_trajectories = trajectoryContainer->size();
214
215 for (G4int i=0; i<n_trajectories; i++)
216 { G4Trajectory* trj = (G4Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
217 if (drawFlag == "all") trj->DrawTrajectory(50);
218 else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.))
219 trj->DrawTrajectory(50);
220 else if ((drawFlag == "neutral")&&(trj->GetCharge() == 0.))
221 trj->DrawTrajectory(50);
222 }
223 }
224}
225
226//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
227
228
229
230G4double XrayFluoEventAction::RandomCut(G4double energy)
231
232{
233 G4double efficiency = 1.;
234 G4double F = 0.15;
235 G4double epsilon = 2.96 * eV;
236 G4double deltaE = 220 * eV;
237 G4double EdepDetect = 0.;
238 //const XrayFluoDataSet* dataSet = runManager->GetEfficiencySet();
239
240 //G4double id = 0;
241
242 //efficiency = dataSet->FindValue(energy,id);
243
244 G4double Random = G4UniformRand();
245
246 if ( Random<efficiency )
247 {
248 G4double sigma = std::sqrt(F*epsilon*energy+std::pow(deltaE/2355,2));
249
250 EdepDetect = G4RandGauss::shoot(energy, sigma );
251
252 }
253 else {EdepDetect = 0.;}
254 return EdepDetect;
255
256}
257
258
Note: See TracBrowser for help on using the repository browser.