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