Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:49:49

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 "RunMessenger.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 #include "G4PhysicalConstants.hh"
0035 #include "G4Run.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4ios.hh"
0038 #include "Randomize.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0041 
0042 RunAction::RunAction() : G4UserRunAction(), fRunMessenger(0), fRndmFreq(1)
0043 {
0044   fRunMessenger = new RunMessenger(this);
0045 
0046   BookHisto();
0047 }
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0050 
0051 RunAction::~RunAction()
0052 {
0053   delete fRunMessenger;
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0057 
0058 void RunAction::BookHisto()
0059 {
0060   // Create or get analysis manager
0061   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0062   analysisManager->SetDefaultFileType("root");
0063   analysisManager->SetFileName("testem10");
0064   analysisManager->SetVerboseLevel(1);
0065   analysisManager->SetFirstHistoId(1);  // start histogram numbering from 1
0066   analysisManager->SetActivation(true);  // enable inactivation of histograms
0067 
0068   // Define histograms start values
0069   const G4int kMaxHisto = 5;
0070   const G4String id[] = {"1", "2", "3", "4", "5"};
0071   const G4String title[] = {"Edep",  // 1
0072                             "XTR Gamma spectrum",  // 2
0073                             "Secondary Gamma spectrum",  // 3
0074                             "Secondary e- spectrum",  // 4
0075                             "Edep.old"};  // 5
0076   // Default values (to be reset via /analysis/h1/set command)
0077   G4int nbins = 100;
0078   G4double vmin = 0.;
0079   G4double vmax = 100.;
0080 
0081   // Create all histograms as inactivated
0082   // as we have not yet set nbins, vmin, vmax
0083   for (G4int k = 0; k < kMaxHisto; k++) {
0084     G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
0085     analysisManager->SetH1Activation(ih, false);
0086   }
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0090 
0091 void RunAction::BeginOfRunAction(const G4Run* aRun)
0092 {
0093   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0094 
0095   // save Rndm status
0096   if (fRndmFreq > 0) {
0097     CLHEP::HepRandom::showEngineStatus();
0098     CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
0099   }
0100 
0101   //  histograms
0102   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0103   if (analysisManager->IsActive()) {
0104     analysisManager->OpenFile();
0105   }
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0109 
0110 void RunAction::EndOfRunAction(const G4Run* run)
0111 {
0112   // print run statisctics
0113   G4int nofEvents = run->GetNumberOfEvent();
0114   G4cout << " ================== run summary =====================" << G4endl;
0115   G4cout << " End of Run TotNbofEvents = " << nofEvents << G4endl;
0116 
0117   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0118   if (analysisManager->GetH1(1)) {
0119     G4cout << " Mean energy deposit in absorber = " << analysisManager->GetH1(1)->mean() / MeV
0120            << " +-" << analysisManager->GetH1(1)->rms() / MeV << "  MeV " << G4endl;
0121   }
0122   if (analysisManager->GetH1(2)) {
0123     G4cout << " Total number of XTR gammas = " << analysisManager->GetH1(2)->entries() << G4endl;
0124   }
0125   if (analysisManager->GetH1(3)) {
0126     G4cout << " Total number of all gammas = " << analysisManager->GetH1(3)->entries() << G4endl;
0127   }
0128 
0129   // save Rndm status
0130   if (fRndmFreq == 1) {
0131     CLHEP::HepRandom::showEngineStatus();
0132     CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
0133   }
0134 
0135   // save histograms
0136   if (analysisManager->IsActive()) {
0137     analysisManager->Write();
0138     analysisManager->CloseFile();
0139   }
0140 }
0141 
0142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....