Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DicomRunAction.cc
Go to the documentation of this file.
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 //
28 
29 #include "DicomRunAction.hh"
30 #include "DicomRun.hh"
31 
32 //-- In order to obtain detector information.
33 #include <fstream>
34 #include <iomanip>
35 #include "G4THitsMap.hh"
36 
37 #include "G4UnitsTable.hh"
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41  fFieldName(15),
42  fFieldValue(14)
43 {
44  // - Prepare data member for DicomRun.
45  // vector represents a list of MultiFunctionalDetector names.
46  fSDName.push_back(G4String("phantomSD"));
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 {
53  fSDName.clear();
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 {
59  // Generate new RUN object, which is specially
60  // dedicated for MultiFunctionalDetector scheme.
61  // Detail description can be found in DicomRun.hh/cc.
62  return new DicomRun(fSDName);
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 {
68  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 {
74  G4cout << " ###### EndOfRunAction " <<G4endl;
75  //- DicomRun object.
76  DicomRun* re02Run = (DicomRun*)aRun;
77  //--- Dump all scored quantities involved in DicomRun.
78  for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){
79  //
80  //---------------------------------------------
81  // Dump accumulated quantities for this RUN.
82  // (Display only central region of x-y plane)
83  // 0 ConcreteSD/DoseDeposit
84  //---------------------------------------------
85  G4THitsMap<G4double>* DoseDeposit = re02Run->GetHitsMap(fSDName[i]+"/DoseDeposit");
86 
87  G4cout << "=============================================================" <<G4endl;
88  G4cout << " Number of event processed : "<< aRun->GetNumberOfEvent() << G4endl;
89  G4cout << "=============================================================" <<G4endl;
90 
91  std::ofstream fileout;
92  G4String fname = "dicom.out";
93  fileout.open(fname);
94  G4cout << " opened file " << fname << " for dose output" << G4endl;
95 
96 
97  if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) {
98  std::ostream *myout = &G4cout;
99  PrintHeader(myout);
100  std::map<G4int,G4double*>::iterator itr = DoseDeposit->GetMap()->begin();
101  for(; itr != DoseDeposit->GetMap()->end(); itr++) {
102  fileout << itr->first
103  << " " << *(itr->second)
104  << G4endl;
105  G4cout << " " << itr->first
106  << " " << std::setprecision(6) << *(itr->second) << " Gy"
107  << G4endl;
108  }
109  G4cout << "============================================="<<G4endl;
110  }
111  fileout.close();
112  G4cout << " closed file " << fname << " for dose output" << G4endl;
113 
114  }
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 void DicomRunAction::PrintHeader(std::ostream *out)
119 {
120  std::vector<G4String> vecScoreName;
121  vecScoreName.push_back("DoseDeposit");
122 
123  // head line
124  //std::string vname = FillString("Volume", ' ', fFieldName+1);
125  //*out << vname << '|';
126  std::string vname;
127  *out << std::setw(10) << "Voxel" << " |";
128  for (std::vector<G4String>::iterator it = vecScoreName.begin();
129  it != vecScoreName.end(); it++) {
130  //vname = FillString((*it),
131 // ' ',
132 // FieldValue+1,
133 // false);
134 // *out << vname << '|';
135  *out << std::setw(fFieldValue) << (*it) << " |";
136  }
137  *out << G4endl;
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 std::string DicomRunAction::FillString(const std::string &name,
142  char c, G4int n, G4bool back)
143 {
144  std::string fname("");
145  G4int k = n - name.size();
146  if (k > 0) {
147  if (back) {
148  fname = name;
149  fname += std::string(k,c);
150  }
151  else {
152  fname = std::string(k,c);
153  fname += name;
154  }
155  }
156  else {
157  fname = name;
158  }
159  return fname;
160 }