Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4cEventAction.cc
Go to the documentation of this file.
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$
27 //
30 
31 #include "B4cEventAction.hh"
32 #include "B4cCalorimeterSD.hh"
33 #include "B4cCalorHit.hh"
34 #include "B4Analysis.hh"
35 
36 #include "G4RunManager.hh"
37 #include "G4Event.hh"
38 #include "G4SDManager.hh"
39 #include "G4HCofThisEvent.hh"
40 #include "G4GenericMessenger.hh"
41 #include "G4UnitsTable.hh"
42 
43 #include "Randomize.hh"
44 #include <iomanip>
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
50  fMessenger(0),
51  fPrintModulo(1)
52 {
53  // Define /B4/event commands using generic messenger class
54  fMessenger = new G4GenericMessenger(this, "/B4/event/", "Event control");
55 
56  // Define /B4/event/setPrintModulo command
57  G4GenericMessenger::Command& setPrintModulo
58  = fMessenger->DeclareProperty("setPrintModulo",
59  fPrintModulo,
60  "Print events modulo n");
61  setPrintModulo.SetRange("value>0");
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  delete fMessenger;
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
74 B4cEventAction::GetHitsCollection(const G4String& hcName,
75  const G4Event* event) const
76 {
77  G4int hcID
79  B4cCalorHitsCollection* hitsCollection
80  = static_cast<B4cCalorHitsCollection*>(
81  event->GetHCofThisEvent()->GetHC(hcID));
82 
83  if ( ! hitsCollection ) {
84  G4cerr << "Cannot access hitsCollection " << hcName << G4endl;
85  exit(1);
86  }
87 
88  return hitsCollection;
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
93 void B4cEventAction::PrintEventStatistics(
94  G4double absoEdep, G4double absoTrackLength,
95  G4double gapEdep, G4double gapTrackLength) const
96 {
97  // print event statistics
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  G4int eventID = event->GetEventID();
117  if ( eventID % fPrintModulo == 0 ) {
118  G4cout << "\n---> Begin of event: " << eventID << G4endl;
119  //CLHEP::HepRandom::showEngineStatus();
120  }
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124 
126 {
127  // Get hits collections
128  B4cCalorHitsCollection* absoHC
129  = GetHitsCollection("AbsorberHitsCollection", event);
131  = GetHitsCollection("GapHitsCollection", event);
132 
133  // Get hit with total values
134  B4cCalorHit* absoHit = (*absoHC)[absoHC->entries()-1];
135  B4cCalorHit* gapHit = (*gapHC)[absoHC->entries()-1];
136 
137  // Print per event (modulo n)
138  //
139  G4int eventID = event->GetEventID();
140  if ( eventID % fPrintModulo == 0) {
141  G4cout << "---> End of event: " << eventID << G4endl;
142 
143  PrintEventStatistics(
144  absoHit->GetEdep(), absoHit->GetTrackLength(),
145  gapHit->GetEdep(), gapHit->GetTrackLength());
146  }
147 
148  // Fill histograms, ntuple
149  //
150 
151  // get analysis manager
152  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
153 
154  // fill histograms
155  analysisManager->FillH1(1, absoHit->GetEdep());
156  analysisManager->FillH1(2, gapHit->GetEdep());
157  analysisManager->FillH1(3, absoHit->GetTrackLength());
158  analysisManager->FillH1(4, gapHit->GetTrackLength());
159 
160  // fill ntuple
161  analysisManager->FillNtupleDColumn(0, absoHit->GetEdep());
162  analysisManager->FillNtupleDColumn(1, gapHit->GetEdep());
163  analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength());
164  analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength());
165  analysisManager->AddNtupleRow();
166 }
167 
168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......