ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4cEventAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B4cEventAction.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 
30 #include "B4cEventAction.hh"
31 #include "B4cCalorimeterSD.hh"
32 #include "B4cCalorHit.hh"
33 #include "B4Analysis.hh"
34 
35 #include "G4RunManager.hh"
36 #include "G4Event.hh"
37 #include "G4SDManager.hh"
38 #include "G4HCofThisEvent.hh"
39 #include "G4UnitsTable.hh"
40 
41 #include "Randomize.hh"
42 #include <iomanip>
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
48  fAbsHCID(-1),
49  fGapHCID(-1)
50 {}
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55 {}
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
61  const G4Event* event) const
62 {
63  auto hitsCollection
64  = static_cast<B4cCalorHitsCollection*>(
65  event->GetHCofThisEvent()->GetHC(hcID));
66 
67  if ( ! hitsCollection ) {
69  msg << "Cannot access hitsCollection ID " << hcID;
70  G4Exception("B4cEventAction::GetHitsCollection()",
71  "MyCode0003", FatalException, msg);
72  }
73 
74  return hitsCollection;
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
80  G4double absoEdep, G4double absoTrackLength,
81  G4double gapEdep, G4double gapTrackLength) const
82 {
83  // print event statistics
84  G4cout
85  << " Absorber: total energy: "
86  << std::setw(7) << G4BestUnit(absoEdep, "Energy")
87  << " total track length: "
88  << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
89  << G4endl
90  << " Gap: total energy: "
91  << std::setw(7) << G4BestUnit(gapEdep, "Energy")
92  << " total track length: "
93  << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
94  << G4endl;
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100 {}
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
105 {
106  // Get hits collections IDs (only once)
107  if ( fAbsHCID == -1 ) {
108  fAbsHCID
109  = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
110  fGapHCID
111  = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
112  }
113 
114  // Get hits collections
115  auto absoHC = GetHitsCollection(fAbsHCID, event);
116  auto gapHC = GetHitsCollection(fGapHCID, event);
117 
118  // Get hit with total values
119  auto absoHit = (*absoHC)[absoHC->entries()-1];
120  auto gapHit = (*gapHC)[gapHC->entries()-1];
121 
122  // Print per event (modulo n)
123  //
124  auto eventID = event->GetEventID();
125  auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
126  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
127  G4cout << "---> End of event: " << eventID << G4endl;
128 
130  absoHit->GetEdep(), absoHit->GetTrackLength(),
131  gapHit->GetEdep(), gapHit->GetTrackLength());
132  }
133 
134  // Fill histograms, ntuple
135  //
136 
137  // get analysis manager
138  auto analysisManager = G4AnalysisManager::Instance();
139 
140  // fill histograms
141  analysisManager->FillH1(0, absoHit->GetEdep());
142  analysisManager->FillH1(1, gapHit->GetEdep());
143  analysisManager->FillH1(2, absoHit->GetTrackLength());
144  analysisManager->FillH1(3, gapHit->GetTrackLength());
145 
146  // fill ntuple
147  analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
148  analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
149  analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
150  analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
151  analysisManager->AddNtupleRow();
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......