source: trunk/source/geometry/magneticfield/test/field03/src/F03EventAction.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

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