File indexing completed on 2026-03-31 07:49:44
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 "DetectorConstruction.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033
0034 #include "G4AccumulableManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Run.hh"
0038 #include "G4RunManager.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4UnitsTable.hh"
0041
0042 namespace B1Con
0043 {
0044
0045
0046
0047 RunAction::RunAction()
0048 {
0049
0050
0051 const G4double milligray = 1.e-3 * gray;
0052 const G4double microgray = 1.e-6 * gray;
0053 const G4double nanogray = 1.e-9 * gray;
0054 const G4double picogray = 1.e-12 * gray;
0055
0056 new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
0057 new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
0058 new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
0059 new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
0060
0061
0062 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0063 accumulableManager->Register(fEdep);
0064 accumulableManager->Register(fEdep2);
0065 accumulableManager->Register(&fEdepPerEvent);
0066 }
0067
0068
0069
0070 void RunAction::BeginOfRunAction(const G4Run*)
0071 {
0072
0073 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0074
0075
0076 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0077 accumulableManager->Reset();
0078
0079 if (IsMaster()) {
0080 fDoseTally = new G4ConvergenceTester("DOSE_TALLY");
0081
0082 }
0083 }
0084
0085
0086
0087 void RunAction::EndOfRunAction(const G4Run* run)
0088 {
0089 G4int nofEvents = run->GetNumberOfEvent();
0090 if (nofEvents == 0) return;
0091
0092
0093 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0094 accumulableManager->Merge();
0095
0096
0097
0098 G4double edep = fEdep.GetValue();
0099 G4double edep2 = fEdep2.GetValue();
0100
0101 G4double rms = edep2 - edep * edep / nofEvents;
0102 if (rms > 0.)
0103 rms = std::sqrt(rms);
0104 else
0105 rms = 0.;
0106
0107 const auto detConstruction = static_cast<const B1::DetectorConstruction*>(
0108 G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0109 G4double mass = detConstruction->GetScoringVolume()->GetMass();
0110 G4double dose = edep / mass;
0111 G4double rmsDose = rms / mass;
0112
0113
0114
0115
0116 const auto generatorAction = static_cast<const B1::PrimaryGeneratorAction*>(
0117 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0118 G4String runCondition;
0119 if (generatorAction) {
0120 const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0121 runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0122 runCondition += " of ";
0123 G4double particleEnergy = particleGun->GetParticleEnergy();
0124 runCondition += G4BestUnit(particleEnergy, "Energy");
0125 }
0126
0127
0128
0129 if (IsMaster()) {
0130 for (auto edepPerEvent : fEdepPerEvent.GetVector()) {
0131 G4double dosePerEvent = edepPerEvent / mass / gray;
0132 fDoseTally->AddScore(dosePerEvent);
0133 }
0134
0135 fDoseTally->ShowResult();
0136 fDoseTally->ShowHistory();
0137 delete fDoseTally;
0138 fDoseTally = nullptr;
0139
0140 G4cout << G4endl << "--------------------End of Global Run-----------------------";
0141 }
0142 else {
0143 G4cout << G4endl << "--------------------End of Local Run------------------------";
0144 }
0145
0146 G4cout << G4endl << " The run consists of " << nofEvents << " " << runCondition << G4endl
0147 << " Cumulated dose per run, in scoring volume : " << G4BestUnit(dose, "Dose")
0148 << " rms = " << G4BestUnit(rmsDose, "Dose") << G4endl
0149 << "------------------------------------------------------------" << G4endl << G4endl;
0150 }
0151
0152
0153
0154 void RunAction::AddEdep(G4double edep)
0155 {
0156 fEdep += edep;
0157 fEdep2 += edep * edep;
0158 fEdepPerEvent.AddValue(edep);
0159 }
0160
0161
0162
0163 }