Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:32:33

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 #include "RunAction.hh"
0030 
0031 #include "Run.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 #include "G4DNAEventScheduler.hh"
0035 #include "G4DNAScavengerMaterial.hh"
0036 #include "G4Run.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4Scheduler.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4VChemistryWorld.hh"
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0042 
0043 RunAction::RunAction() : G4UserRunAction() {}
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0045 
0046 void RunAction::SetEventScheduler(G4DNAEventScheduler* pEventScheduler)
0047 {
0048   fpEventScheduler = pEventScheduler;
0049 }
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0051 
0052 G4Run* RunAction::GenerateRun()
0053 {
0054   Run* run = new Run();
0055   return run;
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0059 
0060 void RunAction::BeginOfRunAction(const G4Run* run)
0061 {
0062   G4cout << "### Run " << run->GetRunID() << " starts." << G4endl;
0063   if (G4Threading::IsMultithreadedApplication() && IsMaster()) {
0064     return;
0065   }
0066   auto runInfo = dynamic_cast<const Run*>(run);
0067   auto GvaluesScorer = dynamic_cast<Scorer<Gvalues>*>(runInfo->GetGvaluesScorer());
0068 
0069   if (fpEventScheduler != nullptr) {
0070     for (const auto& it : GvaluesScorer->GetpScorer()->fTimeToRecord) {
0071       fpEventScheduler->AddTimeToRecord(it);
0072     }
0073   }
0074   GvaluesScorer->SetEventScheduler(fpEventScheduler);
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0078 
0079 void RunAction::EndOfRunAction(const G4Run* run)
0080 {
0081   G4int nofEvents = run->GetNumberOfEvent();
0082   if (nofEvents == 0) {
0083     return;
0084   }
0085   auto pRun = dynamic_cast<const Run*>(run);
0086   G4double sumDose = pRun->GetSumDose();
0087 
0088   if (G4Threading::IsMultithreadedApplication() && IsMaster()) {
0089     G4cout << G4endl << "--------------------------End of Global Run------------------------------"
0090            << G4endl << "The run has " << nofEvents << " events " << G4endl;
0091 
0092     auto masterGvaluesScorer = dynamic_cast<Scorer<Gvalues>*>(pRun->GetGvaluesScorer());
0093 
0094     auto masterDoseLimite = dynamic_cast<Scorer<Dose>*>(pRun->GetSumDoseLimit());
0095 
0096     G4cout << "Number of events recorded by the species scorer : "
0097            << masterGvaluesScorer->GetpScorer()->GetNumberOfRecordedEvents() << " events "
0098            << G4endl;
0099     G4double dose_mean = masterDoseLimite->GetpScorer()->fDosesCutOff / gray;
0100     auto boundingBox = masterDoseLimite->GetChemistryWorld()->GetChemistryBoundary();
0101     G4double V = boundingBox->Volume() / cm3;
0102     G4double DoseInGray = (sumDose / eV) / (0.001 * V * 6.242e+18);
0103     G4cout << "Cut-off dose for each beam line : " << dose_mean << " Gy " << G4endl;
0104     G4cout << "Actual dose : " << DoseInGray << " Gy for " << nofEvents
0105            << " events. Actual average dose : " << DoseInGray / nofEvents << " Gy" << G4endl;
0106     masterGvaluesScorer->OutputAndClear(std::to_string(dose_mean));
0107   }
0108   else {
0109     G4cout << G4endl << "--------------------------End of Local Run------------------------------"
0110            << G4endl << "The run has " << nofEvents << " events. Scavenger info:" << G4endl;
0111     auto pScavengerMaterial =
0112       dynamic_cast<G4DNAScavengerMaterial*>(G4Scheduler::Instance()->GetScavengerMaterial());
0113     pScavengerMaterial->PrintInfo();
0114   }
0115 
0116   G4cout << "Total energy deposited in the world volume : " << sumDose / keV << " keV" << G4endl
0117          << "-------------------------------------------------------------------------" << G4endl
0118          << G4endl;
0119 }
0120 
0121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......