Geant4_10
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 66379 2012-12-18 09:46:33Z 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),fMuonCollID(-1)
54 {;}
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 {;}
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 {
64  if(fTrackerCollID<0||fCalorimeterCollID<0||fMuonCollID<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 
77  if(fTrackerCollID<0||fCalorimeterCollID<0) return;
78 
79  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
82  if(HCE)
83  {
84  THC = (RE01TrackerHitsCollection*)(HCE->GetHC(fTrackerCollID));
85  CHC = (RE01CalorimeterHitsCollection*)(HCE->GetHC(fCalorimeterCollID));
86  }
87 
88  if(THC)
89  {
90  int n_hit = THC->entries();
91  G4cout << G4endl;
92  G4cout << "Tracker hits " <<
93  "--------------------------------------------------------------"
94  << G4endl;
95  G4cout << n_hit << " hits are stored in RE01TrackerHitsCollection."
96  << G4endl;
97  G4cout << "List of hits in tracker" << G4endl;
98  for(int i=0;i<n_hit;i++)
99  { (*THC)[i]->Print(); }
100  }
101  if(CHC)
102  {
103  int n_hit = CHC->entries();
104  G4cout << G4endl;
105  G4cout << "Calorimeter hits "<<
106  "--------------------------------------------------------------"
107  << G4endl;
108  G4cout << n_hit << " hits are stored in RE01CalorimeterHitsCollection."
109  << G4endl;
110  G4double totE = 0;
111  for(int i=0;i<n_hit;i++)
112  { totE += (*CHC)[i]->GetEdep(); }
113  G4cout << " Total energy deposition in calorimeter : "
114  << totE / GeV << " (GeV)" << G4endl;
115  }
116 
117  // get number of stored trajectories
118  G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
119  G4int n_trajectories = 0;
120  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
121  // extract the trajectories and print them out
122  G4cout << G4endl;
123  G4cout << "Trajectories in tracker "<<
124  "--------------------------------------------------------------"
125  << G4endl;
126  for(G4int i=0; i<n_trajectories; i++)
127  {
128  RE01Trajectory* trj =
129  (RE01Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
130  trj->ShowTrajectory();
131  }
132 
133  G4cout << G4endl;
134  G4cout << "Primary particles "<<
135  "--------------------------------------------------------------"
136  << G4endl;
137  G4int n_vertex = evt->GetNumberOfPrimaryVertex();
138  for(G4int iv=0;iv<n_vertex;iv++)
139  {
140  G4PrimaryVertex* pv = evt->GetPrimaryVertex(iv);
141  G4cout << G4endl;
142  G4cout << "Primary vertex "
143  << G4ThreeVector(pv->GetX0(),pv->GetY0(),pv->GetZ0())
144  << " at t = " << (pv->GetT0())/ns << " [ns]" << G4endl;
146  while(pp)
147  {
148  PrintPrimary(pp,0);
149  pp = pp->GetNext();
150  }
151  }
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155 void RE01EventAction::PrintPrimary(G4PrimaryParticle* pp,G4int ind)
156 {
157  for(G4int ii=0;ii<=ind;ii++)
158  { G4cout << " "; }
159  G4cout << "==PDGcode " << pp->GetPDGcode() << " ";
160  if(pp->GetG4code()!=0)
161  { G4cout << "(" << pp->GetG4code()->GetParticleName() << ")"; }
162  else
163  { G4cout << "is not defined in G4"; }
164  G4cout << " " << pp->GetMomentum()/GeV << " [GeV] ";
165  if(pp->GetTrackID()<0)
166  { G4cout << G4endl; }
167  else
168  { G4cout << ">>> G4Track ID " << pp->GetTrackID() << G4endl; }
169 
170  G4PrimaryParticle* daughter = pp->GetDaughter();
171  while(daughter)
172  {
173  PrintPrimary(daughter,ind+1);
174  daughter = daughter->GetNext();
175  }
176 }
177 
178 
G4double GetX0() const
G4ThreeVector GetMomentum() const
Definition of the RE01CalorimeterHit class.
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
virtual void EndOfEventAction(const G4Event *)
G4int GetTrackID() const
CLHEP::Hep3Vector G4ThreeVector
G4int GetNumberOfPrimaryVertex() const
Definition: G4Event.hh:153
virtual ~RE01EventAction()
virtual void ShowTrajectory(std::ostream &os=G4cout) const
G4int entries() const
G4double GetT0() const
int G4int
Definition: G4Types.hh:78
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:178
const G4String & GetParticleName() const
G4ParticleDefinition * GetG4code() const
G4int GetEventID() const
Definition: G4Event.hh:140
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:156
G4int GetPDGcode() const
Definition of the RE01EventAction class.
G4PrimaryParticle * GetNext() const
Definition of the RE01TrackerHit class.
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
G4double GetY0() const
#define G4endl
Definition: G4ios.hh:61
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:174
double G4double
Definition: G4Types.hh:76
#define ns
Definition: xmlparse.cc:597
Definition of the RE01Trajectory class.