Skip to content

Commit

Permalink
A hashmap per layer is a bit faster
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Nov 12, 2019
1 parent 5d234eb commit a08bcc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions RecoTracker/MkFit/interface/MkFitGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class MkFitGeometry {

mkfit::LayerNumberConverter const& layerNumberConverter() const { return *lnc_; }
const std::vector<const DetLayer *>& 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<mkfit::LayerNumberConverter> lnc_; // for pimpl pattern
std::vector<const DetLayer *> dets_;
std::unordered_map<unsigned int, unsigned int> detIdToShortId_;
std::vector<std::unordered_map<unsigned int, unsigned int>> detIdToShortId_;
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/MkFit/plugins/MkFitInputConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions RecoTracker/MkFit/src/MkFitGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ MkFitGeometry::MkFitGeometry(const TrackerGeometry& geom, const GeometricSearchT
}

// Create "short id" aka "unique id within layer"
std::vector<unsigned int> 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;
}
}

Expand Down

0 comments on commit a08bcc4

Please sign in to comment.