ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RunAction.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 "RunAction.hh"
31 #include "Analysis.hh"
32 
33 #include "G4Run.hh"
34 #include "G4RunManager.hh"
35 #include "G4UnitsTable.hh"
36 #include "G4SystemOfUnits.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
40 RunAction::RunAction(const G4String& fileName)
41  : G4UserRunAction(),
42  fFileName(fileName)
43 {
44  // Create analysis manager
45  // The choice of analysis technology is done via selectin of a namespace
46  // in Analysis.hh
47  auto analysisManager = G4AnalysisManager::Instance();
48  G4cout << "Using " << analysisManager->GetType() << G4endl;
49  analysisManager->SetVerboseLevel(1);
50  analysisManager->SetNtupleMerging(true);
51  // Note: merging ntuples is available only with Root output
52 
53  // Set default fileName
54  analysisManager->SetFileName(fFileName);
55 
56  // Create ntuple
57  //
58  analysisManager->CreateNtuple("Screen", "Screen hits");
59  analysisManager->CreateNtupleIColumn("ID"); // column id = 0
60  analysisManager->CreateNtupleIColumn("PDG"); // column id = 1
61  analysisManager->CreateNtupleDColumn("Ekin"); // column id = 2
62  analysisManager->CreateNtupleDColumn("Xpos"); // column id = 3
63  analysisManager->CreateNtupleDColumn("Ypos"); // column id = 4
64  analysisManager->CreateNtupleDColumn("time"); // column id = 5
65  analysisManager->FinishNtuple();
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
71 {
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
77 void RunAction::BeginOfRunAction(const G4Run* /*run*/)
78 {
79  // Get analysis manager
80  auto analysisManager = G4AnalysisManager::Instance();
81 
82  // Open an output file
83  analysisManager->OpenFile();
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
88 void RunAction::EndOfRunAction(const G4Run* /*run*/)
89 {
90  // Save ntuple and close file
91  auto analysisManager = G4AnalysisManager::Instance();
92  analysisManager->Write();
93  analysisManager->CloseFile();
94 }
95 
96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......