Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-05 07:55:49

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 B1RunAction.cc
0027 /// \brief Implementation of the B1RunAction class
0028 
0029 #include "B1RunAction.hh"
0030 
0031 #include "B1DetectorConstruction.hh"
0032 #include "B1PrimaryGeneratorAction.hh"
0033 #include "B1Run.hh"
0034 
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4UnitsTable.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 B1RunAction::B1RunAction() : G4UserRunAction()
0044 {
0045   // add new units for dose
0046   //
0047   const G4double milligray = 1.e-3 * gray;
0048   const G4double microgray = 1.e-6 * gray;
0049   const G4double nanogray = 1.e-9 * gray;
0050   const G4double picogray = 1.e-12 * gray;
0051 
0052   new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
0053   new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
0054   new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
0055   new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 B1RunAction::~B1RunAction() {}
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 G4Run* B1RunAction::GenerateRun()
0065 {
0066   return new B1Run;
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 void B1RunAction::BeginOfRunAction(const G4Run*)
0072 {
0073   // inform the runManager to save random number seed
0074   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 void B1RunAction::EndOfRunAction(const G4Run* run)
0080 {
0081   G4int nofEvents = run->GetNumberOfEvent();
0082   if (nofEvents == 0) return;
0083 
0084   const B1Run* b1Run = static_cast<const B1Run*>(run);
0085 
0086   // Compute dose
0087   //
0088   G4double edep = b1Run->GetEdep();
0089   G4double edep2 = b1Run->GetEdep2();
0090   G4double rms = edep2 - edep * edep / nofEvents;
0091   if (rms > 0.)
0092     rms = std::sqrt(rms);
0093   else
0094     rms = 0.;
0095 
0096   const B1DetectorConstruction* detectorConstruction = static_cast<const B1DetectorConstruction*>(
0097     G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0098   G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
0099   G4double dose = edep / mass;
0100   G4double rmsDose = rms / mass;
0101 
0102   // Run conditions
0103   //  note: There is no primary generator action object for "master"
0104   //        run manager for multi-threaded mode.
0105   const B1PrimaryGeneratorAction* generatorAction = static_cast<const B1PrimaryGeneratorAction*>(
0106     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0107   G4String runCondition;
0108   if (generatorAction) {
0109     const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0110     runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0111     runCondition += " of ";
0112     G4double particleEnergy = particleGun->GetParticleEnergy();
0113     runCondition += G4BestUnit(particleEnergy, "Energy");
0114   }
0115 
0116   // Print
0117   //
0118   if (IsMaster()) {
0119     G4cout << "\n--------------------End of Global Run-----------------------";
0120   }
0121   else {
0122     G4cout << "\n--------------------End of Local Run------------------------";
0123   }
0124 
0125   G4cout << "\n The run consists of " << nofEvents << " " << runCondition
0126          << "\n Dose in scoring volume : " << G4BestUnit(dose, "Dose") << " +- "
0127          << G4BestUnit(rmsDose, "Dose")
0128          << "\n------------------------------------------------------------\n"
0129          << G4endl;
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......