]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliEventAction.cxx
df1bd6076a5f3a19bc5ce58bdc4230bcbfa16b2d
[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   AliTrackingAction::Instance()->PrepareNewEvent();   
119
120   if (fVerboseLevel>0)
121     G4cout << ">>> Event " << event->GetEventID() << G4endl;
122
123   fTimer->Start();
124 }
125
126 //_____________________________________________________________________________
127 void AliEventAction::EndOfEventAction(const G4Event* event)
128 {
129 // Called by G4 kernel at the end of event.
130 // ---
131
132   // finish the last primary track of the current event
133   AliTrackingAction* trackingAction = AliTrackingAction::Instance();
134   trackingAction->FinishPrimaryTrack();   
135
136   // verbose output 
137   if (fVerboseLevel>0) {
138     G4cout << G4endl;
139     G4cout << ">>> End of Event " << event->GetEventID() << G4endl;
140   }
141
142   if (fVerboseLevel>1) {
143     //G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
144     G4int nofPrimaryTracks = gAlice->GetHeader()->GetNprimary();
145     G4int nofSavedTracks = gAlice->GetNtrack();
146     G4int nofAllTracks = trackingAction->GetNofTracks();
147     
148     G4cout  << "    " << nofPrimaryTracks << 
149                " primary tracks processed." << G4endl;
150     G4cout  << "    " << nofSavedTracks << 
151                " tracks saved." << G4endl;
152     G4cout  << "    " << nofAllTracks << 
153                " all tracks processed." << G4endl;
154   }            
155
156   // display event
157   DisplayEvent(event);
158
159   // aliroot finish event
160   gAlice->FinishEvent();    
161
162   if (fVerboseLevel>1) {
163     // print time
164     fTimer->Stop();
165     G4cout << "Time of this event: " << *fTimer << G4endl;
166   }  
167  }