Geant4  10.02
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 92047 2015-08-14 07:23:37Z 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)
56 {
58  fAnalysisManager = G4AnalysisManager::Instance();
59  fAnalysisManager->SetFileName("testem8");
60  fAnalysisManager->SetVerboseLevel(1);
61  fAnalysisManager->SetActivation(true);
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {}
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72 {
73  // Always creating analysis manager
75  G4int nBinsE = param->GetNumberBins();
76  G4int nBinsCluster = param->GetNumberBinsCluster();
77  G4int nMaxCluster = param->GetMaxCluster();
78  G4double maxEnergy = param->GetMaxEnergy();
79  G4double factorALICE = param->GetFactorALICE();
80 
81  //G4cout << "### maxenergy(keV)= " << maxEnergy/keV
82  // << " factorALICE= " << factorALICE << G4endl;
83 
84  // Creating an 1-dimensional histograms in the root directory of the tree
85  fAnalysisManager->SetFirstHistoId(1);
86  fAnalysisManager->CreateH1("h1","Energy deposition in detector (keV)",
87  nBinsE,0.0,maxEnergy/keV);
88  fAnalysisManager->CreateH1("h2","Number of primary clusters",
89  nBinsCluster,0.0,G4double(nMaxCluster));
90  fAnalysisManager->CreateH1("h3","Energy deposition in detector (ADC)",
91  nBinsE,0.0,maxEnergy*factorALICE);
92  fAnalysisManager->OpenFile();
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
98 {
99  fRun = new Run();
100  return fRun;
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
105 void RunAction::BeginOfRunAction(const G4Run* aRun)
106 {
107  G4int id = aRun->GetRunID();
108  G4cout << "### Run " << id << " start analysis activation: "
109  << G4endl;
110 
111  fRun->BeginOfRun();
112 
113  //histograms
114  Book();
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
119 void RunAction::EndOfRunAction(const G4Run*)
120 {
121  // print Run summary
122  G4cout << "RunAction: End of run actions are started " << isMaster
123  << " Nevt= " << fRun->GetNumberOfEvent()
124  << " Edep= " << fRun->GetStat()->mean() << G4endl;
125  if (isMaster) {
126  fRun->EndOfRun();
127  }
128  // save histos and close analysis
129  if (fAnalysisManager->IsActive()) {
130  fAnalysisManager->Write();
131  fAnalysisManager->CloseFile();
132  }
133  //delete fAnalysisManager;
134 
135 #ifdef G4VIS_USE
137  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
138  }
139 #endif
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetMaxEnergy() const
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
void BeginOfRun()
Definition: Run.cc:64
G4int GetNumberBins() const
static G4VVisManager * GetConcreteInstance()
G4int GetNumberBinsCluster() const
G4double GetFactorALICE() const
const G4StatDouble * GetStat() const
Definition: Run.hh:130
void Book()
Definition: RunAction.cc:71
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
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4int GetRunID() const
Definition: G4Run.hh:76
G4int GetMaxCluster() const
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:213
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
Run * fRun
Definition: RunAction.hh:65