Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:46

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 /// \file Dicom2RunAction.cc
0028 /// \brief Implementation of the Dicom2RunAction class
0029 //
0030 
0031 #include "Dicom2RunAction.hh"
0032 
0033 #include "Dicom2Run.hh"
0034 
0035 //-- In order to obtain detector information.
0036 #include "G4RunManager.hh"
0037 #include "G4StatAnalysis.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4THitsMap.hh"
0040 #include "G4UnitsTable.hh"
0041 
0042 #include <fstream>
0043 #include <iomanip>
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 /// Constructor
0047 Dicom2RunAction::Dicom2RunAction() : DicomRunAction() {}
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 /// Destructor.
0051 Dicom2RunAction::~Dicom2RunAction() {}
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 G4Run* Dicom2RunAction::GenerateRun()
0055 {
0056   // Generate new RUN object, which is specially
0057   // dedicated for MultiFunctionalDetector scheme.
0058   //  Detail description can be found in Dicom2Run.hh/cc.
0059   return fDcmrun = new Dicom2Run(fSDName);
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 void Dicom2RunAction::EndOfRunAction(const G4Run* aRun)
0064 {
0065   // Lock the output because of the external calls to DicomRunAction
0066   // otherwise, the output gets too confusing
0067   G4AutoLock l(G4TypeMutex<Dicom2RunAction>());
0068 
0069   G4cout << G4endl;
0070   G4cout << "[==========================================================="
0071          << " DICOM "
0072          << "===========================================================]" << G4endl;
0073   G4cout << G4endl;
0074 
0075   DicomRunAction::EndOfRunAction(aRun);
0076 
0077   G4cout << G4endl;
0078   G4cout << "[==========================================================="
0079          << " DICOM2 "
0080          << "==========================================================]" << G4endl;
0081   G4cout << G4endl;
0082 
0083   G4int nofEvents = aRun->GetNumberOfEvent();
0084 
0085   G4StatAnalysis local_total_dose;
0086 
0087   const Dicom2Run* dcm2Run = static_cast<const Dicom2Run*>(aRun);
0088   //--- Dump all scored quantities involved in Dicom2Run.
0089   for (uintmax_t i = 0; i < fSDName.size(); i++) {
0090     //
0091     //---------------------------------------------
0092     // Dump accumulated quantities for this RUN.
0093     //  (Display only central region of x-y plane)
0094     //      0       ConcreteSD/DoseDeposit
0095     //---------------------------------------------
0096     Dicom2RunVector* DoseDeposit = dcm2Run->GetHitsVector(fSDName[i] + "/DoseDeposit");
0097 
0098     if (DoseDeposit && DoseDeposit->size() != 0) {
0099       for (auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr) {
0100         // this will sometimes return null pointers
0101         if (!DoseDeposit->GetObject(itr)) continue;
0102         local_total_dose += (*DoseDeposit->GetObject(itr));
0103       }
0104     }
0105   }
0106 
0107   if (IsMaster()) {
0108     G4cout << " ###### EndOfRunAction ###### " << G4endl;
0109     //- Dicom2Run object.
0110     const Dicom2Run* re02Run = static_cast<const Dicom2Run*>(aRun);
0111     //--- Dump all scored quantities involved in Dicom2Run.
0112 
0113     for (uintmax_t i = 0; i < fSDName.size(); i++) {
0114       //
0115       //---------------------------------------------
0116       // Dump accumulated quantities for this RUN.
0117       //  (Display only central region of x-y plane)
0118       //      0       ConcreteSD/DoseDeposit
0119       //---------------------------------------------
0120       Dicom2RunVector* DoseDeposit = re02Run->GetHitsVector(fSDName[i] + "/DoseDeposit");
0121 
0122       G4cout << "=============================================================" << G4endl;
0123       G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
0124       G4cout << "=============================================================" << G4endl;
0125 
0126       std::ofstream fileout;
0127       G4String fname = "dicom2-vector.out";
0128       fileout.open(fname);
0129       G4cout << " opened file " << fname << " for dose output" << G4endl;
0130 
0131       if (DoseDeposit && DoseDeposit->size() != 0) {
0132         std::ostream* myout = &G4cout;
0133         PrintHeader(myout);
0134         for (auto itr = DoseDeposit->begin(); itr != DoseDeposit->end(); ++itr) {
0135           auto _idx = DoseDeposit->GetIndex(itr);
0136           G4StatAnalysis* _stat = DoseDeposit->GetObject(itr);
0137           if (_stat && _stat->GetHits() > 0) {
0138             G4StatAnalysis _tmp_stat = *_stat;
0139             _tmp_stat /= CLHEP::gray;
0140             fileout << _idx << "     " << (*_stat) << G4endl;
0141           }
0142         }
0143         G4cout << "=============================================" << G4endl;
0144       }
0145       else {
0146         G4Exception("Dicom2RunAction", "000", JustWarning,
0147                     "DoseDeposit HitsMap is either a null pointer "
0148                     "of the HitsMap was empty");
0149       }
0150       fileout.close();
0151       G4cout << " closed file " << fname << " for dose output" << G4endl;
0152     }
0153   }
0154 
0155   if (IsMaster()) {
0156     // convert to units of Gy
0157     local_total_dose /= gray;
0158     G4cout << "--------------------End of Global Run-----------------------" << G4endl;
0159     G4cout << " The run was " << nofEvents << " events " << G4endl;
0160     G4cout << "      TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
0161     if (nofEvents > 0) {
0162       local_total_dose /= nofEvents;
0163       G4cout << " TOTAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" << G4endl;
0164     }
0165   }
0166   else {
0167     // convert to units of Gy
0168     local_total_dose /= gray;
0169     G4cout << "--------------------End of Local Run------------------------" << G4endl;
0170     G4cout << " The run was " << nofEvents << " events" << G4endl;
0171     G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose << " Gy" << G4endl;
0172     if (nofEvents > 0) {
0173       local_total_dose /= nofEvents;
0174       G4cout << " LOCAL DOSE/Bq-s : \t" << local_total_dose << " Gy/Bq-s" << G4endl;
0175     }
0176   }
0177 
0178   G4cout << G4endl;
0179   G4cout << "Finished : End of Run Action " << aRun->GetRunID() << "\n" << G4endl;
0180 }