]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliEventAction.cxx
Moved from AliTransbit to AliL3Transbit.
[u/mrichter/AliRoot.git] / AliGeant4 / AliEventAction.cxx
index 1b3b8d8a6889232c1d7c1af79a24192558f509b3..57c8a1c6ab8e29c081199165939934ccb5f8ed8d 100644 (file)
@@ -1,45 +1,55 @@
 // $Id$
 // Category: event
 //
+// Author: I. Hrivnacova
+//
+// Class AliEventAction
+// ---------------------
 // See the class description in the header file.
 
+#include <G4Timer.hh>
+   // in order to avoid the odd dependency for the
+   // times system function this include must be the first
+
 #include "AliEventAction.h"
-#include "AliEventActionMessenger.h"
-#include "AliRun.h"
 #include "AliTrackingAction.h"
-#include "AliSensitiveDetector.h"
 #include "AliGlobals.h"
-
-#include "TG4GeometryManager.h"
+#include "AliRun.h"
+#include "AliHeader.h"
 
 #include <G4Event.hh>
 #include <G4TrajectoryContainer.hh>
 #include <G4Trajectory.hh>
 #include <G4VVisManager.hh>
 #include <G4UImanager.hh>
-#include <G4LogicalVolumeStore.hh>
-#include <G4VSensitiveDetector.hh>
 
+//_____________________________________________________________________________
 AliEventAction::AliEventAction()
-  : fVerboseLevel(1), 
+  : AliVerbose("eventAction"),
+    fMessenger(this),
     fDrawFlag("CHARGED")
 {
 //
-  fMessenger = new AliEventActionMessenger(this);
+  fTimer = new G4Timer();
 }
 
