From d249b5130873317b1006afe61fc55c73a962fd95 Mon Sep 17 00:00:00 2001 From: Paola Ferrario Date: Thu, 20 Oct 2022 17:46:02 +0200 Subject: [PATCH 1/2] Avoid ID repetition for hits of the same track and different SD --- source/persistency/PersistencyManager.cc | 13 +++++++------ source/persistency/PersistencyManager.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/persistency/PersistencyManager.cc b/source/persistency/PersistencyManager.cc index e00926829d..949d86c88a 100644 --- a/source/persistency/PersistencyManager.cc +++ b/source/persistency/PersistencyManager.cc @@ -145,6 +145,7 @@ G4bool PersistencyManager::Store(const G4Event* event) StoreTrajectories(event->GetTrajectoryContainer()); // Store ionization hits and sensor hits + ihits_ = nullptr; StoreHits(event->GetHCofThisEvent()); nevt_++; @@ -264,19 +265,19 @@ void PersistencyManager::StoreIonizationHits(G4VHitsCollection* hc) G4int trackid = hit->GetTrackID(); - std::vector* ihits = nullptr; + std::map* >::iterator it = hit_map_.find(trackid); if (it != hit_map_.end()) { - ihits = it->second; + ihits_ = it->second; } else { - ihits = new std::vector; - hit_map_[trackid] = ihits; + ihits_ = new std::vector; + hit_map_[trackid] = ihits_; } - ihits->push_back(1); + ihits_->push_back(1); G4ThreeVector xyz = hit->GetPosition(); - h5writer_->WriteHitInfo(nevt_, trackid, ihits->size() - 1, + h5writer_->WriteHitInfo(nevt_, trackid, ihits_->size() - 1, xyz[0], xyz[1], xyz[2], hit->GetTime(), hit->GetEnergyDeposit(), sdname.c_str()); diff --git a/source/persistency/PersistencyManager.h b/source/persistency/PersistencyManager.h index 26fbf3fe4e..29e5884cf3 100644 --- a/source/persistency/PersistencyManager.h +++ b/source/persistency/PersistencyManager.h @@ -96,6 +96,7 @@ namespace nexus { HDF5Writer* h5writer_; ///< Event writer to hdf5 file + std::vector* ihits_; std::map* > hit_map_; std::vector sns_posvec_; From a2218a7719f20a749cd6f1e674d8c0e57f5c7163 Mon Sep 17 00:00:00 2001 From: Paola Ferrario Date: Fri, 21 Oct 2022 11:48:26 +0200 Subject: [PATCH 2/2] Empty map of hits at the beginning of event, not SD --- source/persistency/PersistencyManager.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/persistency/PersistencyManager.cc b/source/persistency/PersistencyManager.cc index 949d86c88a..689ddbb6f1 100644 --- a/source/persistency/PersistencyManager.cc +++ b/source/persistency/PersistencyManager.cc @@ -146,6 +146,7 @@ G4bool PersistencyManager::Store(const G4Event* event) // Store ionization hits and sensor hits ihits_ = nullptr; + hit_map_.clear(); StoreHits(event->GetHCofThisEvent()); nevt_++; @@ -253,8 +254,6 @@ void PersistencyManager::StoreIonizationHits(G4VHitsCollection* hc) dynamic_cast(hc); if (!hits) return; - hit_map_.clear(); - double evt_energy = 0.; std::string sdname = hits->GetSDname();