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