source: trunk/examples/extended/electromagnetic/TestEm10/src/Em10EventAction.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 7.4 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: Em10EventAction.cc,v 1.6 2006/06/29 16:38:41 gunter Exp $
28// GEANT4 tag $Name: $
29//
30//
31
32//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
33//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
34
35#include "Em10EventAction.hh"
36
37#include "Em10RunAction.hh"
38
39#include "Em10CalorHit.hh"
40#include "Em10EventActionMessenger.hh"
41
42#include "G4Event.hh"
43#include "G4EventManager.hh"
44#include "G4HCofThisEvent.hh"
45#include "G4VHitsCollection.hh"
46#include "G4SDManager.hh"
47#include "G4UImanager.hh"
48#include "G4TrajectoryContainer.hh"
49#include "G4Trajectory.hh"
50#include "G4VVisManager.hh"
51#include "G4ios.hh"
52#include "G4UnitsTable.hh"
53#include "Randomize.hh"
54
55//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
56
57Em10EventAction::Em10EventAction(Em10RunAction* Em10RA)
58:calorimeterCollID(-1),eventMessenger(0),
59 runaction(Em10RA),verboselevel(0),drawFlag("all"),printModulo(10000)
60{
61 eventMessenger = new Em10EventActionMessenger(this);
62}
63
64//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
65
66Em10EventAction::~Em10EventAction()
67{
68 delete eventMessenger;
69}
70
71//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
72
73void Em10EventAction::BeginOfEventAction(const G4Event* evt)
74{
75 G4int evtNb = evt->GetEventID();
76 if (evtNb%printModulo == 0)
77 G4cout << "\n---> Begin of Event: " << evtNb << G4endl;
78
79 if(verboselevel>1)
80 G4cout << "<<< Event " << evtNb << " started." << G4endl;
81
82 if (calorimeterCollID==-1)
83 {
84 G4SDManager * SDman = G4SDManager::GetSDMpointer();
85 calorimeterCollID = SDman->GetCollectionID("CalCollection");
86 }
87
88 nstep = 0. ;
89 nstepCharged = 0. ;
90 nstepNeutral = 0. ;
91 Nch = 0. ;
92 Nne = 0. ;
93 NE=0.;
94 NP=0.;
95 Transmitted=0.;
96 Reflected =0.;
97}
98
99//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
100
101void Em10EventAction::EndOfEventAction(const G4Event* evt)
102{
103 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
104 Em10CalorHitsCollection* CHC = 0;
105 if (HCE)
106 CHC = (Em10CalorHitsCollection*)(HCE->GetHC(calorimeterCollID));
107
108 if (CHC)
109 {
110 int n_hit = CHC->entries();
111 // if(verboselevel==2)
112 // G4cout << " " << n_hit
113 // << " hits are stored in Em10CalorHitsCollection." << G4endl;
114
115 G4double totEAbs=0, totLAbs=0;
116 for (int i=0;i<n_hit;i++)
117 { totEAbs += (*CHC)[i]->GetEdepAbs();
118 totLAbs += (*CHC)[i]->GetTrakAbs();
119 }
120 if(verboselevel==2)
121 G4cout
122 << " Absorber: total energy: " << std::setw(7) <<
123 G4BestUnit(totEAbs,"Energy")
124 << " total track length: " << std::setw(7) <<
125 G4BestUnit(totLAbs,"Length")
126 << G4endl;
127
128 // count event, add deposits to the sum ...
129 runaction->CountEvent() ;
130 runaction->AddTrackLength(totLAbs) ;
131 runaction->AddnStepsCharged(nstepCharged) ;
132 runaction->AddnStepsNeutral(nstepNeutral) ;
133 if(verboselevel==2)
134 G4cout << " Ncharged=" << Nch << " , Nneutral=" << Nne << G4endl;
135 runaction->CountParticles(Nch,Nne);
136 runaction->AddEP(NE,NP);
137 runaction->AddTrRef(Transmitted,Reflected) ;
138 runaction->AddEdeps(totEAbs) ;
139 runaction->FillEn(totEAbs) ;
140
141 nstep=nstepCharged+nstepNeutral ;
142 runaction->FillNbOfSteps(nstep);
143 }
144
145 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
146
147 if(pVVisManager)
148 {
149 G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
150 G4int n_trajectories = 0;
151 if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
152 for(G4int i=0; i<n_trajectories; i++)
153 { G4Trajectory* trj = (G4Trajectory *)((*(evt->GetTrajectoryContainer()))[i]);
154 if (drawFlag == "all") trj->DrawTrajectory(50);
155 else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.))
156 trj->DrawTrajectory(50);
157 }
158 }
159
160 if(verboselevel>0)
161 G4cout << "<<< Event " << evt->GetEventID() << " ended." << G4endl;
162
163
164 //save rndm status
165 if (runaction->GetRndmFreq() == 2)
166 {
167 CLHEP::HepRandom::saveEngineStatus("endOfEvent.rndm");
168 G4int evtNb = evt->GetEventID();
169 if (evtNb%printModulo == 0)
170 {
171 G4cout << "\n---> End of Event: " << evtNb << G4endl;
172 CLHEP::HepRandom::showEngineStatus();
173 }
174 }
175}
176
177//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
178
179G4int Em10EventAction::GetEventno()
180{
181 G4int evno = fpEventManager->GetConstCurrentEvent()->GetEventID() ;
182 return evno ;
183}
184
185//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
186
187void Em10EventAction::setEventVerbose(G4int level)
188{
189 verboselevel = level ;
190}
191
192//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
193
194void Em10EventAction::CountStepsCharged()
195{
196 nstepCharged += 1. ;
197}
198
199//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
200
201void Em10EventAction::CountStepsNeutral()
202{
203 nstepNeutral += 1. ;
204}
205
206//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
207
208void Em10EventAction::AddCharged()
209{
210 Nch += 1.;
211}
212
213//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
214
215void Em10EventAction::AddNeutral()
216{
217 Nne += 1.;
218}
219
220//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
221
222void Em10EventAction::AddE()
223{
224 NE += 1.;
225}
226
227//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
228
229void Em10EventAction::AddP()
230{
231 NP += 1.;
232}
233
234//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
235
236void Em10EventAction::SetTr()
237{
238 Transmitted = 1.;
239}
240
241//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
242
243void Em10EventAction::SetRef()
244{
245 Reflected = 1.;
246}
247
248//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
249
250
251
Note: See TracBrowser for help on using the repository browser.