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