ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dicom2RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Dicom2RunAction.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 //
29 //
30 
31 #include "Dicom2RunAction.hh"
32 #include "Dicom2Run.hh"
33 
34 //-- In order to obtain detector information.
35 #include <fstream>
36 #include <iomanip>
37 #include "G4THitsMap.hh"
38 
39 #include "G4UnitsTable.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4StatAnalysis.hh"
42 
43 #include "G4RunManager.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 { }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 Dicom2Run.hh/cc.
62  return fDcmrun = new Dicom2Run(fSDName);
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 {
68  // Lock the output because of the external calls to DicomRunAction
69  // otherwise, the output gets too confusing
70  G4AutoLock l(G4TypeMutex<Dicom2RunAction>());
71 
72  G4cout << G4endl;
73  G4cout << "[==========================================================="
74  << " DICOM "
75  << "===========================================================]"
76  << G4endl;
77  G4cout << G4endl;
78 
80 
81  G4cout << G4endl;
82  G4cout << "[==========================================================="
83  << " DICOM2 "
84  << "==========================================================]"
85  << G4endl;
86  G4cout << G4endl;
87 
88  G4int nofEvents = aRun->GetNumberOfEvent();
89 
90  G4StatAnalysis local_total_dose;
91 
92  const Dicom2Run* dcm2Run = static_cast<const Dicom2Run*>(aRun);
93  //--- Dump all scored quantities involved in Dicom2Run.
94  for(uintmax_t i = 0; i < fSDName.size(); i++)
95  {
96  //
97  //---------------------------------------------
98  // Dump accumulated quantities for this RUN.
99  // (Display only central region of x-y plane)
100  // 0 ConcreteSD/DoseDeposit
101  //---------------------------------------------
102  Dicom2RunVector* DoseDeposit =
103  dcm2Run->GetHitsVector(fSDName[i]+"/DoseDeposit");
104 
105  if(DoseDeposit && DoseDeposit->size() != 0 )
106  {
107  for(auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr)
108  {
109  // this will sometimes return null pointers
110  if(!DoseDeposit->GetObject(itr))
111  continue;
112  local_total_dose += (*DoseDeposit->GetObject(itr));
113  }
114  }
115  }
116 
117  if(IsMaster())
118  {
119  G4cout << " ###### EndOfRunAction ###### " << G4endl;
120  //- Dicom2Run object.
121  const Dicom2Run* re02Run = static_cast<const Dicom2Run*>(aRun);
122  //--- Dump all scored quantities involved in Dicom2Run.
123 
124  for(uintmax_t i = 0; i < fSDName.size(); i++)
125  {
126  //
127  //---------------------------------------------
128  // Dump accumulated quantities for this RUN.
129  // (Display only central region of x-y plane)
130  // 0 ConcreteSD/DoseDeposit
131  //---------------------------------------------
132  Dicom2RunVector* DoseDeposit =
133  re02Run->GetHitsVector(fSDName[i]+"/DoseDeposit");
134 
135  G4cout << "============================================================="
136  <<G4endl;
137  G4cout << " Number of event processed : "
138  << aRun->GetNumberOfEvent() << G4endl;
139  G4cout << "============================================================="
140  <<G4endl;
141 
142  std::ofstream fileout;
143  G4String fname = "dicom2-vector.out";
144  fileout.open(fname);
145  G4cout << " opened file " << fname << " for dose output" << G4endl;
146 
147  if(DoseDeposit && DoseDeposit->size() != 0)
148  {
149  std::ostream *myout = &G4cout;
150  PrintHeader(myout);
151  for(auto itr = DoseDeposit->begin(); itr != DoseDeposit->end();
152  ++itr)
153  {
154  auto _idx = DoseDeposit->GetIndex(itr);
155  G4StatAnalysis* _stat = DoseDeposit->GetObject(itr);
156  if(_stat && _stat->GetHits() > 0)
157  {
158  G4StatAnalysis _tmp_stat = *_stat;
159  _tmp_stat /= CLHEP::gray;
160  fileout << _idx << " " << (*_stat) << G4endl;
161  }
162  }
163  G4cout << "============================================="<<G4endl;
164  }
165  else
166  {
167  G4Exception("Dicom2RunAction", "000", JustWarning,
168  "DoseDeposit HitsMap is either a null pointer "
169  "of the HitsMap was empty");
170  }
171  fileout.close();
172  G4cout << " closed file " << fname << " for dose output" << G4endl;
173 
174  }
175  }
176 
177 
178  if (IsMaster())
179  {
180  // convert to units of Gy
181  local_total_dose /= gray;
182  G4cout << "--------------------End of Global Run-----------------------"
183  << G4endl;
184  G4cout << " The run was " << nofEvents << " events " << G4endl;
185  G4cout << " TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
186  if(nofEvents > 0)
187  {
188  local_total_dose /= nofEvents;
189  G4cout << " TOTAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s"
190  << G4endl;
191  }
192  }
193  else
194  {
195  // convert to units of Gy
196  local_total_dose /= gray;
197  G4cout << "--------------------End of Local Run------------------------"
198  << G4endl;
199  G4cout << " The run was " << nofEvents << " events" << G4endl;
200  G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
201  if(nofEvents > 0)
202  {
203  local_total_dose /= nofEvents;
204  G4cout << " LOCAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s"
205  << G4endl;
206  }
207  }
208 
209  G4cout << G4endl;
210  G4cout << "Finished : End of Run Action " << aRun->GetRunID() << "\n" << G4endl;
211 
212 }