source: trunk/examples/extended/electromagnetic/TestEm8/src/Em8EventAction.cc@ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

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