Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
DicomRunAction.cc
이 파일의 문서화 페이지로 가기
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 // $Id: DicomRunAction.cc 92820 2015-09-17 15:22:14Z gcosmo $
27 //
30 //
31 
32 #include "DicomRunAction.hh"
33 #include "DicomRun.hh"
34 
35 //-- In order to obtain detector information.
36 #include <fstream>
37 #include <iomanip>
38 #include "G4THitsMap.hh"
39 
40 #include "G4UnitsTable.hh"
41 #include "G4SystemOfUnits.hh"
42 
43 #include "G4RunManager.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 : G4UserRunAction(), fDcmrun(0), fFieldValue(14)
57 {
58  // - Prepare data member for DicomRun.
59  // vector represents a list of MultiFunctionalDetector names.
60  fSDName.push_back(G4String("phantomSD"));
61  fInstance = this;
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 {
68  fSDName.clear();
69  fInstance = 0;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 {
75  // Generate new RUN object, which is specially
76  // dedicated for MultiFunctionalDetector scheme.
77  // Detail description can be found in DicomRun.hh/cc.
78  //return new DicomRun(fSDName);
79  return fDcmrun = new DicomRun(fSDName);
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 {
85  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
86  //inform the runManager to save random number seed
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 {
93  G4int nofEvents = aRun->GetNumberOfEvent();
94  if (nofEvents == 0) return;
95  //print
96  //
97 
98  static double local_total_dose = 0;
99  double total_dose = 0;
100 
101  const DicomRun* reRun = static_cast<const DicomRun*>(aRun);
102  //--- Dump all scored quantities involved in DicomRun.
103  for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){
104  //
105  //---------------------------------------------
106  // Dump accumulated quantities for this RUN.
107  // (Display only central region of x-y plane)
108  // 0 ConcreteSD/DoseDeposit
109  //---------------------------------------------
110  G4THitsMap<G4double>* DoseDeposit =
111  reRun->GetHitsMap(fSDName[i]+"/DoseDeposit");
112 
113  if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) {
114  std::map<G4int,G4double*>::iterator itr =
115  DoseDeposit->GetMap()->begin();
116  for(; itr != DoseDeposit->GetMap()->end(); itr++) {
117  if(!IsMaster()) { local_total_dose += *(itr->second); }
118  total_dose += *(itr->second);
119  }
120  }
121 
122  }
123 
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()) {
148  G4cout << " ###### EndOfRunAction ###### " << G4endl;
149  //- DicomRun object.
150  const DicomRun* re02Run = static_cast<const DicomRun*>(aRun);
151  //--- Dump all scored quantities involved in DicomRun.
152 
153  for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){
154  //
155  //---------------------------------------------
156  // Dump accumulated quantities for this RUN.
157  // (Display only central region of x-y plane)
158  // 0 ConcreteSD/DoseDeposit
159  //---------------------------------------------
160  G4THitsMap<G4double>* DoseDeposit =
161  re02Run->GetHitsMap(fSDName[i]+"/DoseDeposit");
162 
163  G4cout << "============================================================="
164  <<G4endl;
165  G4cout << " Number of event processed : "
166  << aRun->GetNumberOfEvent() << G4endl;
167  G4cout << "============================================================="
168  <<G4endl;
169 
170  std::ofstream fileout;
171  G4String fname = "dicom.out";
172  fileout.open(fname);
173  G4cout << " opened file " << fname << " for dose output" << G4endl;
174 
175  if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) {
176  std::ostream *myout = &G4cout;
177  PrintHeader(myout);
178  std::map<G4int,G4double*>::iterator itr =DoseDeposit->GetMap()->begin();
179  for(; itr != DoseDeposit->GetMap()->end(); itr++) {
180  fileout << itr->first
181  << " " << *(itr->second)/CLHEP::gray
182  << G4endl;
183  G4cout << " " << itr->first
184  << " " << std::setprecision(6)
185  << *(itr->second)/CLHEP::gray << " Gy"
186  << G4endl;
187  }
188  G4cout << "============================================="<<G4endl;
189  } else {
190  G4Exception("DicomRunAction", "000", JustWarning,
191  "DoseDeposit HitsMap is either a null pointer of the HitsMap was empty");
192  }
193  fileout.close();
194  G4cout << " closed file " << fname << " for dose output" << G4endl;
195 
196  }
197  }
198 
199  G4cout << "Finished : End of Run Action " << aRun->GetRunID() << G4endl;
200 
201 }
202 
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204 void DicomRunAction::PrintHeader(std::ostream *out)
205 {
206  std::vector<G4String> vecScoreName;
207  vecScoreName.push_back("DoseDeposit");
208 
209  // head line
210  //
211  std::string vname;
212  *out << std::setw(10) << "Voxel" << " |";
213  for (std::vector<G4String>::iterator it = vecScoreName.begin();
214  it != vecScoreName.end(); it++) {
215  //vname = FillString((*it),
216  // ' ',
217  // FieldValue+1,
218  // false);
219  // *out << vname << '|';
220  *out << std::setw(fFieldValue) << (*it) << " |";
221  }
222  *out << G4endl;
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
226 std::string DicomRunAction::FillString(const std::string &name,
227  char c, G4int n, G4bool back)
228 {
229  std::string fname("");
230  G4int k = n - name.size();
231  if (k > 0) {
232  if (back) {
233  fname = name;
234  fname += std::string(k,c);
235  }
236  else {
237  fname = std::string(k,c);
238  fname += name;
239  }
240  }
241  else {
242  fname = name;
243  }
244  return fname;
245 }
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
const XML_Char * name
Definition: expat.h:151
static constexpr double gray
Definition of the DicomRun class.
#define G4endl
Definition: G4ios.hh:61
std::vector< G4String > fSDName
static constexpr double gray
Definition: G4SIunits.hh:309
Definition of the DicomRunAction class.
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
virtual void BeginOfRunAction(const G4Run *)
virtual void EndOfRunAction(const G4Run *)
void PrintHeader(std::ostream *out)
bool G4bool
Definition: G4Types.hh:79
static DicomRunAction * fInstance
static DicomRunAction * Instance()
std::string FillString(const std::string &name, char c, G4int n, G4bool back=true)
G4int GetRunID() const
Definition: G4Run.hh:76
G4THitsMap< G4double > * GetHitsMap(G4int i) const
Definition: DicomRun.hh:71
G4bool IsMaster() const
Definition: G4Run.hh:46
DicomRun * fDcmrun
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
void SetRandomNumberStore(G4bool flag)
int G4int
Definition: G4Types.hh:78
DicomRunAction()
Constructor.
G4GLOB_DLL std::ostream G4cout
virtual ~DicomRunAction()
Destructor.
Char_t n[5]
virtual G4Run * GenerateRun()
Map_t * GetMap() const
Definition: G4THitsMap.hh:117