File indexing completed on 2026-03-31 07:49:49
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 "RunMessenger.hh"
0032
0033 #include "G4AnalysisManager.hh"
0034 #include "G4PhysicalConstants.hh"
0035 #include "G4Run.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4ios.hh"
0038 #include "Randomize.hh"
0039
0040
0041
0042 RunAction::RunAction() : G4UserRunAction(), fRunMessenger(0), fRndmFreq(1)
0043 {
0044 fRunMessenger = new RunMessenger(this);
0045
0046 BookHisto();
0047 }
0048
0049
0050
0051 RunAction::~RunAction()
0052 {
0053 delete fRunMessenger;
0054 }
0055
0056
0057
0058 void RunAction::BookHisto()
0059 {
0060
0061 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0062 analysisManager->SetDefaultFileType("root");
0063 analysisManager->SetFileName("testem10");
0064 analysisManager->SetVerboseLevel(1);
0065 analysisManager->SetFirstHistoId(1);
0066 analysisManager->SetActivation(true);
0067
0068
0069 const G4int kMaxHisto = 5;
0070 const G4String id[] = {"1", "2", "3", "4", "5"};
0071 const G4String title[] = {"Edep",
0072 "XTR Gamma spectrum",
0073 "Secondary Gamma spectrum",
0074 "Secondary e- spectrum",
0075 "Edep.old"};
0076
0077 G4int nbins = 100;
0078 G4double vmin = 0.;
0079 G4double vmax = 100.;
0080
0081
0082
0083 for (G4int k = 0; k < kMaxHisto; k++) {
0084 G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
0085 analysisManager->SetH1Activation(ih, false);
0086 }
0087 }
0088
0089
0090
0091 void RunAction::BeginOfRunAction(const G4Run* aRun)
0092 {
0093 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0094
0095
0096 if (fRndmFreq > 0) {
0097 CLHEP::HepRandom::showEngineStatus();
0098 CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
0099 }
0100
0101
0102 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0103 if (analysisManager->IsActive()) {
0104 analysisManager->OpenFile();
0105 }
0106 }
0107
0108
0109
0110 void RunAction::EndOfRunAction(const G4Run* run)
0111 {
0112
0113 G4int nofEvents = run->GetNumberOfEvent();
0114 G4cout << " ================== run summary =====================" << G4endl;
0115 G4cout << " End of Run TotNbofEvents = " << nofEvents << G4endl;
0116
0117 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0118 if (analysisManager->GetH1(1)) {
0119 G4cout << " Mean energy deposit in absorber = " << analysisManager->GetH1(1)->mean() / MeV
0120 << " +-" << analysisManager->GetH1(1)->rms() / MeV << " MeV " << G4endl;
0121 }
0122 if (analysisManager->GetH1(2)) {
0123 G4cout << " Total number of XTR gammas = " << analysisManager->GetH1(2)->entries() << G4endl;
0124 }
0125 if (analysisManager->GetH1(3)) {
0126 G4cout << " Total number of all gammas = " << analysisManager->GetH1(3)->entries() << G4endl;
0127 }
0128
0129
0130 if (fRndmFreq == 1) {
0131 CLHEP::HepRandom::showEngineStatus();
0132 CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
0133 }
0134
0135
0136 if (analysisManager->IsActive()) {
0137 analysisManager->Write();
0138 analysisManager->CloseFile();
0139 }
0140 }
0141
0142