Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 07:49:54

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 B1::RunAction class
0028 
0029 #include "RunAction.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033 
0034 #include "G4AccumulableManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleGun.hh"
0038 #include "G4Run.hh"
0039 #include "G4RunManager.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4UnitsTable.hh"
0042 
0043 namespace B1
0044 {
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 RunAction::RunAction()
0049 {
0050   // add new units for dose
0051   //
0052   const G4double milligray = 1.e-3 * gray;
0053   const G4double microgray = 1.e-6 * gray;
0054   const G4double nanogray = 1.e-9 * gray;
0055   const G4double picogray = 1.e-12 * gray;
0056 
0057   new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
0058   new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
0059   new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
0060   new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
0061 
0062   // Register accumulable to the accumulable manager
0063   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0064   accumulableManager->Register(fEdep);
0065   accumulableManager->Register(fEdep2);
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 void RunAction::BeginOfRunAction(const G4Run*)
0071 {
0072   // inform the runManager to save random number seed
0073   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0074 
0075   // reset accumulables to their initial values
0076   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0077   accumulableManager->Reset();
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void RunAction::EndOfRunAction(const G4Run* run)
0083 {
0084   G4int nofEvents = run->GetNumberOfEvent();
0085   if (nofEvents == 0) return;
0086 
0087   // Merge accumulables
0088   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0089   accumulableManager->Merge();
0090 
0091   // Compute dose = total energy deposit in a run and its variance
0092   //
0093   G4double edep = fEdep.GetValue();
0094   G4double edep2 = fEdep2.GetValue();
0095 
0096   G4double rms = edep2 - edep * edep / nofEvents;
0097   if (rms > 0.)
0098     rms = std::sqrt(rms);
0099   else
0100     rms = 0.;
0101 
0102   const auto detConstruction = static_cast<const DetectorConstruction*>(
0103     G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0104   G4double mass = detConstruction->GetScoringVolume()->GetMass();
0105   G4double dose = edep / mass;
0106   G4double rmsDose = rms / mass;
0107 
0108   // Run conditions
0109   //  note: There is no primary generator action object for "master"
0110   //        run manager for multi-threaded mode.
0111   const auto generatorAction = static_cast<const PrimaryGeneratorAction*>(
0112     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0113   G4String runCondition;
0114   if (generatorAction) {
0115     const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0116     runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0117     runCondition += " of ";
0118     G4double particleEnergy = particleGun->GetParticleEnergy();
0119     runCondition += G4BestUnit(particleEnergy, "Energy");
0120   }
0121 
0122   // Print
0123   //
0124   if (IsMaster()) {
0125     G4cout << G4endl << "--------------------End of Global Run-----------------------";
0126   }
0127   else {
0128     G4cout << G4endl << "--------------------End of Local Run------------------------";
0129   }
0130 
0131   G4cout << G4endl << " The run is " << nofEvents << " " << runCondition << G4endl << G4endl;
0132   G4cout << "  --> cumulated edep per run in scoring volume = " << G4BestUnit(edep, "Energy") 
0133          << " = " << edep/joule << " joule" << G4endl;  
0134   G4cout << "  --> mass of scoring volume = " << G4BestUnit(mass, "Mass") << G4endl << G4endl; 
0135   G4cout << " Absorbed dose per run in scoring volume = edep/mass = " << G4BestUnit(dose, "Dose")
0136          << "; rms = " << G4BestUnit(rmsDose, "Dose") << G4endl
0137          << "------------------------------------------------------------" << G4endl << G4endl;
0138 }
0139 
0140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0141 
0142 void RunAction::AddEdep(G4double edep)
0143 {
0144   fEdep += edep;
0145   fEdep2 += edep * edep;
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0149 
0150 }  // namespace B1