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 // $Id: DicomRunAction.cc 92820 2015-09-17 15:22:14Z gcosmo $ 26 // 27 // 27 /// \file DicomRunAction.cc 28 /// \file DicomRunAction.cc 28 /// \brief Implementation of the DicomRunActio 29 /// \brief Implementation of the DicomRunAction class 29 // 30 // 30 31 31 #include "DicomRunAction.hh" 32 #include "DicomRunAction.hh" 32 << 33 #include "DicomRun.hh" 33 #include "DicomRun.hh" 34 34 35 //-- In order to obtain detector information. 35 //-- In order to obtain detector information. 36 #include "G4RunManager.hh" << 36 #include <fstream> 37 #include "G4SystemOfUnits.hh" << 37 #include <iomanip> 38 #include "G4THitsMap.hh" 38 #include "G4THitsMap.hh" >> 39 39 #include "G4UnitsTable.hh" 40 #include "G4UnitsTable.hh" >> 41 #include "G4SystemOfUnits.hh" 40 42 41 #include <fstream> << 43 #include "G4RunManager.hh" 42 #include <iomanip> << 44 >> 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 46 >> 47 DicomRunAction* DicomRunAction::fInstance = 0; >> 48 >> 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 50 >> 51 DicomRunAction* DicomRunAction::Instance() { return fInstance; } 43 52 44 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 /// Constructor 54 /// Constructor 46 DicomRunAction::DicomRunAction() : G4UserRunAc << 55 DicomRunAction::DicomRunAction() >> 56 : G4UserRunAction(), fDcmrun(0), fFieldValue(14) 47 { 57 { 48 // - Prepare data member for DicomRun. << 58 // - Prepare data member for DicomRun. 49 // vector represents a list of MultiFuncti << 59 // vector represents a list of MultiFunctionalDetector names. 50 fSDName.push_back(G4String("phantomSD")); << 60 fSDName.push_back(G4String("phantomSD")); >> 61 fInstance = this; 51 } 62 } 52 63 53 //....oooOO0OOooo........oooOO0OOooo........oo 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 /// Destructor. 65 /// Destructor. 55 DicomRunAction::~DicomRunAction() 66 DicomRunAction::~DicomRunAction() 56 { 67 { 57 fSDName.clear(); 68 fSDName.clear(); >> 69 fInstance = 0; 58 } 70 } 59 71 60 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 61 G4Run* DicomRunAction::GenerateRun() 73 G4Run* DicomRunAction::GenerateRun() 62 { 74 { 63 // Generate new RUN object, which is special 75 // Generate new RUN object, which is specially 64 // dedicated for MultiFunctionalDetector sch 76 // dedicated for MultiFunctionalDetector scheme. 65 // Detail description can be found in Dicom 77 // Detail description can be found in DicomRun.hh/cc. 66 // return new DicomRun(fSDName); << 78 //return new DicomRun(fSDName); 67 return fDcmrun = new DicomRun(fSDName); 79 return fDcmrun = new DicomRun(fSDName); 68 } 80 } 69 81 70 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 void DicomRunAction::BeginOfRunAction(const G4 83 void DicomRunAction::BeginOfRunAction(const G4Run* aRun) 72 { 84 { 73 G4cout << "### Run " << aRun->GetRunID() << 85 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 74 // inform the runManager to save random numb << 86 //inform the runManager to save random number seed 75 G4RunManager::GetRunManager()->SetRandomNumb << 87 G4RunManager::GetRunManager()->SetRandomNumberStore(false); 76 G4RunManager::GetRunManager()->SetRandomNumb << 77 G4RunManager::GetRunManager()->SetRandomNumb << 78 << 79 << 80 G4int progress = aRun->GetNumberOfEventToBeP << 81 progress = (progress < 1) ? 1 : progress; << 82 G4RunManager::GetRunManager()->SetPrintProgr << 83 } 88 } 84 89 85 //....oooOO0OOooo........oooOO0OOooo........oo 90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 86 void DicomRunAction::EndOfRunAction(const G4Ru 91 void DicomRunAction::EndOfRunAction(const G4Run* aRun) 87 { 92 { 88 G4int nofEvents = aRun->GetNumberOfEvent(); 93 G4int nofEvents = aRun->GetNumberOfEvent(); 89 << 94 if (nofEvents == 0) return; 90 static G4double local_total_dose = 0; << 95 //print 91 G4double total_dose = 0; << 96 // 92 << 97 >> 98 static double local_total_dose = 0; >> 99 double total_dose = 0; >> 100 93 const DicomRun* reRun = static_cast<const Di 101 const DicomRun* reRun = static_cast<const DicomRun*>(aRun); 94 //--- Dump all scored quantities involved in 102 //--- Dump all scored quantities involved in DicomRun. 95 for (G4int i = 0; i < (G4int)fSDName.size(); << 103 for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){ 96 // 104 // 97 //---------------------------------------- 105 //--------------------------------------------- 98 // Dump accumulated quantities for this RU 106 // Dump accumulated quantities for this RUN. 99 // (Display only central region of x-y pl 107 // (Display only central region of x-y plane) 100 // 0 ConcreteSD/DoseDeposit 108 // 0 ConcreteSD/DoseDeposit 101 //---------------------------------------- 109 //--------------------------------------------- 102 G4THitsMap<G4double>* DoseDeposit = reRun- << 110 G4THitsMap<G4double>* DoseDeposit = 103 << 111 reRun->GetHitsMap(fSDName[i]+"/DoseDeposit"); 104 if (DoseDeposit && DoseDeposit->GetMap()-> << 112 105 std::map<G4int, G4double*>::iterator itr << 113 if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) { 106 for (; itr != DoseDeposit->GetMap()->end << 114 std::map<G4int,G4double*>::iterator itr = 107 if (!IsMaster()) { << 115 DoseDeposit->GetMap()->begin(); 108 local_total_dose += *(itr->second); << 116 for(; itr != DoseDeposit->GetMap()->end(); itr++) { 109 } << 117 if(!IsMaster()) { local_total_dose += *(itr->second); } 110 total_dose += *(itr->second); 118 total_dose += *(itr->second); 111 } 119 } 112 } 120 } 113 } << 114 121 115 if (IsMaster()) { << 116 G4cout << "--------------------End of Glob << 117 G4cout << " The run was " << nofEvents << << 118 G4cout << "LOCAL TOTAL DOSE : \t" << local << 119 G4cout << " TOTAL DOSE : \t" << total << 120 } << 121 else { << 122 G4cout << "--------------------End of Loca << 123 G4cout << " The run was " << nofEvents << << 124 G4cout << "LOCAL TOTAL DOSE : \t" << local << 125 G4cout << " TOTAL DOSE : \t" << total << 126 } 122 } 127 << 123 128 if (IsMaster()) { << 124 if (IsMaster()) >> 125 { >> 126 G4cout >> 127 << "\n--------------------End of Global Run-----------------------" >> 128 << " \n The run was " << nofEvents << " events " << G4endl; >> 129 G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose/gray >> 130 << " Gy" << std::endl; >> 131 G4cout << " TOTAL DOSE : \t" << total_dose/gray >> 132 << " Gy" << std::endl; >> 133 >> 134 } >> 135 else >> 136 { >> 137 G4cout >> 138 << "\n--------------------End of Local Run------------------------" >> 139 << " \n The run was " << nofEvents << G4endl; >> 140 G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose/gray >> 141 << " Gy" << std::endl; >> 142 G4cout << " TOTAL DOSE : \t" << total_dose/gray >> 143 << " Gy" << std::endl; >> 144 >> 145 } >> 146 >> 147 if(IsMaster()) { 129 G4cout << " ###### EndOfRunAction ###### " 148 G4cout << " ###### EndOfRunAction ###### " << G4endl; 130 //- DicomRun object. 149 //- DicomRun object. 131 const DicomRun* re02Run = static_cast<cons 150 const DicomRun* re02Run = static_cast<const DicomRun*>(aRun); 132 //--- Dump all scored quantities involved 151 //--- Dump all scored quantities involved in DicomRun. 133 << 152 134 for (G4int i = 0; i < (G4int)fSDName.size( << 153 for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){ 135 // 154 // 136 //-------------------------------------- 155 //--------------------------------------------- 137 // Dump accumulated quantities for this 156 // Dump accumulated quantities for this RUN. 138 // (Display only central region of x-y 157 // (Display only central region of x-y plane) 139 // 0 ConcreteSD/DoseDeposit 158 // 0 ConcreteSD/DoseDeposit 140 //-------------------------------------- 159 //--------------------------------------------- 141 G4THitsMap<G4double>* DoseDeposit = re02 << 160 G4THitsMap<G4double>* DoseDeposit = 142 << 161 re02Run->GetHitsMap(fSDName[i]+"/DoseDeposit"); 143 G4cout << "============================= << 162 144 G4cout << " Number of event processed : << 163 G4cout << "=============================================================" 145 G4cout << "============================= << 164 <<G4endl; 146 << 165 G4cout << " Number of event processed : " >> 166 << aRun->GetNumberOfEvent() << G4endl; >> 167 G4cout << "=============================================================" >> 168 <<G4endl; >> 169 147 std::ofstream fileout; 170 std::ofstream fileout; 148 G4String fname = "dicom.out"; 171 G4String fname = "dicom.out"; 149 fileout.open(fname); 172 fileout.open(fname); 150 G4cout << " opened file " << fname << " 173 G4cout << " opened file " << fname << " for dose output" << G4endl; 151 << 174 152 if (DoseDeposit && DoseDeposit->GetMap() << 175 if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) { 153 std::ostream* myout = &G4cout; << 176 std::ostream *myout = &G4cout; 154 PrintHeader(myout); 177 PrintHeader(myout); 155 std::map<G4int, G4double*>::iterator i << 178 std::map<G4int,G4double*>::iterator itr =DoseDeposit->GetMap()->begin(); 156 for (; itr != DoseDeposit->GetMap()->e << 179 for(; itr != DoseDeposit->GetMap()->end(); itr++) { 157 fileout << itr->first << " " << << 180 fileout << itr->first 158 // G4cout << " " << itr->first << 181 << " " << *(itr->second)/CLHEP::gray 159 // << " " << std::setprec << 182 << G4endl; 160 // << *(itr->second)/CLHEP::g << 183 G4cout << " " << itr->first 161 // << G4endl; << 184 << " " << std::setprecision(6) >> 185 << *(itr->second)/CLHEP::gray << " Gy" >> 186 << G4endl; 162 } 187 } 163 G4cout << "=========================== << 188 G4cout << "============================================="<<G4endl; 164 } << 189 } else { 165 else { << 190 G4Exception("DicomRunAction", "000", JustWarning, 166 G4Exception("DicomRunAction", "000", J << 191 "DoseDeposit HitsMap is either a null pointer of the HitsMap was empty"); 167 "DoseDeposit HitsMap is ei << 168 } 192 } 169 fileout.close(); 193 fileout.close(); 170 G4cout << " closed file " << fname << " 194 G4cout << " closed file " << fname << " for dose output" << G4endl; >> 195 171 } 196 } 172 } 197 } 173 << 198 174 G4cout << "Finished : End of Run Action " << 199 G4cout << "Finished : End of Run Action " << aRun->GetRunID() << G4endl; >> 200 175 } 201 } 176 202 177 //....oooOO0OOooo........oooOO0OOooo........oo 203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 178 void DicomRunAction::PrintHeader(std::ostream* << 204 void DicomRunAction::PrintHeader(std::ostream *out) 179 { 205 { 180 std::vector<G4String> vecScoreName; 206 std::vector<G4String> vecScoreName; 181 vecScoreName.push_back("DoseDeposit"); 207 vecScoreName.push_back("DoseDeposit"); 182 << 208 183 // head line 209 // head line 184 // 210 // 185 std::string vname; 211 std::string vname; 186 *out << std::setw(10) << "Voxel" << 212 *out << std::setw(10) << "Voxel" << " |"; 187 << " |"; << 213 for (std::vector<G4String>::iterator it = vecScoreName.begin(); 188 for (std::vector<G4String>::iterator it = ve << 214 it != vecScoreName.end(); it++) { 189 // vname = FillString((*it), << 215 //vname = FillString((*it), 190 // ' ', << 216 // ' ', 191 // FieldValue+1, << 217 // FieldValue+1, 192 // false); << 218 // false); 193 // *out << vname << '|'; << 219 // *out << vname << '|'; 194 *out << std::setw(fFieldValue) << (*it) << 220 *out << std::setw(fFieldValue) << (*it) << " |"; 195 } 221 } 196 *out << G4endl; 222 *out << G4endl; 197 } 223 } 198 224 199 //....oooOO0OOooo........oooOO0OOooo........oo 225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 200 std::string DicomRunAction::FillString(const s << 226 std::string DicomRunAction::FillString(const std::string &name, >> 227 char c, G4int n, G4bool back) 201 { 228 { 202 std::string fname(""); 229 std::string fname(""); 203 G4int k = G4int(n - name.size()); << 230 G4int k = n - name.size(); 204 if (k > 0) { 231 if (k > 0) { 205 if (back) { 232 if (back) { 206 fname = name; 233 fname = name; 207 fname += std::string(k, c); << 234 fname += std::string(k,c); 208 } 235 } 209 else { 236 else { 210 fname = std::string(k, c); << 237 fname = std::string(k,c); 211 fname += name; 238 fname += name; 212 } 239 } 213 } 240 } 214 else { 241 else { 215 fname = name; 242 fname = name; 216 } 243 } 217 return fname; 244 return fname; 218 } 245 } 219 246