Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:28: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 "PrimaryGeneratorAction.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 #include "G4ParticleGun.hh"
0035 #include "G4Run.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4UnitsTable.hh"
0039 #include "Randomize.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 RunAction::RunAction()
0044 {
0045   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0046   analysisManager->SetDefaultFileType("root");
0047   analysisManager->SetVerboseLevel(1);
0048   analysisManager->SetFirstHistoId(1);
0049 
0050   // Creating histograms
0051   //
0052   analysisManager->CreateH1("1", "energy (MeV) deposited in C6F6", 100, 0., 10.);
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 void RunAction::BeginOfRunAction(const G4Run*)
0058 {
0059   // show Rndm status
0060   if (isMaster) G4Random::showEngineStatus();
0061 
0062   // Get analysis manager
0063   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0064 
0065   // Open an output file
0066   //
0067   G4String fileName = "testem4";
0068   analysisManager->OpenFile(fileName);
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 void RunAction::EndOfRunAction(const G4Run* run)
0074 {
0075   G4int nofEvents = run->GetNumberOfEvent();
0076   if (nofEvents == 0) return;
0077 
0078   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0079 
0080   if (isMaster) {
0081     // Run conditions
0082     //  note: There is no primary generator action object for "master"
0083     //        run manager for multi-threaded mode.
0084     PrimaryGeneratorAction* generatorAction =
0085       (PrimaryGeneratorAction*)(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0086     G4String runCondition = " ";
0087     if (generatorAction) {
0088       G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0089       runCondition = particleGun->GetParticleDefinition()->GetParticleName();
0090       runCondition += " of ";
0091       G4double particleEnergy = particleGun->GetParticleEnergy();
0092       runCondition += G4BestUnit(particleEnergy, "Energy");
0093       runCondition += " in a volume of C6F6 ";
0094     }
0095 
0096     G4cout << G4endl << "--------------------End of Global Run------------------------";
0097     G4cout << G4endl << " The run consists of " << nofEvents << " " << runCondition << G4endl;
0098     if (analysisManager->GetH1(1)) {
0099       G4cout << " Energy deposit per event:  mean = "
0100              << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
0101              << "    rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl
0102              << "------------------------------------------------------------" << G4endl;
0103     }
0104   }
0105 
0106   // show Rndm status
0107   if (isMaster) G4Random::showEngineStatus();
0108 
0109   // save histograms
0110   analysisManager->Write();
0111   analysisManager->CloseFile();
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......