]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliRunAction.cxx
Initialize decayer before generation. Important if run inside cocktail.
[u/mrichter/AliRoot.git] / AliGeant4 / AliRunAction.cxx
1 // $Id$
2 // Category: run
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 "AliRunAction.h"
11 #include "AliRunActionMessenger.h"
12 #include "AliSDManager.h"
13 #include "AliGlobals.h"
14 #include "AliRun.h"
15 #include "AliLego.h"
16
17 #include "TG4GeometryManager.h"
18
19 #include <G4Run.hh>
20 #include <G4UImanager.hh>
21
22 AliRunAction::AliRunAction()
23   : fRunID(-1),
24     fVerboseLevel(0)
25 {
26 //
27   fMessenger = new AliRunActionMessenger(this);
28   fTimer = new G4Timer;
29 }
30
31 AliRunAction::AliRunAction(const AliRunAction& right) {
32 //
33   AliGlobals::Exception("AliRunAction is protected from copying.");
34 }
35
36 AliRunAction::~AliRunAction() {
37 //
38   delete fMessenger;
39   delete fTimer;
40 }
41
42 // operators
43
44 AliRunAction& AliRunAction::operator=(const AliRunAction &right)
45 {
46   // check assignement to self
47   if (this == &right) return *this;
48   
49   AliGlobals::Exception("AliRunAction is protected from assigning.");
50
51   return *this;
52 }
53
54 // public methods
55
56 void AliRunAction::BeginOfRunAction(const G4Run* run)
57 {
58 // Called by G4 kernel at the beginning of run.
59 // ---
60
61   fRunID++;
62   
63   // aliroot
64   // store runID in the event header
65   gAlice->GetHeader()->SetRun(fRunID);
66
67   // clear remaining G3 tables
68   if (fRunID == 0)
69     TG4GeometryManager::Instance()->ClearG3TablesFinal();
70
71   // create lego sensitive detectors 
72   // if lego is instantiated
73   AliLego* lego = gAlice->Lego();
74   if (lego) {
75     AliSDManager::Instance()->SetLego(lego);
76     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 0");
77     G4UImanager::GetUIpointer()->ApplyCommand("/aliGenerator/set AliGenerator");
78   }  
79
80   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
81   fTimer->Start();
82 }
83
84 void AliRunAction::EndOfRunAction(const G4Run* run)
85 {
86 // Called by G4 kernel at the end of run.
87 // ---
88
89   fTimer->Stop();
90
91   // delete lego sensitive detectors 
92   // if lego is instantiated
93   AliLego* lego = gAlice->Lego();
94   if (lego) {
95     AliSDManager::Instance()->UnsetLego();
96     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 1");
97   }  
98
99   G4cout << "Time of this run:   " << *fTimer << G4endl;
100   G4cout << "Number of events processed: " << run->GetNumberOfEvent() << G4endl;
101 }