Back to home page

EIC code displayed by LXR

 
 

    


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

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