#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 | SumDepthDoseSD (G4int, G4double) |
G4int | GetSliceNumber (G4double z) const |
G4int | GetNumberOfSlices () const |
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 114 of file RunAction.cc.
00115 { 00116 G4double meanEd = 0., meanEd2 = 0., rmsEd = 0., error_rel_sum = 0.; 00117 if (m_nbEntry) { 00118 meanEd = m_sumEdep/m_nbEntry; meanEd2 = m_sumEdep2/m_nbEntry; 00119 G4double variance = meanEd2 - meanEd*meanEd; 00120 if (variance > 0.) rmsEd = std::sqrt(variance); 00121 error_rel_sum = rmsEd/(meanEd*std::sqrt(double(m_nbEntry))); 00122 } 00123 00124 // choose printing format 00125 std::ios::fmtflags mode = G4cout.flags(); 00126 G4cout.setf(std::ios::fixed,std::ios::floatfield); 00127 G4int prec = G4cout.precision(3); 00128 00129 //print total energy deposit 00130 // 00131 G4cout 00132 << "\n ---> Nb of non-empty events = " << m_nbEntry 00133 << "\n ---> Mean Edep per event = " << G4BestUnit(meanEd,"Energy") 00134 << "\n ---> Total Energy deposited = " << G4BestUnit(m_sumEdep,"Energy") 00135 << " +- " << G4BestUnit(m_sumEdep*error_rel_sum,"Energy") 00136 << " (-> " << 100*error_rel_sum << " %)" 00137 << G4endl; 00138 00139 //get mass of astronaut 00140 // 00141 G4double mass = m_detector->GetAstronaut()->GetLogicalVolume()->GetMass(); 00142 00143 //compute dose 00144 // 00145 G4double dose = m_sumEdep/mass; 00146 G4cout.setf(mode,std::ios::floatfield); 00147 G4cout.precision(5); 00148 G4cout << " ---> Dose = " << G4BestUnit(dose,"Dose") 00149 << " +- " << G4BestUnit(dose*error_rel_sum,"Dose") << "\n" 00150 << G4endl; 00151 00152 // restaure default formats 00153 G4cout.setf(mode,std::ios::floatfield); 00154 G4cout.precision(prec); 00155 00156 // convert m_depthDose array from energy to dose 00157 // 00158 for (G4int k=0; k<m_nbSlices; k++) m_depthDose[k] /= mass; 00159 // 00160 for (G4int k=0; k<m_nbSlices; k++) m_depthDoseSD[k] /= mass; 00161 00162 00163 00164 // write m_depthDose array on a file 00165 // 00166 WriteDepthDose("depthDose"); 00167 00168 // restaure default formats 00169 G4cout.setf(mode,std::ios::floatfield); 00170 G4cout.precision(prec); 00171 }
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 EventAction::EndOfEventAction().
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::SumDepthDoseSD | ( | G4int | k, | |
G4double | edep | |||
) |
Definition at line 83 of file RunAction.cc.
00084 { 00085 // check coherence 00086 if (k >= m_nbSlices) { 00087 G4cout << "\n --> warning from RunAction::SumDepthDoseSD() : " 00088 << " k beyond nb slices : " << k << G4endl; 00089 return; 00090 } 00091 00092 // sum edep 00093 m_depthDoseSD[k] += edep; 00094 }
G4int RunAction::GetSliceNumber | ( | G4double | z | ) | const |
Definition at line 97 of file RunAction.cc.
Referenced by SensitiveDetector::ProcessHits().
00098 { 00099 // compute slice number 00100 G4int k = int(zLocal/m_sliceWidth); 00101 00102 // check coherence 00103 if (k >= m_nbSlices) { 00104 G4cout << "\n --> warning from RunAction::GetSliceNumber() : " 00105 << " k beyond nb slices : " << k << " returning -1" << G4endl; 00106 k = -1; 00107 } 00108 00109 return k; 00110 }
G4int RunAction::GetNumberOfSlices | ( | ) | const [inline] |
Definition at line 39 of file RunAction.hh.
Referenced by SensitiveDetector::Initialize().
00039 {return m_nbSlices;}
void RunAction::WriteDepthDose | ( | G4String | name | ) |
Definition at line 177 of file RunAction.cc.
Referenced by EndOfRunAction().
00178 { 00179 G4String fileName = name + ".ascii"; 00180 std::ofstream File(fileName, std::ios::out); 00181 00182 G4String fileNameSD = name + "SD"+ ".ascii"; 00183 std::ofstream FileSD(fileNameSD, std::ios::out); 00184 00185 std::ios::fmtflags mode = File.flags(); 00186 File.setf( std::ios::scientific, std::ios::floatfield ); 00187 G4int prec = File.precision(4); 00188 00189 std::ios::fmtflags modeSD = FileSD.flags(); 00190 FileSD.setf( std::ios::scientific, std::ios::floatfield ); 00191 G4int precSD = FileSD.precision(4); 00192 00193 File << " Longitudinal depth dose distribution \n " 00194 << "\n zLocal (mm)\t m_depthDose(gray) \n" << G4endl; 00195 00196 FileSD << " Longitudinal depth dose distribution \n " 00197 << "\n zLocal (mm)\t m_depthDose(gray) \n" << G4endl; 00198 00199 G4double zLocal; 00200 for (G4int k=0; k<m_nbSlices; k++) { 00201 zLocal = (k+0.5)*m_sliceWidth; 00202 File << " " << zLocal/mm 00203 << "\t " << m_depthDose[k]/gray << G4endl; 00204 } 00205 00206 // -- write date from SD : 00207 for (G4int k=0; k<m_nbSlices; k++) { 00208 zLocal = (k+0.5)*m_sliceWidth; 00209 FileSD << " " << zLocal/mm 00210 << "\t " << m_depthDoseSD[k]/gray << G4endl; 00211 } 00212 00213 // restaure default formats 00214 File.setf(mode,std::ios::floatfield); 00215 File.precision(prec); 00216 00217 FileSD.setf(modeSD,std::ios::floatfield); 00218 FileSD.precision(precSD); 00219 00220 }
DetectorConstruction* RunAction::m_detector [private] |
G4double RunAction::m_sumEdep [private] |
Definition at line 46 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
G4double RunAction::m_sumEdep2 [private] |
Definition at line 46 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
G4int RunAction::m_nbEntry [private] |
Definition at line 47 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().
std::vector<G4double> RunAction::m_depthDose [private] |
Definition at line 49 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), SumDepthDose(), and WriteDepthDose().
std::vector<G4double> RunAction::m_depthDoseSD [private] |
Definition at line 50 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), SumDepthDoseSD(), and WriteDepthDose().
G4double RunAction::m_astronautHeight [private] |
Definition at line 51 of file RunAction.hh.
Referenced by BeginOfRunAction(), SumDepthDose(), and SumDepthDoseSD().
G4double RunAction::m_sliceWidth [private] |
Definition at line 52 of file RunAction.hh.
Referenced by BeginOfRunAction(), GetSliceNumber(), SumDepthDose(), SumDepthDoseSD(), and WriteDepthDose().
G4int RunAction::m_nbSlices [private] |
Definition at line 53 of file RunAction.hh.
Referenced by BeginOfRunAction(), EndOfRunAction(), GetNumberOfSlices(), GetSliceNumber(), SumDepthDoseSD(), and WriteDepthDose().