Geant4  10.00.p01
B5EventAction.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: B5EventAction.cc 76474 2013-11-11 10:36:34Z gcosmo $
27 //
30 
31 #include "B5EventAction.hh"
32 #include "B5HodoscopeHit.hh"
33 #include "B5DriftChamberHit.hh"
34 #include "B5EmCalorimeterHit.hh"
35 #include "B5HadCalorimeterHit.hh"
36 #include "B5Analysis.hh"
37 
38 #include "G4Event.hh"
39 #include "G4RunManager.hh"
40 #include "G4EventManager.hh"
41 #include "G4HCofThisEvent.hh"
42 #include "G4VHitsCollection.hh"
43 #include "G4SDManager.hh"
44 #include "G4SystemOfUnits.hh"
45 #include "G4ios.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
51  fHHC1ID(-1),
52  fHHC2ID(-1),
53  fDHC1ID(-1),
54  fDHC2ID(-1),
55  fECHCID(-1),
56  fHCHCID(-1)
57 {
58  // set printing per each event
60 }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {}
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70 {
71  if (fHHC1ID==-1) {
73  fHHC1ID = sdManager->GetCollectionID("hodoscope1/hodoscopeColl");
74  fHHC2ID = sdManager->GetCollectionID("hodoscope2/hodoscopeColl");
75  fDHC1ID = sdManager->GetCollectionID("chamber1/driftChamberColl");
76  fDHC2ID = sdManager->GetCollectionID("chamber2/driftChamberColl");
77  fECHCID = sdManager->GetCollectionID("EMcalorimeter/EMcalorimeterColl");
78  fHCHCID = sdManager->GetCollectionID("HadCalorimeter/HadCalorimeterColl");
79  }
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86  G4HCofThisEvent* hce = event->GetHCofThisEvent();
87  if (!hce)
88  {
90  msg << "No hits collection of this event found.\n";
91  G4Exception("B5EventAction::EndOfEventAction()",
92  "B5Code001", JustWarning, msg);
93  return;
94  }
95 
96 
97  // Get hits collections
99  = static_cast<B5HodoscopeHitsCollection*>(hce->GetHC(fHHC1ID));
100 
102  = static_cast<B5HodoscopeHitsCollection*>(hce->GetHC(fHHC2ID));
103 
105  = static_cast<B5DriftChamberHitsCollection*>(hce->GetHC(fDHC1ID));
106 
108  = static_cast<B5DriftChamberHitsCollection*>(hce->GetHC(fDHC2ID));
109 
111  = static_cast<B5EmCalorimeterHitsCollection*>(hce->GetHC(fECHCID));
112 
114  = static_cast<B5HadCalorimeterHitsCollection*>(hce->GetHC(fHCHCID));
115 
116  if ( (!hHC1) || (!hHC2) || (!dHC1) || (!dHC2) || (!ecHC) || (!hcHC) )
117  {
119  msg << "Some of hits collections of this event not found.\n";
120  G4Exception("B5EventAction::EndOfEventAction()",
121  "B5Code001", JustWarning, msg);
122  return;
123  }
124 
125  //
126  // Fill histograms & ntuple
127  //
128 
129  // Get analysis manager
130  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
131 
132  // Fill histograms
133 
134  G4int n_hit = dHC1->entries();
135  analysisManager->FillH1(0, n_hit);
136 
137  for (G4int i=0;i<n_hit;i++)
138  {
139  B5DriftChamberHit* hit = (*dHC1)[i];
140  G4ThreeVector localPos = hit->GetLocalPos();
141  analysisManager->FillH2(0, localPos.x(), localPos.y());
142  }
143 
144  n_hit = dHC2->entries();
145  analysisManager->FillH1(1, n_hit);
146 
147  for (G4int i=0;i<n_hit;i++)
148  {
149  B5DriftChamberHit* hit = (*dHC2)[i];
150  G4ThreeVector localPos = hit->GetLocalPos();
151  analysisManager->FillH2(1, localPos.x(), localPos.y());
152  }
153 
154 
155  // Fill ntuple
156 
157  // Dc1Hits
158  analysisManager->FillNtupleIColumn(0, dHC1->entries());
159  // Dc2Hits
160  analysisManager->FillNtupleIColumn(1, dHC1->entries());
161 
162  // ECEnergy
163  G4int totalEmHit = 0;
164  G4double totalEmE = 0.;
165  for (G4int i=0;i<80;i++)
166  {
167  B5EmCalorimeterHit* hit = (*ecHC)[i];
168  G4double eDep = hit->GetEdep();
169  if (eDep>0.)
170  {
171  totalEmHit++;
172  totalEmE += eDep;
173  }
174  }
175  analysisManager->FillNtupleDColumn(2, totalEmE);
176 
177  // HCEnergy
178  G4int totalHadHit = 0;
179  G4double totalHadE = 0.;
180  for (G4int i=0;i<20;i++)
181  {
182  B5HadCalorimeterHit* hit = (*hcHC)[i];
183  G4double eDep = hit->GetEdep();
184  if (eDep>0.)
185  {
186  totalHadHit++;
187  totalHadE += eDep;
188  }
189  }
190  analysisManager->FillNtupleDColumn(3, totalHadE);
191 
192  // Time 1
193  for (G4int i=0;i<hHC1->entries();i++)
194  {
195  analysisManager->FillNtupleDColumn(4,(*hHC1)[i]->GetTime());
196  }
197 
198  // Time 2
199  for (G4int i=0;i<hHC2->entries();i++)
200  {
201  analysisManager->FillNtupleDColumn(5,(*hHC2)[i]->GetTime());
202  }
203 
204  analysisManager->AddNtupleRow();
205 
206  //
207  // Print diagnostics
208  //
209 
211  if ( printModulo==0 || event->GetEventID() % printModulo != 0) return;
212 
213  G4PrimaryParticle* primary = event->GetPrimaryVertex(0)->GetPrimary(0);
214  G4cout << G4endl
215  << ">>> Event " << event->GetEventID() << " >>> Simulation truth : "
216  << primary->GetG4code()->GetParticleName()
217  << " " << primary->GetMomentum() << G4endl;
218 
219  // Hodoscope 1
220  n_hit = hHC1->entries();
221  G4cout << "Hodoscope 1 has " << n_hit << " hits." << G4endl;
222  for (G4int i=0;i<n_hit;i++)
223  {
224  B5HodoscopeHit* hit = (*hHC1)[i];
225  hit->Print();
226  }
227 
228  // Hodoscope 2
229  n_hit = hHC2->entries();
230  G4cout << "Hodoscope 2 has " << n_hit << " hits." << G4endl;
231  for (G4int i=0;i<n_hit;i++)
232  {
233  B5HodoscopeHit* hit = (*hHC2)[i];
234  hit->Print();
235  }
236 
237  // Drift chamber 1
238  n_hit = dHC1->entries();
239  G4cout << "Drift Chamber 1 has " << n_hit << " hits." << G4endl;
240  for (G4int i2=0;i2<5;i2++)
241  {
242  for (G4int i=0;i<n_hit;i++)
243  {
244  B5DriftChamberHit* hit = (*dHC1)[i];
245  if (hit->GetLayerID()==i2) hit->Print();
246  }
247  }
248 
249  // Drift chamber 2
250  n_hit = dHC2->entries();
251  G4cout << "Drift Chamber 2 has " << n_hit << " hits." << G4endl;
252  for (G4int i2=0;i2<5;i2++)
253  {
254  for (G4int i=0;i<n_hit;i++)
255  {
256  B5DriftChamberHit* hit = (*dHC2)[i];
257  if (hit->GetLayerID()==i2) hit->Print();
258  }
259  }
260 
261  // EM calorimeter
262  G4cout << "EM Calorimeter has " << totalEmHit << " hits. Total Edep is "
263  << totalEmE/MeV << " (MeV)" << G4endl;
264 
265  // Had calorimeter
266  G4cout << "Hadron Calorimeter has " << totalHadHit << " hits. Total Edep is "
267  << totalHadE/MeV << " (MeV)" << G4endl;
268 }
269 
270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const double MeV
Definition: G4SIunits.hh:193
G4int GetPrintProgress()
G4ThreeVector GetMomentum() const
Definition of the B5EventAction class.
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
void SetPrintProgress(G4int i)
G4int entries() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4ParticleDefinition * GetG4code() const
G4int GetEventID() const
Definition: G4Event.hh:140
Definition of the B5EmCalorimeterHit class.
G4ThreeVector GetLocalPos() const
G4bool FillNtupleIColumn(G4int id, G4int value)
G4GLOB_DLL std::ostream G4cout
G4double GetEdep() const
G4bool FillNtupleDColumn(G4int id, G4double value)
Drift chamber hit.
EM Calorimeter hit.
virtual void Print()
Hodoscope hit.
Definition of the B5HodoscopeHit class.
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Selection of the analysis technology.
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
Hadron Calorimeter hit.
G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual void BeginOfEventAction(const G4Event *)
virtual ~B5EventAction()
G4double GetEdep() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4int GetLayerID() const
virtual void EndOfEventAction(const G4Event *)
Definition of the B5DriftChamberHit class.
Definition of the B5HadCalorimeterHit class.