Geant4  10.02.p01
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 94396 2015-11-13 13:37:16Z 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 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
53  fNevent(0),fDtime(0.0),fCalorimeterCollectionId(-1)
54 {
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  if ( fNevent > 0 ) {
62  G4cout << "Internal Real Elapsed Time /event is: "<< fDtime /fNevent<< G4endl;
63  }
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
71  G4cout<<" ------ Start ExGflashEventAction ----- "<<G4endl;
72  fNevent=evt->GetEventID();
73  G4cout<<" Start generating event Nr "<<fNevent<<G4endl<<G4endl;
74 }
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
79 {
81  G4cout << G4endl;
82  G4cout << "******************************************";
83  G4cout << G4endl;
84  G4cout << "Internal Real Elapsed Time is: "<< fTimerIntern.GetRealElapsed();
85  G4cout << G4endl;
86  G4cout << "Internal System Elapsed Time: " << fTimerIntern.GetSystemElapsed();
87  G4cout << G4endl;
88  G4cout << "Internal GetUserElapsed Time: " << fTimerIntern.GetUserElapsed();
89  G4cout << G4endl;
90  G4cout << "******************************************"<< G4endl;
92  G4cout<<" ------ ExGflashEventAction::End of event nr. "<<fNevent<<" -----"<< G4endl;
93 
95  G4String colNam;
96  fCalorimeterCollectionId=SDman->GetCollectionID(colNam="ExGflashCollection");
97  if (fCalorimeterCollectionId<0) return;
98  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
99  ExGflashHitsCollection* THC = 0;
100  G4double totE = 0;
101  // Read out of the crysta ECAL
103  if (THC)
104  {
106  int n_hit = THC->entries();
107  G4cout<<" " << n_hit<< " hits are stored in ExGflashHitsCollection "<<G4endl;
108  G4PrimaryVertex* pvertex=evt->GetPrimaryVertex();
110  G4ThreeVector vtx=pvertex->GetPosition();
111  G4PrimaryParticle* pparticle=pvertex->GetPrimary();
112  // direction of the Shower
113  G4ThreeVector mom=pparticle->GetMomentum()/pparticle->GetMomentum().mag();
114 
115  //@@@ ExGflashEventAction: Magicnumber
116  G4double energyincrystal[100];
117  for (int i=0;i<100;i++) energyincrystal[i]=0.;
118 
119  //@@@ ExGflashEventAction: Magicnumber
121  for (int i=0;i<n_hit;i++)
122  {
123  G4double estep = (*THC)[i]->GetEdep()/GeV;
124  if (estep >0.0)
125  {
126  totE += (*THC)[i]->GetEdep()/GeV;
127  G4int num=(*THC)[i]->GetCrystalNum();
128 
129  energyincrystal[num]+=(*THC)[i]->GetEdep()/GeV;
130  //G4cout << num << G4endl;
131  // G4cout << " Crystal Nummer " << (*THC)[i]->GetCrystalNum() << G4endl;
132  // G4cout << (*THC)[i]->GetCrystalNum() /10 <<
133  // " "<<(*THC)[i]->GetCrystalNum()%10 << G4endl;
134 
135  G4ThreeVector hitpos=(*THC)[i]->GetPos();
136  G4ThreeVector l (hitpos.x(), hitpos.y(), hitpos.z());
137  // distance from shower start
138  l = l - vtx;
139  // projection on shower axis = longitudinal profile
140  G4ThreeVector longitudinal = l;
141  // shower profiles (Radial)
142  G4ThreeVector radial = vtx.cross(l);
143  }
144  }
145  G4double max = 0;
146  G4int index = 0;
147  //Find crystal with maximum energy
148  for (int i=0;i<100;i++)
149  {
150  //G4cout << i <<" " << energyincrystal[i] << G4endl;
151  if (max <energyincrystal[i])
152  {
153  max=energyincrystal[i];
154  index = i;
155  }
156  }
157  //G4cout << index <<" NMAX " << index << G4endl;
158 
159  // 3x3 matrix of crystals around the crystal with the maximum energy deposit
160  G4double e3x3 =
161  energyincrystal[index]+energyincrystal[index+1]+energyincrystal[index-1]+
162  energyincrystal[index-10]+energyincrystal[index-9]+energyincrystal[index-11]+
163  energyincrystal[index+10]+energyincrystal[index+11]+energyincrystal[index+9];
164 
165  // 5x5 matrix of crystals around the crystal with the maximum energy deposit
166  G4double e5x5 =
167  energyincrystal[index]+energyincrystal[index+1]+energyincrystal[index-1]+
168  energyincrystal[index+2]+energyincrystal[index-2]+
169  energyincrystal[index-10]+energyincrystal[index-9]+energyincrystal[index-11]+
170  energyincrystal[index-8]+energyincrystal[index-12]+
171  energyincrystal[index+10]+energyincrystal[index+11]+energyincrystal[index+9]+
172  energyincrystal[index+12]+energyincrystal[index+8];
173 
174  G4cout << " e1 " << energyincrystal[index]
175  << " e3x3 " << e3x3<< " GeV e5x5 " <<e5x5 <<G4endl;
176  }
177 
178  G4cout << " Total energy deposited in the calorimeter: " << totE << " (GeV)" << G4endl;
179  G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
180  G4int n_trajectories = 0;
181  if(trajectoryContainer){ n_trajectories = trajectoryContainer->entries(); }
182  G4cout << " " << n_trajectories << " trajectories stored in this event." << G4endl;
183 
184 }
185 
186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
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:189
G4int GetEventID() const
Definition: G4Event.hh:151
G4PrimaryParticle * GetPrimary(G4int i=0) const
virtual void EndOfEventAction(const G4Event *)
G4GLOB_DLL std::ostream G4cout
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
static const double GeV
Definition: G4SIunits.hh:214
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
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
virtual void BeginOfEventAction(const G4Event *)
void Start()
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
double G4double
Definition: G4Types.hh:76