ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B4RunAction.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 "B4RunAction.hh"
31 #include "B4Analysis.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 
41  : G4UserRunAction()
42 {
43  // set printing event number per each event
45 
46  // Create analysis manager
47  // The choice of analysis technology is done via selectin of a namespace
48  // in B4Analysis.hh
49  auto analysisManager = G4AnalysisManager::Instance();
50  G4cout << "Using " << analysisManager->GetType() << G4endl;
51 
52  // Create directories
53  //analysisManager->SetHistoDirectoryName("histograms");
54  //analysisManager->SetNtupleDirectoryName("ntuple");
55  analysisManager->SetVerboseLevel(1);
56  analysisManager->SetNtupleMerging(true);
57  // Note: merging ntuples is available only with Root output
58 
59  // Book histograms, ntuple
60  //
61 
62  // Creating histograms
63  analysisManager->CreateH1("Eabs","Edep in absorber", 100, 0., 800*MeV);
64  analysisManager->CreateH1("Egap","Edep in gap", 100, 0., 100*MeV);
65  analysisManager->CreateH1("Labs","trackL in absorber", 100, 0., 1*m);
66  analysisManager->CreateH1("Lgap","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 {
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  auto 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  auto analysisManager = G4AnalysisManager::Instance();
108  if ( analysisManager->GetH1(1) ) {
109  G4cout << G4endl << " ----> print histograms statistic ";
110  if(isMaster) {
111  G4cout << "for the entire run " << G4endl << G4endl;
112  }
113  else {
114  G4cout << "for the local thread " << G4endl << G4endl;
115  }
116 
117  G4cout << " EAbs : mean = "
118  << G4BestUnit(analysisManager->GetH1(0)->mean(), "Energy")
119  << " rms = "
120  << G4BestUnit(analysisManager->GetH1(0)->rms(), "Energy") << G4endl;
121 
122  G4cout << " EGap : mean = "
123  << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
124  << " rms = "
125  << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
126 
127  G4cout << " LAbs : mean = "
128  << G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
129  << " rms = "
130  << G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
131 
132  G4cout << " LGap : mean = "
133  << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
134  << " rms = "
135  << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
136  }
137 
138  // save histograms & ntuple
139  //
140  analysisManager->Write();
141  analysisManager->CloseFile();
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......