Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file DicomRunAction.cc 28 /// \brief Implementation of the DicomRunActio 29 // 30 31 #include "DicomRunAction.hh" 32 33 #include "DicomRun.hh" 34 35 //-- In order to obtain detector information. 36 #include "G4RunManager.hh" 37 #include "G4SystemOfUnits.hh" 38 #include "G4THitsMap.hh" 39 #include "G4UnitsTable.hh" 40 41 #include <fstream> 42 #include <iomanip> 43 44 //....oooOO0OOooo........oooOO0OOooo........oo 45 /// Constructor 46 DicomRunAction::DicomRunAction() : G4UserRunAc 47 { 48 // - Prepare data member for DicomRun. 49 // vector represents a list of MultiFuncti 50 fSDName.push_back(G4String("phantomSD")); 51 } 52 53 //....oooOO0OOooo........oooOO0OOooo........oo 54 /// Destructor. 55 DicomRunAction::~DicomRunAction() 56 { 57 fSDName.clear(); 58 } 59 60 //....oooOO0OOooo........oooOO0OOooo........oo 61 G4Run* DicomRunAction::GenerateRun() 62 { 63 // Generate new RUN object, which is special 64 // dedicated for MultiFunctionalDetector sch 65 // Detail description can be found in Dicom 66 // return new DicomRun(fSDName); 67 return fDcmrun = new DicomRun(fSDName); 68 } 69 70 //....oooOO0OOooo........oooOO0OOooo........oo 71 void DicomRunAction::BeginOfRunAction(const G4 72 { 73 G4cout << "### Run " << aRun->GetRunID() << 74 // inform the runManager to save random numb 75 G4RunManager::GetRunManager()->SetRandomNumb 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 } 84 85 //....oooOO0OOooo........oooOO0OOooo........oo 86 void DicomRunAction::EndOfRunAction(const G4Ru 87 { 88 G4int nofEvents = aRun->GetNumberOfEvent(); 89 90 static G4double local_total_dose = 0; 91 G4double total_dose = 0; 92 93 const DicomRun* reRun = static_cast<const Di 94 //--- Dump all scored quantities involved in 95 for (G4int i = 0; i < (G4int)fSDName.size(); 96 // 97 //---------------------------------------- 98 // Dump accumulated quantities for this RU 99 // (Display only central region of x-y pl 100 // 0 ConcreteSD/DoseDeposit 101 //---------------------------------------- 102 G4THitsMap<G4double>* DoseDeposit = reRun- 103 104 if (DoseDeposit && DoseDeposit->GetMap()-> 105 std::map<G4int, G4double*>::iterator itr 106 for (; itr != DoseDeposit->GetMap()->end 107 if (!IsMaster()) { 108 local_total_dose += *(itr->second); 109 } 110 total_dose += *(itr->second); 111 } 112 } 113 } 114 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 } 127 128 if (IsMaster()) { 129 G4cout << " ###### EndOfRunAction ###### " 130 //- DicomRun object. 131 const DicomRun* re02Run = static_cast<cons 132 //--- Dump all scored quantities involved 133 134 for (G4int i = 0; i < (G4int)fSDName.size( 135 // 136 //-------------------------------------- 137 // Dump accumulated quantities for this 138 // (Display only central region of x-y 139 // 0 ConcreteSD/DoseDeposit 140 //-------------------------------------- 141 G4THitsMap<G4double>* DoseDeposit = re02 142 143 G4cout << "============================= 144 G4cout << " Number of event processed : 145 G4cout << "============================= 146 147 std::ofstream fileout; 148 G4String fname = "dicom.out"; 149 fileout.open(fname); 150 G4cout << " opened file " << fname << " 151 152 if (DoseDeposit && DoseDeposit->GetMap() 153 std::ostream* myout = &G4cout; 154 PrintHeader(myout); 155 std::map<G4int, G4double*>::iterator i 156 for (; itr != DoseDeposit->GetMap()->e 157 fileout << itr->first << " " << 158 // G4cout << " " << itr->first 159 // << " " << std::setprec 160 // << *(itr->second)/CLHEP::g 161 // << G4endl; 162 } 163 G4cout << "=========================== 164 } 165 else { 166 G4Exception("DicomRunAction", "000", J 167 "DoseDeposit HitsMap is ei 168 } 169 fileout.close(); 170 G4cout << " closed file " << fname << " 171 } 172 } 173 174 G4cout << "Finished : End of Run Action " << 175 } 176 177 //....oooOO0OOooo........oooOO0OOooo........oo 178 void DicomRunAction::PrintHeader(std::ostream* 179 { 180 std::vector<G4String> vecScoreName; 181 vecScoreName.push_back("DoseDeposit"); 182 183 // head line 184 // 185 std::string vname; 186 *out << std::setw(10) << "Voxel" 187 << " |"; 188 for (std::vector<G4String>::iterator it = ve 189 // vname = FillString((*it), 190 // ' ', 191 // FieldValue+1, 192 // false); 193 // *out << vname << '|'; 194 *out << std::setw(fFieldValue) << (*it) << 195 } 196 *out << G4endl; 197 } 198 199 //....oooOO0OOooo........oooOO0OOooo........oo 200 std::string DicomRunAction::FillString(const s 201 { 202 std::string fname(""); 203 G4int k = G4int(n - name.size()); 204 if (k > 0) { 205 if (back) { 206 fname = name; 207 fname += std::string(k, c); 208 } 209 else { 210 fname = std::string(k, c); 211 fname += name; 212 } 213 } 214 else { 215 fname = name; 216 } 217 return fname; 218 } 219