]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliEventAction.cxx
added tests for existence trackingAction
[u/mrichter/AliRoot.git] / AliGeant4 / AliEventAction.cxx
CommitLineData
676fb573 1// $Id$
2// Category: event
3//
7005154f 4// Author: I. Hrivnacova
5//
6// Class AliEventAction
7// ---------------------
676fb573 8// See the class description in the header file.
9
b1327f8f 10#include <G4Timer.hh>
11 // in order to avoid the odd dependency for the
12 // times system function this include must be the first
13
676fb573 14#include "AliEventAction.h"
676fb573 15#include "AliTrackingAction.h"
676fb573 16#include "AliGlobals.h"
03b03ccb 17#include "AliRun.h"
d68d8174 18#include "AliHeader.h"
676fb573 19
676fb573 20#include <G4Event.hh>
21#include <G4TrajectoryContainer.hh>
22#include <G4Trajectory.hh>
23#include <G4VVisManager.hh>
24#include <G4UImanager.hh>
676fb573 25
78ca1e9c 26//_____________________________________________________________________________
676fb573 27AliEventAction::AliEventAction()
7005154f 28 : fMessenger(this),
29 fVerboseLevel(1),
676fb573 30 fDrawFlag("CHARGED")
31{
32//
b1327f8f 33 fTimer = new G4Timer();
676fb573 34}
35
78ca1e9c 36//_____________________________________________________________________________
7005154f 37AliEventAction::AliEventAction(const AliEventAction& right)
38 : fMessenger(this) {
676fb573 39//
40 AliGlobals::Exception("AliEventAction is protected from copying.");
41}
42
78ca1e9c 43//_____________________________________________________________________________
676fb573 44AliEventAction::~AliEventAction() {
45//
b1327f8f 46 delete fTimer;
676fb573 47}
48
49// operators
50
78ca1e9c 51//_____________________________________________________________________________
676fb573 52AliEventAction& AliEventAction::operator=(const AliEventAction &right)
53{
54 // check assignement to self
55 if (this == &right) return *this;
56
57 AliGlobals::Exception("AliEventAction is protected from assigning.");
58
59 return *this;
60}
61
62// private methods
63
78ca1e9c 64//_____________________________________________________________________________
676fb573 65void AliEventAction::DisplayEvent(const G4Event* event) const
66{
67// Draws trajectories.
68// ---
69
676fb573 70 // trajectories processing
71 G4TrajectoryContainer* trajectoryContainer
72 = event->GetTrajectoryContainer();
73
74 G4int nofTrajectories = 0;
75 if (trajectoryContainer)
76 { nofTrajectories = trajectoryContainer->entries(); }
77
03b03ccb 78 if (fVerboseLevel>0 && nofTrajectories>0) {
676fb573 79 G4cout << " " << nofTrajectories;
5f1d09c5 80 G4cout << " trajectories stored." << G4endl;
676fb573 81 }
82
83 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
84 if(pVVisManager && nofTrajectories>0)
85 {
86 G4UImanager::GetUIpointer()->ApplyCommand("/vis~/draw/current");
87
88 for (G4int i=0; i<nofTrajectories; i++)
89 {
90 G4VTrajectory* vtrajectory = (*(event->GetTrajectoryContainer()))[i];
91 G4Trajectory* trajectory = dynamic_cast<G4Trajectory*>(vtrajectory);
92 if (!trajectory) {
93 AliGlobals::Exception(
94 "AliEventAction::DisplayEvent: Unknown trajectory type.");
95 }
5f1d09c5 96 if ( (fDrawFlag == "ALL") ||
97 ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
98 trajectory->DrawTrajectory(50);
0646e189 99 // the argument number defines the size of the step points
100 // use 2000 to make step points well visible
676fb573 101 }
102 }
103 G4UImanager::GetUIpointer()->ApplyCommand("/vis~/show/view");
104 }
105}
106
107// public methods
108
78ca1e9c 109//_____________________________________________________________________________
676fb573 110void AliEventAction::BeginOfEventAction(const G4Event* event)
111{
112// Called by G4 kernel at the beginning of event.
113// ---
114
115 G4int eventID = event->GetEventID();
116
03b03ccb 117 // reset the tracks counters
17e5b037 118 if(AliTrackingAction::Instance())
119 AliTrackingAction::Instance()->PrepareNewEvent();
676fb573 120
121 if (fVerboseLevel>0)
5f1d09c5 122 G4cout << ">>> Event " << event->GetEventID() << G4endl;
b1327f8f 123
124 fTimer->Start();
676fb573 125}
126
78ca1e9c 127//_____________________________________________________________________________
676fb573 128void AliEventAction::EndOfEventAction(const G4Event* event)
129{
130// Called by G4 kernel at the end of event.
131// ---
132
03b03ccb 133 // finish the last primary track of the current event
134 AliTrackingAction* trackingAction = AliTrackingAction::Instance();
17e5b037 135 if (trackingAction) trackingAction->FinishPrimaryTrack();
676fb573 136
03b03ccb 137 // verbose output
676fb573 138 if (fVerboseLevel>0) {
d68d8174 139 G4cout << G4endl;
140 G4cout << ">>> End of Event " << event->GetEventID() << G4endl;
141 }
142
143 if (fVerboseLevel>1) {
03b03ccb 144 //G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
145 G4int nofPrimaryTracks = gAlice->GetHeader()->GetNprimary();
146 G4int nofSavedTracks = gAlice->GetNtrack();
17e5b037 147
676fb573 148 G4cout << " " << nofPrimaryTracks <<
5f1d09c5 149 " primary tracks processed." << G4endl;
03b03ccb 150 G4cout << " " << nofSavedTracks <<
151 " tracks saved." << G4endl;
17e5b037 152 if (trackingAction) {
153 G4int nofAllTracks = trackingAction->GetNofTracks();
154 G4cout << " " << nofAllTracks <<
155 " all tracks processed." << G4endl;
156 }
676fb573 157 }
158
159 // display event
160 DisplayEvent(event);
161
03b03ccb 162 // aliroot finish event
676fb573 163 gAlice->FinishEvent();
676fb573 164
d68d8174 165 if (fVerboseLevel>1) {
e012a2ec 166 // print time
167 fTimer->Stop();
03b03ccb 168 G4cout << "Time of this event: " << *fTimer << G4endl;
e012a2ec 169 }
b1327f8f 170 }