]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliEventAction.cxx
added tests for existence trackingAction
[u/mrichter/AliRoot.git] / AliGeant4 / AliEventAction.cxx
1 // $Id$
2 // Category: event
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliEventAction
7 // ---------------------
8 // See the class description in the header file.
9
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
14 #include "AliEventAction.h"
15 #include "AliTrackingAction.h"
16 #include "AliGlobals.h"
17 #include "AliRun.h"
18 #include "AliHeader.h"
19
20 #include <G4Event.hh>
21 #include <G4TrajectoryContainer.hh>
22 #include <G4Trajectory.hh>
23 #include <G4VVisManager.hh>
24 #include <G4UImanager.hh>
25
26 //_____________________________________________________________________________
27 AliEventAction::AliEventAction()
28   : fMessenger(this),
29     fVerboseLevel(1), 
30     fDrawFlag("CHARGED")
31 {
32 //
33   fTimer = new G4Timer();
34 }
35
36 //_____________________________________________________________________________
37 AliEventAction::AliEventAction(const AliEventAction& right)
38   : fMessenger(this) {
39 //
40   AliGlobals::Exception("AliEventAction is protected from copying.");
41 }
42
43 //_____________________________________________________________________________
44 AliEventAction::~AliEventAction() {
45 //
46   delete fTimer;
47 }
48
49 // operators
50
51 //_____________________________________________________________________________
52 AliEventAction& 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
64 //_____________________________________________________________________________
65 void AliEventAction::DisplayEvent(const G4Event* event) const
66 {
67 // Draws trajectories.
68 // ---
69
70   // trajectories processing
71   G4TrajectoryContainer* trajectoryContainer 
72     = event->GetTrajectoryContainer();
73
74   G4int nofTrajectories = 0;
75   if (trajectoryContainer)
76   { nofTrajectories = trajectoryContainer->entries(); }
77   
78   if (fVerboseLevel>0 && nofTrajectories>0) {
79     G4cout << "    " << nofTrajectories; 
80     G4cout << " trajectories stored." << G4endl;
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       }
96       if ( (fDrawFlag == "ALL") ||
97           ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
98          trajectory->DrawTrajectory(50); 
99             // the argument number defines the size of the step points
100             // use 2000 to make step points well visible
101       } 
102     }      
103     G4UImanager::GetUIpointer()->ApplyCommand("/vis~/show/view");
104   }  
105 }
106
107 // public methods
108
109 //_____________________________________________________________________________
110 void AliEventAction::BeginOfEventAction(const G4Event* event)
111 {
112 // Called by G4 kernel at the beginning of event.
113 // ---
114
115   G4int eventID = event->GetEventID();
116
117   // reset the tracks counters
118   if(AliTrackingAction::Instance()) 
119     AliTrackingAction::Instance()->PrepareNewEvent();   
120
121   if (fVerboseLevel>0)
122     G4cout << ">>> Event " << event->GetEventID() << G4endl;
123
124   fTimer->Start();
125 }
126
127 //_____________________________________________________________________________
128 void AliEventAction::EndOfEventAction(const G4Event* event)
129 {
130 // Called by G4 kernel at the end of event.
131 // ---
132
133   // finish the last primary track of the current event
134   AliTrackingAction* trackingAction = AliTrackingAction::Instance();
135   if (trackingAction) trackingAction->FinishPrimaryTrack();   
136
137   // verbose output 
138   if (fVerboseLevel>0) {
139     G4cout << G4endl;
140     G4cout << ">>> End of Event " << event->GetEventID() << G4endl;
141   }
142
143   if (fVerboseLevel>1) {
144     //G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
145     G4int nofPrimaryTracks = gAlice->GetHeader()->GetNprimary();
146     G4int nofSavedTracks = gAlice->GetNtrack();
147    
148     G4cout  << "    " << nofPrimaryTracks << 
149                " primary tracks processed." << G4endl;
150     G4cout  << "    " << nofSavedTracks << 
151                " tracks saved." << G4endl;
152     if (trackingAction) {
153        G4int nofAllTracks = trackingAction->GetNofTracks();
154        G4cout  << "    " << nofAllTracks << 
155                   " all tracks processed." << G4endl;
156     }     
157   }            
158
159   // display event
160   DisplayEvent(event);
161
162   // aliroot finish event
163   gAlice->FinishEvent();    
164
165   if (fVerboseLevel>1) {
166     // print time
167     fTimer->Stop();
168     G4cout << "Time of this event: " << *fTimer << G4endl;
169   }  
170  }