00001
00002
00003
00004
00005
00006 #include "RunAction.hh"
00007 #include "DetectorConstruction.hh"
00008
00009 #include "G4Run.hh"
00010 #include "G4RunManager.hh"
00011 #include "G4UnitsTable.hh"
00012
00013 #include <iomanip>
00014
00015
00016
00017 RunAction::RunAction(DetectorConstruction* det)
00018 :m_detector(det)
00019 { }
00020
00021
00022
00023 RunAction::~RunAction()
00024 { }
00025
00026
00027
00028 void RunAction::BeginOfRunAction(const G4Run* run)
00029 {
00030 G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
00031
00032
00033
00034 m_sumEdep = m_sumEdep2 = 0.;
00035 m_nbEntry = 0;
00036
00037
00038
00039 m_nbSlices = 100;
00040 m_astronautHeight = m_detector->GetAstronautHeight();
00041 m_sliceWidth = m_astronautHeight/m_nbSlices;
00042 m_depthDose.resize(m_nbSlices, 0.);
00043 }
00044
00045
00046
00047 void RunAction::EndOfRunAction(const G4Run*)
00048 {
00049 G4double meanEd = 0., meanEd2 = 0., rmsEd = 0., error_rel_sum = 0.;
00050 if (m_nbEntry) {
00051 meanEd = m_sumEdep/m_nbEntry; meanEd2 = m_sumEdep2/m_nbEntry;
00052 G4double variance = meanEd2 - meanEd*meanEd;
00053 if (variance > 0.) rmsEd = std::sqrt(variance);
00054 error_rel_sum = rmsEd/(meanEd*std::sqrt(double(m_nbEntry)));
00055 }
00056
00057
00058 std::ios::fmtflags mode = G4cout.flags();
00059 G4cout.setf(std::ios::fixed,std::ios::floatfield);
00060 G4int prec = G4cout.precision(3);
00061
00062
00063
00064 G4cout
00065 << "\n ---> Nb of non-empty events = " << m_nbEntry
00066 << "\n ---> Mean Edep per event = " << G4BestUnit(meanEd,"Energy")
00067 << "\n ---> Total Energy deposited = " << G4BestUnit(m_sumEdep,"Energy")
00068 << " +- " << G4BestUnit(m_sumEdep*error_rel_sum,"Energy")
00069 << " (-> " << 100*error_rel_sum << " %)"
00070 << G4endl;
00071
00072
00073
00074 G4double mass = m_detector->GetAstronaut()->GetLogicalVolume()->GetMass();
00075
00076
00077
00078 G4double dose = m_sumEdep/mass;
00079 G4cout.setf(mode,std::ios::floatfield);
00080 G4cout.precision(5);
00081 G4cout << " ---> Dose = " << G4BestUnit(dose,"Dose")
00082 << " +- " << G4BestUnit(dose*error_rel_sum,"Dose") << "\n"
00083 << G4endl;
00084
00085
00086 G4cout.setf(mode,std::ios::floatfield);
00087 G4cout.precision(prec);
00088 }
00089
00090