File indexing completed on 2026-09-21 08:28:59
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 "PrimaryGeneratorAction.hh"
0032
0033 #include "G4AnalysisManager.hh"
0034 #include "G4ParticleGun.hh"
0035 #include "G4Run.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4UnitsTable.hh"
0039 #include "Randomize.hh"
0040
0041
0042
0043 RunAction::RunAction()
0044 {
0045 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0046 analysisManager->SetDefaultFileType("root");
0047 analysisManager->SetVerboseLevel(1);
0048 analysisManager->SetFirstHistoId(1);
0049
0050
0051
0052 analysisManager->CreateH1("1", "energy (MeV) deposited in C6F6", 100, 0., 10.);
0053 }
0054
0055
0056
0057 void RunAction::BeginOfRunAction(const G4Run*)
0058 {
0059
0060 if (isMaster) G4Random::showEngineStatus();
0061
0062
0063 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0064
0065
0066
0067 G4String fileName = "testem4";
0068 analysisManager->OpenFile(fileName);
0069 }
0070
0071
0072
0073 void RunAction::EndOfRunAction(const G4Run* run)
0074 {
0075 G4int nofEvents = run->GetNumberOfEvent();
0076 if (nofEvents == 0) return;
0077
0078 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0079
0080 if (isMaster) {
0081
0082
0083
0084 PrimaryGeneratorAction* generatorAction =
0085 (PrimaryGeneratorAction*)(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0086 G4String runCondition = " ";
0087 if (generatorAction) {
0088 G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0089 runCondition = particleGun->GetParticleDefinition()->GetParticleName();
0090 runCondition += " of ";
0091 G4double particleEnergy = particleGun->GetParticleEnergy();
0092 runCondition += G4BestUnit(particleEnergy, "Energy");
0093 runCondition += " in a volume of C6F6 ";
0094 }
0095
0096 G4cout << G4endl << "--------------------End of Global Run------------------------";
0097 G4cout << G4endl << " The run consists of " << nofEvents << " " << runCondition << G4endl;
0098 if (analysisManager->GetH1(1)) {
0099 G4cout << " Energy deposit per event: mean = "
0100 << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
0101 << " rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl
0102 << "------------------------------------------------------------" << G4endl;
0103 }
0104 }
0105
0106
0107 if (isMaster) G4Random::showEngineStatus();
0108
0109
0110 analysisManager->Write();
0111 analysisManager->CloseFile();
0112 }
0113
0114