Back to home page

EIC code displayed by LXR

 
 

    


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

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