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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/DICOM/src/DicomRunAction.cc (Version 11.3.0) and /examples/extended/medical/DICOM/src/DicomRunAction.cc (Version 11.1.2)


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