// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // $Id: DicomRunAction.cc 74809 2013-10-22 09:49:26Z gcosmo $ // /// \file DicomRunAction.cc /// \brief Implementation of the DicomRunAction class // #include "DicomRunAction.hh" #include "DicomRun.hh" //-- In order to obtain detector information. #include #include #include "G4THitsMap.hh" #include "G4UnitsTable.hh" #include "G4SystemOfUnits.hh" #include "G4RunManager.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... DicomRunAction* DicomRunAction::fgInstance = 0; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... DicomRunAction* DicomRunAction::Instance() { return fgInstance; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... /// Constructor DicomRunAction::DicomRunAction() : G4UserRunAction(), dcmrun(0), fFieldValue(14) { // - Prepare data member for DicomRun. // vector represents a list of MultiFunctionalDetector names. fSDName.push_back(G4String("phantomSD")); fgInstance = this; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... /// Destructor. DicomRunAction::~DicomRunAction() { fSDName.clear(); fgInstance = 0; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4Run* DicomRunAction::GenerateRun() { // Generate new RUN object, which is specially // dedicated for MultiFunctionalDetector scheme. // Detail description can be found in DicomRun.hh/cc. //return new DicomRun(fSDName); return dcmrun = new DicomRun(fSDName); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void DicomRunAction::BeginOfRunAction(const G4Run* aRun) { G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; //inform the runManager to save random number seed G4RunManager::GetRunManager()->SetRandomNumberStore(false); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void DicomRunAction::EndOfRunAction(const G4Run* aRun) { G4int nofEvents = aRun->GetNumberOfEvent(); if (nofEvents == 0) return; //print // static double local_total_dose = 0; double total_dose = 0; const DicomRun* reRun = static_cast(aRun); //--- Dump all scored quantities involved in DicomRun. for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){ // //--------------------------------------------- // Dump accumulated quantities for this RUN. // (Display only central region of x-y plane) // 0 ConcreteSD/DoseDeposit //--------------------------------------------- G4THitsMap* DoseDeposit = reRun->GetHitsMap(fSDName[i]+"/DoseDeposit"); if( DoseDeposit && DoseDeposit->GetMap()->size() != 0 ) { std::map::iterator itr = DoseDeposit->GetMap()->begin(); for(; itr != DoseDeposit->GetMap()->end(); itr++) { if(!IsMaster()) { local_total_dose += *(itr->second); } total_dose += *(itr->second); } } } if (IsMaster()) { G4cout << "\n--------------------End of Global Run-----------------------" << " \n The run was " << nofEvents << " events " << G4endl; G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose/gray << " Gy" << std::endl; G4cout << " TOTAL DOSE : \t" << total_dose/gray << " Gy" << std::endl; } else { G4cout << "\n--------------------End of Local Run------------------------" << " \n The run was " << nofEvents << G4endl; G4cout << "LOCAL TOTAL DOSE : \t" << local_total_dose/gray << " Gy" << std::endl; G4cout << " TOTAL DOSE : \t" << total_dose/gray << " Gy" << std::endl; } if(IsMaster()) { G4cout << " ###### EndOfRunAction ###### " << G4endl; //- DicomRun object. const DicomRun* re02Run = static_cast(aRun); //--- Dump all scored quantities involved in DicomRun. for ( G4int i = 0; i < (G4int)fSDName.size(); i++ ){ // //--------------------------------------------- // Dump accumulated quantities for this RUN. // (Display only central region of x-y plane) // 0 ConcreteSD/DoseDeposit //--------------------------------------------- G4THitsMap* DoseDeposit = re02Run->GetHitsMap(fSDName[i]+"/DoseDeposit"); G4cout << "=============================================================" <GetNumberOfEvent() << G4endl; G4cout << "=============================================================" <GetMap()->size() != 0 ) { std::ostream *myout = &G4cout; PrintHeader(myout); std::map::iterator itr = DoseDeposit->GetMap()->begin(); for(; itr != DoseDeposit->GetMap()->end(); itr++) { fileout << itr->first << " " << *(itr->second)/CLHEP::gray << G4endl; G4cout << " " << itr->first << " " << std::setprecision(6) << *(itr->second)/CLHEP::gray << " Gy" << G4endl; } G4cout << "============================================="<GetRunID() << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void DicomRunAction::PrintHeader(std::ostream *out) { std::vector vecScoreName; vecScoreName.push_back("DoseDeposit"); // head line // std::string vname; *out << std::setw(10) << "Voxel" << " |"; for (std::vector::iterator it = vecScoreName.begin(); it != vecScoreName.end(); it++) { //vname = FillString((*it), // ' ', // FieldValue+1, // false); // *out << vname << '|'; *out << std::setw(fFieldValue) << (*it) << " |"; } *out << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... std::string DicomRunAction::FillString(const std::string &name, char c, G4int n, G4bool back) { std::string fname(""); G4int k = n - name.size(); if (k > 0) { if (back) { fname = name; fname += std::string(k,c); } else { fname = std::string(k,c); fname += name; } } else { fname = name; } return fname; }