Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE01EventAction.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 //
28 //
29 // $Id: RE01EventAction.cc 97383 2016-06-02 09:56:35Z gcosmo $
30 //
31 
32 #include "RE01EventAction.hh"
33 #include "RE01TrackerHit.hh"
34 #include "RE01CalorimeterHit.hh"
35 
36 #include "G4Event.hh"
37 #include "G4EventManager.hh"
38 #include "G4HCofThisEvent.hh"
39 #include "G4VHitsCollection.hh"
40 #include "G4TrajectoryContainer.hh"
41 #include "G4VVisManager.hh"
42 #include "G4SDManager.hh"
43 #include "G4UImanager.hh"
44 #include "G4ios.hh"
45 #include "RE01Trajectory.hh"
46 #include "G4PrimaryVertex.hh"
47 #include "G4PrimaryParticle.hh"
48 #include "G4SystemOfUnits.hh"
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53  fTrackerCollID(-1),fCalorimeterCollID(-1)
54 {;}
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 {;}
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 {
64  if(fTrackerCollID<0||fCalorimeterCollID<0)
65  {
66  G4String colNam;
67  fTrackerCollID = SDman->GetCollectionID(colNam="trackerCollection");
68  fCalorimeterCollID = SDman->GetCollectionID(colNam="calCollection");
69  }
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 {
75  G4cout << ">>> Summary of Event " << evt->GetEventID() << G4endl;
76  if(evt->GetNumberOfPrimaryVertex()==0)
77  {
78  G4cout << "Event is empty." << G4endl;
79  return;
80  }
81 
82  if(fTrackerCollID<0||fCalorimeterCollID<0) return;
83 
84  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
87  if(HCE)
88  {
89  THC = (RE01TrackerHitsCollection*)(HCE->GetHC(fTrackerCollID));
90  CHC = (RE01CalorimeterHitsCollection*)(HCE->GetHC(fCalorimeterCollID));
91  }
92 
93  if(THC)
94  {
95  int n_hit = THC->entries();
96  G4cout << G4endl;
97  G4cout << "Tracker hits " <<
98  "--------------------------------------------------------------"
99  << G4endl;
100  G4cout << n_hit << " hits are stored in RE01TrackerHitsCollection."
101  << G4endl;
103  {
104  G4cout << "List of hits in tracker" << G4endl;
105  for(int i=0;i<n_hit;i++)
106  { (*THC)[i]->Print(); }
107  }
108  }
109  if(CHC)
110  {
111  int n_hit = CHC->entries();
112  G4cout << G4endl;
113  G4cout << "Calorimeter hits "<<
114  "--------------------------------------------------------------"
115  << G4endl;
116  G4cout << n_hit << " hits are stored in RE01CalorimeterHitsCollection."
117  << G4endl;
118  G4double totE = 0;
119  for(int i=0;i<n_hit;i++)
120  { totE += (*CHC)[i]->GetEdep(); }
121  G4cout << " Total energy deposition in calorimeter : "
122  << totE / GeV << " (GeV)" << G4endl;
123  }
124 
125  // get number of stored trajectories
126  G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
127  G4int n_trajectories = 0;
128  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
129  // extract the trajectories and print them out
130  G4cout << G4endl;
131  G4cout << "Trajectories in tracker "<<
132  "--------------------------------------------------------------"
133  << G4endl;
135  {
136  for(G4int i=0; i<n_trajectories; i++)
137  {
138  RE01Trajectory* trj =
139  (RE01Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
140  trj->ShowTrajectory();
141  }
142  }
143 
144  G4cout << G4endl;
145  G4cout << "Primary particles "<<
146  "--------------------------------------------------------------"
147  << G4endl;
148  G4int n_vertex = evt->GetNumberOfPrimaryVertex();
149  for(G4int iv=0;iv<n_vertex;iv++)
150  {
151  G4PrimaryVertex* pv = evt->GetPrimaryVertex(iv);
152  G4cout << G4endl;
153  G4cout << "Primary vertex "
154  << G4ThreeVector(pv->GetX0(),pv->GetY0(),pv->GetZ0())
155  << " at t = " << (pv->GetT0())/ns << " [ns]" << G4endl;
157  {
159  while(pp)
160  {
161  PrintPrimary(pp,0);
162  pp = pp->GetNext();
163  }
164  }
165  }
166 }
167 
168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
169 void RE01EventAction::PrintPrimary(G4PrimaryParticle* pp,G4int ind)
170 {
171  for(G4int ii=0;ii<=ind;ii++)
172  { G4cout << " "; }
173  G4cout << "==PDGcode " << pp->GetPDGcode() << " ";
174  if(pp->GetG4code()!=0)
175  { G4cout << "(" << pp->GetG4code()->GetParticleName() << ")"; }
176  else
177  { G4cout << "is not defined in G4"; }
178  G4cout << " " << pp->GetMomentum()/GeV << " [GeV] ";
179  if(pp->GetTrackID()<0)
180  { G4cout << G4endl; }
181  else
182  { G4cout << ">>> G4Track ID " << pp->GetTrackID() << G4endl; }
183 
184  G4PrimaryParticle* daughter = pp->GetDaughter();
185  while(daughter)
186  {
187  PrintPrimary(daughter,ind+1);
188  daughter = daughter->GetNext();
189  }
190 }
191 
192 
G4double GetX0() const
G4ThreeVector GetMomentum() const
Definition of the RE01CalorimeterHit class.
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
virtual void EndOfEventAction(const G4Event *)
G4int GetTrackID() const
CLHEP::Hep3Vector G4ThreeVector
G4int GetNumberOfPrimaryVertex() const
Definition: G4Event.hh:164
virtual ~RE01EventAction()
virtual void ShowTrajectory(std::ostream &os=G4cout) const
G4int entries() const
G4double GetT0() const
G4EventManager * fpEventManager
int G4int
Definition: G4Types.hh:78
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:189
const G4String & GetParticleName() const
G4ParticleDefinition * GetG4code() const
G4int GetEventID() const
Definition: G4Event.hh:151
G4PrimaryParticle * GetPrimary(G4int i=0) const
G4GLOB_DLL std::ostream G4cout
virtual void BeginOfEventAction(const G4Event *)
G4PrimaryParticle * GetDaughter() const
G4double GetZ0() const
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
G4int GetPDGcode() const
Definition of the RE01EventAction class.
G4PrimaryParticle * GetNext() const
Definition of the RE01TrackerHit class.
G4int GetVerboseLevel()
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
static constexpr double GeV
Definition: G4SIunits.hh:217
G4double GetY0() const
#define G4endl
Definition: G4ios.hh:61
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
double G4double
Definition: G4Types.hh:76
#define ns
Definition: xmlparse.cc:614
Definition of the RE01Trajectory class.