Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: B4dEventAction.cc 100946 2016-11-03 11:28:08Z gcosmo $
27 //
30 
31 #include "B4dEventAction.hh"
32 #include "B4Analysis.hh"
33 
34 #include "G4RunManager.hh"
35 #include "G4Event.hh"
36 #include "G4SDManager.hh"
37 #include "G4HCofThisEvent.hh"
38 #include "G4UnitsTable.hh"
39 
40 #include "Randomize.hh"
41 #include <iomanip>
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
47  fAbsoEdepHCID(-1),
48  fGapEdepHCID(-1),
49  fAbsoTrackLengthHCID(-1),
50  fGapTrackLengthHCID(-1)
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
62  const G4Event* event) const
63 {
64  auto hitsCollection
65  = static_cast<G4THitsMap<G4double>*>(
66  event->GetHCofThisEvent()->GetHC(hcID));
67 
68  if ( ! hitsCollection ) {
70  msg << "Cannot access hitsCollection ID " << hcID;
71  G4Exception("B4dEventAction::GetHitsCollection()",
72  "MyCode0003", FatalException, msg);
73  }
74 
75  return hitsCollection;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  G4double sumValue = 0.;
83  for ( auto it : *hitsMap->GetMap() ) {
84  // hitsMap->GetMap() returns the map of std::map<G4int, G4double*>
85  sumValue += *(it.second);
86  }
87  return sumValue;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93  G4double absoEdep, G4double absoTrackLength,
94  G4double gapEdep, G4double gapTrackLength) const
95 {
96  // Print event statistics
97  //
98  G4cout
99  << " Absorber: total energy: "
100  << std::setw(7) << G4BestUnit(absoEdep, "Energy")
101  << " total track length: "
102  << std::setw(7) << G4BestUnit(absoTrackLength, "Length")
103  << G4endl
104  << " Gap: total energy: "
105  << std::setw(7) << G4BestUnit(gapEdep, "Energy")
106  << " total track length: "
107  << std::setw(7) << G4BestUnit(gapTrackLength, "Length")
108  << G4endl;
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
114 {}
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  // Get hist collections IDs
121  if ( fAbsoEdepHCID == -1 ) {
123  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
124  fGapEdepHCID
127  = G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
129  = G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
130  }
131 
132  // Get sum values from hits collections
133  //
134  auto absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
135  auto gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
136 
137  auto absoTrackLength
139  auto gapTrackLength
141 
142  // get analysis manager
143  auto analysisManager = G4AnalysisManager::Instance();
144 
145  // fill histograms
146  //
147  analysisManager->FillH1(0, absoEdep);
148  analysisManager->FillH1(1, gapEdep);
149  analysisManager->FillH1(2, absoTrackLength);
150  analysisManager->FillH1(3, gapTrackLength);
151 
152  // fill ntuple
153  //
154  analysisManager->FillNtupleDColumn(0, absoEdep);
155  analysisManager->FillNtupleDColumn(1, gapEdep);
156  analysisManager->FillNtupleDColumn(2, absoTrackLength);
157  analysisManager->FillNtupleDColumn(3, gapTrackLength);
158  analysisManager->AddNtupleRow();
159 
160  //print per event (modulo n)
161  //
162  auto eventID = event->GetEventID();
163  auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
164  if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
165  G4cout << "---> End of event: " << eventID << G4endl;
166  PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4int fGapTrackLengthHCID
#define G4endl
Definition: G4ios.hh:61
virtual ~B4dEventAction()
virtual void BeginOfEventAction(const G4Event *event)
virtual void EndOfEventAction(const G4Event *event)
double G4double
Definition: G4Types.hh:76
Definition of the B4dEventAction class.
G4THitsMap< G4double > * GetHitsCollection(G4int hcID, const G4Event *event) const
G4int fAbsoTrackLengthHCID
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength, G4double gapEdep, G4double gapTrackLength) const
G4int GetPrintProgress()
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4double GetSum(G4THitsMap< G4double > *hitsMap) const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
Map_t * GetMap() const
Definition: G4THitsMap.hh:117