diff --git a/DataFormats/Common/interface/MultiSpan.h b/DataFormats/Common/interface/MultiSpan.h new file mode 100644 index 0000000000000..7ed33185f25d6 --- /dev/null +++ b/DataFormats/Common/interface/MultiSpan.h @@ -0,0 +1,153 @@ +// Author: Felice Pantaleo (CERN), 2023, felice.pantaleo@cern.ch +#ifndef DataFormats_Common_MultiSpan_h +#define DataFormats_Common_MultiSpan_h + +#include +#include +#include +#include +#include + +namespace edm { + + /** +* @brief A view-like container that provides a contiguous indexing interface over multiple disjoint spans. +* +* MultiSpan allows to append multiple `std::vector` as std::span instances and access them through a +* single global index as if they formed one continuous sequence. +* +* This class is read-only and does not take ownership of the underlying data. +* It is intended for iteration over heterogeneous but logically connected data ranges without copying +* or merging them into a single container. +* +* To find a span that corresponds to a global index, a binary search is used, making the access time logarithmic in the number of spans. +* This means when iterating over the elements the binary search over spans is repeated for every element. +* +*/ + template + class MultiSpan { + public: + MultiSpan() = default; + + void add(std::span sp) { + spans_.emplace_back(sp); + offsets_.push_back(totalSize_); + totalSize_ += sp.size(); + } + + const T& operator[](const std::size_t globalIndex) const { +#ifndef NDEBUG + if (globalIndex >= totalSize_) { + throw std::out_of_range("Global index out of range"); + } +#endif + const auto [spanIndex, indexWithinSpan] = spanAndLocalIndex(globalIndex); + return spans_[spanIndex][indexWithinSpan]; + } + + std::size_t globalIndex(const std::size_t spanIndex, const std::size_t indexWithinSpan) const { +#ifndef NDEBUG + if (spanIndex >= spans_.size()) { + throw std::out_of_range("spanIndex index out of range"); + } + if (indexWithinSpan >= spans_[spanIndex].size()) { + throw std::out_of_range("indexWithinSpan index out of range"); + } +#endif + + return offsets_[spanIndex] + indexWithinSpan; + } + + std::pair spanAndLocalIndex(const std::size_t globalIndex) const { +#ifndef NDEBUG + if (globalIndex >= totalSize_) { + throw std::out_of_range("Global index out of range"); + } +#endif + auto it = std::upper_bound(offsets_.begin(), offsets_.end(), globalIndex); + std::size_t spanIndex = std::distance(offsets_.begin(), it) - 1; + std::size_t indexWithinSpan = globalIndex - offsets_[spanIndex]; + + return {spanIndex, indexWithinSpan}; + } + + std::size_t size() const { return totalSize_; } + + class ConstRandomAccessIterator { + public: + using iterator_category = std::random_access_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + + ConstRandomAccessIterator(const MultiSpan& ms, const std::size_t index) : ms_(&ms), currentIndex_(index) {} + + reference operator*() const { return (*ms_)[currentIndex_]; } + pointer operator->() const { return &(*ms_)[currentIndex_]; } + + reference operator[](difference_type n) const { return (*ms_)[currentIndex_ + n]; } + + ConstRandomAccessIterator& operator++() { + ++currentIndex_; + return *this; + } + ConstRandomAccessIterator operator++(int) { + auto tmp = *this; + ++(*this); + return tmp; + } + ConstRandomAccessIterator& operator--() { + --currentIndex_; + return *this; + } + ConstRandomAccessIterator operator--(int) { + auto tmp = *this; + --(*this); + return tmp; + } + + ConstRandomAccessIterator& operator+=(difference_type n) { + currentIndex_ += n; + return *this; + } + ConstRandomAccessIterator& operator-=(difference_type n) { + currentIndex_ -= n; + return *this; + } + + ConstRandomAccessIterator operator+(difference_type n) const { + return ConstRandomAccessIterator(*ms_, currentIndex_ + n); + } + + ConstRandomAccessIterator operator-(difference_type n) const { + return ConstRandomAccessIterator(*ms_, currentIndex_ - n); + } + + difference_type operator-(const ConstRandomAccessIterator& other) const { + return currentIndex_ - other.currentIndex_; + } + + bool operator==(const ConstRandomAccessIterator& other) const { return currentIndex_ == other.currentIndex_; } + bool operator!=(const ConstRandomAccessIterator& other) const { return currentIndex_ != other.currentIndex_; } + auto operator<=>(const ConstRandomAccessIterator& other) const { return currentIndex_ <=> other.currentIndex_; } + + private: + const MultiSpan* ms_; + std::size_t currentIndex_; + }; + + using const_iterator = ConstRandomAccessIterator; + + const_iterator begin() const { return const_iterator(*this, 0); } + const_iterator end() const { return const_iterator(*this, totalSize_); } + + private: + std::vector> spans_; + std::vector offsets_; + std::size_t totalSize_{0}; + }; + +} // namespace edm + +#endif // DataFormats_Common_MultiSpan_h diff --git a/DataFormats/Common/test/test_catch2_MultiSpan.cpp b/DataFormats/Common/test/test_catch2_MultiSpan.cpp new file mode 100644 index 0000000000000..ff8a093c8007b --- /dev/null +++ b/DataFormats/Common/test/test_catch2_MultiSpan.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +#include "DataFormats/Common/interface/MultiSpan.h" + +TEST_CASE("MultiSpan basic indexing", "[MultiSpan]") { + edm::MultiSpan emptyMultiSpan; + edm::MultiSpan ms; + + std::vector a = {1, 2, 3}; + std::vector b = {4, 5}; + + ms.add(a); + ms.add(b); + + using ElementType = decltype(ms[0]); + // Check that the const-correctness of the MultiSpan + static_assert(!std::is_assignable::value, + "It should not be possible to assign to an element of MultiSpan; See PR #48826"); + + SECTION("Empty MultiSpan") { + REQUIRE(emptyMultiSpan.size() == 0); + REQUIRE(emptyMultiSpan.begin() == emptyMultiSpan.end()); + REQUIRE_THROWS_AS(emptyMultiSpan[0], std::out_of_range); + REQUIRE_THROWS_AS(emptyMultiSpan.globalIndex(0, 0), std::out_of_range); + } + + SECTION("Size is correct") { REQUIRE(ms.size() == 5); } + + SECTION("Range check") { + REQUIRE_THROWS_AS(ms[5], std::out_of_range); + REQUIRE_THROWS_AS(ms.globalIndex(2, 0), std::out_of_range); + REQUIRE_THROWS_AS(ms.globalIndex(1, 2), std::out_of_range); + REQUIRE_THROWS_AS(ms.spanAndLocalIndex(5), std::out_of_range); + } + + SECTION("Indexing returns correct values") { + REQUIRE(ms[0] == 1); + REQUIRE(ms[1] == 2); + REQUIRE(ms[2] == 3); + REQUIRE(ms[3] == 4); + REQUIRE(ms[4] == 5); + } + + SECTION("Global index from span index and local index") { + REQUIRE(ms.globalIndex(0, 0) == 0); + REQUIRE(ms.globalIndex(0, 2) == 2); + REQUIRE(ms.globalIndex(1, 0) == 3); + REQUIRE(ms.globalIndex(1, 1) == 4); + } + + SECTION("Span and local index from global index") { + auto [span0, local0] = ms.spanAndLocalIndex(0); + REQUIRE(span0 == 0); + REQUIRE(local0 == 0); + + auto [span1, local1] = ms.spanAndLocalIndex(4); + REQUIRE(span1 == 1); + REQUIRE(local1 == 1); + } + + SECTION("Iterators work with range-based for") { + std::vector collected; + for (auto val : ms) { + collected.push_back(val); + } + REQUIRE(collected == std::vector{1, 2, 3, 4, 5}); + } + + SECTION("Random access iterator supports arithmetic") { + auto it = ms.begin(); + REQUIRE(*(it + 2) == 3); + REQUIRE(*(ms.end() - 2) == 4); + REQUIRE((ms.end() - ms.begin()) == 5); + } + + SECTION("std::find works") { + auto it = std::find(ms.begin(), ms.end(), 4); + REQUIRE(it != ms.end()); + REQUIRE(*it == 4); + REQUIRE((it - ms.begin()) == 3); + } + + SECTION("std::distance returns correct result") { + auto dist = std::distance(ms.begin(), ms.end()); + REQUIRE(dist == 5); + } + + SECTION("std::copy copies all values") { + std::vector out(5); + std::copy(ms.begin(), ms.end(), out.begin()); + + REQUIRE(ms[0] == out[0]); + REQUIRE(ms[1] == out[1]); + REQUIRE(ms[2] == out[2]); + REQUIRE(ms[3] == out[3]); + REQUIRE(ms[4] == out[4]); + } +} diff --git a/DataFormats/HGCalReco/interface/MultiVectorManager.h b/DataFormats/HGCalReco/interface/MultiVectorManager.h deleted file mode 100644 index d434ea1f48ba3..0000000000000 --- a/DataFormats/HGCalReco/interface/MultiVectorManager.h +++ /dev/null @@ -1,85 +0,0 @@ -// Author: Felice Pantaleo (CERN), 2023, felice.pantaleo@cern.ch -#ifndef DataFormats_HGCalReco_MultiVectorManager_h -#define DataFormats_HGCalReco_MultiVectorManager_h - -#include -#include -#include -#include - -template -class MultiVectorManager { -public: - void addVector(std::span vec) { - vectors.emplace_back(vec); - offsets.push_back(totalSize); - totalSize += vec.size(); - } - - T& operator[](size_t globalIndex) { - return const_cast(static_cast(this)->operator[](globalIndex)); - } - - const T& operator[](size_t globalIndex) const { - assert(globalIndex < totalSize && "Global index out of range"); - - auto it = std::upper_bound(offsets.begin(), offsets.end(), globalIndex); - size_t vectorIndex = std::distance(offsets.begin(), it) - 1; - size_t localIndex = globalIndex - offsets[vectorIndex]; - - return vectors[vectorIndex][localIndex]; - } - - size_t getGlobalIndex(size_t vectorIndex, size_t localIndex) const { - assert(vectorIndex < vectors.size() && "Vector index out of range"); - - const auto& vec = vectors[vectorIndex]; - assert(localIndex < vec.size() && "Local index out of range"); - - return offsets[vectorIndex] + localIndex; - } - - std::pair getVectorAndLocalIndex(size_t globalIndex) const { - assert(globalIndex < totalSize && "Global index out of range"); - - auto it = std::upper_bound(offsets.begin(), offsets.end(), globalIndex); - size_t vectorIndex = std::distance(offsets.begin(), it) - 1; - size_t localIndex = globalIndex - offsets[vectorIndex]; - - return {vectorIndex, localIndex}; - } - - size_t size() const { return totalSize; } - - class Iterator { - public: - using iterator_category = std::forward_iterator_tag; - using difference_type = std::ptrdiff_t; - using value_type = T; - using pointer = T*; - using reference = T&; - - Iterator(const MultiVectorManager& manager, size_t index) : manager(manager), currentIndex(index) {} - - bool operator!=(const Iterator& other) const { return currentIndex != other.currentIndex; } - - T& operator*() const { return const_cast(manager[currentIndex]); } - - void operator++() { ++currentIndex; } - - private: - const MultiVectorManager& manager; - size_t currentIndex; - }; - - Iterator begin() const { return Iterator(*this, 0); } - - Iterator end() const { return Iterator(*this, totalSize); } - -private: - std::vector> vectors; - std::vector offsets; - size_t totalSize = 0; -}; - -#endif diff --git a/DataFormats/HGCalReco/interface/Trackster.h b/DataFormats/HGCalReco/interface/Trackster.h index d9b927d0a6b13..f5dd825d9ec7a 100644 --- a/DataFormats/HGCalReco/interface/Trackster.h +++ b/DataFormats/HGCalReco/interface/Trackster.h @@ -9,7 +9,7 @@ #include "DataFormats/Provenance/interface/ProductID.h" #include "DataFormats/Math/interface/Vector3D.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include @@ -117,7 +117,7 @@ namespace ticl { calculateRawEmPt(); } template - inline void mergeTracksters(const MultiVectorManager &allTracksters, const std::vector &others) { + inline void mergeTracksters(const edm::MultiSpan &allTracksters, const std::vector &others) { for (auto &other : others) { *this += allTracksters[other]; } diff --git a/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h b/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h index 18c6773ad81dc..3c6a830561203 100644 --- a/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h +++ b/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h @@ -22,7 +22,7 @@ #include "DataFormats/HGCalReco/interface/Common.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" namespace edm { class Event; @@ -40,7 +40,7 @@ namespace ticl { const edm::EventSetup& es; const std::vector& layerClusters; const edm::ValueMap>& layerClustersTime; - const MultiVectorManager& tracksters; + const edm::MultiSpan& tracksters; const std::vector>& linkedResultTracksters; const edm::Handle> tracksHandle; const std::vector& maskedTracks; @@ -49,7 +49,7 @@ namespace ticl { const edm::EventSetup& eS, const std::vector& lC, const edm::ValueMap>& lcT, - const MultiVectorManager& tS, + const edm::MultiSpan& tS, const std::vector>& links, const edm::Handle> trks, const std::vector& mT) diff --git a/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h b/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h index 16468318d2d2e..fd5e399aa8aa3 100644 --- a/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h +++ b/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h @@ -19,7 +19,7 @@ #include "DataFormats/HGCalReco/interface/Common.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "TrackingTools/GeomPropagators/interface/Propagator.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" @@ -53,13 +53,13 @@ namespace ticl { const edm::EventSetup& es; const std::vector& layerClusters; const edm::ValueMap>& layerClustersTime; - const MultiVectorManager& tracksters; + const edm::MultiSpan& tracksters; Inputs(const edm::Event& eV, const edm::EventSetup& eS, const std::vector& lC, const edm::ValueMap>& lT, - const MultiVectorManager& tS) + const edm::MultiSpan& tS) : ev(eV), es(eS), layerClusters(lC), layerClustersTime(lT), tracksters(tS) {} }; diff --git a/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.cc b/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.cc index 994494cac337d..b64a8742614d9 100644 --- a/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.cc +++ b/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.cc @@ -83,7 +83,7 @@ Vector GeneralInterpretationAlgo::propagateTrackster(const Trackster &t, return tPoint; } -void GeneralInterpretationAlgo::findTrackstersInWindow(const MultiVectorManager &tracksters, +void GeneralInterpretationAlgo::findTrackstersInWindow(const edm::MultiSpan &tracksters, const std::vector> &seedingCollection, const std::array &tracksterTiles, const std::vector &tracksterPropPoints, diff --git a/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.h b/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.h index f5346d4a35e79..c64d3efcfd08c 100644 --- a/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.h +++ b/RecoHGCal/TICL/plugins/GeneralInterpretationAlgo.h @@ -37,7 +37,7 @@ namespace ticl { float zVal, std::array &tracksterTiles); - void findTrackstersInWindow(const MultiVectorManager &tracksters, + void findTrackstersInWindow(const edm::MultiSpan &tracksters, const std::vector> &seedingCollection, const std::array &tracksterTiles, const std::vector &tracksterPropPoints, diff --git a/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc b/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc index 7a49e9a67f9e9..1155fda9c75ee 100644 --- a/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc +++ b/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc @@ -1,6 +1,6 @@ // Author: Felice Pantaleo, Wahid Redjeb, Aurora Perego (CERN) - felice.pantaleo@cern.ch, wahid.redjeb@cern.ch, aurora.perego@cern.ch Date: 12/2023 #include // unique_ptr -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" @@ -280,11 +280,11 @@ void TICLCandidateProducer::produce(edm::Event &evt, const edm::EventSetup &es) auto resultMask = std::make_unique>(original_global_mask); std::vector>> general_tracksters_h(general_tracksters_tokens_.size()); - MultiVectorManager generalTrackstersManager; + edm::MultiSpan generalTrackstersSpan; for (unsigned int i = 0; i < general_tracksters_tokens_.size(); ++i) { evt.getByToken(general_tracksters_tokens_[i], general_tracksters_h[i]); - //Fill MultiVectorManager - generalTrackstersManager.addVector(*general_tracksters_h[i]); + //Fill MultiSpan + generalTrackstersSpan.add(*general_tracksters_h[i]); } //now get the general_tracksterlinks_tokens_ std::vector>>> general_tracksterlinks_h( @@ -297,7 +297,7 @@ void TICLCandidateProducer::produce(edm::Event &evt, const edm::EventSetup &es) auto &links_vector = generalTracksterLinksGlobalId.back(); links_vector.resize((*general_tracksterlinks_h[i])[j].size()); for (unsigned int k = 0; k < links_vector.size(); ++k) { - links_vector[k] = generalTrackstersManager.getGlobalIndex(i, (*general_tracksterlinks_h[i])[j][k]); + links_vector[k] = generalTrackstersSpan.globalIndex(i, (*general_tracksterlinks_h[i])[j][k]); } } } @@ -310,7 +310,7 @@ void TICLCandidateProducer::produce(edm::Event &evt, const edm::EventSetup &es) es, layerClusters, layerClustersTimes, - generalTrackstersManager, + generalTrackstersSpan, generalTracksterLinksGlobalId, tracks_h, maskTracks); diff --git a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc index 24fac33f2ca92..cedb67b7a324c 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc @@ -1,7 +1,7 @@ // Author: Felice Pantaleo, Wahid Redjeb (CERN) - felice.pantaleo@cern.ch, wahid.redjeb@cern.ch // Date: 12/2023 #include // unique_ptr -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" @@ -203,11 +203,11 @@ void TracksterLinksProducer::produce(edm::Event &evt, const edm::EventSetup &es) auto resultMask = std::make_unique>(original_global_mask); std::vector>> tracksters_h(tracksters_tokens_.size()); - MultiVectorManager trackstersManager; + edm::MultiSpan trackstersManager; for (unsigned int i = 0; i < tracksters_tokens_.size(); ++i) { evt.getByToken(tracksters_tokens_[i], tracksters_h[i]); - //Fill MultiVectorManager - trackstersManager.addVector(*tracksters_h[i]); + //Fill MultiSpan + trackstersManager.add(*tracksters_h[i]); } // Linking diff --git a/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h b/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h index 041505e60934a..6597e2a5ac365 100644 --- a/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h +++ b/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h @@ -9,7 +9,7 @@ #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" @@ -67,7 +67,7 @@ namespace hgcal { const HGCRecHitCollection *eerh_, *fhrh_, *bhrh_; const std::unordered_map *hitMap_; - std::unique_ptr> rechitManager_; + std::unique_ptr> rechitSpan_; }; } // namespace hgcal diff --git a/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc b/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc index fffe3696e7c59..3865853304215 100644 --- a/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc +++ b/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc @@ -31,10 +31,10 @@ void ClusterTools::getEvent(const edm::Event& ev) { fhrh_ = &ev.get(fhtok); bhrh_ = &ev.get(bhtok); hitMap_ = &ev.get(hitMapToken_); - rechitManager_ = std::make_unique>(); - rechitManager_->addVector(*eerh_); - rechitManager_->addVector(*fhrh_); - rechitManager_->addVector(*bhrh_); + rechitSpan_ = std::make_unique>(); + rechitSpan_->add(*eerh_); + rechitSpan_->add(*fhrh_); + rechitSpan_->add(*bhrh_); } void ClusterTools::getEventSetup(const edm::EventSetup& es) { rhtools_.setGeometry(es.getData(caloGeometryToken_)); } @@ -42,7 +42,7 @@ void ClusterTools::getEventSetup(const edm::EventSetup& es) { rhtools_.setGeomet float ClusterTools::getClusterHadronFraction(const reco::CaloCluster& clus) const { float energy = 0.f, energyHad = 0.f; const auto& hits = clus.hitsAndFractions(); - const auto& rhmanager = *rechitManager_; + const auto& rhspan = *rechitSpan_; for (const auto& hit : hits) { const auto& id = hit.first; const float fraction = hit.second; @@ -51,7 +51,7 @@ float ClusterTools::getClusterHadronFraction(const reco::CaloCluster& clus) cons continue; } unsigned int rechitIndex = hitIter->second; - float hitEnergy = rhmanager[rechitIndex].energy() * fraction; + float hitEnergy = rhspan[rechitIndex].energy() * fraction; energy += hitEnergy; if (id.det() == DetId::HGCalHSi || id.det() == DetId::HGCalHSc || (id.det() == DetId::Forward && id.subdetId() == HGCHEF) || @@ -122,7 +122,7 @@ bool ClusterTools::getWidths(const reco::CaloCluster& clus, double sumw = 0.; double sumlogw = 0.; - const auto& rhmanager = *rechitManager_; + const auto& rhspan = *rechitSpan_; for (unsigned int ih = 0; ih < nhit; ++ih) { const DetId& id = (clus.hitsAndFractions())[ih].first; @@ -135,7 +135,7 @@ bool ClusterTools::getWidths(const reco::CaloCluster& clus, continue; } unsigned int rechitIndex = hitIter->second; - float hitEnergy = rhmanager[rechitIndex].energy(); + float hitEnergy = rhspan[rechitIndex].energy(); GlobalPoint cellPos = rhtools_.getPosition(id); double weight = hitEnergy; diff --git a/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc b/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc index c9480adb95883..741d1614bc508 100644 --- a/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc +++ b/RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc @@ -13,7 +13,7 @@ #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" class RecHitMapProducer : public edm::global::EDProducer<> { public: @@ -75,13 +75,13 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event // TODO may be worth to avoid dependency on the order // of the collections, maybe using a map - MultiVectorManager rechitManager; - rechitManager.addVector(*ee_hits); - rechitManager.addVector(*fh_hits); - rechitManager.addVector(*bh_hits); + edm::MultiSpan rechitSpan; + rechitSpan.add(*ee_hits); + rechitSpan.add(*fh_hits); + rechitSpan.add(*bh_hits); - for (unsigned int i = 0; i < rechitManager.size(); ++i) { - const auto recHitDetId = rechitManager[i].detid(); + for (unsigned int i = 0; i < rechitSpan.size(); ++i) { + const auto recHitDetId = rechitSpan[i].detid(); hitMapHGCal->emplace(recHitDetId, i); } @@ -89,11 +89,11 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event if (!hgcalOnly_) { auto hitMapBarrel = std::make_unique(); - MultiVectorManager barrelRechitManager; - barrelRechitManager.addVector(evt.get(barrel_hits_token_[0])); - barrelRechitManager.addVector(evt.get(barrel_hits_token_[1])); - for (unsigned int i = 0; i < barrelRechitManager.size(); ++i) { - const auto recHitDetId = barrelRechitManager[i].detId(); + edm::MultiSpan barrelRechitSpan; + barrelRechitSpan.add(evt.get(barrel_hits_token_[0])); + barrelRechitSpan.add(evt.get(barrel_hits_token_[1])); + for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) { + const auto recHitDetId = barrelRechitSpan[i].detId(); hitMapBarrel->emplace(recHitDetId, i); } evt.put(std::move(hitMapBarrel), "barrelRecHitMap"); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc index 79bd14cf4444e..909d2579843a6 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc @@ -10,7 +10,7 @@ #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" class AllHitToTracksterAssociatorsProducer : public edm::global::EDProducer<> { public: @@ -65,7 +65,7 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE Handle> hitMap; iEvent.getByToken(hitMapToken_, hitMap); - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; for (const auto& token : hitsTokens_) { Handle hitsHandle; iEvent.getByToken(token, hitsHandle); @@ -76,11 +76,11 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE << "Missing HGCRecHitCollection for one of the hitsTokens."; continue; } - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } - // Check if rechitManager is empty - if (rechitManager.size() == 0) { + // Check if rechitSpan is empty + if (rechitSpan.size() == 0) { edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") << "No valid HGCRecHitCollections found. Association maps will be empty."; for (const auto& tracksterToken : tracksterCollectionTokens_) { @@ -101,7 +101,7 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE continue; } - auto hitToTracksterMap = std::make_unique>(rechitManager.size()); + auto hitToTracksterMap = std::make_unique>(rechitSpan.size()); auto tracksterToHitMap = std::make_unique>(tracksters->size()); for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) { diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc index 43a2d2b33869d..5656661fe70c0 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc @@ -10,7 +10,7 @@ #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/Provenance/interface/ProductID.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" @@ -104,7 +104,7 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, const edm::EventSetup&) const { using namespace edm; - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; for (const auto& token : hitsTokens_) { Handle hitsHandle; iEvent.getByToken(token, hitsHandle); @@ -114,11 +114,11 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, << "Missing HGCRecHitCollection for one of the hitsTokens."; continue; } - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } - // Check if rechitManager is empty - if (rechitManager.size() == 0) { + // Check if rechitSpan is empty + if (rechitSpan.size() == 0) { edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") << "No valid HGCRecHitCollections found. Association maps will be empty."; @@ -267,7 +267,7 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, const auto& hitElement = recoTracksterHitsAndFractions[i]; unsigned int hitIndex = hitElement.index(); float recoFraction = hitElement.fraction(); - const auto& recHit = rechitManager[hitIndex]; + const auto& recHit = rechitSpan[hitIndex]; float squaredRecoFraction = recoFraction * recoFraction; float rechitEnergy = recHit.energy(); float squaredRecHitEnergy = rechitEnergy * rechitEnergy; @@ -325,7 +325,7 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) { unsigned int hitIndex = recoTracksterHitsAndFractions[i].index(); - const auto& recHit = rechitManager[hitIndex]; + const auto& recHit = rechitSpan[hitIndex]; float recoFraction = recoTracksterHitsAndFractions[i].fraction(); float rechitEnergy = recHit.energy(); float squaredRecHitEnergy = rechitEnergy * rechitEnergy; @@ -377,7 +377,7 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, simFractions[i] = it->fraction(); } float simFraction = simFractions[i]; - const auto& recHit = rechitManager[hitIndex]; + const auto& recHit = rechitSpan[hitIndex]; float rechitEnergy = recHit.energy(); float squaredSimFraction = simFraction * simFraction; float squaredRecHitEnergy = rechitEnergy * rechitEnergy; @@ -414,7 +414,7 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) { const auto& hitIndex = simTracksterHitsAndFractions[i].index(); float simFraction = simFractions[i]; - const auto& recHit = rechitManager[hitIndex]; + const auto& recHit = rechitSpan[hitIndex]; float rechitEnergy = recHit.energy(); float squaredRecHitEnergy = rechitEnergy * rechitEnergy; float simSharedEnergy = rechitEnergy * simFraction; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.cc index 98c2c8c06e507..28276db3bec72 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.cc @@ -11,7 +11,7 @@ #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" HitToLayerClusterAssociatorProducer::HitToLayerClusterAssociatorProducer(const edm::ParameterSet &pset) : LCCollectionToken_(consumes>(pset.getParameter("layer_clusters"))), @@ -36,15 +36,15 @@ void HitToLayerClusterAssociatorProducer::produce(edm::StreamID, Handle> hitMap; iEvent.getByToken(hitMapToken_, hitMap); - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; for (const auto &token : hitsTokens_) { Handle hitsHandle; iEvent.getByToken(token, hitsHandle); - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } // Create association map - auto hitToLayerClusterMap = std::make_unique>(rechitManager.size()); + auto hitToLayerClusterMap = std::make_unique>(rechitSpan.size()); // Loop over layer clusters for (unsigned int lcId = 0; lcId < layer_clusters->size(); ++lcId) { diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.h index 0de840901986d..c90f181f5012b 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.h +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToLayerClusterAssociatorProducer.h @@ -18,7 +18,7 @@ #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" class HitToLayerClusterAssociatorProducer : public edm::global::EDProducer<> { public: diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc index 8d83db9036d07..3b26c6b5c8ad1 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc @@ -11,7 +11,7 @@ #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/Provenance/interface/ProductID.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" @@ -42,7 +42,7 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, Handle> hitMap; iEvent.getByToken(hitMapToken_, hitMap); - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; // Loop over tokens with index to access corresponding InputTag for (size_t i = 0; i < hitsTokens_.size(); ++i) { const auto &token = hitsTokens_[i]; @@ -55,11 +55,11 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, << "Missing HGCRecHitCollection for tag: " << hitsTags_[i].encode(); continue; } - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } - // Check if rechitManager is empty after processing hitsTokens_ - if (rechitManager.size() == 0) { + // Check if rechitSpan is empty after processing hitsTokens_ + if (rechitSpan.size() == 0) { edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") << "No valid HGCRecHitCollections found. Association maps will be empty."; // Store empty maps in the event @@ -69,8 +69,8 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, } // Create association maps - auto hitToSimClusterMap = std::make_unique>(rechitManager.size()); - auto hitToCaloParticleMap = std::make_unique>(rechitManager.size()); + auto hitToSimClusterMap = std::make_unique>(rechitSpan.size()); + auto hitToCaloParticleMap = std::make_unique>(rechitSpan.size()); // Loop over caloParticles for (unsigned int cpId = 0; cpId < caloParticles.size(); ++cpId) { diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.h index 533dc44f929fc..213006f44aaf1 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.h +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.h @@ -16,7 +16,7 @@ #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/Provenance/interface/ProductID.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.cc index 5c422348cd9cd..d65dec5918e2d 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.cc @@ -13,7 +13,7 @@ #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/Provenance/interface/ProductID.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" HitToTracksterAssociatorProducer::HitToTracksterAssociatorProducer(const edm::ParameterSet &pset) : LCCollectionToken_(consumes>(pset.getParameter("layer_clusters"))), @@ -42,15 +42,15 @@ void HitToTracksterAssociatorProducer::produce(edm::StreamID, edm::Event &iEvent Handle> hitMap; iEvent.getByToken(hitMapToken_, hitMap); - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; for (const auto &token : hitsTokens_) { Handle hitsHandle; iEvent.getByToken(token, hitsHandle); - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } // Create association map - auto hitToTracksterMap = std::make_unique>(rechitManager.size()); + auto hitToTracksterMap = std::make_unique>(rechitSpan.size()); auto tracksterToHitMap = std::make_unique>(tracksters->size()); // Loop over tracksters diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.h index b0529134ea9e5..0c0f072bd9d65 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.h +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToTracksterAssociatorProducer.h @@ -15,7 +15,7 @@ #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" #include "DataFormats/Provenance/interface/ProductID.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" class HitToTracksterAssociatorProducer : public edm::global::EDProducer<> { diff --git a/Validation/HGCalValidation/interface/BarrelVHistoProducerAlgo.h b/Validation/HGCalValidation/interface/BarrelVHistoProducerAlgo.h index 48039365c34a8..59b59d6b6be3a 100644 --- a/Validation/HGCalValidation/interface/BarrelVHistoProducerAlgo.h +++ b/Validation/HGCalValidation/interface/BarrelVHistoProducerAlgo.h @@ -23,7 +23,7 @@ #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/Vertex/interface/SimVertex.h" @@ -238,7 +238,7 @@ class BarrelVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollection& recSimColl, const ticl::SimToRecoCollection& simRecColl, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; void layerClusters_to_SimClusters(const Histograms& histograms, const int count, edm::Handle clusterHandle, @@ -251,7 +251,7 @@ class BarrelVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& recSimColl, const ticl::SimToRecoCollectionWithSimClusters& simRecColl, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; void tracksters_to_SimTracksters_fp(const Histograms& histograms, const int count, @@ -270,7 +270,7 @@ class BarrelVHistoProducerAlgo { std::vector const& simVertices, unsigned int layers, std::unordered_map const&, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; void fill_generic_cluster_histos(const Histograms& histograms, const int count, edm::Handle clusterHandle, @@ -283,7 +283,7 @@ class BarrelVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollection& recSimColl, const ticl::SimToRecoCollection& simRecColl, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; void fill_simCluster_histos(const Histograms& histograms, std::vector const& simClusters, unsigned int layers) const; @@ -299,7 +299,7 @@ class BarrelVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& recSimColl, const ticl::SimToRecoCollectionWithSimClusters& simRecColl, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; void fill_cluster_histos(const Histograms& histograms, const int count, const reco::CaloCluster& cluster) const; double distance2(const double x1, const double y1, const double x2, const double y2) const; @@ -309,7 +309,7 @@ class BarrelVHistoProducerAlgo { DetId findmaxhit(const reco::CaloCluster& cluster, std::unordered_map const&, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; struct detIdInfoInCluster { bool operator==(const detIdInfoInCluster& o) const { return clusterId == o.clusterId; }; diff --git a/Validation/HGCalValidation/interface/BarrelValidator.h b/Validation/HGCalValidation/interface/BarrelValidator.h index 3424d3c1d5947..8617539151c56 100644 --- a/Validation/HGCalValidation/interface/BarrelValidator.h +++ b/Validation/HGCalValidation/interface/BarrelValidator.h @@ -32,7 +32,7 @@ #include "SimDataFormats/Associations/interface/LayerClusterToSimClusterAssociator.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" class PileupSummaryInfo; @@ -66,7 +66,7 @@ class BarrelValidator : public DQMGlobalEDAnalyzer { std::vector& selected_cPeff, unsigned int layers, std::unordered_map const&, - MultiVectorManager const& barrelHits) const; + edm::MultiSpan const& barrelHits) const; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); diff --git a/Validation/HGCalValidation/interface/HGCalValidator.h b/Validation/HGCalValidation/interface/HGCalValidator.h index 6d9fc41877ed4..b1412490bfe02 100644 --- a/Validation/HGCalValidation/interface/HGCalValidator.h +++ b/Validation/HGCalValidation/interface/HGCalValidator.h @@ -32,7 +32,7 @@ #include "SimDataFormats/Associations/interface/LayerClusterToSimClusterAssociator.h" #include "SimDataFormats/Associations/interface/TICLAssociationMap.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" class PileupSummaryInfo; @@ -67,7 +67,7 @@ class HGCalValidator : public DQMGlobalEDAnalyzer { std::vector& selected_cPeff, unsigned int layers, std::unordered_map const&, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); diff --git a/Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h b/Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h index d129580d18c04..6798662c884e7 100644 --- a/Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h +++ b/Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h @@ -22,7 +22,7 @@ #include "DataFormats/HGCalReco/interface/Trackster.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "DataFormats/HGCalReco/interface/MultiVectorManager.h" +#include "DataFormats/Common/interface/MultiSpan.h" #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" #include "SimDataFormats/Vertex/interface/SimVertex.h" @@ -282,7 +282,7 @@ class HGVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollection& recSimColl, const ticl::SimToRecoCollection& simRecColl, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; void layerClusters_to_SimClusters(const Histograms& histograms, const int count, edm::Handle clusterHandle, @@ -295,7 +295,7 @@ class HGVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& recSimColl, const ticl::SimToRecoCollectionWithSimClusters& simRecColl, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; void tracksters_to_SimTracksters_fp(const Histograms& histograms, const int count, @@ -314,7 +314,7 @@ class HGVHistoProducerAlgo { std::vector const& simVertices, unsigned int layers, std::unordered_map const&, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; void fill_generic_cluster_histos(const Histograms& histograms, const int count, edm::Handle clusterHandle, @@ -329,7 +329,7 @@ class HGVHistoProducerAlgo { std::vector thicknesses, const ticl::RecoToSimCollection& recSimColl, const ticl::SimToRecoCollection& simRecColl, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; void fill_simCluster_histos(const Histograms& histograms, std::vector const& simClusters, unsigned int layers, @@ -346,7 +346,7 @@ class HGVHistoProducerAlgo { unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& recSimColl, const ticl::SimToRecoCollectionWithSimClusters& simRecColl, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; void fill_cluster_histos(const Histograms& histograms, const int count, const reco::CaloCluster& cluster) const; void fill_trackster_histos(const Histograms& histograms, const int count, @@ -362,7 +362,7 @@ class HGVHistoProducerAlgo { std::vector const& cPSelectedIndices, std::unordered_map const& hitMap, unsigned int layers, - MultiVectorManager const& hits, + edm::MultiSpan const& hits, bool mapsFound, const edm::Handle& trackstersToSimTrackstersByLCsMapH, const edm::Handle& simTrackstersToTrackstersByLCsMapH, @@ -380,7 +380,7 @@ class HGVHistoProducerAlgo { DetId findmaxhit(const reco::CaloCluster& cluster, std::unordered_map const&, - MultiVectorManager const& hits) const; + edm::MultiSpan const& hits) const; struct detIdInfoInCluster { bool operator==(const detIdInfoInCluster& o) const { return clusterId == o.clusterId; }; diff --git a/Validation/HGCalValidation/plugins/BarrelValidator.cc b/Validation/HGCalValidation/plugins/BarrelValidator.cc index f60df6c27c288..3db3692681886 100644 --- a/Validation/HGCalValidation/plugins/BarrelValidator.cc +++ b/Validation/HGCalValidation/plugins/BarrelValidator.cc @@ -221,7 +221,7 @@ void BarrelValidator::cpParametersAndSelection(const Histograms& histograms, std::vector& selected_cPeff, unsigned int layers, std::unordered_map const& barrelHitMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { selected_cPeff.reserve(cPeff.size()); size_t j = 0; @@ -278,11 +278,11 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, event.getByToken(barrelHitMap_, barrelHitMapHandle); const std::unordered_map& barrelHitMap = *barrelHitMapHandle; - MultiVectorManager barrelRechitManager; + edm::MultiSpan barrelRechitSpan; for (const auto& token : barrel_hits_tokens_) { Handle> hitsHandle; event.getByToken(token, hitsHandle); - barrelRechitManager.addVector(*hitsHandle); + barrelRechitSpan.add(*hitsHandle); } //Some general info on layers etc. @@ -301,13 +301,8 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, // HGCRecHit are given to select the SimHits which are also reconstructed LogTrace("BarrelValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl; std::vector selected_cPeff; - cpParametersAndSelection(histograms, - caloParticles, - simVertices, - selected_cPeff, - totallayers_to_monitor_, - barrelHitMap, - barrelRechitManager); + cpParametersAndSelection( + histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, barrelHitMap, barrelRechitSpan); //get collections from the event //simClusters @@ -368,7 +363,7 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, totallayers_to_monitor_, recSimColl[0], simRecColl[0], - barrelRechitManager); + barrelRechitSpan); //General Info on simClusters LogTrace("BarrelValidator") << "\n# of SimClusters: " << nSimClusters @@ -393,7 +388,7 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, totallayers_to_monitor_, recSimColl[0], simRecColl[0], - barrelRechitManager); + barrelRechitSpan); for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) { histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]); diff --git a/Validation/HGCalValidation/plugins/HGCalValidator.cc b/Validation/HGCalValidation/plugins/HGCalValidator.cc index 1a328fd250f1e..d4896b27bcdc0 100644 --- a/Validation/HGCalValidation/plugins/HGCalValidator.cc +++ b/Validation/HGCalValidation/plugins/HGCalValidator.cc @@ -343,7 +343,7 @@ void HGCalValidator::cpParametersAndSelection(const Histograms& histograms, std::vector& selected_cPeff, unsigned int layers, std::unordered_map const& hitMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { selected_cPeff.reserve(cPeff.size()); size_t j = 0; @@ -416,13 +416,13 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, event.getByToken(hitMap_, hitMapHandle); const std::unordered_map& hitMap = *hitMapHandle; - MultiVectorManager rechitManager; + edm::MultiSpan rechitSpan; for (const auto& token : hits_tokens_) { Handle hitsHandle; event.getByToken(token, hitsHandle); if (!hitsHandle.isValid()) continue; - rechitManager.addVector(*hitsHandle); + rechitSpan.add(*hitsHandle); } //Some general info on layers etc. @@ -442,7 +442,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl; std::vector selected_cPeff; cpParametersAndSelection( - histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, hitMap, rechitManager); + histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, hitMap, rechitSpan); //get collections from the event //simClusters @@ -529,7 +529,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, totallayers_to_monitor_, recSimColl, simRecColl, - rechitManager); + rechitSpan); //General Info on simClusters LogTrace("HGCalValidator") << "\n# of SimClusters: " << nSimClusters @@ -556,7 +556,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, thicknesses_to_monitor_, recSimColl, simRecColl, - rechitManager); + rechitSpan); for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) { histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]); @@ -618,7 +618,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, selected_cPeff, hitMap, totallayers_to_monitor_, - rechitManager, + rechitSpan, mapsFound, trackstersToSimTrackstersMapH, simTrackstersToTrackstersMapH, diff --git a/Validation/HGCalValidation/src/BarrelVHistoProducerAlgo.cc b/Validation/HGCalValidation/src/BarrelVHistoProducerAlgo.cc index 6f7b18e34cee2..2b01b8fff9504 100644 --- a/Validation/HGCalValidation/src/BarrelVHistoProducerAlgo.cc +++ b/Validation/HGCalValidation/src/BarrelVHistoProducerAlgo.cc @@ -663,7 +663,7 @@ void BarrelVHistoProducerAlgo::fill_caloparticle_histos( std::vector const& simVertices, unsigned int layers, std::unordered_map const& barrelHitMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { const auto eta = getEta(caloParticle.eta()); if (histograms.h_caloparticle_eta.count(pdgid)) { histograms.h_caloparticle_eta.at(pdgid)->Fill(eta); @@ -833,7 +833,7 @@ void BarrelVHistoProducerAlgo::BarrelVHistoProducerAlgo::fill_simClusterAssociat unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap, const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { //Each event to be treated as two events: an event in +ve endcap, //plus another event in -ve endcap. In this spirit there will be //a layer variable (layerid) that maps the layers in : @@ -878,7 +878,7 @@ void BarrelVHistoProducerAlgo::layerClusters_to_CaloParticles( unsigned int layers, const ticl::RecoToSimCollection& cpsInLayerClusterMap, const ticl::SimToRecoCollection& cPOnLayerMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { const auto nLayerClusters = clusters.size(); std::unordered_map> detIdToCaloParticleId_Map; @@ -1153,7 +1153,7 @@ void BarrelVHistoProducerAlgo::layerClusters_to_SimClusters( unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap, const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { // Here fill the plots to compute the different metrics linked to // reco-level, namely fake-rate and merge-rate. In this loop should *not* // restrict only to the selected SimClusters. @@ -1341,7 +1341,7 @@ void BarrelVHistoProducerAlgo::fill_generic_cluster_histos( unsigned int layers, const ticl::RecoToSimCollection& cpsInLayerClusterMap, const ticl::SimToRecoCollection& cPOnLayerMap, - MultiVectorManager const& barrelHits) const { + edm::MultiSpan const& barrelHits) const { //To keep track of total num of layer clusters per layer //tnlcpl[layerid] std::vector tnlcpl(1000, 0); //tnlcpl.clear(); tnlcpl.reserve(1000); @@ -1404,7 +1404,7 @@ void BarrelVHistoProducerAlgo::setRecHitTools(std::shared_ptr const& hitMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { const auto& hits_and_fractions = cluster.hitsAndFractions(); DetId themaxid; diff --git a/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc b/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc index 0a40557bca318..ee5a942b47cad 100644 --- a/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc +++ b/Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc @@ -1453,7 +1453,7 @@ void HGVHistoProducerAlgo::fill_caloparticle_histos(const Histograms& histograms std::vector const& simVertices, unsigned int layers, std::unordered_map const& hitMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { const auto eta = getEta(caloParticle.eta()); if (histograms.h_caloparticle_eta.count(pdgid)) { histograms.h_caloparticle_eta.at(pdgid)->Fill(eta); @@ -1719,7 +1719,7 @@ void HGVHistoProducerAlgo::HGVHistoProducerAlgo::fill_simClusterAssociation_hist unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap, const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { //Each event to be treated as two events: an event in +ve endcap, //plus another event in -ve endcap. In this spirit there will be //a layer variable (layerid) that maps the layers in : @@ -1761,7 +1761,7 @@ void HGVHistoProducerAlgo::layerClusters_to_CaloParticles(const Histograms& hist unsigned int layers, const ticl::RecoToSimCollection& cpsInLayerClusterMap, const ticl::SimToRecoCollection& cPOnLayerMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { const auto nLayerClusters = clusters.size(); std::unordered_map> detIdToCaloParticleId_Map; @@ -2034,7 +2034,7 @@ void HGVHistoProducerAlgo::layerClusters_to_SimClusters( unsigned int layers, const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap, const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { // Here fill the plots to compute the different metrics linked to // reco-level, namely fake-rate and merge-rate. In this loop should *not* // restrict only to the selected SimClusters. @@ -2221,7 +2221,7 @@ void HGVHistoProducerAlgo::fill_generic_cluster_histos(const Histograms& histogr std::vector thicknesses, const ticl::RecoToSimCollection& cpsInLayerClusterMap, const ticl::SimToRecoCollection& cPOnLayerMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { //Each event to be treated as two events: an event in +ve endcap, //plus another event in -ve endcap. In this spirit there will be //a layer variable (layerid) that maps the layers in : @@ -2708,7 +2708,7 @@ void HGVHistoProducerAlgo::fill_trackster_histos( std::vector const& cPSelectedIndices, std::unordered_map const& hitMap, unsigned int layers, - MultiVectorManager const& hits, + edm::MultiSpan const& hits, bool mapsFound, const edm::Handle& trackstersToSimTrackstersByLCsMapH, const edm::Handle& simTrackstersToTrackstersByLCsMapH, @@ -2959,7 +2959,7 @@ void HGVHistoProducerAlgo::setRecHitTools(std::shared_ptr re DetId HGVHistoProducerAlgo::findmaxhit(const reco::CaloCluster& cluster, std::unordered_map const& hitMap, - MultiVectorManager const& hits) const { + edm::MultiSpan const& hits) const { const auto& hits_and_fractions = cluster.hitsAndFractions(); DetId themaxid;