#include <RunAction.hh>
Public Member Functions | |
RunAction (DetectorConstruction *) | |
~RunAction () | |
void | BeginOfRunAction (const G4Run *) |
void | EndOfRunAction (const G4Run *) |
void | SumEvents (G4double e) |
void | SumDepthDose (G4double, G4double) |
void | SumDepthDoseSD (G4double, G4double) |
void | WriteDepthDose (G4String) |
Private Attributes | |
DetectorConstruction * | m_detector |
G4double | m_sumEdep |
G4double | m_sumEdep2 |
G4int | m_nbEntry |
std::vector< G4double > | m_depthDose |
std::vector< G4double > | m_depthDoseSD |
G4double | m_astronautHeight |
G4double | m_sliceWidth |
G4int | m_nbSlices |
Definition at line 19 of file RunAction.hh.
RunAction::RunAction | ( | DetectorConstruction * | det | ) |
RunAction::~RunAction | ( | ) |
void RunAction::BeginOfRunAction | ( | const G4Run * | run | ) |
Definition at line 28 of file RunAction.cc.
00029 { 00030 G4cout << "### Run " << run->GetRunID() << " start." << G4endl; 00031 00032 //initialize total energy deposit 00033 // 00034 m_sumEdep = m_sumEdep2 = 0.; 00035 m_nbEntry = 0; 00036 00037 //construct vector of m_depthDose distribution 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 m_depthDoseSD.resize(m_nbSlices, 0.); 00044 00045 }
void RunAction::EndOfRunAction | ( | const G4Run * | ) |
Definition at line 85 of file RunAction.cc.
00086 { 00087 G4double meanEd = 0., meanEd2 = 0., rmsEd = 0., error_rel_sum = 0.; 00088 if (m_nbEntry) { 00089 meanEd = m_sumEdep/m_nbEntry; meanEd2 = m_sumEdep2/m_nbEntry; 00090 G4double variance = meanEd2 - meanEd*meanEd; 00091 if (variance > 0.) rmsEd = std::sqrt(variance); 00092 error_rel_sum = rmsEd/(meanEd*std::sqrt(double(m_nbEntry))); 00093 } 00094 00095 // choose printing format 00096 std::ios::fmtflags mode = G4cout.flags(); 00097 G4cout.setf(std::ios::fixed,std::ios::floatfield); 00098 G4int prec = G4cout.precision(3); 00099 00100 //print total energy deposit 00101 // 00102 G4cout 00103 << "\n ---> Nb of non-empty events = " << m_nbEntry 00104 << "\n ---> Mean Edep per event = " << G4BestUnit(meanEd,"Energy") 00105 << "\n ---> Total Energy deposited = " << G4BestUnit(m_sumEdep,"Energy") 00106 << " +- " << G4BestUnit(m_sumEdep*error_rel_sum,"Energy") 00107 << " (-> " << 100*error_rel_sum << " %)" 00108 << G4endl; 00109 00110 //get mass of astronaut 00111 // 00112 G4double mass = m_detector->GetAstronaut()->GetLogicalVolume()->GetMass(); 00113 00114 //compute dose 00115 // 00116 G4double dose = m_sumEdep/mass; 00117 G4cout.setf(mode,std::ios::floatfield); 00118 G4cout.precision(5); 00119 G4cout << " ---> Dose = " << G4BestUnit(dose,"Dose") 00120 << " +- " << G4BestUnit(dose*error_rel_sum,"Dose") << "\n" 00121 << G4endl; 00122 00123 // restaure default formats 00124 G4cout.setf(mode,std::ios::floatfield); 00125 G4cout.precision(prec); 00126 00127 // convert m_depthDose array from energy to dose 00128 // 00129 for (G4int k=0; k<m_nbSlices; k++) m_depthDose[k] /= mass; 00130 // 00131 for (G4int k=0; k<m_nbSlices; k++) m_depthDoseSD[k] /= mass; 00132 00133 00134 00135 // write m_depthDose array on a file 00136 // 00137 WriteDepthDose("depthDose"); 00138 00139 // restaure default formats 00140 G4cout.setf(mode,std::ios::floatfield); 00141 G4cout.precision(prec); 00142 }
void RunAction::SumEvents | ( | G4double | e | ) | [inline] |
Definition at line 29 of file RunAction.hh.
Referenced by EventAction::EndOfEventAction().
00029 { m_sumEdep += e; m_sumEdep2 += e*e; m_nbEntry++; };
void RunAction::SumDepthDose | ( | G4double | zLocal, | |
G4double | edep | |||
) |
Definition at line 49 of file RunAction.cc.
Referenced by SteppingAction::UserSteppingAction().
00050 { 00051 // check coherence 00052 if (zLocal > m_astronautHeight) { 00053 G4cout << "\n --> warning from RunAction::SumDepthDose() : " 00054 << " zLocal beyond astronaut height : " << zLocal/mm << G4endl; 00055 return; 00056 } 00057 00058 // compute slice number 00059 G4int k = int(zLocal/m_sliceWidth); 00060 00061 // sum edep 00062 m_depthDose[k] += edep; 00063 }
void RunAction::SumDepthDoseSD | ( | G4double | zLocal, | |
G4double | edep | |||
) |
Definition at line 66 of file RunAction.cc.
Referenced by SensitiveDetector::ProcessHits().
00067 { 00068 // check coherence 00069 if (zLocal > m_astronautHeight) { 00070 G4cout << "\n --> warning from RunAction::SumDepthDose() : " 00071 << " zLocal beyond astronaut height : " << zLocal/mm << G4endl; 00072 return; 00073 } 00074 00075 // compute slice number 00076 G4int k = int(zLocal/m_sliceWidth); 00077 00078 // sum edep 00079 m_depthDoseSD[k] += edep; 00080 }
void RunAction::WriteDepthDose | ( | G4String | name | ) |
Definition at line 148 of file RunAction.cc.
Referenced by EndOfRunAction().
00149 { 00150 G4String fileName = name + ".ascii"; 00151 std::ofstream File(fileName, std::ios::out); 00152 00153 G4String fileNameSD = name + "SD"+ ".ascii"; 00154 std::ofstream FileSD(fileNameSD, std::ios::out); 00155 00156 std::ios::fmtflags mode = File.flags(); 00157 File.setf( std::ios::scientific, std::ios::floatfield ); 00158 G4int prec = File.precision(4); 00159 00160 std::ios::fmtflags modeSD = FileSD.flags(); 00161 FileSD.setf( std::ios::scientific, std::ios::floatfield ); 00162 G4int precSD = FileSD.precision(4); 00163 00164 File << " Longitudinal depth dose distribution \n " 00165 << "\n zLocal (mm)\t m_depthDose(gray) \n" << G4endl; 00166 00167 FileSD << " Longitudinal depth dose distribution \n " 00168 << "\n zLocal (mm)\t m_depthDose(gray) \n" << G4endl; 00169 00170 G4double zLocal; 00171 for (G4int k=0; k<m_nbSlices; k++) { 00172 zLocal = (k+0.5)*m_sliceWidth; 00173 File << " " << zLocal/mm 00174 << "\t " << m_depthDose[k]/gray << G4endl; 00175 } 00176 00177 // -- write date from SD : 00178 for (G4int k=0; k<m_nbSlices; k++) { 00179 zLocal = (k+0.5)*m_sliceWidth; 00180 FileSD << " " << zLocal/mm 00181 << "\t " << m_depthDoseSD[k]/gray << G4endl; 00182 } 00183 00184 // restaure default formats 00185 File.setf(mode,std::ios::floatfield); 00186 File.precision(prec); 00187 00188 FileSD.setf(modeSD,std::ios::floatfield); 00189 FileSD.precision(precSD); 00190 00191 }
DetectorConstruction* RunAction::m_detector [private] |
G4double RunAction::m_sumEdep [private] |
Definition at line 40 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
G4double RunAction::m_sumEdep2 [private] |
Definition at line 40 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
G4int RunAction::m_nbEntry [private] |
Definition at line 41 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
std::vector<G4double> RunAction::m_depthDose [private] |
Definition at line 43 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), SumDepthDose(), and WriteDepthDose().
std::vector<G4double> RunAction::m_depthDoseSD [private] |
Definition at line 44 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), SumDepthDoseSD(), and WriteDepthDose().
G4double RunAction::m_astronautHeight [private] |
Definition at line 45 of file RunAction.hh.
Referenced by BeginOfRunAction(), SumDepthDose(), and SumDepthDoseSD().
G4double RunAction::m_sliceWidth [private] |
Definition at line 46 of file RunAction.hh.
Referenced by BeginOfRunAction(), SumDepthDose(), SumDepthDoseSD(), and WriteDepthDose().
G4int RunAction::m_nbSlices [private] |
Definition at line 47 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and WriteDepthDose().