Back to home page

EIC code displayed by LXR

 
 

    


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

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