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