File indexing completed on 2026-06-05 07:55:49
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 "B1RunAction.hh"
0030
0031 #include "B1DetectorConstruction.hh"
0032 #include "B1PrimaryGeneratorAction.hh"
0033 #include "B1Run.hh"
0034
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4UnitsTable.hh"
0040
0041
0042
0043 B1RunAction::B1RunAction() : G4UserRunAction()
0044 {
0045
0046
0047 const G4double milligray = 1.e-3 * gray;
0048 const G4double microgray = 1.e-6 * gray;
0049 const G4double nanogray = 1.e-9 * gray;
0050 const G4double picogray = 1.e-12 * gray;
0051
0052 new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
0053 new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
0054 new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
0055 new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
0056 }
0057
0058
0059
0060 B1RunAction::~B1RunAction() {}
0061
0062
0063
0064 G4Run* B1RunAction::GenerateRun()
0065 {
0066 return new B1Run;
0067 }
0068
0069
0070
0071 void B1RunAction::BeginOfRunAction(const G4Run*)
0072 {
0073
0074 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0075 }
0076
0077
0078
0079 void B1RunAction::EndOfRunAction(const G4Run* run)
0080 {
0081 G4int nofEvents = run->GetNumberOfEvent();
0082 if (nofEvents == 0) return;
0083
0084 const B1Run* b1Run = static_cast<const B1Run*>(run);
0085
0086
0087
0088 G4double edep = b1Run->GetEdep();
0089 G4double edep2 = b1Run->GetEdep2();
0090 G4double rms = edep2 - edep * edep / nofEvents;
0091 if (rms > 0.)
0092 rms = std::sqrt(rms);
0093 else
0094 rms = 0.;
0095
0096 const B1DetectorConstruction* detectorConstruction = static_cast<const B1DetectorConstruction*>(
0097 G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0098 G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
0099 G4double dose = edep / mass;
0100 G4double rmsDose = rms / mass;
0101
0102
0103
0104
0105 const B1PrimaryGeneratorAction* generatorAction = static_cast<const B1PrimaryGeneratorAction*>(
0106 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0107 G4String runCondition;
0108 if (generatorAction) {
0109 const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0110 runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0111 runCondition += " of ";
0112 G4double particleEnergy = particleGun->GetParticleEnergy();
0113 runCondition += G4BestUnit(particleEnergy, "Energy");
0114 }
0115
0116
0117
0118 if (IsMaster()) {
0119 G4cout << "\n--------------------End of Global Run-----------------------";
0120 }
0121 else {
0122 G4cout << "\n--------------------End of Local Run------------------------";
0123 }
0124
0125 G4cout << "\n The run consists of " << nofEvents << " " << runCondition
0126 << "\n Dose in scoring volume : " << G4BestUnit(dose, "Dose") << " +- "
0127 << G4BestUnit(rmsDose, "Dose")
0128 << "\n------------------------------------------------------------\n"
0129 << G4endl;
0130 }
0131
0132