Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/extended/medical/dna/chem6/src/RunAction.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 /// \file RunAction.cc
0027 /// \brief Implementation of the RunAction class
0028 
0029 // This example is provided by the Geant4-DNA collaboration
0030 // chem6 example is derived from chem4 and chem5 examples
0031 //
0032 // Any report or published results obtained using the Geant4-DNA software
0033 // shall cite the following Geant4-DNA collaboration publication:
0034 // J. Appl. Phys. 125 (2019) 104301
0035 // Med. Phys. 45 (2018) e722-e739
0036 // J. Comput. Phys. 274 (2014) 841-882
0037 // Med. Phys. 37 (2010) 4692-4708
0038 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157-178
0039 // The Geant4-DNA web site is available at http://geant4-dna.org
0040 //
0041 // Authors: W. G. Shin and S. Incerti (CENBG, France)
0042 
0043 #include "RunAction.hh"
0044 
0045 #include "Run.hh"
0046 
0047 #include "G4Run.hh"
0048 #include "G4RunManager.hh"
0049 #include "G4SystemOfUnits.hh"
0050 #include "G4UnitsTable.hh"
0051 #include "G4DNAChemistryManager.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0054 
0055 extern std::ofstream out;
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0058 
0059 G4Run *RunAction::GenerateRun() {
0060   const auto run = new Run();
0061   return run;
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0065 
0066 void RunAction::BeginOfRunAction(const G4Run *run) {
0067   // ensure that the chemistry is notified!
0068   if (G4DNAChemistryManager::GetInstanceIfExists() != nullptr)
0069     G4DNAChemistryManager::GetInstanceIfExists()->BeginOfRunAction(run);
0070   G4cout << "### Run " << run->GetRunID() << " starts." << G4endl;
0071 
0072   // informs the runManager to save random number seed
0073   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0077 
0078 void RunAction::EndOfRunAction(const G4Run *run) {
0079   // ensure that the chemistry is notified!
0080   if (G4DNAChemistryManager::GetInstanceIfExists() != nullptr)
0081     G4DNAChemistryManager::GetInstanceIfExists()->EndOfRunAction(run);
0082 
0083   const G4int nofEvents = run->GetNumberOfEvent();
0084   if (nofEvents == 0) { return; }
0085 
0086   // results
0087   //
0088   const auto chem6Run = static_cast<const Run *>(run);
0089   const G4double sumDose = chem6Run->GetSumDose();
0090 
0091   // print
0092   //
0093   if (IsMaster()) {
0094     G4cout << G4endl << "--------------------End of Global Run-----------------------" << G4endl
0095         << "  The run has " << nofEvents << " events " << G4endl;
0096 
0097     ScoreSpecies *masterScorer = dynamic_cast<ScoreSpecies *>(chem6Run->GetPrimitiveScorer());
0098 
0099     G4cout << "Number of events recorded by the species scorer = "
0100         << masterScorer->GetNumberOfRecordedEvents() << G4endl;
0101 
0102     // LET
0103     const auto aRun = (Run *) run;
0104     const G4THitsMap<G4double> *totLET = aRun->GetLET();
0105     const G4int nOfEvent = totLET->entries();
0106     G4double LET_mean = 0;
0107     G4double LET_square = 0;
0108     for (G4int i = 0; i < nOfEvent; i++) {
0109       const G4double *LET = (*totLET)[i];
0110       if (!LET) continue;
0111       LET_mean += *LET;
0112       LET_square += (*LET) * (*LET);
0113     }
0114     LET_mean /= nOfEvent;
0115     LET_square = std::sqrt(LET_square / nOfEvent - std::pow(LET_mean, 2));
0116 
0117     if (nOfEvent > 1) {
0118       out << std::setw(12) << "LET" << std::setw(12) << LET_mean << std::setw(12) << "LET_SD"
0119           << std::setw(12) << LET_square / (nOfEvent - 1) << '\n';
0120     } else {
0121       out << std::setw(12) << "LET" << std::setw(12) << LET_mean << std::setw(12) << "LET_SD"
0122           << std::setw(12) << LET_square << '\n';
0123     }
0124 
0125     masterScorer->OutputAndClear();
0126 
0127     out << '\n';
0128   } else {
0129     G4cout << G4endl << "--------------------End of Local Run------------------------" << G4endl
0130         << "  The run has " << nofEvents << " events" << G4endl;
0131   }
0132 
0133   G4cout << " Total energy deposited in the world volume : " << sumDose / eV << " eV" << G4endl
0134       << " ------------------------------------------------------------" << G4endl << G4endl;
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....