Loading...
Searching...
No Matches
Par03EventAction.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#include "Par03EventAction.hh"
27#include "Par03Hit.hh"
29
30#include "G4AnalysisManager.hh"
31#include "G4SDManager.hh"
32#include "G4HCofThisEvent.hh"
33#include "G4Event.hh"
34#include "G4EventManager.hh"
35
38 , fHitCollectionID(-1)
39 , fTimer()
40 , fDetector(aDetector)
41{}
42
43//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52
54{
55 fTimer.Stop();
56 // Get hits collection ID (only once)
57 if(fHitCollectionID == -1)
58 {
59 fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("hits");
60 }
61 // Get hits collection
62 auto hitsCollection = static_cast<Par03HitsCollection*>(
63 aEvent->GetHCofThisEvent()->GetHC(fHitCollectionID));
64
65 if(hitsCollection == nullptr)
66 {
67 G4ExceptionDescription msg;
68 msg << "Cannot access hitsCollection ID " << fHitCollectionID;
69 G4Exception("Par03EventAction::GetHitsCollection()", "MyCode0001",
70 FatalException, msg);
71 }
72 // Get analysis manager
73 auto analysisManager = G4AnalysisManager::Instance();
74 // Retrieve only once detector dimensions
75 if(fCellSizeZ == 0)
76 {
79 }
80
81 // Retrieve information from primary vertex and primary particle
82 // To calculate shower axis and entry point to the detector
83 auto primaryVertex = G4EventManager::GetEventManager()
84 ->GetConstCurrentEvent()
85 ->GetPrimaryVertex();
86 auto primaryParticle = primaryVertex->GetPrimary(0);
87 G4double primaryEnergy = primaryParticle->GetTotalEnergy();
88 // Estimate from vertex and particle direction the entry point to the detector
89 // Calculate entrance point to the detector located at z = 0
90 auto primaryDirection = primaryParticle->GetMomentumDirection();
91 auto primaryEntrance = primaryVertex->GetPosition() -
92 primaryVertex->GetPosition().z() * primaryDirection;
93 G4double cosDirection = std::cos(primaryDirection.theta());
94 G4double sinDirection = std::sin(primaryDirection.theta());
95
96 // Fill histograms
97 Par03Hit* hit = nullptr;
98 G4double hitEn = 0;
99 G4double totalEnergy = 0;
100 G4int hitZ = -1;
101 G4int hitRho = -1;
102 G4int hitType = -1;
103 G4double tDistance = 0., rDistance = 0.;
104 G4double tFirstMoment = 0., tSecondMoment = 0.;
105 G4double rFirstMoment = 0., rSecondMoment = 0.;
106 for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++)
107 {
108 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit));
109 hitZ = hit->GetZid();
110 hitRho = hit->GetRhoId();
111 hitEn = hit->GetEdep();
112 hitType = hit->GetType();
113 if(hitEn > 0)
114 {
115 totalEnergy += hitEn;
116 tDistance =
117 hitZ * fCellSizeZ * cosDirection +
118 (hitRho * fCellSizeRho - primaryEntrance.perp()) * sinDirection;
119 rDistance =
120 hitZ * fCellSizeZ * (-sinDirection) +
121 (hitRho * fCellSizeRho - primaryEntrance.perp()) * cosDirection;
122 tFirstMoment += hitEn * tDistance;
123 rFirstMoment += hitEn * rDistance;
124 analysisManager->FillH1(4, tDistance, hitEn);
125 analysisManager->FillH1(5, rDistance, hitEn);
126 analysisManager->FillH1(10, hitType);
127 }
128 }
129 tFirstMoment /= totalEnergy;
130 rFirstMoment /= totalEnergy;
131 analysisManager->FillH1(0, primaryEnergy / GeV);
132 analysisManager->FillH1(1, totalEnergy / GeV);
133 analysisManager->FillH1(2, totalEnergy / primaryEnergy);
134 analysisManager->FillH1(3, fTimer.GetRealElapsed());
135 analysisManager->FillH1(6, tFirstMoment);
136 analysisManager->FillH1(7, rFirstMoment);
137
138 // Second loop over hits to calculate second moments
139 for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++)
140 {
141 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit));
142 hitEn = hit->GetEdep();
143 hitZ = hit->GetZid();
144 hitRho = hit->GetRhoId();
145 if(hitEn > 0)
146 {
147 tDistance = hitZ * fCellSizeZ * cosDirection +
148 (hitRho * fCellSizeRho - primaryEntrance.r()) * sinDirection;
149 rDistance = hitZ * fCellSizeZ * (-sinDirection) +
150 (hitRho * fCellSizeRho - primaryEntrance.r()) * cosDirection;
151 tSecondMoment += hitEn * std::pow(tDistance - tFirstMoment, 2);
152 rSecondMoment += hitEn * std::pow(rDistance - rFirstMoment, 2);
153 }
154 }
155 tSecondMoment /= totalEnergy;
156 rSecondMoment /= totalEnergy;
157 analysisManager->FillH1(8, tSecondMoment);
158 analysisManager->FillH1(9, rSecondMoment);
159}
G4THitsCollection< Par03Hit > Par03HitsCollection
Definition Par03Hit.hh:132
Par03DetectorConstruction * fDetector
Pointer to detector construction to retrieve (once) the detector dimensions.
G4double fCellSizeRho
Size of cell along radius of cylinder.
G4int fHitCollectionID
ID of a hit collection to analyse.
virtual void BeginOfEventAction(const G4Event *aEvent) final
Timer is started.
G4Timer fTimer
Timer measurement.
Par03EventAction(Par03DetectorConstruction *aDetector)
G4double fCellSizeZ
Size of cell along Z axis.
virtual ~Par03EventAction()
virtual void EndOfEventAction(const G4Event *aEvent) final
Hits collection is retrieved, analysed, and histograms are filled.
Hit class to store energy deposited in the sensitive detector.
G4int GetRhoId() const
Get rho id of the cell in the readout segmentation.
Definition Par03Hit.hh:93
G4int GetZid() const
Get Z id of the cell in the readout segmentation.
Definition Par03Hit.hh:89
G4int GetType() const
Get type (0 = full sim, 1 = fast sim)
Definition Par03Hit.hh:105
G4double GetEdep() const
Get energy.
Definition Par03Hit.hh:85

Applications | User Support | Publications | Collaboration