Geant4_10
B4RunAction.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 // $Id: B4RunAction.cc 75215 2013-10-29 16:07:06Z gcosmo $
27 //
30 
31 #include "B4RunAction.hh"
32 #include "B4Analysis.hh"
33 
34 #include "G4Run.hh"
35 #include "G4RunManager.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4SystemOfUnits.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
42  : G4UserRunAction()
43 {
44  // set printing event number per each event
46 
47  // Create analysis manager
48  // The choice of analysis technology is done via selectin of a namespace
49  // in B4Analysis.hh
50  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
51  G4cout << "Using " << analysisManager->GetType() << G4endl;
52 
53  // Create directories
54  //analysisManager->SetHistoDirectoryName("histograms");
55  //analysisManager->SetNtupleDirectoryName("ntuple");
56  analysisManager->SetVerboseLevel(1);
57  analysisManager->SetFirstHistoId(1);
58 
59  // Book histograms, ntuple
60  //
61 
62  // Creating histograms
63  analysisManager->CreateH1("1","Edep in absorber", 100, 0., 800*MeV);
64  analysisManager->CreateH1("2","Edep in gap", 100, 0., 100*MeV);
65  analysisManager->CreateH1("3","trackL in absorber", 100, 0., 1*m);
66  analysisManager->CreateH1("4","trackL in gap", 100, 0., 50*cm);
67 
68  // Creating ntuple
69  //
70  analysisManager->CreateNtuple("B4", "Edep and TrackL");
71  analysisManager->CreateNtupleDColumn("Eabs");
72  analysisManager->CreateNtupleDColumn("Egap");
73  analysisManager->CreateNtupleDColumn("Labs");
74  analysisManager->CreateNtupleDColumn("Lgap");
75  analysisManager->FinishNtuple();
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  delete G4AnalysisManager::Instance();
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
87 void B4RunAction::BeginOfRunAction(const G4Run* /*run*/)
88 {
89  //inform the runManager to save random number seed
90  //G4RunManager::GetRunManager()->SetRandomNumberStore(true);
91 
92  // Get analysis manager
93  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
94 
95  // Open an output file
96  //
97  G4String fileName = "B4";
98  analysisManager->OpenFile(fileName);
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
103 void B4RunAction::EndOfRunAction(const G4Run* /*run*/)
104 {
105  // print histogram statistics
106  //
107  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
108  if ( analysisManager->GetH1(1) ) {
109  G4cout << "\n ----> print histograms statistic ";
110  if(isMaster) {
111  G4cout << "for the entire run \n" << G4endl;
112  }
113  else {
114  G4cout << "for the local thread \n" << G4endl;
115  }
116 
117  G4cout << " EAbs : mean = "
118  << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
119  << " rms = "
120  << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
121 
122  G4cout << " EGap : mean = "
123  << G4BestUnit(analysisManager->GetH1(2)->mean(), "Energy")
124  << " rms = "
125  << G4BestUnit(analysisManager->GetH1(2)->rms(), "Energy") << G4endl;
126 
127  G4cout << " LAbs : mean = "
128  << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
129  << " rms = "
130  << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
131 
132  G4cout << " LGap : mean = "
133  << G4BestUnit(analysisManager->GetH1(4)->mean(), "Length")
134  << " rms = "
135  << G4BestUnit(analysisManager->GetH1(4)->rms(), "Length") << G4endl;
136  }
137 
138  // save histograms & ntuple
139  //
140  analysisManager->Write();
141  analysisManager->CloseFile();
142 
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetPrintProgress(G4int i)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4GLOB_DLL std::ostream G4cout
Definition: G4Run.hh:46
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
virtual void EndOfRunAction(const G4Run *)
Definition: B4RunAction.cc:103
virtual void BeginOfRunAction(const G4Run *)
Definition: B4RunAction.cc:87
#define G4endl
Definition: G4ios.hh:61
virtual ~B4RunAction()
Definition: B4RunAction.cc:80