source: trunk/examples/extended/parameterisations/gflash/src/ExGflashEventAction.cc@ 850

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

update

File size: 6.9 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// Created by Joanna Weng 26.11.2004
27using namespace std;
28
29#include "ExGflashEventAction.hh"
30#include "ExGflashHit.hh"
31#include "G4EventManager.hh"
32#include "G4SDManager.hh"
33#include "G4TrajectoryContainer.hh"
34#include "G4Trajectory.hh"
35#include "G4VVisManager.hh"
36#include "G4UImanager.hh"
37#include "G4TrajectoryContainer.hh"
38#include "G4VVisManager.hh"
39#include "G4Event.hh"
40//std
41#include <iostream>
42#include <algorithm>
43//Gflash
44
45
46#include "G4Timer.hh"
47extern G4Timer Timer;
48extern G4Timer Timerintern;
49
50
51
52ExGflashEventAction::ExGflashEventAction():
53nevent(0),dtime(0.0),calorimeterCollectionId(-1)
54{
55}
56
57ExGflashEventAction::~ExGflashEventAction()
58{
59 cout << "Internal Real Elapsed Time /event is: "<< dtime /nevent<< endl;
60}
61
62
63void ExGflashEventAction::BeginOfEventAction(const G4Event *evt){
64 Timerintern.Start();
65 cout<<" ------ Start ExGflashEventAction ----- "<<endl;
66 nevent=evt->GetEventID();
67 cout<<" Start generating event Nr "<<nevent<<endl<<endl;
68}
69
70void ExGflashEventAction::EndOfEventAction(const G4Event *evt)
71{
72 Timerintern.Stop();
73 cout << endl;
74 cout << "******************************************";
75 cout << endl;
76 cout << "Internal Real Elapsed Time is: "<< Timerintern.GetRealElapsed();
77 cout << endl;
78 cout << "Internal System Elapsed Time: " << Timerintern.GetSystemElapsed();
79 cout << endl;
80 cout << "Internal GetUserElapsed Time: " << Timerintern.GetUserElapsed();
81 cout << endl;
82 cout << "******************************************"<< endl;
83 dtime+=Timerintern.GetRealElapsed();
84 cout<<" ------ ExGflashEventAction::End of event nr. "<<nevent<<" -----"<< endl;
85
86 G4SDManager * SDman = G4SDManager::GetSDMpointer();
87 G4String colNam;
88 calorimeterCollectionId=SDman->GetCollectionID(colNam="ExGflashCollection");
89 if (calorimeterCollectionId<0) return;
90 G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
91 ExGflashHitsCollection* THC = 0;
92 G4double totE = 0;
93 // Read out of the crysta ECAL
94 THC=(ExGflashHitsCollection *)(HCE->GetHC(calorimeterCollectionId));
95 if (THC) {
96 /// Hits in sensitive Detector
97 int n_hit = THC->entries();
98 cout<<" " << n_hit<< " hits are stored in ExGflashHitsCollection "<<endl;
99 G4PrimaryVertex* pvertex=evt->GetPrimaryVertex();
100 ///Computing (x,y,z) of vertex of initial particles
101 G4ThreeVector vtx=pvertex->GetPosition();
102 G4PrimaryParticle* pparticle=pvertex->GetPrimary();
103 // direction of the Shower
104 G4ThreeVector mom=pparticle->GetMomentum()/pparticle->GetMomentum().mag();
105
106 //@@@ ExGflashEventAction: Magicnumber
107 G4double energyincrystal[100];
108 for (int i=0;i<100;i++) energyincrystal[i]=0.;
109
110 //@@@ ExGflashEventAction: Magicnumber
111 /// For all Hits in sensitive detector
112 for (int i=0;i<n_hit;i++)
113 {
114 G4double estep = (*THC)[i]->GetEdep()/GeV;
115 if (estep >0.0)
116 {
117 totE += (*THC)[i]->GetEdep()/GeV;
118 G4int num=(*THC)[i]->GetCrystalNum();
119
120 energyincrystal[num]+=(*THC)[i]->GetEdep()/GeV;
121 //std::cout << num << std::endl;
122 //@@@ExGflashEventAction: was bringen die namespace statt using namespace std ?
123 // std::cout << " Crystal Nummer " << (*THC)[i]->GetCrystalNum() << std::endl;
124 // std::cout << (*THC)[i]->GetCrystalNum() /10 << " "<<(*THC)[i]->GetCrystalNum()%10 << std::endl;
125
126 G4ThreeVector hitpos=(*THC)[i]->GetPos();
127 G4ThreeVector l (hitpos.x(), hitpos.y(), hitpos.z());
128 // distance from shower start
129 l = l - vtx;
130 // projection on shower axis = longitudinal profile
131 G4ThreeVector longitudinal = l;
132 // shower profiles (Radial)
133 G4ThreeVector radial = vtx.cross(l);
134 }
135 }
136 G4double max=0;
137 G4int index=0;
138 //Find crystal with maximum energy
139 for (int i=0;i<100;i++)
140 {
141 //std::cout << i <<" " << energyincrystal[i] << std::endl;
142 if (max <energyincrystal[i])
143 {
144 max=energyincrystal[i];
145 index = i;
146 }
147 }
148 //std::cout << index <<" NMAX " << index << std::endl;
149
150 // 3x3 matrix of crystals around the crystal with the maximum energy deposit
151 G4double e3x3 = 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 = energyincrystal[index]+energyincrystal[index+1]+energyincrystal[index-1]+energyincrystal[index+2]+energyincrystal[index-2]+
157 energyincrystal[index-10]+energyincrystal[index-9]+energyincrystal[index-11]+energyincrystal[index-8]+energyincrystal[index-12]+
158 energyincrystal[index+10]+energyincrystal[index+11]+energyincrystal[index+9]+energyincrystal[index+12]+energyincrystal[index+8];
159
160 std::cout << " e1 " << energyincrystal[index] << " e3x3 " << e3x3<< " GeV e5x5 " <<e5x5 <<std::endl;
161 }
162
163 G4cout << " Total energy deposited in the calorimeter: " << totE << " (GeV)" << G4endl;
164 G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
165 G4int n_trajectories = 0;
166 if(trajectoryContainer){ n_trajectories = trajectoryContainer->entries(); }
167 G4cout << " " << n_trajectories << " trajectories stored in this event." << endl;
168 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
169
170 if(pVVisManager)
171 {
172 cout << "DRAWING " <<n_trajectories << endl;
173 for(G4int i=0; i<n_trajectories; i++) { (*(evt->GetTrajectoryContainer()))[i]->DrawTrajectory(50); }
174 }
175
176}
177
178
179
180
181
182
183
184
185
186
187
188
Note: See TracBrowser for help on using the repository browser.