#include "RunAction.hh" #include "PrimaryGeneratorAction.hh" #include "DetectorConstruction.hh" #include "G4RunManager.hh" #include "G4Run.hh" #include "G4AccumulableManager.hh" #include "G4LogicalVolumeStore.hh" #include "G4LogicalVolume.hh" #include "G4UnitsTable.hh" #include "G4SystemOfUnits.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... RunAction::RunAction() : G4UserRunAction(), fEdep(0.), fEdep2(0.) { // add new units for dose const G4double milligray = 1.e-3*gray; const G4double microgray = 1.e-6*gray; const G4double nanogray = 1.e-9*gray; const G4double picogray = 1.e-12*gray; new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray); new G4UnitDefinition("microgray", "microGy" , "Dose", microgray); new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray); new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray); // Register accumulable to the accumulable manager G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); accumulableManager->RegisterAccumulable(fEdep); accumulableManager->RegisterAccumulable(fEdep2); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... RunAction::~RunAction() {} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void RunAction::BeginOfRunAction(const G4Run*) { // inform the runManager to save random number seed G4RunManager::GetRunManager()->SetRandomNumberStore(false); // reset accumulables to their initial values G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); accumulableManager->Reset(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void RunAction::EndOfRunAction(const G4Run* run) { G4int nofEvents = run->GetNumberOfEvent(); if (nofEvents == 0) return; // Merge accumulables G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); accumulableManager->Merge(); // Compute dose = total energy deposit per mass in a run and its variance G4double edep = fEdep.GetValue(); G4double edep2 = fEdep2.GetValue(); G4double rms = edep2 - edep*edep/nofEvents; if (rms > 0.) rms = std::sqrt(rms); else rms = 0.; const DetectorConstruction* detectorConstruction = static_cast (G4RunManager::GetRunManager()->GetUserDetectorConstruction()); G4double mass = detectorConstruction->GetScoringVolume()->GetMass(); G4double dose = edep/mass; G4double rmsDose = rms/mass; //------- // Print //------- if (IsMaster()) { G4cout << G4endl << "--------------------End of Global Run-----------------------"; } else { G4cout << G4endl << "--------------------End of Local Run------------------------"; } G4cout << G4endl << " The run consists of " << nofEvents << " " << G4endl << " Cumulated dose per run, in scoring volume : " << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose") << G4endl << "------------------------------------------------------------" << G4endl << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void RunAction::AddEdep(G4double edep) { fEdep += edep; fEdep2 += edep*edep; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......