Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:51

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