ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4dEventAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B4dEventAction.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 "B4dEventAction.hh"
31 #include "B4Analysis.hh"
32 
33 #include "G4RunManager.hh"
34 #include "G4Event.hh"
35 #include "G4SDManager.hh"
36 #include "G4HCofThisEvent.hh"
37 #include "G4UnitsTable.hh"
38 
39 #include "Randomize.hh"
40 #include <iomanip>
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
46  fAbsoEdepHCID(-1),
47  fGapEdepHCID(-1),
48  fAbsoTrackLengthHCID(-1),
49  fGapTrackLengthHCID(-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<G4THitsMap<G4double>*>(
65  event->GetHCofThisEvent()->GetHC(hcID));
66 
67  if ( ! hitsCollection ) {
69  msg << "Cannot access hitsCollection ID " << hcID;
70  G4Exception("B4dEventAction::GetHitsCollection()",
71  "MyCode0003", FatalException, msg);
72  }
73 
74  return hitsCollection;
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
80 {
81  G4double sumValue = 0.;
82  for ( auto it : *hitsMap->GetMap() ) {
83  // hitsMap->GetMap() returns the map of std::map<G4int, G4double*>
84  sumValue += *(it.second);
85  }
86  return sumValue;
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92  G4double absoEdep, G4double absoTrackLength,
93  G4double gapEdep, G4double gapTrackLength) const
94 {
95  // Print event statistics
96  //
97  G4cout
98  << " Absorber: total energy: "
99  << std::setw(7) << G4BestUnit(absoEdep, "Energy")
100  << " total track length: "
101  << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
102  << G4endl
103  << " Gap: total energy: "
104  << std::setw(7) << G4BestUnit(gapEdep, "Energy")
105  << " total track length: "
106  << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
107  << G4endl;
108 }
109 
110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111 
113 {}
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
119  // Get hist collections IDs
120  if ( fAbsoEdepHCID == -1 ) {
122  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
123  fGapEdepHCID
126  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
128  = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
129  }
130 
131  // Get sum values from hits collections
132  //
133  auto absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
134  auto gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
135 
136  auto absoTrackLength
138  auto gapTrackLength
140 
141  // get analysis manager
142  auto analysisManager = G4AnalysisManager::Instance();
143 
144  // fill histograms
145  //
146  analysisManager->FillH1(0, absoEdep);
147  analysisManager->FillH1(1, gapEdep);
148  analysisManager->FillH1(2, absoTrackLength);
149  analysisManager->FillH1(3, gapTrackLength);
150 
151  // fill ntuple
152  //
153  analysisManager->FillNtupleDColumn(0, absoEdep);
154  analysisManager->FillNtupleDColumn(1, gapEdep);
155  analysisManager->FillNtupleDColumn(2, absoTrackLength);
156  analysisManager->FillNtupleDColumn(3, gapTrackLength);
157  analysisManager->AddNtupleRow();
158 
159  //print per event (modulo n)
160  //
161  auto eventID = event->GetEventID();
162  auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
163  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
164  G4cout << "---> End of event: " << eventID << G4endl;
165  PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
166  }
167 }
168 
169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......