Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-27 07:33:03

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 "PhysicsList.hh"
0034 #include "PrimaryGeneratorAction.hh"
0035 #include "Run.hh"
0036 #include "StepMax.hh"
0037 
0038 #include "G4EmCalculator.hh"
0039 #include "G4EmParameters.hh"
0040 #include "Randomize.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys, PrimaryGeneratorAction* kin)
0045   : fDetector(det), fPhysics(phys), fPrimary(kin)
0046 {
0047   // Book predefined histograms
0048   fHistoManager = new HistoManager();
0049 }
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 RunAction::~RunAction()
0054 {
0055   delete fHistoManager;
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 G4Run* RunAction::GenerateRun()
0061 {
0062   fRun = new Run(fDetector);
0063   return fRun;
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 void RunAction::BeginOfRunAction(const G4Run*)
0069 {
0070   // show Rndm status
0071   if (isMaster) {
0072     G4Random::showEngineStatus();
0073     G4EmParameters::Instance()->Dump();
0074   }
0075   // histograms
0076   //
0077   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0078   if (analysisManager->IsActive()) {
0079     analysisManager->OpenFile();
0080   }
0081 
0082   if (!fPrimary) return;
0083 
0084   // keep run condition
0085   G4ParticleDefinition* particle = fPrimary->GetParticleGun()->GetParticleDefinition();
0086   G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
0087   fRun->SetPrimary(particle, energy);
0088 
0089   // get CsdaRange from EmCalculator
0090   //
0091   G4EmCalculator emCalculator;
0092   G4Material* material = fDetector->GetAbsorMaterial();
0093 
0094   G4double csdaRange = DBL_MAX;
0095   if (particle->GetPDGCharge() != 0.) {
0096     csdaRange = emCalculator.GetCSDARange(energy, particle, material);
0097     fRun->SetCsdaRange(csdaRange);
0098   }
0099 
0100   // set StepMax from histos 1 and 8
0101   //
0102   G4double stepMax = csdaRange;
0103   G4int ih = 1;
0104   if (analysisManager->GetH1Activation(ih))
0105     stepMax = analysisManager->GetH1Width(ih) * analysisManager->GetH1Unit(ih);
0106   ih = 8;
0107   if (analysisManager->GetH1Activation(ih)) {
0108     G4double width = analysisManager->GetH1Width(ih);
0109     stepMax = std::min(stepMax, width * csdaRange);
0110   }
0111   fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
0112 
0113   /// G4cout << "\n---> stepMax from histos 1 and 8 = "
0114   ///        << G4BestUnit(stepMax,"Length") << G4endl;
0115 }
0116 
0117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0118 
0119 void RunAction::EndOfRunAction(const G4Run*)
0120 {
0121   if (isMaster) fRun->EndOfRun();
0122 
0123   // save histograms
0124   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0125   if (analysisManager->IsActive()) {
0126     analysisManager->Write();
0127     analysisManager->CloseFile();
0128   }
0129 
0130   // show Rndm status
0131   if (isMaster) G4Random::showEngineStatus();
0132 }
0133 
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......