-AliEventAction::AliEventAction(const AliEventAction& right) {
+//_____________________________________________________________________________
+AliEventAction::AliEventAction(const AliEventAction& right)
+  : AliVerbose(""),
+    fMessenger(this) {
 //
   AliGlobals::Exception("AliEventAction is protected from copying.");
 }
 
+//_____________________________________________________________________________
 AliEventAction::~AliEventAction() {
 //
-  delete fMessenger;
+  delete fTimer;
 }
 
 // operators
 
+//_____________________________________________________________________________
 AliEventAction& AliEventAction::operator=(const AliEventAction &right)
 {
   // check assignement to self
@@ -52,49 +62,47 @@ AliEventAction& AliEventAction::operator=(const AliEventAction &right)
 
 // private methods
 
+//_____________________________________________________________________________
 void AliEventAction::DisplayEvent(const G4Event* event) const
 {
 // Draws trajectories.
 // ---
 
+  if (G4VVisManager::GetConcreteInstance()) {
 
-  // trajectories processing
-  G4TrajectoryContainer* trajectoryContainer 
-    = event->GetTrajectoryContainer();
+    // trajectories processing
+    G4TrajectoryContainer* trajectoryContainer 
+      = event->GetTrajectoryContainer();
 
-  G4int nofTrajectories = 0;
-  if (trajectoryContainer)
-  { nofTrajectories = trajectoryContainer->entries(); }
+    G4int nofTrajectories = 0;
+    if (trajectoryContainer)
+      nofTrajectories = trajectoryContainer->entries(); 
   
-  if (fVerboseLevel>0) {
-    G4cout << "    " << nofTrajectories; 
-    G4cout << " trajectories stored." << endl;
-  }  
+    if (VerboseLevel() > 0 && nofTrajectories > 0) {
+      G4cout << "    " << nofTrajectories; 
+      G4cout << " trajectories stored." << G4endl;
+    }  
 
-  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
-  if(pVVisManager && nofTrajectories>0)
-  {
-    G4UImanager::GetUIpointer()->ApplyCommand("/vis~/draw/current");
-
-    for (G4int i=0; i<nofTrajectories; i++)
-    { 
+    for (G4int i=0; i<nofTrajectories; i++) { 
       G4VTrajectory* vtrajectory = (*(event->GetTrajectoryContainer()))[i];
       G4Trajectory* trajectory = dynamic_cast<G4Trajectory*>(vtrajectory);
       if (!trajectory) {
         AliGlobals::Exception(
          "AliEventAction::DisplayEvent: Unknown trajectory type.");
       }
-      else if ( (fDrawFlag == "ALL") ||
-               ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
-        trajectory->DrawTrajectory(2000); 
+      if ( (fDrawFlag == "ALL") ||
+          ((fDrawFlag == "CHARGED") && (trajectory->GetCharge() != 0.))){
+        trajectory->DrawTrajectory(50); 
+           // the argument number defines the size of the step points
+           // use 2000 to make step points well visible
       }        
     }      
-    G4UImanager::GetUIpointer()->ApplyCommand("/vis~/show/view");
-  }  
+  }
 }
 
 // public methods
 
+//_____________________________________________________________________________
 void AliEventAction::BeginOfEventAction(const G4Event* event)
 {
 // Called by G4 kernel at the beginning of event.
@@ -102,44 +110,57 @@ void AliEventAction::BeginOfEventAction(const G4Event* event)
 
   G4int eventID = event->GetEventID();
 
-  // reset the counters (primary tracks, saved tracks)
-  AliTrackingAction* trackingAction
-    = AliTrackingAction::Instance();
-  trackingAction->PrepareNewEvent();   
+  // reset the tracks counters
+  if(AliTrackingAction::Instance()) 
+    AliTrackingAction::Instance()->PrepareNewEvent();   
 
-  if (fVerboseLevel>0)
-    G4cout << ">>> Event " << event->GetEventID() << endl;
+  if (VerboseLevel() > 0) {
+    G4cout << ">>> Event " << event->GetEventID() << G4endl;
+  }  
+
+  fTimer->Start();
 }
 
+//_____________________________________________________________________________
 void AliEventAction::EndOfEventAction(const G4Event* event)
 {
 // Called by G4 kernel at the end of event.
 // ---
 
-  // save the last primary track store of
-  // the current event
-  AliTrackingAction* trackingAction
-    = AliTrackingAction::Instance();
-  trackingAction->SaveAndDestroyTrack();   
+  // finish the last primary track of the current event
+  AliTrackingAction* trackingAction = AliTrackingAction::Instance();
+  if (trackingAction) trackingAction->FinishPrimaryTrack();   
 
-  if (fVerboseLevel>0) {
-    G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
+  if (VerboseLevel() > 0) {
+    G4cout << G4endl;
+    G4cout << ">>> End of Event " << event->GetEventID() << G4endl;
+  }
+
+  if (VerboseLevel() > 1) {
+    //G4int nofPrimaryTracks = trackingAction->GetNofPrimaryTracks();
+    G4int nofPrimaryTracks = gAlice->GetHeader()->GetNprimary();
+    G4int nofSavedTracks = gAlice->GetNtrack();
+   
     G4cout  << "    " << nofPrimaryTracks << 
-               " primary tracks processed." << endl;
+               " primary tracks processed." << G4endl;
+    G4cout  << "    " << nofSavedTracks << 
+               " tracks saved." << G4endl;
+    if (trackingAction) {
+       G4int nofAllTracks = trackingAction->GetNofTracks();
+       G4cout  << "    " << nofAllTracks << 
+                  " all tracks processed." << G4endl;
+    }    
   }           
 
   // display event
   DisplayEvent(event);
 
-  // aliroot
-  // store event header data
-  gAlice->GetHeader()->SetEvent(event->GetEventID());
-  gAlice->GetHeader()->SetNvertex(event->GetNumberOfPrimaryVertex());
-  gAlice->GetHeader()->SetNprimary(trackingAction->GetNofPrimaryTracks());
-  gAlice->GetHeader()->SetNtrack(trackingAction->GetNofSavedTracks());
-
+  // aliroot finish event
   gAlice->FinishEvent();    
-}
-
-
 
+  if (VerboseLevel() > 1) {
+    // print time
+    fTimer->Stop();
+    G4cout << "Time of this event: " << *fTimer << G4endl;
+  }  
+ }