File indexing completed on 2025-02-23 09:22:01
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 #include "EventAction.hh"
0030
0031 #include "AnalysisManager.hh"
0032 #include "ChromosomeHit.hh"
0033 #include "ChromosomeMapper.hh"
0034 #include "DNAGeometry.hh"
0035 #include "DNAHit.hh"
0036 #include "DetectorConstruction.hh"
0037
0038 #include "G4RunManager.hh"
0039
0040
0041
0042 EventAction::EventAction(AnalysisManager* man) : fAnalysisManager(man) {}
0043
0044
0045
0046 void EventAction::Initialize()
0047 {
0048
0049 const auto* det = dynamic_cast<const DetectorConstruction*>(
0050 G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0051 fDNAGeometry = det->GetDNAGeometry();
0052
0053
0054 std::vector<G4String> keys = fDNAGeometry->GetChromosomeMapper()->GetChromosomeKeys();
0055 for (const auto& key : keys) {
0056 uint32_t key_i = G4::hashing::crc32::Hash(key);
0057 fChromoHitMap[key_i] = nullptr;
0058 }
0059 fInitialized = true;
0060 }
0061
0062
0063
0064 void EventAction::BeginOfEventAction(const G4Event*)
0065 {
0066 if (!fInitialized) {
0067 Initialize();
0068 }
0069
0070 fEdepCell = 0;
0071 fTraLenCell = 0;
0072 fTraLenChro = 0;
0073
0074
0075 fDNAHits.reserve(10000);
0076
0077 std::vector<G4String> keys = fDNAGeometry->GetChromosomeMapper()->GetChromosomeKeys();
0078
0079 for (const auto& it : keys) {
0080 uint32_t key_i = G4::hashing::crc32::Hash(it);
0081 fChromoHitMap[key_i] = new ChromosomeHit(it);
0082 }
0083 }
0084
0085
0086
0087 void EventAction::EndOfEventAction(const G4Event*)
0088 {
0089
0090 fAnalysisManager->ProcessPrimary(fprimstoppos, fTraLenCell, fTraLenChro);
0091 fAnalysisManager->ProcessDNAHitsVector(fDNAHits);
0092 fAnalysisManager->ProcessChromosomeHitMap(fChromoHitMap);
0093 fAnalysisManager->ProcessCellEdep(fEdepCell);
0094
0095
0096 for (auto& it : fChromoHitMap) {
0097 delete it.second;
0098 }
0099
0100 for (auto& fDNAHit : fDNAHits) {
0101 delete fDNAHit;
0102 }
0103 fDNAHits.clear();
0104 }
0105
0106
0107
0108 void EventAction::AddChromosomeEdep(const G4String& key, const G4double& e, const G4bool& isDNA)
0109 {
0110 uint32_t key_i = G4::hashing::crc32::Hash(key);
0111 auto it = fChromoHitMap.find(key_i);
0112 if (it != fChromoHitMap.end()) {
0113 if (isDNA) {
0114 it->second->AddDNAEdep(e);
0115 }
0116 else {
0117 it->second->AddChromosomeEdep(e);
0118 }
0119 }
0120 else {
0121 G4ExceptionDescription errmsg;
0122 errmsg << "Energy deposit in unknown chromosome: " << key << G4endl;
0123 G4Exception("EventAction::AddChromosomeEdep", "ERR_UNKNOWN_CHROMOSOME", FatalException, errmsg);
0124 }
0125 }
0126
0127
0128
0129 void EventAction::AddCellEdep(const G4double& edep)
0130 {
0131 fEdepCell += edep;
0132 }
0133
0134
0135
0136 void EventAction::AddTrackLengthCell(const G4double& tl)
0137 {
0138 fTraLenCell += tl;
0139 }
0140
0141
0142
0143 void EventAction::AddTrackLengthChro(const G4double& tl)
0144 {
0145 fTraLenChro += tl;
0146 }
0147
0148