Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file Dicom2RunAction.cc 27 /// \file Dicom2RunAction.cc 28 /// \brief Implementation of the Dicom2RunActi 28 /// \brief Implementation of the Dicom2RunAction class 29 // 29 // 30 30 31 #include "Dicom2RunAction.hh" 31 #include "Dicom2RunAction.hh" 32 << 33 #include "Dicom2Run.hh" 32 #include "Dicom2Run.hh" 34 33 35 //-- In order to obtain detector information. 34 //-- In order to obtain detector information. 36 #include "G4RunManager.hh" << 35 #include <fstream> 37 #include "G4StatAnalysis.hh" << 36 #include <iomanip> 38 #include "G4SystemOfUnits.hh" << 39 #include "G4THitsMap.hh" 37 #include "G4THitsMap.hh" >> 38 40 #include "G4UnitsTable.hh" 39 #include "G4UnitsTable.hh" >> 40 #include "G4SystemOfUnits.hh" >> 41 #include "G4StatAnalysis.hh" 41 42 42 #include <fstream> << 43 #include "G4RunManager.hh" 43 #include <iomanip> << 44 44 45 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 /// Constructor 46 /// Constructor 47 Dicom2RunAction::Dicom2RunAction() : DicomRunA << 47 Dicom2RunAction::Dicom2RunAction() >> 48 : DicomRunAction() >> 49 { } 48 50 49 //....oooOO0OOooo........oooOO0OOooo........oo 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 50 /// Destructor. 52 /// Destructor. 51 Dicom2RunAction::~Dicom2RunAction() {} << 53 Dicom2RunAction::~Dicom2RunAction() >> 54 { } 52 55 53 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 G4Run* Dicom2RunAction::GenerateRun() 57 G4Run* Dicom2RunAction::GenerateRun() 55 { 58 { 56 // Generate new RUN object, which is special << 59 // Generate new RUN object, which is specially 57 // dedicated for MultiFunctionalDetector sch << 60 // dedicated for MultiFunctionalDetector scheme. 58 // Detail description can be found in Dicom << 61 // Detail description can be found in Dicom2Run.hh/cc. 59 return fDcmrun = new Dicom2Run(fSDName); << 62 return fDcmrun = new Dicom2Run(fSDName); 60 } 63 } 61 64 62 //....oooOO0OOooo........oooOO0OOooo........oo 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 void Dicom2RunAction::EndOfRunAction(const G4R 66 void Dicom2RunAction::EndOfRunAction(const G4Run* aRun) 64 { 67 { 65 // Lock the output because of the external c << 68 // Lock the output because of the external calls to DicomRunAction 66 // otherwise, the output gets too confusing << 69 // otherwise, the output gets too confusing 67 G4AutoLock l(G4TypeMutex<Dicom2RunAction>()) << 70 G4AutoLock l(G4TypeMutex<Dicom2RunAction>()); 68 << 71 69 G4cout << G4endl; << 72 G4cout << G4endl; 70 G4cout << "[================================ << 73 G4cout << "[===========================================================" 71 << " DICOM " << 74 << " DICOM " 72 << "================================= << 75 << "===========================================================]" 73 G4cout << G4endl; << 76 << G4endl; 74 << 77 G4cout << G4endl; 75 DicomRunAction::EndOfRunAction(aRun); << 78 76 << 79 DicomRunAction::EndOfRunAction(aRun); 77 G4cout << G4endl; << 80 78 G4cout << "[================================ << 81 G4cout << G4endl; 79 << " DICOM2 " << 82 G4cout << "[===========================================================" 80 << "================================= << 83 << " DICOM2 " 81 G4cout << G4endl; << 84 << "==========================================================]" 82 << 85 << G4endl; 83 G4int nofEvents = aRun->GetNumberOfEvent(); << 86 G4cout << G4endl; 84 << 87 85 G4StatAnalysis local_total_dose; << 88 G4int nofEvents = aRun->GetNumberOfEvent(); 86 << 87 const Dicom2Run* dcm2Run = static_cast<const << 88 //--- Dump all scored quantities involved in << 89 for (uintmax_t i = 0; i < fSDName.size(); i+ << 90 // << 91 //---------------------------------------- << 92 // Dump accumulated quantities for this RU << 93 // (Display only central region of x-y pl << 94 // 0 ConcreteSD/DoseDeposit << 95 //---------------------------------------- << 96 Dicom2RunVector* DoseDeposit = dcm2Run->Ge << 97 << 98 if (DoseDeposit && DoseDeposit->size() != << 99 for (auto itr = DoseDeposit->begin(); it << 100 // this will sometimes return null poi << 101 if (!DoseDeposit->GetObject(itr)) cont << 102 local_total_dose += (*DoseDeposit->Get << 103 } << 104 } << 105 } << 106 89 107 if (IsMaster()) { << 90 G4StatAnalysis local_total_dose; 108 G4cout << " ###### EndOfRunAction ###### " << 91 109 //- Dicom2Run object. << 92 const Dicom2Run* dcm2Run = static_cast<const Dicom2Run*>(aRun); 110 const Dicom2Run* re02Run = static_cast<con << 111 //--- Dump all scored quantities involved 93 //--- Dump all scored quantities involved in Dicom2Run. >> 94 for(uintmax_t i = 0; i < fSDName.size(); i++) >> 95 { >> 96 // >> 97 //--------------------------------------------- >> 98 // Dump accumulated quantities for this RUN. >> 99 // (Display only central region of x-y plane) >> 100 // 0 ConcreteSD/DoseDeposit >> 101 //--------------------------------------------- >> 102 Dicom2RunVector* DoseDeposit = >> 103 dcm2Run->GetHitsVector(fSDName[i]+"/DoseDeposit"); >> 104 >> 105 if(DoseDeposit && DoseDeposit->size() != 0 ) >> 106 { >> 107 for(auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr) >> 108 { >> 109 // this will sometimes return null pointers >> 110 if(!DoseDeposit->GetObject(itr)) >> 111 continue; >> 112 local_total_dose += (*DoseDeposit->GetObject(itr)); >> 113 } >> 114 } >> 115 } >> 116 >> 117 if(IsMaster()) >> 118 { >> 119 G4cout << " ###### EndOfRunAction ###### " << G4endl; >> 120 //- Dicom2Run object. >> 121 const Dicom2Run* re02Run = static_cast<const Dicom2Run*>(aRun); >> 122 //--- Dump all scored quantities involved in Dicom2Run. >> 123 >> 124 for(uintmax_t i = 0; i < fSDName.size(); i++) >> 125 { >> 126 // >> 127 //--------------------------------------------- >> 128 // Dump accumulated quantities for this RUN. >> 129 // (Display only central region of x-y plane) >> 130 // 0 ConcreteSD/DoseDeposit >> 131 //--------------------------------------------- >> 132 Dicom2RunVector* DoseDeposit = >> 133 re02Run->GetHitsVector(fSDName[i]+"/DoseDeposit"); >> 134 >> 135 G4cout << "=============================================================" >> 136 <<G4endl; >> 137 G4cout << " Number of event processed : " >> 138 << aRun->GetNumberOfEvent() << G4endl; >> 139 G4cout << "=============================================================" >> 140 <<G4endl; >> 141 >> 142 std::ofstream fileout; >> 143 G4String fname = "dicom2-vector.out"; >> 144 fileout.open(fname); >> 145 G4cout << " opened file " << fname << " for dose output" << G4endl; >> 146 >> 147 if(DoseDeposit && DoseDeposit->size() != 0) >> 148 { >> 149 std::ostream *myout = &G4cout; >> 150 PrintHeader(myout); >> 151 for(auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); >> 152 ++itr) >> 153 { >> 154 auto _idx = DoseDeposit->GetIndex(itr); >> 155 G4StatAnalysis* _stat = DoseDeposit->GetObject(itr); >> 156 if(_stat && _stat->GetHits() > 0) >> 157 { >> 158 G4StatAnalysis _tmp_stat = *_stat; >> 159 _tmp_stat /= CLHEP::gray; >> 160 fileout << _idx << " " << (*_stat) << G4endl; >> 161 } >> 162 } >> 163 G4cout << "============================================="<<G4endl; >> 164 } >> 165 else >> 166 { >> 167 G4Exception("Dicom2RunAction", "000", JustWarning, >> 168 "DoseDeposit HitsMap is either a null pointer " >> 169 "of the HitsMap was empty"); >> 170 } >> 171 fileout.close(); >> 172 G4cout << " closed file " << fname << " for dose output" << G4endl; 112 173 113 for (uintmax_t i = 0; i < fSDName.size(); << 114 // << 115 //-------------------------------------- << 116 // Dump accumulated quantities for this << 117 // (Display only central region of x-y << 118 // 0 ConcreteSD/DoseDeposit << 119 //-------------------------------------- << 120 Dicom2RunVector* DoseDeposit = re02Run-> << 121 << 122 G4cout << "============================= << 123 G4cout << " Number of event processed : << 124 G4cout << "============================= << 125 << 126 std::ofstream fileout; << 127 G4String fname = "dicom2-vector.out"; << 128 fileout.open(fname); << 129 G4cout << " opened file " << fname << " << 130 << 131 if (DoseDeposit && DoseDeposit->size() ! << 132 std::ostream* myout = &G4cout; << 133 PrintHeader(myout); << 134 for (auto itr = DoseDeposit->begin(); << 135 auto _idx = DoseDeposit->GetIndex(it << 136 G4StatAnalysis* _stat = DoseDeposit- << 137 if (_stat && _stat->GetHits() > 0) { << 138 G4StatAnalysis _tmp_stat = *_stat; << 139 _tmp_stat /= CLHEP::gray; << 140 fileout << _idx << " " << (*_s << 141 } << 142 } 174 } 143 G4cout << "=========================== << 144 } << 145 else { << 146 G4Exception("Dicom2RunAction", "000", << 147 "DoseDeposit HitsMap is ei << 148 "of the HitsMap was empty" << 149 } << 150 fileout.close(); << 151 G4cout << " closed file " << fname << " << 152 } 175 } 153 } << 154 176 155 if (IsMaster()) { << 177 156 // convert to units of Gy << 178 if (IsMaster()) 157 local_total_dose /= gray; << 179 { 158 G4cout << "--------------------End of Glob << 180 // convert to units of Gy 159 G4cout << " The run was " << nofEvents << << 181 local_total_dose /= gray; 160 G4cout << " TOTAL DOSE : \t" << local << 182 G4cout << "--------------------End of Global Run-----------------------" 161 if (nofEvents > 0) { << 183 << G4endl; 162 local_total_dose /= nofEvents; << 184 G4cout << " The run was " << nofEvents << " events " << G4endl; 163 G4cout << " TOTAL DOSE/Bq-s : \t" << loc << 185 G4cout << " TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl; >> 186 if(nofEvents > 0) >> 187 { >> 188 local_total_dose /= nofEvents; >> 189 G4cout << " TOTAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" >> 190 << G4endl; >> 191 } 164 } 192 } 165 } << 193 else 166 else { << 194 { 167 // convert to units of Gy << 195 // convert to units of Gy 168 local_total_dose /= gray; << 196 local_total_dose /= gray; 169 G4cout << "--------------------End of Loca << 197 G4cout << "--------------------End of Local Run------------------------" 170 G4cout << " The run was " << nofEvents << << 198 << G4endl; 171 G4cout << "LOCAL TOTAL DOSE : \t" << local << 199 G4cout << " The run was " << nofEvents << " events" << G4endl; 172 if (nofEvents > 0) { << 200 G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl; 173 local_total_dose /= nofEvents; << 201 if(nofEvents > 0) 174 G4cout << " LOCAL DOSE/Bq-s : \t" << loc << 202 { >> 203 local_total_dose /= nofEvents; >> 204 G4cout << " LOCAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" >> 205 << G4endl; >> 206 } 175 } 207 } 176 } << 177 208 178 G4cout << G4endl; << 209 G4cout << G4endl; 179 G4cout << "Finished : End of Run Action " << << 210 G4cout << "Finished : End of Run Action " << aRun->GetRunID() << "\n" << G4endl; >> 211 180 } 212 } 181 213