File indexing completed on 2026-09-18 08:32:33
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 "Run.hh"
0032
0033 #include "G4AnalysisManager.hh"
0034 #include "G4DNAEventScheduler.hh"
0035 #include "G4DNAScavengerMaterial.hh"
0036 #include "G4Run.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4Scheduler.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4VChemistryWorld.hh"
0041
0042
0043 RunAction::RunAction() : G4UserRunAction() {}
0044
0045
0046 void RunAction::SetEventScheduler(G4DNAEventScheduler* pEventScheduler)
0047 {
0048 fpEventScheduler = pEventScheduler;
0049 }
0050
0051
0052 G4Run* RunAction::GenerateRun()
0053 {
0054 Run* run = new Run();
0055 return run;
0056 }
0057
0058
0059
0060 void RunAction::BeginOfRunAction(const G4Run* run)
0061 {
0062 G4cout << "### Run " << run->GetRunID() << " starts." << G4endl;
0063 if (G4Threading::IsMultithreadedApplication() && IsMaster()) {
0064 return;
0065 }
0066 auto runInfo = dynamic_cast<const Run*>(run);
0067 auto GvaluesScorer = dynamic_cast<Scorer<Gvalues>*>(runInfo->GetGvaluesScorer());
0068
0069 if (fpEventScheduler != nullptr) {
0070 for (const auto& it : GvaluesScorer->GetpScorer()->fTimeToRecord) {
0071 fpEventScheduler->AddTimeToRecord(it);
0072 }
0073 }
0074 GvaluesScorer->SetEventScheduler(fpEventScheduler);
0075 }
0076
0077
0078
0079 void RunAction::EndOfRunAction(const G4Run* run)
0080 {
0081 G4int nofEvents = run->GetNumberOfEvent();
0082 if (nofEvents == 0) {
0083 return;
0084 }
0085 auto pRun = dynamic_cast<const Run*>(run);
0086 G4double sumDose = pRun->GetSumDose();
0087
0088 if (G4Threading::IsMultithreadedApplication() && IsMaster()) {
0089 G4cout << G4endl << "--------------------------End of Global Run------------------------------"
0090 << G4endl << "The run has " << nofEvents << " events " << G4endl;
0091
0092 auto masterGvaluesScorer = dynamic_cast<Scorer<Gvalues>*>(pRun->GetGvaluesScorer());
0093
0094 auto masterDoseLimite = dynamic_cast<Scorer<Dose>*>(pRun->GetSumDoseLimit());
0095
0096 G4cout << "Number of events recorded by the species scorer : "
0097 << masterGvaluesScorer->GetpScorer()->GetNumberOfRecordedEvents() << " events "
0098 << G4endl;
0099 G4double dose_mean = masterDoseLimite->GetpScorer()->fDosesCutOff / gray;
0100 auto boundingBox = masterDoseLimite->GetChemistryWorld()->GetChemistryBoundary();
0101 G4double V = boundingBox->Volume() / cm3;
0102 G4double DoseInGray = (sumDose / eV) / (0.001 * V * 6.242e+18);
0103 G4cout << "Cut-off dose for each beam line : " << dose_mean << " Gy " << G4endl;
0104 G4cout << "Actual dose : " << DoseInGray << " Gy for " << nofEvents
0105 << " events. Actual average dose : " << DoseInGray / nofEvents << " Gy" << G4endl;
0106 masterGvaluesScorer->OutputAndClear(std::to_string(dose_mean));
0107 }
0108 else {
0109 G4cout << G4endl << "--------------------------End of Local Run------------------------------"
0110 << G4endl << "The run has " << nofEvents << " events. Scavenger info:" << G4endl;
0111 auto pScavengerMaterial =
0112 dynamic_cast<G4DNAScavengerMaterial*>(G4Scheduler::Instance()->GetScavengerMaterial());
0113 pScavengerMaterial->PrintInfo();
0114 }
0115
0116 G4cout << "Total energy deposited in the world volume : " << sumDose / keV << " keV" << G4endl
0117 << "-------------------------------------------------------------------------" << G4endl
0118 << G4endl;
0119 }
0120
0121