From a08bcc4dbe69a7b2eca21b7ac4bff503708351cc Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Thu, 10 Oct 2019 13:30:45 -0700 Subject: [PATCH] A hashmap per layer is a bit faster --- RecoTracker/MkFit/interface/MkFitGeometry.h | 6 +++--- RecoTracker/MkFit/plugins/MkFitInputConverter.cc | 2 +- RecoTracker/MkFit/src/MkFitGeometry.cc | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/RecoTracker/MkFit/interface/MkFitGeometry.h b/RecoTracker/MkFit/interface/MkFitGeometry.h index 0cd0843846611..1cad71a322b67 100644 --- a/RecoTracker/MkFit/interface/MkFitGeometry.h +++ b/RecoTracker/MkFit/interface/MkFitGeometry.h @@ -24,14 +24,14 @@ class MkFitGeometry { mkfit::LayerNumberConverter const& layerNumberConverter() const { return *lnc_; } const std::vector& detLayers() const { return dets_; } - unsigned int uniqueIdInLayer(unsigned int detId) const { - return detIdToShortId_.at(detId); + unsigned int uniqueIdInLayer(int layer, unsigned int detId) const { + return detIdToShortId_.at(layer).at(detId); } private: std::unique_ptr lnc_; // for pimpl pattern std::vector dets_; - std::unordered_map detIdToShortId_; + std::vector> detIdToShortId_; }; #endif diff --git a/RecoTracker/MkFit/plugins/MkFitInputConverter.cc b/RecoTracker/MkFit/plugins/MkFitInputConverter.cc index e9190441cf873..106c574280a88 100644 --- a/RecoTracker/MkFit/plugins/MkFitInputConverter.cc +++ b/RecoTracker/MkFit/plugins/MkFitInputConverter.cc @@ -200,8 +200,8 @@ void MkFitInputConverter::convertHits(const HitCollection& hits, const auto subdet = detid.subdetId(); const auto layer = ttopo.layer(detid); const auto isStereo = ttopo.isStereo(detid); - const auto uniqueIdInLayer = mkFitGeom.uniqueIdInLayer(detid.rawId()); const auto ilay = mkFitGeom.layerNumberConverter().convertLayerNumber(subdet, layer, false, isStereo, isPlusSide(detid)); + const auto uniqueIdInLayer = mkFitGeom.uniqueIdInLayer(ilay, detid.rawId()); hitIndexMap.increaseLayerSize(ilay, detset.size()); // to minimize memory allocations for(const auto& hit: detset) { diff --git a/RecoTracker/MkFit/src/MkFitGeometry.cc b/RecoTracker/MkFit/src/MkFitGeometry.cc index 76f02873beaa9..011f838b29955 100644 --- a/RecoTracker/MkFit/src/MkFitGeometry.cc +++ b/RecoTracker/MkFit/src/MkFitGeometry.cc @@ -50,12 +50,14 @@ MkFitGeometry::MkFitGeometry(const TrackerGeometry& geom, const GeometricSearchT } // Create "short id" aka "unique id within layer" - std::vector idInLayer(lnc_->nLayers(), 0); + detIdToShortId_.resize(lnc_->nLayers()); for(const auto& detId: geom.detIds()) { const auto ilay = lnc_->convertLayerNumber(detId.subdetId(), ttopo.layer(detId), false, ttopo.isStereo(detId), isPlusSide(detId)); - detIdToShortId_[detId.rawId()] = idInLayer[ilay]++; + auto& map = detIdToShortId_[ilay]; + const unsigned int ind = map.size(); // Make sure the short id fits in the 12 bits... - assert(idInLayer[ilay] < (int)1<<11); + assert(ind < (int)1<<11); + map[detId.rawId()] = ind; } }