Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:36:57

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 B3b::RunAction class
0028 
0029 #include "RunAction.hh"
0030 
0031 #include "PrimaryGeneratorAction.hh"
0032 #include "Run.hh"
0033 
0034 #include "G4ParticleGun.hh"
0035 #include "G4Run.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4UnitsTable.hh"
0039 
0040 using namespace B3;
0041 
0042 namespace B3b
0043 {
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 RunAction::RunAction()
0048 {
0049   // add new units for dose
0050   //
0051   const G4double milligray = 1.e-3 * gray;
0052   const G4double microgray = 1.e-6 * gray;
0053   const G4double nanogray = 1.e-9 * gray;
0054   const G4double picogray = 1.e-12 * gray;
0055 
0056   new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
0057   new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
0058   new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
0059   new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 G4Run* RunAction::GenerateRun()
0065 {
0066   return new Run;
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 void RunAction::BeginOfRunAction(const G4Run* run)
0072 {
0073   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
0074 
0075   // inform the runManager to save random number seed
0076   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0077 }
0078 
0079 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0080 
0081 void RunAction::EndOfRunAction(const G4Run* run)
0082 {
0083   G4int nofEvents = run->GetNumberOfEvent();
0084   if (nofEvents == 0) return;
0085 
0086   // Run conditions
0087   //  note: There is no primary generator action object for "master"
0088   //        run manager for multi-threaded mode.
0089   const auto generatorAction = static_cast<const PrimaryGeneratorAction*>(
0090     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0091   G4String partName;
0092   if (generatorAction) {
0093     G4ParticleDefinition* particle = generatorAction->GetParticleGun()->GetParticleDefinition();
0094     partName = particle->GetParticleName();
0095   }
0096 
0097   // results
0098   //
0099   const Run* b3Run = static_cast<const Run*>(run);
0100   G4int nbGoodEvents = b3Run->GetNbGoodEvents();
0101   G4double sumDose = b3Run->GetSumDose();
0102   G4StatAnalysis statDose = b3Run->GetStatDose();
0103 
0104   // print
0105   //
0106   if (IsMaster()) {
0107     G4cout << G4endl << "--------------------End of Global Run-----------------------" << G4endl
0108            << "  The run was " << nofEvents << " events ";
0109   }
0110   else {
0111     G4cout << G4endl << "--------------------End of Local Run------------------------" << G4endl
0112            << "  The run was " << nofEvents << " " << partName;
0113   }
0114   statDose /= gray;
0115   G4cout << "; Nb of 'good' e+ annihilations: " << nbGoodEvents << G4endl
0116          << " Total dose in patient : " << G4BestUnit(sumDose, "Dose") << G4endl
0117          << " Total dose in patient : " << statDose << " Gy" << G4endl
0118          << "------------------------------------------------------------" << G4endl << G4endl;
0119 }
0120 
0121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0122 
0123 }  // namespace B3b