]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliEventAction.cxx
path to perl changes to /usr/bin/perl
[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   : AliVerbose("eventAction"),
29     fMessenger(this),
30     fDrawFlag("CHARGED")
31 {
32 //
33   fTimer = new G4Timer();
34 }
35
36 //_____________________________________________________________________________
37 AliEventAction::AliEventAction(const AliEventAction& right)
38   : AliVerbose(""),
39     fMessenger(this) {
40 //
41   AliGlobals::Exception("AliEventAction is protected from copying.");
42 }
43
44 //_____________________________________________________________________________
45 AliEventAction::~AliEventAction() {
46 //
47   delete fTimer;
48 }
49
50 // operators
51
52 //_____________________________________________________________________________
53 AliEventAction& AliEventAction::operator=(const AliEventAction &right)
54 {
55   // check assignement to self
56   if (this == &right) return *this;
57   
58   AliGlobals::Exception("AliEventAction is protected from assigning.");
59
60   return *this;
61 }
62
63 // private methods
64
65 //_____________________________________________________________________________
66 void AliEventAction::DisplayEvent(const G4Event* event) const
67 {
68 // Draws trajectories.
69 // ---
70
71   if (G4VVisManager::GetConcreteInstance()) {
72
73     // trajectories processing
74     G4TrajectoryContainer* trajectoryContainer 
75       = event->GetTrajectoryContainer();
76
77     G4int nofTrajectories = 0;
78     if (trajectoryContainer)
79       nofTrajectories = trajectoryContainer->entries(); 
80   
81     if (VerboseLevel() > 0 && nofTrajectories > 0) {
82       G4cout << "    " << nofTrajectories; 
83       G4cout << " trajectories stored." << G4endl;
84     }  
85
86     for (G4int i=0; i<nofTrajectories; i++) { 
87       G4VTrajectory* vtrajectory = (*(event->GetTrajectoryContainer()))[i];
88       G4Trajectory* trajectory = dynamic_cast<G4Trajectory*>(vtrajectory);
89       if (!trajectory) {
90         AliGlobals::Exception(
91           "AliEventAction::DisplayEvent: Unknown trajectory type.");
92       }
93       if ( (fDrawFlag == "ALL") ||
94           ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
95          trajectory->DrawTrajectory(50); 
96             // the argument number defines the size of the step points
97             // use 2000 to make step points well visible
98       } 
99     }      
100   }
101 }
102
103 // public methods
104
105 //_____________________________________________________________________________
106 void AliEventAction::BeginOfEventAction(const G4Event* event)
107 {
108 // Called by G4 kernel at the beginning of event.
109 // ---
110
111   G4int eventID = event->GetEventID();
112
113   // reset the tracks counters
114   if(AliTrackingAction::Instance()) 
115     AliTrackingAction::Instance()->PrepareNewEvent();   
116
117   if (VerboseLevel() > 0) {
118     G4cout << ">>> Event " << event->GetEventID() << G4endl;
119   }  
120
121   fTimer->Start();
122 }
123
124 //_____________________________________________________________________________
125 void AliEventAction::EndOfEventAction(const G4Event* event)
126 {
127 // Called by G4 kernel at the end of event.
128 // ---
129
130   // finish the last primary track of the current event
131   AliTrackingAction* trackingAction = AliTrackingAction::Instance();
132   if (trackingAction) trackingAction->FinishPrimaryTrack();   
133
134   if (VerboseLevel() > 0) {
135     G4cout << G4endl;
136     G4cout << ">>> End of Event " << event->GetEventID() << G4endl;
137   }
138
139   if (VerboseLevel() > 1) {
140     //G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
141     G4int nofPrimaryTracks = gAlice->GetHeader()->GetNprimary();
142     G4int nofSavedTracks = gAlice->GetNtrack();
143    
144     G4cout  << "    " << nofPrimaryTracks << 
145                " primary tracks processed." << G4endl;
146     G4cout  << "    " << nofSavedTracks << 
147                " tracks saved." << G4endl;
148     if (trackingAction) {
149        G4int nofAllTracks = trackingAction->GetNofTracks();
150        G4cout  << "    " << nofAllTracks << 
151                   " all tracks processed." << G4endl;
152     }     
153   }            
154
155   // display event
156   DisplayEvent(event);
157
158   // aliroot finish event
159   gAlice->FinishEvent();    
160
161   if (VerboseLevel() > 1) {
162     // print time
163     fTimer->Stop();
164     G4cout << "Time of this event: " << *fTimer << G4endl;
165   }  
166  }