File indexing completed on 2025-02-23 09:21:46
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
0030
0031 #include "Dicom2RunAction.hh"
0032
0033 #include "Dicom2Run.hh"
0034
0035
0036 #include "G4RunManager.hh"
0037 #include "G4StatAnalysis.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4THitsMap.hh"
0040 #include "G4UnitsTable.hh"
0041
0042 #include <fstream>
0043 #include <iomanip>
0044
0045
0046
0047 Dicom2RunAction::Dicom2RunAction() : DicomRunAction() {}
0048
0049
0050
0051 Dicom2RunAction::~Dicom2RunAction() {}
0052
0053
0054 G4Run* Dicom2RunAction::GenerateRun()
0055 {
0056
0057
0058
0059 return fDcmrun = new Dicom2Run(fSDName);
0060 }
0061
0062
0063 void Dicom2RunAction::EndOfRunAction(const G4Run* aRun)
0064 {
0065
0066
0067 G4AutoLock l(G4TypeMutex<Dicom2RunAction>());
0068
0069 G4cout << G4endl;
0070 G4cout << "[==========================================================="
0071 << " DICOM "
0072 << "===========================================================]" << G4endl;
0073 G4cout << G4endl;
0074
0075 DicomRunAction::EndOfRunAction(aRun);
0076
0077 G4cout << G4endl;
0078 G4cout << "[==========================================================="
0079 << " DICOM2 "
0080 << "==========================================================]" << G4endl;
0081 G4cout << G4endl;
0082
0083 G4int nofEvents = aRun->GetNumberOfEvent();
0084
0085 G4StatAnalysis local_total_dose;
0086
0087 const Dicom2Run* dcm2Run = static_cast<const Dicom2Run*>(aRun);
0088
0089 for (uintmax_t i = 0; i < fSDName.size(); i++) {
0090
0091
0092
0093
0094
0095
0096 Dicom2RunVector* DoseDeposit = dcm2Run->GetHitsVector(fSDName[i] + "/DoseDeposit");
0097
0098 if (DoseDeposit && DoseDeposit->size() != 0) {
0099 for (auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr) {
0100
0101 if (!DoseDeposit->GetObject(itr)) continue;
0102 local_total_dose += (*DoseDeposit->GetObject(itr));
0103 }
0104 }
0105 }
0106
0107 if (IsMaster()) {
0108 G4cout << " ###### EndOfRunAction ###### " << G4endl;
0109
0110 const Dicom2Run* re02Run = static_cast<const Dicom2Run*>(aRun);
0111
0112
0113 for (uintmax_t i = 0; i < fSDName.size(); i++) {
0114
0115
0116
0117
0118
0119
0120 Dicom2RunVector* DoseDeposit = re02Run->GetHitsVector(fSDName[i] + "/DoseDeposit");
0121
0122 G4cout << "=============================================================" << G4endl;
0123 G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
0124 G4cout << "=============================================================" << G4endl;
0125
0126 std::ofstream fileout;
0127 G4String fname = "dicom2-vector.out";
0128 fileout.open(fname);
0129 G4cout << " opened file " << fname << " for dose output" << G4endl;
0130
0131 if (DoseDeposit && DoseDeposit->size() != 0) {
0132 std::ostream* myout = &G4cout;
0133 PrintHeader(myout);
0134 for (auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr) {
0135 auto _idx = DoseDeposit->GetIndex(itr);
0136 G4StatAnalysis* _stat = DoseDeposit->GetObject(itr);
0137 if (_stat && _stat->GetHits() > 0) {
0138 G4StatAnalysis _tmp_stat = *_stat;
0139 _tmp_stat /= CLHEP::gray;
0140 fileout << _idx << " " << (*_stat) << G4endl;
0141 }
0142 }
0143 G4cout << "=============================================" << G4endl;
0144 }
0145 else {
0146 G4Exception("Dicom2RunAction", "000", JustWarning,
0147 "DoseDeposit HitsMap is either a null pointer "
0148 "of the HitsMap was empty");
0149 }
0150 fileout.close();
0151 G4cout << " closed file " << fname << " for dose output" << G4endl;
0152 }
0153 }
0154
0155 if (IsMaster()) {
0156
0157 local_total_dose /= gray;
0158 G4cout << "--------------------End of Global Run-----------------------" << G4endl;
0159 G4cout << " The run was " << nofEvents << " events " << G4endl;
0160 G4cout << " TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
0161 if (nofEvents > 0) {
0162 local_total_dose /= nofEvents;
0163 G4cout << " TOTAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" << G4endl;
0164 }
0165 }
0166 else {
0167
0168 local_total_dose /= gray;
0169 G4cout << "--------------------End of Local Run------------------------" << G4endl;
0170 G4cout << " The run was " << nofEvents << " events" << G4endl;
0171 G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
0172 if (nofEvents > 0) {
0173 local_total_dose /= nofEvents;
0174 G4cout << " LOCAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" << G4endl;
0175 }
0176 }
0177
0178 G4cout << G4endl;
0179 G4cout << "Finished : End of Run Action " << aRun->GetRunID() << "\n" << G4endl;
0180 }