File indexing completed on 2026-04-27 07:33:03
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 "DetectorConstruction.hh"
0032 #include "HistoManager.hh"
0033 #include "PhysicsList.hh"
0034 #include "PrimaryGeneratorAction.hh"
0035 #include "Run.hh"
0036 #include "StepMax.hh"
0037
0038 #include "G4EmCalculator.hh"
0039 #include "G4EmParameters.hh"
0040 #include "Randomize.hh"
0041
0042
0043
0044 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys, PrimaryGeneratorAction* kin)
0045 : fDetector(det), fPhysics(phys), fPrimary(kin)
0046 {
0047
0048 fHistoManager = new HistoManager();
0049 }
0050
0051
0052
0053 RunAction::~RunAction()
0054 {
0055 delete fHistoManager;
0056 }
0057
0058
0059
0060 G4Run* RunAction::GenerateRun()
0061 {
0062 fRun = new Run(fDetector);
0063 return fRun;
0064 }
0065
0066
0067
0068 void RunAction::BeginOfRunAction(const G4Run*)
0069 {
0070
0071 if (isMaster) {
0072 G4Random::showEngineStatus();
0073 G4EmParameters::Instance()->Dump();
0074 }
0075
0076
0077 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0078 if (analysisManager->IsActive()) {
0079 analysisManager->OpenFile();
0080 }
0081
0082 if (!fPrimary) return;
0083
0084
0085 G4ParticleDefinition* particle = fPrimary->GetParticleGun()->GetParticleDefinition();
0086 G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
0087 fRun->SetPrimary(particle, energy);
0088
0089
0090
0091 G4EmCalculator emCalculator;
0092 G4Material* material = fDetector->GetAbsorMaterial();
0093
0094 G4double csdaRange = DBL_MAX;
0095 if (particle->GetPDGCharge() != 0.) {
0096 csdaRange = emCalculator.GetCSDARange(energy, particle, material);
0097 fRun->SetCsdaRange(csdaRange);
0098 }
0099
0100
0101
0102 G4double stepMax = csdaRange;
0103 G4int ih = 1;
0104 if (analysisManager->GetH1Activation(ih))
0105 stepMax = analysisManager->GetH1Width(ih) * analysisManager->GetH1Unit(ih);
0106 ih = 8;
0107 if (analysisManager->GetH1Activation(ih)) {
0108 G4double width = analysisManager->GetH1Width(ih);
0109 stepMax = std::min(stepMax, width * csdaRange);
0110 }
0111 fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
0112
0113
0114
0115 }
0116
0117
0118
0119 void RunAction::EndOfRunAction(const G4Run*)
0120 {
0121 if (isMaster) fRun->EndOfRun();
0122
0123
0124 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0125 if (analysisManager->IsActive()) {
0126 analysisManager->Write();
0127 analysisManager->CloseFile();
0128 }
0129
0130
0131 if (isMaster) G4Random::showEngineStatus();
0132 }
0133
0134