Geant4  10.00.p02
ExGflashEventAction.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: ExGflashEventAction.cc 75838 2013-11-06 17:25:50Z gcosmo $
27 //
30 //
31 // Created by Joanna Weng 26.11.2004
32 
33 
34 #include "ExGflashEventAction.hh"
35 #include "ExGflashHit.hh"
36 #include "G4EventManager.hh"
37 #include "G4SDManager.hh"
38 #include "G4UImanager.hh"
39 #include "G4TrajectoryContainer.hh"
40 #include "G4Event.hh"
41 #include "G4SystemOfUnits.hh"
42 //std
43 #include <iostream>
44 #include <algorithm>
45 //Gflash
46 using namespace std;
47 
48 
50 fNevent(0),fDtime(0.0),fCalorimeterCollectionId(-1)
51 {
52 }
53 
55 {
56  if ( fNevent > 0 ) G4cout << "Internal Real Elapsed Time /event is: "<< fDtime /fNevent<< G4endl;
57 }
58 
59 
61 {
63  G4cout<<" ------ Start ExGflashEventAction ----- "<<G4endl;
64  fNevent=evt->GetEventID();
65  G4cout<<" Start generating event Nr "<<fNevent<<G4endl<<G4endl;
66 }
67 
69 {
71  G4cout << G4endl;
72  G4cout << "******************************************";
73  G4cout << G4endl;
74  G4cout << "Internal Real Elapsed Time is: "<< fTimerIntern.GetRealElapsed();
75  G4cout << G4endl;
76  G4cout << "Internal System Elapsed Time: " << fTimerIntern.GetSystemElapsed();
77  G4cout << G4endl;
78  G4cout << "Internal GetUserElapsed Time: " << fTimerIntern.GetUserElapsed();
79  G4cout << G4endl;
80  G4cout << "******************************************"<< G4endl;
82  G4cout<<" ------ ExGflashEventAction::End of event nr. "<<fNevent<<" -----"<< G4endl;
83 
85  G4String colNam;
86  fCalorimeterCollectionId=SDman->GetCollectionID(colNam="ExGflashCollection");
87  if (fCalorimeterCollectionId<0) return;
88  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
89  ExGflashHitsCollection* THC = 0;
90  G4double totE = 0;
91  // Read out of the crysta ECAL
93  if (THC)
94  {
96  int n_hit = THC->entries();
97  G4cout<<" " << n_hit<< " hits are stored in ExGflashHitsCollection "<<G4endl;
98  G4PrimaryVertex* pvertex=evt->GetPrimaryVertex();
100  G4ThreeVector vtx=pvertex->GetPosition();
101  G4PrimaryParticle* pparticle=pvertex->GetPrimary();
102  // direction of the Shower
103  G4ThreeVector mom=pparticle->GetMomentum()/pparticle->GetMomentum().mag();
104 
105  //@@@ ExGflashEventAction: Magicnumber
106  G4double energyincrystal[100];
107  for (int i=0;i<100;i++) energyincrystal[i]=0.;
108 
109  //@@@ ExGflashEventAction: Magicnumber
111  for (int i=0;i<n_hit;i++)
112  {
113  G4double estep = (*THC)[i]->GetEdep()/GeV;
114  if (estep >0.0)
115  {
116  totE += (*THC)[i]->GetEdep()/GeV;
117  G4int num=(*THC)[i]->GetCrystalNum();
118 
119  energyincrystal[num]+=(*THC)[i]->GetEdep()/GeV;
120  //G4cout << num << G4endl;
121  // G4cout << " Crystal Nummer " << (*THC)[i]->GetCrystalNum() << G4endl;
122  // G4cout << (*THC)[i]->GetCrystalNum() /10 <<
123  // " "<<(*THC)[i]->GetCrystalNum()%10 << G4endl;
124 
125  G4ThreeVector hitpos=(*THC)[i]->GetPos();
126  G4ThreeVector l (hitpos.x(), hitpos.y(), hitpos.z());
127  // distance from shower start
128  l = l - vtx;
129  // projection on shower axis = longitudinal profile
130  G4ThreeVector longitudinal = l;
131  // shower profiles (Radial)
132  G4ThreeVector radial = vtx.cross(l);
133  }
134  }
135  G4double max = 0;
136  G4int index = 0;
137  //Find crystal with maximum energy
138  for (int i=0;i<100;i++)
139  {
140  //G4cout << i <<" " << energyincrystal[i] << G4endl;
141  if (max <energyincrystal[i])
142  {
143  max=energyincrystal[i];
144  index = i;
145  }
146  }
147  //G4cout << index <<" NMAX " << index << G4endl;
148 
149  // 3x3 matrix of crystals around the crystal with the maximum energy deposit
150  G4double e3x3 =
151  energyincrystal[index]+energyincrystal[index+1]+energyincrystal[index-1]+
152  energyincrystal[index-10]+energyincrystal[index-9]+energyincrystal[index-11]+
153  energyincrystal[index+10]+energyincrystal[index+11]+energyincrystal[index+9];
154 
155  // 5x5 matrix of crystals around the crystal with the maximum energy deposit
156  G4double e5x5 =
157  energyincrystal[index]+energyincrystal[index+1]+energyincrystal[index-1]+
158  energyincrystal[index+2]+energyincrystal[index-2]+
159  energyincrystal[index-10]+energyincrystal[index-9]+energyincrystal[index-11]+
160  energyincrystal[index-8]+energyincrystal[index-12]+
161  energyincrystal[index+10]+energyincrystal[index+11]+energyincrystal[index+9]+
162  energyincrystal[index+12]+energyincrystal[index+8];
163 
164  G4cout << " e1 " << energyincrystal[index]
165  << " e3x3 " << e3x3<< " GeV e5x5 " <<e5x5 <<G4endl;
166  }
167 
168  G4cout << " Total energy deposited in the calorimeter: " << totE << " (GeV)" << G4endl;
169  G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
170  G4int n_trajectories = 0;
171  if(trajectoryContainer){ n_trajectories = trajectoryContainer->entries(); }
172  G4cout << " " << n_trajectories << " trajectories stored in this event." << G4endl;
173 
174 }
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
G4ThreeVector GetMomentum() const
G4double GetSystemElapsed() const
Definition: G4Timer.cc:119
G4VHitsCollection * GetHC(G4int i)
G4ThreeVector GetPosition() const
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
CLHEP::Hep3Vector G4ThreeVector
G4int entries() const
int G4int
Definition: G4Types.hh:78
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:178
G4int GetEventID() const
Definition: G4Event.hh:140
G4PrimaryParticle * GetPrimary(G4int i=0) const
void EndOfEventAction(const G4Event *)
G4GLOB_DLL std::ostream G4cout
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
static const double GeV
Definition: G4SIunits.hh:196
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:156
Definition of the ExGflashEventAction class.
Definition of the ExGflashHit class.
G4double GetRealElapsed() const
Definition: G4Timer.cc:107
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void Stop()
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
#define G4endl
Definition: G4ios.hh:61
void BeginOfEventAction(const G4Event *)
void Start()
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:174
double G4double
Definition: G4Types.hh:76