Warning, file /geant4/examples/extended/parameterisations/Par03/src/Par03EventAction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "Par03EventAction.hh"
0027
0028 #include "Par03DetectorConstruction.hh"
0029 #include "Par03Hit.hh"
0030
0031 #include "G4AnalysisManager.hh"
0032 #include "G4Event.hh"
0033 #include "G4EventManager.hh"
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4SDManager.hh"
0036
0037 Par03EventAction::Par03EventAction(Par03DetectorConstruction* aDetector)
0038 : G4UserEventAction(), fHitCollectionID(-1), fTimer(), fDetector(aDetector)
0039 {}
0040
0041
0042
0043 Par03EventAction::~Par03EventAction() = default;
0044
0045
0046
0047 void Par03EventAction::BeginOfEventAction(const G4Event*)
0048 {
0049 fTimer.Start();
0050 }
0051
0052
0053
0054 void Par03EventAction::EndOfEventAction(const G4Event* aEvent)
0055 {
0056 fTimer.Stop();
0057
0058 if (fHitCollectionID == -1) {
0059 fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("hits");
0060 }
0061
0062 auto hitsCollection =
0063 static_cast<Par03HitsCollection*>(aEvent->GetHCofThisEvent()->GetHC(fHitCollectionID));
0064
0065 if (hitsCollection == nullptr) {
0066 G4ExceptionDescription msg;
0067 msg << "Cannot access hitsCollection ID " << fHitCollectionID;
0068 G4Exception("Par03EventAction::GetHitsCollection()", "MyCode0001", FatalException, msg);
0069 }
0070
0071 auto analysisManager = G4AnalysisManager::Instance();
0072
0073 if (fCellSizeZ == 0) {
0074 fCellSizeZ = fDetector->GetLength() / fDetector->GetNbOfLayers();
0075 fCellSizeRho = fDetector->GetRadius() / fDetector->GetNbOfRhoCells();
0076 }
0077
0078
0079
0080 auto primaryVertex =
0081 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetPrimaryVertex();
0082 auto primaryParticle = primaryVertex->GetPrimary(0);
0083 G4double primaryEnergy = primaryParticle->GetTotalEnergy();
0084
0085
0086 auto primaryDirection = primaryParticle->GetMomentumDirection();
0087 auto primaryEntrance =
0088 primaryVertex->GetPosition() - primaryVertex->GetPosition().z() * primaryDirection;
0089 G4double cosDirection = std::cos(primaryDirection.theta());
0090 G4double sinDirection = std::sin(primaryDirection.theta());
0091
0092
0093 Par03Hit* hit = nullptr;
0094 G4double hitEn = 0;
0095 G4double totalEnergy = 0;
0096 G4int hitZ = -1;
0097 G4int hitRho = -1;
0098 G4int hitType = -1;
0099 G4double tDistance = 0., rDistance = 0.;
0100 G4double tFirstMoment = 0., tSecondMoment = 0.;
0101 G4double rFirstMoment = 0., rSecondMoment = 0.;
0102 for (size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) {
0103 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit));
0104 hitZ = hit->GetZid();
0105 hitRho = hit->GetRhoId();
0106 hitEn = hit->GetEdep();
0107 hitType = hit->GetType();
0108 if (hitEn > 0) {
0109 totalEnergy += hitEn;
0110 tDistance = hitZ * fCellSizeZ * cosDirection
0111 + (hitRho * fCellSizeRho - primaryEntrance.perp()) * sinDirection;
0112 rDistance = hitZ * fCellSizeZ * (-sinDirection)
0113 + (hitRho * fCellSizeRho - primaryEntrance.perp()) * cosDirection;
0114 tFirstMoment += hitEn * tDistance;
0115 rFirstMoment += hitEn * rDistance;
0116 analysisManager->FillH1(4, tDistance, hitEn);
0117 analysisManager->FillH1(5, rDistance, hitEn);
0118 analysisManager->FillH1(10, hitType);
0119 }
0120 }
0121 tFirstMoment /= totalEnergy;
0122 rFirstMoment /= totalEnergy;
0123 analysisManager->FillH1(0, primaryEnergy / GeV);
0124 analysisManager->FillH1(1, totalEnergy / GeV);
0125 analysisManager->FillH1(2, totalEnergy / primaryEnergy);
0126 analysisManager->FillH1(3, fTimer.GetRealElapsed());
0127 analysisManager->FillH1(6, tFirstMoment);
0128 analysisManager->FillH1(7, rFirstMoment);
0129
0130
0131 for (size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) {
0132 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit));
0133 hitEn = hit->GetEdep();
0134 hitZ = hit->GetZid();
0135 hitRho = hit->GetRhoId();
0136 if (hitEn > 0) {
0137 tDistance = hitZ * fCellSizeZ * cosDirection
0138 + (hitRho * fCellSizeRho - primaryEntrance.r()) * sinDirection;
0139 rDistance = hitZ * fCellSizeZ * (-sinDirection)
0140 + (hitRho * fCellSizeRho - primaryEntrance.r()) * cosDirection;
0141 tSecondMoment += hitEn * std::pow(tDistance - tFirstMoment, 2);
0142 rSecondMoment += hitEn * std::pow(rDistance - rFirstMoment, 2);
0143 }
0144 }
0145 tSecondMoment /= totalEnergy;
0146 rSecondMoment /= totalEnergy;
0147 analysisManager->FillH1(8, tSecondMoment);
0148 analysisManager->FillH1(9, rSecondMoment);
0149 }