File indexing completed on 2025-10-16 08:10:14
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
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 #include "RunAction.hh"
0046
0047 #include "Run.hh"
0048
0049 #include "G4Run.hh"
0050 #include "G4RunManager.hh"
0051 #include "G4SystemOfUnits.hh"
0052 #include "G4UnitsTable.hh"
0053 #include "G4DNAChemistryManager.hh"
0054
0055
0056
0057 extern std::ofstream out;
0058
0059 RunAction::RunAction() : G4UserRunAction() {}
0060
0061
0062
0063 RunAction::~RunAction() {}
0064
0065
0066
0067 G4Run* RunAction::GenerateRun()
0068 {
0069 Run* run = new Run();
0070 return run;
0071 }
0072
0073
0074
0075 void RunAction::BeginOfRunAction(const G4Run* run)
0076 {
0077
0078 if (G4DNAChemistryManager::GetInstanceIfExists() != nullptr)
0079 G4DNAChemistryManager::GetInstanceIfExists()->BeginOfRunAction(run);
0080 G4cout << "### Run " << run->GetRunID() << " starts." << G4endl;
0081
0082
0083 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0084 }
0085
0086
0087
0088 void RunAction::EndOfRunAction(const G4Run* run)
0089 {
0090
0091 if (G4DNAChemistryManager::GetInstanceIfExists() != nullptr)
0092 G4DNAChemistryManager::GetInstanceIfExists()->EndOfRunAction(run);
0093
0094 G4int nofEvents = run->GetNumberOfEvent();
0095 if (nofEvents == 0) return;
0096
0097
0098
0099 const Run* chem6Run = static_cast<const Run*>(run);
0100 G4double sumDose = chem6Run->GetSumDose();
0101
0102
0103
0104 if (IsMaster()) {
0105 G4cout << G4endl << "--------------------End of Global Run-----------------------" << G4endl
0106 << " The run has " << nofEvents << " events " << G4endl;
0107
0108 ScoreSpecies* masterScorer = dynamic_cast<ScoreSpecies*>(chem6Run->GetPrimitiveScorer());
0109
0110 G4cout << "Number of events recorded by the species scorer = "
0111 << masterScorer->GetNumberOfRecordedEvents() << G4endl;
0112
0113
0114 Run* aRun = (Run*)run;
0115 G4THitsMap<G4double>* totLET = aRun->GetLET();
0116 G4int nOfEvent = totLET->entries();
0117 G4double LET_mean = 0;
0118 G4double LET_square = 0;
0119 for (G4int i = 0; i < nOfEvent; i++) {
0120 G4double* LET = (*totLET)[i];
0121 if (!LET) continue;
0122 LET_mean += *LET;
0123 LET_square += (*LET) * (*LET);
0124 }
0125 LET_mean /= nOfEvent;
0126 LET_square = std::sqrt(LET_square / nOfEvent - std::pow(LET_mean, 2));
0127
0128 if (nOfEvent > 1) {
0129 out << std::setw(12) << "LET" << std::setw(12) << LET_mean << std::setw(12) << "LET_SD"
0130 << std::setw(12) << LET_square / (nOfEvent - 1) << '\n';
0131 }
0132 else {
0133 out << std::setw(12) << "LET" << std::setw(12) << LET_mean << std::setw(12) << "LET_SD"
0134 << std::setw(12) << LET_square << '\n';
0135 }
0136
0137 masterScorer->OutputAndClear();
0138
0139 out << '\n';
0140 }
0141 else {
0142 G4cout << G4endl << "--------------------End of Local Run------------------------" << G4endl
0143 << " The run has " << nofEvents << " events" << G4endl;
0144 }
0145
0146 G4cout << " Total energy deposited in the world volume : " << sumDose / eV << " eV" << G4endl
0147 << " ------------------------------------------------------------" << G4endl << G4endl;
0148 }
0149
0150