]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliEventAction.cxx
This commit was generated by cvs2svn to compensate for changes in r1459,
[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 "AliEventAction.h"
7 #include "AliEventActionMessenger.h"
8 #include "AliRun.h"
9 #include "AliTrackingAction.h"
10 #include "AliSensitiveDetector.h"
11 #include "AliGlobals.h"
12
13 #include "TG4GeometryManager.h"
14
15 #include <G4Event.hh>
16 #include <G4TrajectoryContainer.hh>
17 #include <G4Trajectory.hh>
18 #include <G4VVisManager.hh>
19 #include <G4UImanager.hh>
20 #include <G4LogicalVolumeStore.hh>
21 #include <G4VSensitiveDetector.hh>
22
23 AliEventAction::AliEventAction()
24   : fVerboseLevel(1), 
25     fDrawFlag("CHARGED")
26 {
27 //
28   fMessenger = new AliEventActionMessenger(this);
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 }
40
41 // operators
42
43 AliEventAction& AliEventAction::operator=(const AliEventAction &right)
44 {
45   // check assignement to self
46   if (this == &right) return *this;
47   
48   AliGlobals::Exception("AliEventAction is protected from assigning.");
49
50   return *this;
51 }
52
53 // private methods
54
55 void AliEventAction::DisplayEvent(const G4Event* event) const
56 {
57 // Draws trajectories.
58 // ---
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) {
70     G4cout << "    " << nofTrajectories; 
71     G4cout << " trajectories stored." << endl;
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       else if ( (fDrawFlag == "ALL") ||
88                ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
89         trajectory->DrawTrajectory(2000); 
90       } 
91     }      
92     G4UImanager::GetUIpointer()->ApplyCommand("/vis~/show/view");
93   }  
94 }
95
96 // public methods
97
98 void AliEventAction::BeginOfEventAction(const G4Event* event)
99 {
100 // Called by G4 kernel at the beginning of event.
101 // ---
102
103   G4int eventID = event->GetEventID();
104
105   // reset the counters (primary tracks, saved tracks)
106   AliTrackingAction* trackingAction
107     = AliTrackingAction::Instance();
108   trackingAction->PrepareNewEvent();   
109
110   if (fVerboseLevel>0)
111     G4cout << ">>> Event " << event->GetEventID() << endl;
112 }
113
114 void AliEventAction::EndOfEventAction(const G4Event* event)
115 {
116 // Called by G4 kernel at the end of event.
117 // ---
118
119   // save the last primary track store of
120   // the current event
121   AliTrackingAction* trackingAction
122     = AliTrackingAction::Instance();
123   trackingAction->SaveAndDestroyTrack();   
124
125   if (fVerboseLevel>0) {
126     G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
127     G4cout  << "    " << nofPrimaryTracks << 
128                " primary tracks processed." << endl;
129   }            
130
131   // display event
132   DisplayEvent(event);
133
134   // aliroot
135   // store event header data
136   gAlice->GetHeader()->SetEvent(event->GetEventID());
137   gAlice->GetHeader()->SetNvertex(event->GetNumberOfPrimaryVertex());
138   gAlice->GetHeader()->SetNprimary(trackingAction->GetNofPrimaryTracks());
139   gAlice->GetHeader()->SetNtrack(trackingAction->GetNofSavedTracks());
140
141   gAlice->FinishEvent();    
142 }
143
144
145