File indexing completed on 2025-01-31 09:22:13
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
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #include "GammaRayTelEventAction.hh"
0042 #include "GammaRayTelTrackerHit.hh"
0043 #include "GammaRayTelAnticoincidenceHit.hh"
0044 #include "GammaRayTelCalorimeterHit.hh"
0045 #include "GammaRayTelAnalysis.hh"
0046 #include "GammaRayTelDigi.hh"
0047 #include "GammaRayTelDigitizer.hh"
0048
0049 #include "G4DigiManager.hh"
0050 #include "G4Event.hh"
0051 #include "G4EventManager.hh"
0052 #include "G4HCofThisEvent.hh"
0053 #include "G4ios.hh"
0054 #include "G4SDManager.hh"
0055 #include "G4SystemOfUnits.hh"
0056 #include "G4UImanager.hh"
0057 #include "G4UnitsTable.hh"
0058 #include "G4VHitsCollection.hh"
0059 #include "Randomize.hh"
0060
0061
0062
0063
0064
0065
0066 GammaRayTelEventAction::GammaRayTelEventAction(GammaRayTelRunAction *runAction) : theRunAction(runAction) {
0067 auto *digitizer = new GammaRayTelDigitizer("GammaRayTelDigitizer");
0068 G4DigiManager::GetDMpointer()->AddNewModule(digitizer);
0069 }
0070
0071
0072
0073 GammaRayTelEventAction::~GammaRayTelEventAction() {
0074 }
0075
0076
0077
0078 void GammaRayTelEventAction::BeginOfEventAction(const G4Event *event) {
0079 G4int eventIdentifer = event->GetEventID();
0080 G4cout << "Event: " << eventIdentifer << G4endl;
0081 auto *sensitiveDetectorManager = G4SDManager::GetSDMpointer();
0082
0083 if (trackerCollectionID == -1) {
0084 trackerCollectionID = sensitiveDetectorManager->GetCollectionID("TrackerCollection");
0085 }
0086 if (anticoincidenceCollectionID == -1) {
0087 anticoincidenceCollectionID = sensitiveDetectorManager->GetCollectionID("AnticoincidenceCollection");
0088 }
0089 if (calorimeterCollectionID == -1) {
0090 calorimeterCollectionID = sensitiveDetectorManager->GetCollectionID("CalorimeterCollection");
0091 }
0092 }
0093
0094
0095
0096 void GammaRayTelEventAction::EndOfEventAction(const G4Event *event) {
0097 G4int eventIdentifier = event->GetEventID();
0098
0099 if (theRunAction == nullptr) {
0100 G4Exception("GammaRayTelEventAction::BeginOfEventAction()", "GTR0001", FatalException, "Null pointer to Run Action: this should not be");
0101 }
0102
0103 #ifdef G4STORE_DATA
0104 auto *outputFile = theRunAction->GetOutputFile();
0105 #endif
0106
0107 auto *collection = event->GetHCofThisEvent();
0108 GammaRayTelTrackerHitsCollection *trackerCollection{nullptr};
0109
0110
0111
0112 auto *fDM = G4DigiManager::GetDMpointer();
0113 GammaRayTelAnalysis *analysis = GammaRayTelAnalysis::getInstance();
0114
0115 if (collection != nullptr) {
0116 trackerCollection = (GammaRayTelTrackerHitsCollection*) (collection->GetHC(trackerCollectionID));
0117
0118
0119
0120 if (trackerCollection != nullptr) {
0121 G4int numberOfHits = trackerCollection->entries();
0122 G4cout << "Number of tracker hits in this event: " << numberOfHits << G4endl;
0123
0124 G4double depositedEnergy{0};
0125 G4int stripNumber;
0126 G4int planeNumber;
0127 G4int isXPlane;
0128
0129
0130
0131 for (auto i = 0; i < numberOfHits; i++) {
0132
0133 depositedEnergy = (*trackerCollection)[i]->GetDepositedEnergy();
0134 stripNumber = (*trackerCollection)[i]->GetStripNumber();
0135 planeNumber = (*trackerCollection)[i]->GetSiliconPlaneNumber();
0136 isXPlane = (*trackerCollection)[i]->GetPlaneType();
0137
0138 #ifdef G4STORE_DATA
0139 (*outputFile) << std::setw(7) << eventIdentifier
0140 << " " << depositedEnergy/keV
0141 << " " << stripNumber
0142 << " " << planeNumber
0143 << " " << isXPlane
0144 << " " << (*trackerCollection)[i]->GetPosition().x() / mm
0145 << " " << (*trackerCollection)[i]->GetPosition().y() / mm
0146 << " " << (*trackerCollection)[i]->GetPosition().z() / mm
0147 << " " << G4endl;
0148 #else
0149 G4cout << std::setw(7) << eventIdentifier
0150 << " " << depositedEnergy / keV
0151 << " " << stripNumber
0152 << " " << planeNumber
0153 << " " << isXPlane
0154 << " " << (*trackerCollection)[i]->GetPosition().x() / mm
0155 << " " << (*trackerCollection)[i]->GetPosition().y() / mm
0156 << " " << (*trackerCollection)[i]->GetPosition().z() / mm
0157 << " " << G4endl;
0158 #endif
0159
0160
0161 if (isXPlane != 0) {
0162 if (analysis->GetHisto2DMode() == "position") {
0163 analysis->InsertPositionXZ((*trackerCollection)[i]->GetPosition().x() / mm, (*trackerCollection)[i]->GetPosition().z() / mm);
0164 } else {
0165 analysis->InsertPositionXZ(stripNumber, planeNumber);
0166 }
0167
0168 if (planeNumber == 0) {
0169 analysis->InsertEnergy(depositedEnergy / keV);
0170 }
0171 analysis->InsertHits(planeNumber);
0172 } else {
0173 if (analysis->GetHisto2DMode() == "position") {
0174 analysis->InsertPositionYZ((*trackerCollection)[i]->GetPosition().y() / mm, (*trackerCollection)[i]->GetPosition().z() / mm);
0175 } else {
0176 analysis->InsertPositionYZ(stripNumber, planeNumber);
0177 }
0178 if (planeNumber == 0) {
0179 analysis->InsertEnergy(depositedEnergy / keV);
0180 }
0181 analysis->InsertHits(planeNumber);
0182 }
0183 analysis->setNtuple(depositedEnergy / keV, planeNumber,
0184 (*trackerCollection)[i]->GetPosition().x() / mm,
0185 (*trackerCollection)[i]->GetPosition().y() / mm,
0186 (*trackerCollection)[i]->GetPosition().z() / mm
0187 );
0188 }
0189 analysis->EndOfEvent(numberOfHits);
0190 }
0191
0192 auto *myDM = (GammaRayTelDigitizer*) fDM->FindDigitizerModule("GammaRayTelDigitizer");
0193 myDM->Digitize();
0194
0195 #ifdef G4STORE_DATA
0196
0197
0198
0199 auto digitsCollectionIdentifier = fDM->GetDigiCollectionID("DigitsCollection");
0200
0201
0202 auto *digitsCollection = (GammaRayTelDigitsCollection*) fDM->GetDigiCollection(digitsCollectionIdentifier);
0203
0204 if (digitsCollection != nullptr) {
0205 auto numberOfDigits = digitsCollection->entries();
0206
0207
0208 G4int stripNumber;
0209 G4int planeNumber;
0210 G4int isXPlane;
0211
0212 for (auto i = 0; i < numberOfDigits; i++) {
0213
0214 stripNumber = (*digitsCollection)[i]->GetStripNumber();
0215 planeNumber = (*digitsCollection)[i]->GetPlaneNumber();
0216 isXPlane = (*digitsCollection)[i]->GetPlaneType();
0217
0218 (*outputFile) << std::setw(7)
0219 << eventIdentifier
0220 << " " << stripNumber
0221 << " " << planeNumber
0222 << " " << isXPlane
0223 << " " << G4endl;
0224 }
0225 }
0226 #endif
0227 }
0228 }