source: trunk/examples/extended/runAndEvent/RE01/src/RE01EventAction.cc @ 807

Last change on this file since 807 was 807, checked in by garnier, 16 years ago

update

File size: 5.7 KB
Line 
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: RE01EventAction.cc,v 1.2 2006/06/29 17:43:55 gunter Exp $
27// GEANT4 tag $Name:  $
28//
29
30
31#include "RE01EventAction.hh"
32
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
49RE01EventAction::RE01EventAction()
50{
51  trackerCollID = -1;
52  calorimeterCollID = -1;
53  muonCollID = -1;
54}
55
56RE01EventAction::~RE01EventAction()
57{;}
58
59void RE01EventAction::BeginOfEventAction(const G4Event*)
60{
61  G4SDManager * SDman = G4SDManager::GetSDMpointer();
62  if(trackerCollID<0||calorimeterCollID<0||muonCollID<0)
63  {
64    G4String colNam;
65    trackerCollID = SDman->GetCollectionID(colNam="trackerCollection");
66    calorimeterCollID = SDman->GetCollectionID(colNam="calCollection");
67  }
68}
69
70void RE01EventAction::EndOfEventAction(const G4Event* evt)
71{
72  G4cout << ">>> Summary of Event " << evt->GetEventID() << G4endl;
73 
74  if(trackerCollID<0||calorimeterCollID<0) return;
75
76  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
77  RE01TrackerHitsCollection* THC = 0;
78  RE01CalorimeterHitsCollection* CHC = 0;
79  if(HCE)
80  {
81    THC = (RE01TrackerHitsCollection*)(HCE->GetHC(trackerCollID));
82    CHC = (RE01CalorimeterHitsCollection*)(HCE->GetHC(calorimeterCollID));
83  }
84
85  if(THC)
86  {
87    int n_hit = THC->entries();
88    G4cout << G4endl;
89    G4cout << "Tracker hits --------------------------------------------------------------" << G4endl;
90    G4cout << n_hit << " hits are stored in RE01TrackerHitsCollection." << G4endl;
91    G4cout << "List of hits in tracker" << G4endl;
92    for(int i=0;i<n_hit;i++)
93    { (*THC)[i]->Print(); }
94  }
95  if(CHC)
96  {
97    int n_hit = CHC->entries();
98    G4cout << G4endl;
99    G4cout << "Calorimeter hits --------------------------------------------------------------" << G4endl;
100    G4cout << n_hit << " hits are stored in RE01CalorimeterHitsCollection." << G4endl;
101    G4double totE = 0;
102    for(int i=0;i<n_hit;i++)
103    { totE += (*CHC)[i]->GetEdep(); }
104    G4cout << "     Total energy deposition in calorimeter : "
105         << totE / GeV << " (GeV)" << G4endl;
106  }
107
108  // get number of stored trajectories
109  G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
110  G4int n_trajectories = 0;
111  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
112  // extract the trajectories and print them out
113  G4cout << G4endl;
114  G4cout << "Trajectories in tracker --------------------------------------------------------------" << G4endl;
115  for(G4int i=0; i<n_trajectories; i++) 
116  {
117    RE01Trajectory* trj = (RE01Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
118    trj->ShowTrajectory();
119  }
120   
121  G4cout << G4endl;
122  G4cout << "Primary particles --------------------------------------------------------------" << G4endl;
123  G4int n_vertex = evt->GetNumberOfPrimaryVertex();
124  for(G4int iv=0;iv<n_vertex;iv++)
125  {
126    G4PrimaryVertex* pv = evt->GetPrimaryVertex(iv);
127    G4cout << G4endl;
128    G4cout << "Primary vertex "
129           << G4ThreeVector(pv->GetX0(),pv->GetY0(),pv->GetZ0())
130           << "   at t = " << (pv->GetT0())/ns << " [ns]" << G4endl;
131    G4PrimaryParticle* pp = pv->GetPrimary();
132    while(pp)
133    {
134      PrintPrimary(pp,0);
135      pp = pp->GetNext();
136    }
137  }
138}
139
140void RE01EventAction::PrintPrimary(G4PrimaryParticle* pp,G4int ind)
141{
142  for(G4int ii=0;ii<=ind;ii++)
143  { G4cout << "  "; }
144  G4cout << "==PDGcode " << pp->GetPDGcode() << " ";
145  if(pp->GetG4code()!=0)
146  { G4cout << "(" << pp->GetG4code()->GetParticleName() << ")"; }
147  else
148  { G4cout << "is not defined in G4"; }
149  G4cout << " " << pp->GetMomentum()/GeV << " [GeV] ";
150  if(pp->GetTrackID()<0)
151  { G4cout << G4endl; }
152  else
153  { G4cout << ">>> G4Track ID " << pp->GetTrackID() << G4endl; }
154
155  G4PrimaryParticle* daughter = pp->GetDaughter();
156  while(daughter)
157  {
158    PrintPrimary(daughter,ind+1);
159    daughter = daughter->GetNext();
160  }
161}
162
163
Note: See TracBrowser for help on using the repository browser.