Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
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 }
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 {
50 }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
54 void B4RunAction::BeginOfRunAction(const G4Run* run)
55 {
56  G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
57 
58  //inform the runManager to save random number seed
59  //G4RunManager::GetRunManager()->SetRandomNumberStore(true);
60 
61  // Book histograms, ntuple
62  //
63 
64  // Create analysis manager
65  // The choice of analysis technology is done via selectin of a namespace
66  // in B4Analysis.hh
67  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
68  G4cout << "Using " << analysisManager->GetType()
69  << " analysis manager" << G4endl;
70 
71  // Create directories
72  //analysisManager->SetHistoDirectoryName("histograms");
73  //analysisManager->SetNtupleDirectoryName("ntuple");
74 
75  // Open an output file
76  //
77  G4String fileName = "B4";
78  analysisManager->OpenFile(fileName);
79  analysisManager->SetFirstHistoId(1);
80 
81  // Creating histograms
82  //
83  analysisManager->CreateH1("1","Edep in absorber", 100, 0., 800*MeV);
84  analysisManager->CreateH1("2","Edep in gap", 100, 0., 100*MeV);
85  analysisManager->CreateH1("3","trackL in absorber", 100, 0., 1*m);
86  analysisManager->CreateH1("4","trackL in gap", 100, 0., 50*cm);
87 
88  // Creating ntuple
89  //
90  analysisManager->CreateNtuple("B4", "Edep and TrackL");
91  analysisManager->CreateNtupleDColumn("Eabs");
92  analysisManager->CreateNtupleDColumn("Egap");
93  analysisManager->CreateNtupleDColumn("Labs");
94  analysisManager->CreateNtupleDColumn("Lgap");
95  analysisManager->FinishNtuple();
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
100 void B4RunAction::EndOfRunAction(const G4Run* aRun)
101 {
102  G4int nofEvents = aRun->GetNumberOfEvent();
103  if ( nofEvents == 0 ) return;
104 
105  // print histogram statistics
106  //
107  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
108  if ( analysisManager->GetH1(1) ) {
109  G4cout << "\n ----> print histograms statistic \n" << G4endl;
110 
111  G4cout
112  << " EAbs : mean = " << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
113  << " rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy")
114  << G4endl;
115  G4cout
116  << " EGap : mean = " << G4BestUnit(analysisManager->GetH1(2)->mean(), "Energy")
117  << " rms = " << G4BestUnit(analysisManager->GetH1(2)->rms(), "Energy")
118  << G4endl;
119  G4cout
120  << " LAbs : mean = " << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
121  << " rms = " << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length")
122  << G4endl;
123  G4cout
124  << " LGap : mean = " << G4BestUnit(analysisManager->GetH1(4)->mean(), "Length")
125  << " rms = " << G4BestUnit(analysisManager->GetH1(4)->rms(), "Length")
126  << G4endl;
127  }
128 
129  // save histograms
130  //
131  analysisManager->Write();
132  analysisManager->CloseFile();
133 
134  // complete cleanup
135  //
136  delete G4AnalysisManager::Instance();
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......