Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
GarfieldRunAction.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/// \file GarfieldRunAction.cc
27/// \brief Implementation of the GarfieldRunAction class
28
29#include "GarfieldRunAction.hh"
30
31#include "G4Run.hh"
32#include "G4RunManager.hh"
33#include "G4SystemOfUnits.hh"
34#include "G4UnitsTable.hh"
35#include "GarfieldAnalysis.hh"
36
37//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38
40 // Print event number for each event
41 G4RunManager::GetRunManager()->SetPrintProgress(1);
42
43 // Create analysis manager
44 // The choice of analysis technology is done in GarfieldAnalysis.hh
45 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
46 G4cout << "Using " << analysisManager->GetType() << G4endl;
47
48 // Create directories
49 // analysisManager->SetHistoDirectoryName("histograms");
50 // analysisManager->SetNtupleDirectoryName("ntuple");
51 analysisManager->SetVerboseLevel(1);
52 analysisManager->SetFirstHistoId(1);
53
54 // Book histograms
55 analysisManager->CreateH1("1", "Edep in absorber", 100, 0., 800 * MeV);
56 analysisManager->CreateH1("2", "Track length in absorber", 100, 0., 1 * m);
57 analysisManager->CreateH1("3", "Edep in gas", 1000, 0., 100 * keV);
58
59 analysisManager->CreateH1("4", "Avalanche size in gas", 10000, 0, 10000);
60 analysisManager->CreateH1("5", "Gain", 1000, 0., 100);
61 analysisManager->CreateH3("1", "Track position", 200, -10 * cm, 10 * cm, 29,
62 -1.45 * cm, 1.45 * cm, 29, -1.45 * cm, 1.45 * cm);
63
64 // Book ntuple
65 analysisManager->CreateNtuple("Garfield", "Edep and TrackL");
66 analysisManager->CreateNtupleDColumn("Eabs");
67 analysisManager->CreateNtupleDColumn("Labs");
68 analysisManager->CreateNtupleDColumn("Egas");
69 analysisManager->CreateNtupleDColumn("AvalancheSize");
70 analysisManager->CreateNtupleDColumn("Gain");
71 analysisManager->FinishNtuple();
72}
73
74//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75
77#if (G4VERSION_NUMBER < 1100)
78 auto analysisManager = G4AnalysisManager::Instance();
79 if (analysisManager) delete analysisManager;
80#endif
81}
82
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84
85void GarfieldRunAction::BeginOfRunAction(const G4Run* /*run*/) {
86 // Inform the runManager to save random number seed
87 // G4RunManager::GetRunManager()->SetRandomNumberStore(true);
88
89 // Get analysis manager
90 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
91
92 // Open an output file
93 G4String fileName = "Garfield.root";
94 analysisManager->OpenFile(fileName);
95}
96
97//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98
99void GarfieldRunAction::EndOfRunAction(const G4Run* /*run*/) {
100 // Print histogram statistics
101 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
102 if (analysisManager->GetH1(1)) {
103 G4cout << G4endl << " ----> print histograms statistic ";
104 if (isMaster) {
105 G4cout << "for the entire run " << G4endl << G4endl;
106 } else {
107 G4cout << "for the local thread " << G4endl << G4endl;
108 }
109
110 G4cout << " EAbs : mean = "
111 << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
112 << " rms = "
113 << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
114
115 G4cout << " LAbs : mean = "
116 << G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
117 << " rms = "
118 << G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
119
120 G4cout << " EGas : mean = "
121 << G4BestUnit(analysisManager->GetH1(3)->mean(), "Energy")
122 << " rms = "
123 << G4BestUnit(analysisManager->GetH1(3)->rms(), "Energy") << G4endl;
124
125 G4cout << " Avalanche size : mean = " << analysisManager->GetH1(4)->mean()
126 << " rms = " << analysisManager->GetH1(4)->rms() << G4endl;
127
128 G4cout << " Gain : mean = " << analysisManager->GetH1(5)->mean()
129 << " rms = " << analysisManager->GetH1(5)->rms() << G4endl;
130 }
131
132 // Save histograms and ntuple
133 analysisManager->Write();
134 analysisManager->CloseFile();
135}
136
137//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Selection of the analysis technology.
Definition of the GarfieldRunAction class.
virtual void BeginOfRunAction(const G4Run *)
virtual void EndOfRunAction(const G4Run *)