ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B5RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B5RunAction.cc
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 //
29 
30 #include "B5RunAction.hh"
31 #include "B5EventAction.hh"
32 
33 #include "G4Run.hh"
34 #include "G4UnitsTable.hh"
35 #include "G4SystemOfUnits.hh"
36 #include "g4analysis.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
41  : G4UserRunAction(),
42  fEventAction(eventAction)
43 {
44  // Create the analysis manager using a new factory method.
45  // The choice of analysis technology is done via the function argument.
46  auto analysisManager = G4Analysis::ManagerInstance("root");
47  G4cout << "Using " << analysisManager->GetType() << G4endl;
48 
49  // Default settings
50  analysisManager->SetNtupleMerging(true);
51  // Note: merging ntuples is available only with Root output
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 {
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  auto 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  auto analysisManager = G4AnalysisManager::Instance();
120  analysisManager->Write();
121  analysisManager->CloseFile();
122 
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......