Loading...
Searching...
No Matches
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//
26//
27/// \file B4/B4b/src/RunAction.cc
28/// \brief Implementation of the B4b::RunAction class
29
30#include "RunAction.hh"
31#include "RunData.hh"
32
33#include "G4AnalysisManager.hh"
34#include "G4Run.hh"
35#include "G4RunManager.hh"
36#include "G4UnitsTable.hh"
37#include "G4SystemOfUnits.hh"
38
39namespace B4b
40{
41
42//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43
45{
46 // set printing event number per each event
47 G4RunManager::GetRunManager()->SetPrintProgress(1);
48
49 // Create analysis manager
50 // The choice of analysis technology is done via selectin of a namespace
51 // in Analysis.hh
52 auto analysisManager = G4AnalysisManager::Instance();
53
54 // Create directories
55 //analysisManager->SetHistoDirectoryName("histograms");
56 //analysisManager->SetNtupleDirectoryName("ntuple");
57 analysisManager->SetVerboseLevel(1);
58 analysisManager->SetNtupleMerging(true);
59 // Note: merging ntuples is available only with Root output
60
61 // Book histograms, ntuple
62 //
63
64 // Creating histograms
65 analysisManager->CreateH1("Eabs" ,"Edep in absorber", 110, 0., 330*MeV);
66 analysisManager->CreateH1("Egap" ,"Edep in gap", 100, 0., 30*MeV);
67 analysisManager->CreateH1("Labs" ,"trackL in absorber", 100, 0., 50*cm);
68 analysisManager->CreateH1("Lgap" ,"trackL in gap", 100, 0., 50*cm);
69
70 // Creating ntuple
71 //
72 analysisManager->CreateNtuple("B4", "Edep and TrackL");
73 analysisManager->CreateNtupleDColumn("Eabs");
74 analysisManager->CreateNtupleDColumn("Egap");
75 analysisManager->CreateNtupleDColumn("Labs");
76 analysisManager->CreateNtupleDColumn("Lgap");
77 analysisManager->FinishNtuple();
78}
79
80//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81
83{
84 return (new RunData);
85}
86
87//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88
90{
91 G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
92
93 //inform the runManager to save random number seed
94 //G4RunManager::GetRunManager()->SetRandomNumberStore(true);
95
96 // Get analysis manager
97 auto analysisManager = G4AnalysisManager::Instance();
98
99 // Open an output file
100 //
101 G4String fileName = "B4.root";
102 // Other supported output types:
103 // G4String fileName = "B4.csv";
104 // G4String fileName = "B4.hdf5";
105 // G4String fileName = "B4.xml";
106 analysisManager->OpenFile(fileName);
107 G4cout << "Using " << analysisManager->GetType() << G4endl;
108}
109
110//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111
112void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
113{
114 // print histogram statistics
115 //
116 auto analysisManager = G4AnalysisManager::Instance();
117 if ( analysisManager->GetH1(1) ) {
118 G4cout << G4endl << " ----> print histograms statistic ";
119 if(isMaster) {
120 G4cout << "for the entire run " << G4endl << G4endl;
121 }
122 else {
123 G4cout << "for the local thread " << G4endl << G4endl;
124 }
125
126 G4cout << " EAbs : mean = "
127 << G4BestUnit(analysisManager->GetH1(0)->mean(), "Energy")
128 << " rms = "
129 << G4BestUnit(analysisManager->GetH1(0)->rms(), "Energy") << G4endl;
130
131 G4cout << " EGap : mean = "
132 << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
133 << " rms = "
134 << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
135
136 G4cout << " LAbs : mean = "
137 << G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
138 << " rms = "
139 << G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
140
141 G4cout << " LGap : mean = "
142 << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
143 << " rms = "
144 << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
145 }
146
147 // save histograms & ntuple
148 //
149 analysisManager->Write();
150 analysisManager->CloseFile();
151
152}
153
154//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155
156}
Definition of the B4b::RunData class.
void BeginOfRunAction(const G4Run *) override
Definition RunAction.cc:89
void EndOfRunAction(const G4Run *) override
Definition RunAction.cc:112
G4Run * GenerateRun() override
Definition RunAction.cc:82
Run data class.

Applications | User Support | Publications | Collaboration