File indexing completed on 2026-09-15 08:28:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "RunAction.hh"
0030
0031 #include "G4AnalysisManager.hh"
0032 #include "G4GenericMessenger.hh"
0033 #include "G4Run.hh"
0034 #include "G4RunManager.hh"
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4UnitsTable.hh"
0037
0038
0039
0040 RunAction::RunAction()
0041 {
0042
0043 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0044 analysisManager->SetDefaultFileType("root");
0045 analysisManager->SetVerboseLevel(1);
0046
0047 #ifdef G4MULTITHREADED
0048 analysisManager->SetNtupleMerging(true);
0049 #endif
0050
0051
0052 analysisManager->SetHistoDirectoryName("histo");
0053 analysisManager->SetNtupleDirectoryName("ntuple");
0054
0055
0056
0057
0058
0059
0060
0061 analysisManager->CreateH1("EAbs", "Edep in absorber (MeV)", 100, 0., 800 * MeV);
0062
0063 analysisManager->CreateH1("EGap", "Edep in gap (MeV)", 100, 0., 100 * MeV);
0064
0065 analysisManager->CreateH1("LAbs", "trackL in absorber (mm)", 100, 0., 1 * m);
0066
0067 analysisManager->CreateH1("LGap", "trackL in gap (mm)", 100, 0., 50 * cm);
0068
0069
0070
0071
0072
0073
0074
0075 analysisManager->CreateNtuple("Ntuple1", "Edep");
0076 analysisManager->CreateNtupleDColumn("Eabs");
0077 analysisManager->CreateNtupleDColumn("Egap");
0078 analysisManager->FinishNtuple();
0079
0080
0081
0082 analysisManager->CreateNtuple("Ntuple2", "TrackL");
0083 analysisManager->CreateNtupleDColumn("Labs");
0084 analysisManager->CreateNtupleDColumn("Lgap");
0085 analysisManager->FinishNtuple();
0086
0087 DefineCommands();
0088 }
0089
0090
0091
0092 RunAction::~RunAction() = default;
0093
0094
0095
0096 void RunAction::BeginOfRunAction(const G4Run* run)
0097 {
0098 G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
0099 }
0100
0101
0102
0103 void RunAction::EndOfRunAction(const G4Run* ) {}
0104
0105
0106
0107 void RunAction::PrintStatistic()
0108 {
0109 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0110
0111 G4cout << "\n ----> print histograms statistic \n" << G4endl;
0112 for (G4int i = 0; i < analysisManager->GetNofH1s(); ++i) {
0113 auto h1 = analysisManager->GetH1(i);
0114
0115 if (h1 == nullptr) continue;
0116
0117 G4String name = analysisManager->GetH1Name(i);
0118 G4String unitCategory;
0119 if (name[0U] == 'E') {
0120 unitCategory = "Energy";
0121 }
0122 if (name[0U] == 'L') {
0123 unitCategory = "Length";
0124 }
0125
0126
0127
0128 G4cout << name << ": mean = " << G4BestUnit(h1->mean(), unitCategory)
0129 << " rms = " << G4BestUnit(h1->rms(), unitCategory) << G4endl;
0130 }
0131 }
0132
0133
0134
0135 void RunAction::DefineCommands()
0136 {
0137
0138 fMessenger = new G4GenericMessenger(this, "/AnaEx03/runAction/", "Run action commands");
0139
0140
0141 auto& printStatisticCmd = fMessenger->DeclareMethod("printStatistic", &RunAction::PrintStatistic,
0142 "Print statistic at the end of Run.");
0143 printStatisticCmd.SetToBeBroadcasted(false);
0144 }
0145
0146