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