Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:16

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 //
0027 /// \file B4/B4c/src/EventAction.cc
0028 /// \brief Implementation of the B4c::EventAction class
0029 
0030 #include "EventAction.hh"
0031 
0032 #include "CalorHit.hh"
0033 
0034 #include "G4AnalysisManager.hh"
0035 #include "G4Event.hh"
0036 #include "G4HCofThisEvent.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4SDManager.hh"
0039 #include "G4UnitsTable.hh"
0040 
0041 #include <iomanip>
0042 
0043 namespace B4c
0044 {
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 CalorHitsCollection* EventAction::GetHitsCollection(G4int hcID, const G4Event* event) const
0049 {
0050   auto hitsCollection = static_cast<CalorHitsCollection*>(event->GetHCofThisEvent()->GetHC(hcID));
0051 
0052   if (!hitsCollection) {
0053     G4ExceptionDescription msg;
0054     msg << "Cannot access hitsCollection ID " << hcID;
0055     G4Exception("EventAction::GetHitsCollection()", "MyCode0003", FatalException, msg);
0056   }
0057 
0058   return hitsCollection;
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 void EventAction::PrintEventStatistics(G4double absoEdep, G4double absoTrackLength,
0064                                        G4double gapEdep, G4double gapTrackLength) const
0065 {
0066   // print event statistics
0067   G4cout << "   Absorber: total energy: " << std::setw(7) << G4BestUnit(absoEdep, "Energy")
0068          << "       total track length: " << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
0069          << G4endl << "        Gap: total energy: " << std::setw(7) << G4BestUnit(gapEdep, "Energy")
0070          << "       total track length: " << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
0071          << G4endl;
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 void EventAction::BeginOfEventAction(const G4Event* /*event*/) {}
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 void EventAction::EndOfEventAction(const G4Event* event)
0081 {
0082   // Get hits collections IDs (only once)
0083   if (fAbsHCID == -1) {
0084     fAbsHCID = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
0085     fGapHCID = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
0086   }
0087 
0088   // Get hits collections
0089   auto absoHC = GetHitsCollection(fAbsHCID, event);
0090   auto gapHC = GetHitsCollection(fGapHCID, event);
0091 
0092   // Get hit with total values
0093   auto absoHit = (*absoHC)[absoHC->entries() - 1];
0094   auto gapHit = (*gapHC)[gapHC->entries() - 1];
0095 
0096   // Print per event (modulo n)
0097   //
0098   auto eventID = event->GetEventID();
0099   auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
0100   if ((printModulo > 0) && (eventID % printModulo == 0)) {
0101     PrintEventStatistics(absoHit->GetEdep(), absoHit->GetTrackLength(), gapHit->GetEdep(),
0102                          gapHit->GetTrackLength());
0103     G4cout << "--> End of event: " << eventID << "\n" << G4endl;
0104   }
0105 
0106   // Fill histograms, ntuple
0107   //
0108 
0109   // get analysis manager
0110   auto analysisManager = G4AnalysisManager::Instance();
0111 
0112   // fill histograms
0113   analysisManager->FillH1(0, absoHit->GetEdep());
0114   analysisManager->FillH1(1, gapHit->GetEdep());
0115   analysisManager->FillH1(2, absoHit->GetTrackLength());
0116   analysisManager->FillH1(3, gapHit->GetTrackLength());
0117 
0118   // fill ntuple
0119   analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
0120   analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
0121   analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
0122   analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
0123   analysisManager->AddNtupleRow();
0124 }
0125 
0126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0127 
0128 }  // namespace B4c