Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-02 07:36:30

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