Geant4  10.02.p02
B5RunAction.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: B5RunAction.cc 74204 2013-10-01 07:04:43Z ihrivnac $
27 //
30 
31 #include "B5RunAction.hh"
32 #include "B5EventAction.hh"
33 #include "B5Analysis.hh"
34 
35 #include "G4Run.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4SystemOfUnits.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
42  : G4UserRunAction(),
43  fEventAction(eventAction)
44 {
45  // Create analysis manager
46  // The choice of analysis technology is done via selectin of a namespace
47  // in B5Analysis.hh
48  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
49  G4cout << "Using " << analysisManager->GetType() << G4endl;
50 
51  // Default settings
52  analysisManager->SetVerboseLevel(1);
53  analysisManager->SetFileName("B5");
54 
55  // Book histograms, ntuple
56  //
57 
58  // Creating 1D histograms
59  analysisManager
60  ->CreateH1("Chamber1","Drift Chamber 1 # Hits", 50, 0., 50); // h1 Id = 0
61  analysisManager
62  ->CreateH1("Chamber2","Drift Chamber 2 # Hits", 50, 0., 50); // h1 Id = 1
63 
64  // Creating 2D histograms
65  analysisManager
66  ->CreateH2("Chamber1 XY","Drift Chamber 1 X vs Y", // h2 Id = 0
67  50, -1000., 1000, 50, -300., 300.);
68  analysisManager
69  ->CreateH2("Chamber2 XY","Drift Chamber 2 X vs Y", // h2 Id = 1
70  50, -1500., 1500, 50, -300., 300.);
71 
72  // Creating ntuple
73  //
74  if ( fEventAction ) {
75  analysisManager->CreateNtuple("B5", "Hits");
76  analysisManager->CreateNtupleIColumn("Dc1Hits"); // column Id = 0
77  analysisManager->CreateNtupleIColumn("Dc2Hits"); // column Id = 1
78  analysisManager->CreateNtupleDColumn("ECEnergy"); // column Id = 2
79  analysisManager->CreateNtupleDColumn("HCEnergy"); // column Id = 3
80  analysisManager->CreateNtupleDColumn("Time1"); // column Id = 4
81  analysisManager->CreateNtupleDColumn("Time2"); // column Id = 5
82  analysisManager // column Id = 6
83  ->CreateNtupleDColumn("ECEnergyVector", fEventAction->GetEmCalEdep());
84  analysisManager // column Id = 7
85  ->CreateNtupleDColumn("HCEnergyVector", fEventAction->GetHadCalEdep());
86  analysisManager->FinishNtuple();
87  }
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  delete G4AnalysisManager::Instance();
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100 {
101  //inform the runManager to save random number seed
102  //G4RunManager::GetRunManager()->SetRandomNumberStore(true);
103 
104  // Get analysis manager
105  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
106 
107  // Open an output file
108  // The default file name is set in B5RunAction::B5RunAction(),
109  // it can be overwritten in a macro
110  analysisManager->OpenFile();
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114 
115 void B5RunAction::EndOfRunAction(const G4Run* /*run*/)
116 {
117  // save histograms & ntuple
118  //
119  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
120  analysisManager->Write();
121  analysisManager->CloseFile();
122 
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void BeginOfRunAction(const G4Run *)
Definition: B5RunAction.cc:99
G4int CreateNtupleIColumn(const G4String &name)
Definition of the B5EventAction class.
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
void SetVerboseLevel(G4int verboseLevel)
G4int CreateNtuple(const G4String &name, const G4String &title)
G4bool SetFileName(const G4String &fileName)
B5EventAction * fEventAction
Definition: B5RunAction.hh:53
G4bool OpenFile(const G4String &fileName="")
B5RunAction(B5EventAction *eventAction)
Definition: B5RunAction.cc:41
G4GLOB_DLL std::ostream G4cout
std::vector< G4double > & GetEmCalEdep()
Definition: G4Run.hh:46
Definition of the B5RunAction class.
Event action.
Selection of the analysis technology.
G4String GetType() const
virtual ~B5RunAction()
Definition: B5RunAction.cc:92
#define G4endl
Definition: G4ios.hh:61
G4int CreateNtupleDColumn(const G4String &name)
std::vector< G4double > & GetHadCalEdep()
G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
virtual void EndOfRunAction(const G4Run *)
Definition: B5RunAction.cc:115