]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliRunAction.cxx
added function for drawing histograms one by one; added function for loading histogra...
[u/mrichter/AliRoot.git] / AliGeant4 / AliRunAction.cxx
1 // $Id$
2 // Category: run
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliRunAction
7 // ------------------
8 // See the class description in the header file.
9
10 #include <G4Timer.hh>
11    // in order to avoid the odd dependency for the
12    // times system function this include must be the first
13
14 #include "AliRunAction.h"
15 #include "AliSDConstruction.h"
16 #include "AliGlobals.h"
17 #include "AliRun.h"
18 #include "AliHeader.h"
19 #include "AliLego.h"
20
21 #include "TG4SDManager.h"
22 #include "TG4VSDConstruction.h"
23
24 #include <G4Run.hh>
25 #include <G4UImanager.hh>
26
27 //_____________________________________________________________________________
28 AliRunAction::AliRunAction()
29   : fMessenger(this),
30     fRunID(-1),
31     fVerboseLevel(0)
32 {
33 //
34   fTimer = new G4Timer;
35 }
36
37 //_____________________________________________________________________________
38 AliRunAction::AliRunAction(const AliRunAction& right) 
39   : fMessenger(this) {
40 //
41   AliGlobals::Exception("AliRunAction is protected from copying.");
42 }
43
44 //_____________________________________________________________________________
45 AliRunAction::~AliRunAction() {
46 //
47   delete fTimer;
48 }
49
50 // operators
51
52 //_____________________________________________________________________________
53 AliRunAction& AliRunAction::operator=(const AliRunAction &right)
54 {
55   // check assignement to self
56   if (this == &right) return *this;
57   
58   AliGlobals::Exception("AliRunAction is protected from assigning.");
59
60   return *this;
61 }
62
63 // private methods
64
65 //_____________________________________________________________________________
66 AliSDConstruction* AliRunAction::GetSDConstruction() const
67 {
68 // Gets sensitive detectors construction and checks type.
69 // ---
70
71   TG4VSDConstruction* tg4SDConstruction 
72      = TG4SDManager::Instance()->GetSDConstruction();
73
74   AliSDConstruction* aliSDConstruction
75      = dynamic_cast<AliSDConstruction*>(tg4SDConstruction);
76
77   if (!aliSDConstruction) {
78      G4String text = "AliRunAction::GetSDConstruction:\n";
79      text = text + "    Unknown type.";
80      AliGlobals::Exception(text);
81      return 0;
82   }
83   
84   return aliSDConstruction;
85 }
86
87 // public methods
88
89 //_____________________________________________________________________________
90 void AliRunAction::BeginOfRunAction(const G4Run* run)
91 {
92 // Called by G4 kernel at the beginning of run.
93 // ---
94
95   fRunID++;
96   
97   // aliroot
98   // store runID in the event header
99   gAlice->GetHeader()->SetRun(fRunID);
100
101   // create lego sensitive detectors 
102   // if lego is instantiated
103   AliLego* lego = gAlice->Lego();
104   if (lego) {
105     GetSDConstruction()->SetLego(lego);
106     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 0");
107     G4UImanager::GetUIpointer()->ApplyCommand("/aliGenerator/set AliGenerator");
108   }  
109
110   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
111   fTimer->Start();
112 }
113
114 //_____________________________________________________________________________
115 void AliRunAction::EndOfRunAction(const G4Run* run)
116 {
117 // Called by G4 kernel at the end of run.
118 // ---
119
120   fTimer->Stop();
121
122   // delete lego sensitive detectors 
123   // if lego is instantiated
124   AliLego* lego = gAlice->Lego();
125   if (lego) {
126     GetSDConstruction()->UnsetLego();
127     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 1");
128   }  
129
130   G4cout << "Time of this run:   " << *fTimer << G4endl;
131   G4cout << "Number of events processed: " << run->GetNumberOfEvent() << G4endl;
132 }