File indexing completed on 2025-01-31 09:22:21
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 "EventAction.hh"
0027
0028 #include "SiPMHit.hh"
0029 #include "SiliconPixelHit.hh"
0030
0031 #include "G4Event.hh"
0032 #include "G4SDManager.hh"
0033 #include "G4GenericMessenger.hh"
0034 #include "G4AnalysisManager.hh"
0035
0036
0037
0038 EventAction::EventAction() : G4UserEventAction() { DefineCommands(); }
0039
0040
0041
0042 EventAction::~EventAction() {}
0043
0044
0045
0046 void EventAction::BeginOfEventAction(const G4Event *) {
0047 fPrimariesPDG.clear();
0048 fPrimariesEnergy.clear();
0049 fPrimariesX.clear();
0050 fPrimariesY.clear();
0051 fPrimariesZ.clear();
0052
0053 fSiHitsID.clear();
0054 fSiHitsX.clear();
0055 fSiHitsY.clear();
0056 fSiHitsZ.clear();
0057 fSiHitsEdep.clear();
0058 fSiHitsEdepNonIonising.clear();
0059 fSiHitsTOA.clear();
0060 fSiHitsTOAlast.clear();
0061 fSiHitsType.clear();
0062
0063 fSiPMhitsID.clear();
0064 fSiPMhitsX.clear();
0065 fSiPMhitsY.clear();
0066 fSiPMhitsZ.clear();
0067 fSiPMhitsEdep.clear();
0068 fSiPMhitsEdepNonIonising.clear();
0069 fSiPMhitsTOA.clear();
0070 fSiPMhitsType.clear();
0071 }
0072
0073
0074
0075 void EventAction::EndOfEventAction(const G4Event *event) {
0076
0077 if (event->GetNumberOfPrimaryVertex() == 0)
0078 return;
0079
0080 auto analysisManager = G4AnalysisManager::Instance();
0081 analysisManager->FillNtupleIColumn(0, event->GetEventID());
0082
0083 for (G4int iVertex = 0; iVertex < event->GetNumberOfPrimaryVertex();
0084 iVertex++) {
0085 auto vertex = event->GetPrimaryVertex(iVertex);
0086 fPrimariesX.push_back(vertex->GetX0() / CLHEP::cm);
0087 fPrimariesY.push_back(vertex->GetY0() / CLHEP::cm);
0088 fPrimariesZ.push_back(vertex->GetZ0() / CLHEP::cm);
0089 for (G4int iParticle = 0; iParticle < vertex->GetNumberOfParticle();
0090 iParticle++) {
0091 auto particle = vertex->GetPrimary(iParticle);
0092 fPrimariesPDG.push_back(particle->GetPDGcode());
0093 fPrimariesEnergy.push_back(particle->GetTotalEnergy() / CLHEP::GeV);
0094 }
0095 }
0096
0097 auto hce = event->GetHCofThisEvent();
0098 auto sdManager = G4SDManager::GetSDMpointer();
0099 G4int collId;
0100
0101
0102 collId = sdManager->GetCollectionID("SiliconPixelHitCollection");
0103 auto hc = hce->GetHC(collId);
0104 if (!hc)
0105 return;
0106 double esumHGCAL = 0;
0107 double cogzHGCAL = 0;
0108 int NhitsHGCAL = 0;
0109 for (unsigned int i = 0; i < hc->GetSize(); ++i) {
0110 auto hit = static_cast<SiliconPixelHit *>(hc->GetHit(i));
0111 hit->Digitise(fHitTimeCut / CLHEP::ns, fToaThreshold / CLHEP::keV);
0112
0113 if (hit->isValidHit()) {
0114 fSiHitsID.push_back(hit->ID());
0115 fSiHitsX.push_back(hit->GetX());
0116 fSiHitsY.push_back(hit->GetY());
0117 fSiHitsZ.push_back(hit->GetZ());
0118 fSiHitsEdep.push_back(hit->GetEdep());
0119 fSiHitsEdepNonIonising.push_back(hit->GetEdepNonIonizing());
0120 fSiHitsTOA.push_back(hit->GetTOA());
0121 fSiHitsTOAlast.push_back(hit->GetLastTOA());
0122 fSiHitsType.push_back(0);
0123
0124 NhitsHGCAL++;
0125 esumHGCAL += hit->GetEdep() * CLHEP::keV / CLHEP::MeV;
0126 cogzHGCAL += hit->GetZ() * hit->GetEdep();
0127 }
0128 }
0129 if (esumHGCAL > 0)
0130 cogzHGCAL /= esumHGCAL;
0131
0132 analysisManager->FillNtupleDColumn(23, esumHGCAL / CLHEP::GeV);
0133 analysisManager->FillNtupleDColumn(24, cogzHGCAL);
0134 analysisManager->FillNtupleIColumn(25, NhitsHGCAL);
0135
0136
0137 collId = sdManager->GetCollectionID("SiPMHitCollection");
0138 hc = hce->GetHC(collId);
0139 if (!hc)
0140 return;
0141 double esumAHCAL = 0;
0142 double cogzAHCAL = 0;
0143 int NhitsAHCAL = 0;
0144 for (unsigned int i = 0; i < hc->GetSize(); ++i) {
0145 auto hit = static_cast<SiPMHit *>(hc->GetHit(i));
0146 hit->Digitise(-1, 0);
0147
0148 if (hit->isValidHit()) {
0149 fSiPMhitsID.push_back(hit->ID());
0150 fSiPMhitsX.push_back(hit->GetX());
0151 fSiPMhitsY.push_back(hit->GetY());
0152 fSiPMhitsZ.push_back(hit->GetZ());
0153 fSiPMhitsEdep.push_back(hit->GetEdep());
0154 fSiPMhitsEdepNonIonising.push_back(hit->GetEdepNonIonizing());
0155 fSiPMhitsTOA.push_back(hit->GetTOA());
0156 fSiPMhitsType.push_back(1);
0157
0158 NhitsAHCAL++;
0159 esumAHCAL += hit->GetEdep() * CLHEP::keV / CLHEP::MeV;
0160 cogzAHCAL += hit->GetZ() * hit->GetEdep();
0161 }
0162 }
0163 if (esumAHCAL > 0)
0164 cogzAHCAL /= esumAHCAL;
0165
0166 analysisManager->FillNtupleDColumn(26, esumAHCAL / CLHEP::GeV);
0167 analysisManager->FillNtupleDColumn(27, cogzAHCAL);
0168 analysisManager->FillNtupleIColumn(28, NhitsAHCAL);
0169
0170 analysisManager->AddNtupleRow();
0171 }
0172
0173
0174
0175 void EventAction::DefineCommands() {
0176
0177 fMessenger = new G4GenericMessenger(this, "/HGCalTestbeam/hits/",
0178 "Primary generator control");
0179
0180
0181 auto &timeCutCmd = fMessenger->DeclarePropertyWithUnit(
0182 "timeCut", "ns", fHitTimeCut,
0183 "Size of time window for hit digitalisation");
0184 timeCutCmd.SetParameterName("timeCut", true);
0185 timeCutCmd.SetRange("timeCut>=-1");
0186 timeCutCmd.SetDefaultValue("-1");
0187
0188
0189 auto &toaThresholdCmd = fMessenger->DeclarePropertyWithUnit(
0190 "toaThreshold", "keV", fToaThreshold, "Threshold for TOA activation");
0191 toaThresholdCmd.SetParameterName("toaThreshold", true);
0192 toaThresholdCmd.SetRange("toaThreshold>=0");
0193 toaThresholdCmd.SetDefaultValue("0");
0194 }
0195
0196