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