Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:31:14

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 "HistoManager.hh"
0032 
0033 #include "G4AccumulableManager.hh"
0034 #include "G4Run.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4UnitsTable.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 RunAction::RunAction(HistoManager* histo) : fHistoManager(histo)
0041 {
0042   // Register accumulable to the accumulable manager
0043   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0044   accumulableManager->Register(fSumEAbs);
0045   accumulableManager->Register(fSum2EAbs);
0046   accumulableManager->Register(fSumEGap);
0047   accumulableManager->Register(fSum2EGap);
0048   accumulableManager->Register(fSumLAbs);
0049   accumulableManager->Register(fSum2LAbs);
0050   accumulableManager->Register(fSumLGap);
0051   accumulableManager->Register(fSum2LGap);
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 RunAction::~RunAction() = default;
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 void RunAction::BeginOfRunAction(const G4Run* aRun)
0061 {
0062   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0063 
0064   // reset accumulables to their initial values
0065   G4AccumulableManager::Instance()->Reset();
0066 
0067   // histograms
0068   //
0069   fHistoManager->Book();
0070 }
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 
0074 void RunAction::FillPerEvent(G4double EAbs, G4double EGap, G4double LAbs, G4double LGap)
0075 {
0076   // accumulate statistic
0077   //
0078   fSumEAbs += EAbs;
0079   fSum2EAbs += EAbs * EAbs;
0080   fSumEGap += EGap;
0081   fSum2EGap += EGap * EGap;
0082 
0083   fSumLAbs += LAbs;
0084   fSum2LAbs += LAbs * LAbs;
0085   fSumLGap += LGap;
0086   fSum2LGap += LGap * LGap;
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0090 
0091 void RunAction::EndOfRunAction(const G4Run* aRun)
0092 {
0093   // Merge accumulables
0094   G4AccumulableManager::Instance()->Merge();
0095 
0096   G4int nofEvents = aRun->GetNumberOfEvent();
0097   if (nofEvents == 0) {
0098     // close open files
0099     fHistoManager->Save();
0100     return;
0101   }
0102 
0103   // compute statistics: mean and rms
0104   //
0105   auto sumEAbs = fSumEAbs.GetValue();
0106   auto sum2EAbs = fSum2EAbs.GetValue();
0107   sumEAbs /= nofEvents;
0108   sum2EAbs /= nofEvents;
0109   auto rmsEAbs = sum2EAbs - sumEAbs * sumEAbs;
0110   if (rmsEAbs > 0.) {
0111     rmsEAbs = std::sqrt(rmsEAbs);
0112   }
0113   else {
0114     rmsEAbs = 0.;
0115   }
0116 
0117   auto sumEGap = fSumEGap.GetValue();
0118   auto sum2EGap = fSum2EGap.GetValue();
0119   sumEGap /= nofEvents;
0120   sum2EGap /= nofEvents;
0121   auto rmsEGap = sum2EGap - sumEGap * sumEGap;
0122   if (rmsEGap > 0.) {
0123     rmsEGap = std::sqrt(rmsEGap);
0124   }
0125   else {
0126     rmsEGap = 0.;
0127   }
0128 
0129   auto sumLAbs = fSumLAbs.GetValue();
0130   auto sum2LAbs = fSum2LAbs.GetValue();
0131   sumLAbs /= nofEvents;
0132   sum2LAbs /= nofEvents;
0133   auto rmsLAbs = sum2LAbs - sumLAbs * sumLAbs;
0134   if (rmsLAbs > 0.) {
0135     rmsLAbs = std::sqrt(rmsLAbs);
0136   }
0137   else {
0138     rmsLAbs = 0.;
0139   }
0140 
0141   auto sumLGap = fSumLGap.GetValue();
0142   auto sum2LGap = fSum2LGap.GetValue();
0143   sumLGap /= nofEvents;
0144   sum2LGap /= nofEvents;
0145   G4double rmsLGap = sum2LGap - sumLGap * sumLGap;
0146   if (rmsLGap > 0.) {
0147     rmsLGap = std::sqrt(rmsLGap);
0148   }
0149   else {
0150     rmsLGap = 0.;
0151   }
0152 
0153   // print
0154   //
0155   G4cout << "\n--------------------End of Run------------------------------\n"
0156          << "\n mean Energy in Absorber : " << G4BestUnit(sumEAbs, "Energy") << " +- "
0157          << G4BestUnit(rmsEAbs, "Energy")
0158          << "\n mean Energy in Gap      : " << G4BestUnit(sumEGap, "Energy") << " +- "
0159          << G4BestUnit(rmsEGap, "Energy") << G4endl;
0160 
0161   G4cout << "\n mean trackLength in Absorber : " << G4BestUnit(sumLAbs, "Length") << " +- "
0162          << G4BestUnit(rmsLAbs, "Length")
0163          << "\n mean trackLength in Gap      : " << G4BestUnit(sumLGap, "Length") << " +- "
0164          << G4BestUnit(rmsLGap, "Length")
0165          << "\n------------------------------------------------------------\n"
0166          << G4endl;
0167 
0168   // save histograms
0169   //
0170   fHistoManager->PrintStatistic();
0171   fHistoManager->Save();
0172 }
0173 
0174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......