File indexing completed on 2025-01-18 09:16:36
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 "FARunAction.hh"
0030 #include "FAPrimaryGeneratorAction.hh"
0031 #include "FADetectorConstruction.hh"
0032
0033 #include "G4RunManager.hh"
0034 #include "G4Run.hh"
0035 #include "G4AccumulableManager.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4UnitsTable.hh"
0039 #include "G4SystemOfUnits.hh"
0040
0041 RunAction::RunAction()
0042 : G4UserRunAction(),
0043 fEdep(0.),
0044 fEdep2(0.)
0045 {
0046
0047
0048 const G4double milligray = 1.e-3*gray;
0049 const G4double microgray = 1.e-6*gray;
0050 const G4double nanogray = 1.e-9*gray;
0051 const G4double picogray = 1.e-12*gray;
0052
0053 new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
0054 new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
0055 new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
0056 new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
0057
0058
0059 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0060 accumulableManager->RegisterAccumulable(fEdep);
0061 accumulableManager->RegisterAccumulable(fEdep2);
0062 }
0063
0064 void RunAction::BeginOfRunAction(const G4Run*)
0065 {
0066
0067 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0068
0069
0070 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0071 accumulableManager->Reset();
0072 }
0073
0074 void RunAction::EndOfRunAction(const G4Run* run)
0075 {
0076 G4int nofEvents = run->GetNumberOfEvent();
0077 if (nofEvents == 0) return;
0078
0079
0080 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0081 accumulableManager->Merge();
0082
0083
0084
0085 G4double edep = fEdep.GetValue();
0086 G4double edep2 = fEdep2.GetValue();
0087
0088 G4double rms = edep2 - edep*edep/nofEvents;
0089 if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
0090
0091 const auto* detectorConstruction
0092 = static_cast<const DetectorConstruction*>
0093 (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0094 G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
0095 G4double dose = edep/mass;
0096 G4double rmsDose = rms/mass;
0097
0098
0099
0100
0101 const auto* generatorAction
0102 = static_cast<const PrimaryGeneratorAction*>
0103 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0104 G4String runCondition;
0105 if (generatorAction)
0106 {
0107 const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0108 runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0109 runCondition += " of ";
0110 G4double particleEnergy = particleGun->GetParticleEnergy();
0111 runCondition += G4BestUnit(particleEnergy,"Energy");
0112 }
0113
0114
0115
0116 if (IsMaster()) {
0117 G4cout
0118 << G4endl
0119 << "--------------------End of Global Run-----------------------";
0120 }
0121 else {
0122 G4cout
0123 << G4endl
0124 << "--------------------End of Local Run------------------------";
0125 }
0126
0127 G4cout
0128 << G4endl
0129 << " The run consists of " << nofEvents << " "<< runCondition
0130 << G4endl
0131 << " Cumulated dose per run, in scoring volume : "
0132 << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose")
0133 << G4endl
0134 << "------------------------------------------------------------"
0135 << G4endl
0136 << G4endl;
0137 }
0138
0139 void RunAction::AddEdep(G4double edep)
0140 {
0141 fEdep += edep;
0142 fEdep2 += edep*edep;
0143 }
0144