Geant4  10.01.p02
RunAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 // $Id: RunAction.cc 85243 2014-10-27 08:22:42Z gcosmo $
30 //
31 //---------------------------------------------------------------------------
32 //
33 // ClassName: RunAction
34 //
35 // Author: V.Ivanchenko 01.09.2010
36 //
37 //----------------------------------------------------------------------------
38 //
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
43 #include "RunAction.hh"
44 #include "Run.hh"
45 #include "TestParameters.hh"
46 #include "G4Run.hh"
47 #include "G4RunManager.hh"
48 #include "G4UImanager.hh"
49 #include "G4VVisManager.hh"
50 #include "G4SystemOfUnits.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55  : G4UserRunAction(), fAnalysisManager(0), fRun(0), fHistName("testem8")
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {}
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
67  // Always creating analysis manager
68  fAnalysisManager = G4AnalysisManager::Instance();
69  fAnalysisManager->SetActivation(true);
70  fAnalysisManager->SetVerboseLevel(1);
71 
72  // Open file histogram file
73  fAnalysisManager->OpenFile(fHistName);
74  fAnalysisManager->SetFirstHistoId(1);
75 
77  G4int nBinsE = param->GetNumberBins();
78  G4int nBinsCluster = param->GetNumberBinsCluster();
79  G4double maxEnergy = param->GetMaxEnergy();
80  G4double factorALICE = param->GetFactorALICE();
81 
82  // Creating an 1-dimensional histograms in the root directory of the tree
83  fAnalysisManager->CreateH1("h1","Energy deposition in detector (keV)",
84  nBinsE,0.0,maxEnergy/keV);
85  fAnalysisManager->CreateH1("h2","Number of primary clusters",
86  nBinsE,-0.5,G4double(nBinsCluster)-0.5);
87  fAnalysisManager->CreateH1("h3","Energy deposition in detector (ADC)",
88  nBinsE,0.0,maxEnergy* factorALICE/keV);
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  fRun = new Run();
96  return fRun;
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
101 void RunAction::BeginOfRunAction(const G4Run* aRun)
102 {
103  G4int id = aRun->GetRunID();
104  G4cout << "### Run " << id << " start" << G4endl;
105 
106  fRun->BeginOfRun();
107  //histograms
108  //
109  Book();
110 
111 #ifdef G4VIS_USE
113 
115 
116  if(pVVisManager)
117  {
118  UI->ApplyCommand("/vis/scene/notifyHandlers");
119  }
120 #endif
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124 
125 void RunAction::EndOfRunAction(const G4Run*)
126 {
127  // print Run summary
128  G4cout << "RunAction: End of run actions are started " << isMaster
129  << " Nevt= " << fRun->GetNumberOfEvent()
130  << " Edep= " << fRun->GetStat()->mean() << G4endl;
131  if (isMaster) {
132  fRun->EndOfRun();
133  }
134  // save histos and close analysis
135 
136  if(fAnalysisManager->IsActive()) {
137  fAnalysisManager->Write();
138  fAnalysisManager->CloseFile();
139  delete fAnalysisManager;
140  }
141 
142 #ifdef G4VIS_USE
144  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
145  }
146 #endif
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetMaxEnergy() const
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
void BeginOfRun()
Definition: Run.cc:62
G4int GetNumberBins() const
static G4VVisManager * GetConcreteInstance()
G4int GetNumberBinsCluster() const
G4double GetFactorALICE() const
const G4StatDouble * GetStat() const
Definition: Run.hh:129
void Book()
Definition: RunAction.cc:65
virtual G4Run * GenerateRun()
Definition: RunAction.cc:66
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4String fHistName
Definition: RunAction.hh:81
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
~RunAction()
Definition: RunAction.cc:52
G4AnalysisManager * fAnalysisManager
Definition: RunAction.hh:77
G4double mean() const
Definition: G4StatDouble.cc:77
static TestParameters * GetPointer()
void EndOfRun()
Definition: Run.cc:147
#define G4endl
Definition: G4ios.hh:61
static const double keV
Definition: G4SIunits.hh:195
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
Run * fRun
Definition: RunAction.hh:65