G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
RunAction.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
27
28#include "RunAction.hh"
29
30// Callgrind instrumentation macros — gate collection around the tracking run
31// so initialization (STEP load, geometry construction, physics init) is excluded
32// from the profile. When valgrind headers are not available the macros expand to
33// no-ops so the binary is usable without valgrind.
34#ifdef HAVE_VALGRIND_CALLGRIND_H
35#include <valgrind/callgrind.h>
36#else
37#define CALLGRIND_START_INSTRUMENTATION \
38 do { \
39 } while (0)
40#define CALLGRIND_STOP_INSTRUMENTATION \
41 do { \
42 } while (0)
43#define CALLGRIND_TOGGLE_COLLECT \
44 do { \
45 } while (0)
46#endif
47
48#include "G4AnalysisManager.hh"
49#include "G4RunManager.hh"
50#include "G4SystemOfUnits.hh"
51#include "G4UnitsTable.hh"
52#include "globals.hh"
53
54namespace B4 {
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
59 // set printing event number per each event
60 G4RunManager::GetRunManager()->SetPrintProgress(1);
61
62 // Create analysis manager
63 // The choice of the output format is done via the specified
64 // file extension.
65 auto analysisManager = G4AnalysisManager::Instance();
66
67 // Create directories
68 // analysisManager->SetHistoDirectoryName("histograms");
69 // analysisManager->SetNtupleDirectoryName("ntuple");
70 analysisManager->SetVerboseLevel(1);
71 analysisManager->SetNtupleMerging(true);
72 // Note: merging ntuples is available only with Root output
73
74 // Book histograms, ntuple
75 //
76
77 // Creating histograms
78 analysisManager->CreateH1("Eabs", "Edep in absorber", 110, 0., 330 * MeV);
79 analysisManager->CreateH1("Egap", "Edep in gap", 100, 0., 30 * MeV);
80 analysisManager->CreateH1("Labs", "trackL in absorber", 100, 0., 50 * cm);
81 analysisManager->CreateH1("Lgap", "trackL in gap", 100, 0., 50 * cm);
82
83 // Creating ntuple
84 //
85 analysisManager->CreateNtuple("B4", "Edep and TrackL");
86 analysisManager->CreateNtupleDColumn("Eabs");
87 analysisManager->CreateNtupleDColumn("Egap");
88 analysisManager->CreateNtupleDColumn("Labs");
89 analysisManager->CreateNtupleDColumn("Lgap");
90 analysisManager->FinishNtuple();
91}
92
93//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94
95void RunAction::BeginOfRunAction(const G4Run* /*run*/) {
98 // inform the runManager to save random number seed
99 // G4RunManager::GetRunManager()->SetRandomNumberStore(true);
100
101 // Get analysis manager
102 auto analysisManager = G4AnalysisManager::Instance();
103
104 // Open an output file
105 //
106 G4String fileName = "B4.root";
107 // Other supported output types:
108 // G4String fileName = "B4.csv";
109 // G4String fileName = "B4.hdf5";
110 // G4String fileName = "B4.xml";
111 analysisManager->OpenFile(fileName);
112 G4cout << "Using " << analysisManager->GetType() << G4endl;
113}
114
115//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116
117void RunAction::EndOfRunAction(const G4Run* /*run*/) {
120 // print histogram statistics
121 //
122 auto analysisManager = G4AnalysisManager::Instance();
123 if (analysisManager->GetH1(1)) {
124 G4cout << G4endl << " ----> print histograms statistic ";
125 if (isMaster) {
126 G4cout << "for the entire run " << G4endl << G4endl;
127 } else {
128 G4cout << "for the local thread " << G4endl << G4endl;
129 }
130
131 G4cout << " EAbs : mean = " << G4BestUnit(analysisManager->GetH1(0)->mean(), "Energy")
132 << " rms = " << G4BestUnit(analysisManager->GetH1(0)->rms(), "Energy") << G4endl;
133
134 G4cout << " EGap : mean = " << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
135 << " rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
136
137 G4cout << " LAbs : mean = " << G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
138 << " rms = " << G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
139
140 G4cout << " LGap : mean = " << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
141 << " rms = " << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
142 }
143
144 // save histograms & ntuple
145 //
146 analysisManager->Write();
147 analysisManager->CloseFile();
148}
149
150//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151
152} // namespace B4
#define CALLGRIND_START_INSTRUMENTATION
Definition RunAction.cc:37
#define CALLGRIND_TOGGLE_COLLECT
Definition RunAction.cc:43
#define CALLGRIND_STOP_INSTRUMENTATION
Definition RunAction.cc:40
void BeginOfRunAction(const G4Run *) override
Definition RunAction.cc:95
void EndOfRunAction(const G4Run *) override
Definition RunAction.cc:117