Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 07:40:59

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 "DetectorConstruction.hh"
0032 #include "HistoManager.hh"
0033 #include "PrimaryGeneratorAction.hh"
0034 #include "Run.hh"
0035 #include "RunActionMessenger.hh"
0036 
0037 #include "G4RunManager.hh"
0038 #include "G4Timer.hh"
0039 #include "Randomize.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim)
0044   : fDetector(det), fPrimary(prim)
0045 {
0046   fRunMessenger = new RunActionMessenger(this);
0047   fHistoManager = new HistoManager();
0048 }
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 RunAction::~RunAction()
0053 {
0054   delete fRunMessenger;
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 G4Run* RunAction::GenerateRun()
0060 {
0061   fRun = new Run(fDetector);
0062   return fRun;
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void RunAction::BeginOfRunAction(const G4Run*)
0068 {
0069   // keep run condition
0070   if (fPrimary) {
0071     G4ParticleDefinition* particle = fPrimary->GetParticleGun()->GetParticleDefinition();
0072     G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
0073     fRun->SetPrimary(particle, energy);
0074   }
0075 
0076   // histograms
0077   //
0078   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0079   if (analysis->IsActive()) analysis->OpenFile();
0080 
0081   // save Rndm status and open the timer
0082 
0083   if (isMaster) {
0084     //    G4Random::showEngineStatus();
0085     fTimer = new G4Timer();
0086     fTimer->Start();
0087   }
0088 }
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0091 
0092 void RunAction::EndOfRunAction(const G4Run*)
0093 {
0094   // compute and print statistic
0095   if (isMaster) {
0096     fTimer->Stop();
0097     if (!((G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM))) {
0098       G4cout << "\n"
0099              << "Total number of events:  " << fRun->GetNumberOfEvent() << G4endl;
0100       G4cout << "Master thread time:  " << *fTimer << G4endl;
0101     }
0102     delete fTimer;
0103     fRun->EndOfRun();
0104   }
0105   // save histograms
0106   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0107   if (analysis->IsActive()) {
0108     analysis->Write();
0109     analysis->CloseFile();
0110   }
0111 
0112   // show Rndm status
0113   //  if (isMaster)  G4Random::showEngineStatus();
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 void RunAction::SetEdepAndRMS(G4int i, G4double edep, G4double rms, G4double lim)
0119 {
0120   if (fRun) fRun->SetEdepAndRMS(i, edep, rms, lim);
0121 }
0122 
0123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0124 
0125 void RunAction::SetApplyLimit(G4bool val)
0126 {
0127   if (fRun) fRun->SetApplyLimit(val);
0128 }
0129 
0130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......