Warning, file /geant4/examples/extended/analysis/AnaEx03/src/RunAction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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
0030
0031
0032
0033
0034 #include "RunAction.hh"
0035
0036 #include "G4AnalysisManager.hh"
0037 #include "G4GenericMessenger.hh"
0038 #include "G4Run.hh"
0039 #include "G4RunManager.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4UnitsTable.hh"
0042
0043
0044
0045 RunAction::RunAction()
0046 {
0047
0048
0049
0050 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0051 analysisManager->SetDefaultFileType("root");
0052 analysisManager->SetVerboseLevel(1);
0053
0054 #ifdef G4MULTITHREADED
0055 analysisManager->SetNtupleMerging(true);
0056 #endif
0057
0058
0059 analysisManager->SetHistoDirectoryName("histo");
0060 analysisManager->SetNtupleDirectoryName("ntuple");
0061
0062
0063
0064
0065
0066
0067
0068 analysisManager->CreateH1("EAbs", "Edep in absorber (MeV)", 100, 0., 800 * MeV);
0069
0070 analysisManager->CreateH1("EGap", "Edep in gap (MeV)", 100, 0., 100 * MeV);
0071
0072 analysisManager->CreateH1("LAbs", "trackL in absorber (mm)", 100, 0., 1 * m);
0073
0074 analysisManager->CreateH1("LGap", "trackL in gap (mm)", 100, 0., 50 * cm);
0075
0076
0077
0078
0079
0080
0081
0082 analysisManager->CreateNtuple("Ntuple1", "Edep");
0083 analysisManager->CreateNtupleDColumn("Eabs");
0084 analysisManager->CreateNtupleDColumn("Egap");
0085 analysisManager->FinishNtuple();
0086
0087
0088
0089 analysisManager->CreateNtuple("Ntuple2", "TrackL");
0090 analysisManager->CreateNtupleDColumn("Labs");
0091 analysisManager->CreateNtupleDColumn("Lgap");
0092 analysisManager->FinishNtuple();
0093
0094 DefineCommands();
0095 }
0096
0097
0098
0099 RunAction::~RunAction() = default;
0100
0101
0102
0103 void RunAction::BeginOfRunAction(const G4Run* run)
0104 {
0105 G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
0106 }
0107
0108
0109
0110 void RunAction::EndOfRunAction(const G4Run* ) {}
0111
0112
0113
0114 void RunAction::PrintStatistic()
0115 {
0116 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0117
0118 G4cout << "\n ----> print histograms statistic \n" << G4endl;
0119 for (G4int i = 0; i < analysisManager->GetNofH1s(); ++i) {
0120 auto h1 = analysisManager->GetH1(i);
0121
0122 if (h1 == nullptr) continue;
0123
0124 G4String name = analysisManager->GetH1Name(i);
0125 G4String unitCategory;
0126 if (name[0U] == 'E') {
0127 unitCategory = "Energy";
0128 }
0129 if (name[0U] == 'L') {
0130 unitCategory = "Length";
0131 }
0132
0133
0134
0135 G4cout << name << ": mean = " << G4BestUnit(h1->mean(), unitCategory)
0136 << " rms = " << G4BestUnit(h1->rms(), unitCategory) << G4endl;
0137 }
0138 }
0139
0140
0141
0142 void RunAction::DefineCommands()
0143 {
0144
0145 fMessenger = new G4GenericMessenger(this, "/AnaEx03/runAction/", "Run action commands");
0146
0147
0148 auto& printStatisticCmd = fMessenger->DeclareMethod("printStatistic", &RunAction::PrintStatistic,
0149 "Print statistic at the end of Run.");
0150 printStatisticCmd.SetToBeBroadcasted(false);
0151 }
0152
0153