]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliEventAction.cxx
52d3a17b03346eb4f88a2e6729a670947f1fcc2b
[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 "AliRun.h"
13 #include "AliTrackingAction.h"
14 #include "AliSensitiveDetector.h"
15 #include "AliGlobals.h"
16
17 #include "TG4GeometryManager.h"
18
19 #include <G4Event.hh>
20 #include <G4TrajectoryContainer.hh>
21 #include <G4Trajectory.hh>
22 #include <G4VVisManager.hh>
23 #include <G4UImanager.hh>
24 #include <G4LogicalVolumeStore.hh>
25 #include <G4VSensitiveDetector.hh>
26
27 AliEventAction::AliEventAction()
28   : fVerboseLevel(1), 
29     fDrawFlag("CHARGED")
30 {
31 //
32   fMessenger = new AliEventActionMessenger(this);
33   fTimer = new G4Timer();
34 }
35
36 AliEventAction::AliEventAction(const AliEventAction& right) {
37 //
38   AliGlobals::Exception("AliEventAction is protected from copying.");
39 }
40
41 AliEventAction::~AliEventAction() {
42 //
43   delete fMessenger;
44   delete fTimer;
45 }
46
47 // operators
48
49 AliEventAction& AliEventAction::operator=(const AliEventAction &right)
50 {
51   // check assignement to self
52   if (this == &right) return *this;
53   
54   AliGlobals::Exception("AliEventAction is protected from assigning.");
55
56   return *this;
57 }
58
59 // private methods
60
61 void AliEventAction::DisplayEvent(const G4Event* event) const
62 {
63 // Draws trajectories.
64 // ---
65
66
67   // trajectories processing
68   G4TrajectoryContainer* trajectoryContainer 
69     = event->GetTrajectoryContainer();
70
71   G4int nofTrajectories = 0;
72   if (trajectoryContainer)
73   { nofTrajectories = trajectoryContainer->entries(); }
74   
75   if (fVerboseLevel>0) {
76     G4cout << "    " << nofTrajectories; 
77     G4cout << " trajectories stored." << G4endl;
78   }  
79
80   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
81   if(pVVisManager && nofTrajectories>0)
82   {
83     G4UImanager::GetUIpointer()->ApplyCommand("/vis~/draw/current");
84
85     for (G4int i=0; i<nofTrajectories; i++)
86     { 
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     G4UImanager::GetUIpointer()->ApplyCommand("/vis~/show/view");
101   }  
102 }
103
104 // public methods
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 counters (primary tracks, saved tracks)
114   AliTrackingAction* trackingAction
115     = AliTrackingAction::Instance();
116   trackingAction->PrepareNewEvent();   
117
118   if (fVerboseLevel>0)
119     G4cout << ">>> Event " << event->GetEventID() << G4endl;
120
121   fTimer->Start();
122 }
123
124 void AliEventAction::EndOfEventAction(const G4Event* event)
125 {
126 // Called by G4 kernel at the end of event.
127 // ---
128
129   // save the last primary track store of
130   // the current event
131   AliTrackingAction* trackingAction
132     = AliTrackingAction::Instance();
133   trackingAction->SaveAndDestroyTrack();   
134
135   if (fVerboseLevel>0) {
136     G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
137     G4int nofTracks = trackingAction->GetNofTracks();
138     G4cout  << "    " << nofPrimaryTracks << 
139                " primary tracks processed." << G4endl;
140     G4cout  << "    " << nofTracks << 
141                " all tracks processed." << G4endl;
142   }            
143
144   // display event
145   DisplayEvent(event);
146
147   // aliroot
148   // store event header data
149   gAlice->GetHeader()->SetEvent(event->GetEventID());
150   gAlice->GetHeader()->SetNvertex(event->GetNumberOfPrimaryVertex());
151   gAlice->GetHeader()->SetNprimary(trackingAction->GetNofPrimaryTracks());
152   gAlice->GetHeader()->SetNtrack(trackingAction->GetNofSavedTracks());
153
154   gAlice->FinishEvent();    
155
156   if (fVerboseLevel>0) {
157     // print time
158     fTimer->Stop();
159     G4cout << "Time of this event = " << *fTimer << G4endl;
160   }  
161  }