From 2950fe0b35083076d0d3fb0f9f73ce64454fe001 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 19 Dec 2024 17:33:47 -0800 Subject: [PATCH 1/4] use concrete type ThreeThresholdAlgorithm in ClusterFromRaw; keep benefiting from .cc inlines --- .../interface/ThreeThresholdAlgorithm.h | 8 ++---- .../plugins/ClustersFromRawProducer.cc | 25 +++++++++++++------ .../src/ThreeThresholdAlgorithm.cc | 13 ++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h index 2c4551ef40550..78fb892404dbf 100644 --- a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h +++ b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h @@ -16,13 +16,9 @@ class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm { void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, std::vector& out) const override; void stripByStripEnd(State& state, std::vector& out) const override; - void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, output_t::TSFastFiller& out) const override { - if (candidateEnded(state, strip)) - endCandidate(state, out); - addToCandidate(state, strip, adc); - } + void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, output_t::TSFastFiller& out) const override; - void stripByStripEnd(State& state, output_t::TSFastFiller& out) const override { endCandidate(state, out); } + void stripByStripEnd(State& state, output_t::TSFastFiller& out) const override; private: template diff --git a/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc b/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc index 8622f0c32a929..327b79744ff57 100644 --- a/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc +++ b/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc @@ -4,6 +4,7 @@ #include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingFactory.h" #include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithm.h" +#include "RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h" #include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingAlgorithms.h" #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" @@ -91,7 +92,7 @@ namespace { class ClusterFiller final : public StripClusterizerAlgorithm::output_t::Getter { public: ClusterFiller(const FEDRawDataCollection& irawColl, - StripClusterizerAlgorithm& iclusterizer, + const ThreeThresholdAlgorithm& iclusterizer, SiStripRawProcessingAlgorithms& irawAlgos, bool idoAPVEmulatorCheck, bool legacy, @@ -118,7 +119,7 @@ namespace { const FEDRawDataCollection& rawColl; - StripClusterizerAlgorithm& clusterizer; + const ThreeThresholdAlgorithm& clusterizer; const SiStripClusterizerConditions& conditions; SiStripRawProcessingAlgorithms& rawAlgos; @@ -194,8 +195,13 @@ class SiStripClusterizerFromRaw final : public edm::stream::EDProducer<> { std::unique_ptr > output( onDemand ? new edmNew::DetSetVector( - std::shared_ptr::Getter>(std::make_shared( - *rawData, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)), + std::shared_ptr::Getter>( + std::make_shared(*rawData, + dynamic_cast(*clusterizer_), + *rawAlgos_, + doAPVEmulatorCheck_, + legacy_, + hybridZeroSuppressed_)), clusterizer_->conditions().allDetIds()) : new edmNew::DetSetVector()); @@ -265,7 +271,12 @@ void SiStripClusterizerFromRaw::initialize(const edm::EventSetup& es) { } void SiStripClusterizerFromRaw::run(const FEDRawDataCollection& rawColl, edmNew::DetSetVector& output) { - ClusterFiller filler(rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_); + ClusterFiller filler(rawColl, + dynamic_cast(*clusterizer_), + *rawAlgos_, + doAPVEmulatorCheck_, + legacy_, + hybridZeroSuppressed_); // loop over good det in cabling for (auto idet : clusterizer_->conditions().allDetIds()) { @@ -287,7 +298,7 @@ namespace { typedef void pointer; typedef void reference; - StripByStripAdder(StripClusterizerAlgorithm& clusterizer, + StripByStripAdder(const ThreeThresholdAlgorithm& clusterizer, StripClusterizerAlgorithm::State& state, StripClusterizerAlgorithm::output_t::TSFastFiller& record) : clusterizer_(clusterizer), state_(state), record_(record) {} @@ -302,7 +313,7 @@ namespace { StripByStripAdder& operator++(int) { return *this; } private: - StripClusterizerAlgorithm& clusterizer_; + const ThreeThresholdAlgorithm& clusterizer_; StripClusterizerAlgorithm::State& state_; StripClusterizerAlgorithm::output_t::TSFastFiller& record_; }; diff --git a/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc b/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc index c2cf5b8962896..92e5af1e7f135 100644 --- a/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc +++ b/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc @@ -150,6 +150,19 @@ void ThreeThresholdAlgorithm::stripByStripAdd(State& state, addToCandidate(state, SiStripDigi(strip, adc)); } +void ThreeThresholdAlgorithm::stripByStripAdd(State& state, + uint16_t strip, + uint8_t adc, + output_t::TSFastFiller& out) const { + if (candidateEnded(state, strip)) + endCandidate(state, out); + addToCandidate(state, strip, adc); +} + void ThreeThresholdAlgorithm::stripByStripEnd(State& state, std::vector& out) const { endCandidate(state, out); } + +void ThreeThresholdAlgorithm::stripByStripEnd(State& state, output_t::TSFastFiller& out) const { + endCandidate(state, out); +} From 0cbff7f767f54a1819f4154bc1ee6f2bd4b4cc58 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 20 Dec 2024 10:35:45 -0800 Subject: [PATCH 2/4] use concrete type ThreeThresholdAlgorithm in ClusterFromRaw; move inlines to the .h --- .../interface/ThreeThresholdAlgorithm.h | 125 ++++++++++++++++- .../src/ThreeThresholdAlgorithm.cc | 127 ------------------ 2 files changed, 123 insertions(+), 129 deletions(-) diff --git a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h index 78fb892404dbf..2696b0da295b6 100644 --- a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h +++ b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h @@ -1,8 +1,16 @@ #ifndef RecoLocalTracker_SiStripClusterizer_ThreeThresholdAlgorithm_h #define RecoLocalTracker_SiStripClusterizer_ThreeThresholdAlgorithm_h + +#include "DataFormats/SiStripCluster/interface/SiStripCluster.h" +#include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h" +#include "DataFormats/SiStripDigi/interface/SiStripDigi.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithm.h" #include "RecoLocalTracker/SiStripClusterizer/interface/SiStripApvShotCleaner.h" +#include +#include + class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm { friend class StripClusterizerAlgorithmFactory; @@ -16,9 +24,13 @@ class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm { void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, std::vector& out) const override; void stripByStripEnd(State& state, std::vector& out) const override; - void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, output_t::TSFastFiller& out) const override; + void stripByStripAdd(State& state, uint16_t strip, uint8_t adc, output_t::TSFastFiller& out) const override { + if (candidateEnded(state, strip)) + endCandidate(state, out); + addToCandidate(state, strip, adc); + } - void stripByStripEnd(State& state, output_t::TSFastFiller& out) const override; + void stripByStripEnd(State& state, output_t::TSFastFiller& out) const override { endCandidate(state, out); } private: template @@ -60,4 +72,113 @@ class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm { float minGoodCharge; }; +template +inline void ThreeThresholdAlgorithm::clusterizeDetUnit_(const digiDetSet& digis, output_t::TSFastFiller& output) const { + const auto& cond = conditions(); + if (cond.isModuleBad(digis.detId())) + return; + + auto const& det = cond.findDetId(digis.detId()); + if (!det.valid()) + return; + +#ifdef EDM_ML_DEBUG + if (!cond.isModuleUsable(digis.detId())) + edm::LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl; +#endif + + typename digiDetSet::const_iterator scan(digis.begin()), end(digis.end()); + + SiStripApvShotCleaner ApvCleaner; + if (RemoveApvShots) { + ApvCleaner.clean(digis, scan, end); + } + + output.reserve(16); + State state(det); + while (scan != end) { + while (scan != end && !candidateEnded(state, scan->strip())) + addToCandidate(state, *scan++); + endCandidate(state, output); + } +} + +inline bool ThreeThresholdAlgorithm::candidateEnded(State const& state, const uint16_t& testStrip) const { + uint16_t holes = testStrip - state.lastStrip - 1; + return (((!state.ADCs.empty()) & // a candidate exists, and + (holes > MaxSequentialHoles) // too many holes if not all are bad strips, and + ) && + (holes > MaxSequentialBad || // (too many bad strips anyway, or + !state.det().allBadBetween(state.lastStrip, testStrip) // not all holes are bad strips) + )); +} + +inline void ThreeThresholdAlgorithm::addToCandidate(State& state, uint16_t strip, uint8_t adc) const { + float Noise = state.det().noise(strip); + if (adc < static_cast(Noise * ChannelThreshold) || state.det().bad(strip)) + return; + + if (state.candidateLacksSeed) + state.candidateLacksSeed = adc < static_cast(Noise * SeedThreshold); + if (state.ADCs.empty()) + state.lastStrip = strip - 1; // begin candidate + while (++state.lastStrip < strip) + state.ADCs.push_back(0); // pad holes + + if (state.ADCs.size() <= MaxClusterSize) + state.ADCs.push_back(adc); + state.noiseSquared += Noise * Noise; +} + +inline void ThreeThresholdAlgorithm::clusterizeDetUnit(const edmNew::DetSet& digis, + output_t::TSFastFiller& output) const { + clusterizeDetUnit_(digis, output); +} + +template +inline void ThreeThresholdAlgorithm::endCandidate(State& state, T& out) const { + if (candidateAccepted(state)) { + applyGains(state); + if (MaxAdjacentBad > 0) + appendBadNeighbors(state); + if (minGoodCharge <= 0 || + siStripClusterTools::chargePerCM(state.det().detId, state.ADCs.begin(), state.ADCs.end()) > minGoodCharge) + out.push_back(std::move(SiStripCluster(firstStrip(state), state.ADCs.begin(), state.ADCs.end()))); + } + clearCandidate(state); +} + +inline bool ThreeThresholdAlgorithm::candidateAccepted(State const& state) const { + return (!state.candidateLacksSeed && state.ADCs.size() <= MaxClusterSize && + state.noiseSquared * ClusterThresholdSquared <= + std::pow(float(std::accumulate(state.ADCs.begin(), state.ADCs.end(), int(0))), 2.f)); +} + +inline void ThreeThresholdAlgorithm::applyGains(State& state) const { + uint16_t strip = firstStrip(state); + for (auto& adc : state.ADCs) { +#ifdef EDM_ML_DEBUG + // if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) ); +#endif + // if(adc > 253) continue; //saturated, do not scale + auto charge = int(float(adc) * state.det().weight(strip++) + 0.5f); //adding 0.5 turns truncation into rounding + if (adc < 254) + adc = (charge > 1022 ? 255 : (charge > 253 ? 254 : charge)); + } +} + +inline void ThreeThresholdAlgorithm::appendBadNeighbors(State& state) const { + uint8_t max = MaxAdjacentBad; + while (0 < max--) { + if (state.det().bad(firstStrip(state) - 1)) { + state.ADCs.insert(state.ADCs.begin(), 0); + } + if (state.det().bad(state.lastStrip + 1)) { + state.ADCs.push_back(0); + state.lastStrip++; + } + } +} + + #endif diff --git a/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc b/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc index 92e5af1e7f135..329e6310993b5 100644 --- a/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc +++ b/RecoLocalTracker/SiStripClusterizer/src/ThreeThresholdAlgorithm.cc @@ -1,11 +1,4 @@ #include "RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h" -#include "DataFormats/SiStripDigi/interface/SiStripDigi.h" -#include "DataFormats/SiStripCluster/interface/SiStripCluster.h" -#include -#include -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h" ThreeThresholdAlgorithm::ThreeThresholdAlgorithm( const edm::ESGetToken& conditionsToken, @@ -29,117 +22,10 @@ ThreeThresholdAlgorithm::ThreeThresholdAlgorithm( RemoveApvShots(removeApvShots), minGoodCharge(minGoodCharge) {} -template -inline void ThreeThresholdAlgorithm::clusterizeDetUnit_(const digiDetSet& digis, output_t::TSFastFiller& output) const { - const auto& cond = conditions(); - if (cond.isModuleBad(digis.detId())) - return; - - auto const& det = cond.findDetId(digis.detId()); - if (!det.valid()) - return; - -#ifdef EDM_ML_DEBUG - if (!cond.isModuleUsable(digis.detId())) - edm::LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl; -#endif - - typename digiDetSet::const_iterator scan(digis.begin()), end(digis.end()); - - SiStripApvShotCleaner ApvCleaner; - if (RemoveApvShots) { - ApvCleaner.clean(digis, scan, end); - } - - output.reserve(16); - State state(det); - while (scan != end) { - while (scan != end && !candidateEnded(state, scan->strip())) - addToCandidate(state, *scan++); - endCandidate(state, output); - } -} - -inline bool ThreeThresholdAlgorithm::candidateEnded(State const& state, const uint16_t& testStrip) const { - uint16_t holes = testStrip - state.lastStrip - 1; - return (((!state.ADCs.empty()) & // a candidate exists, and - (holes > MaxSequentialHoles) // too many holes if not all are bad strips, and - ) && - (holes > MaxSequentialBad || // (too many bad strips anyway, or - !state.det().allBadBetween(state.lastStrip, testStrip) // not all holes are bad strips) - )); -} - -inline void ThreeThresholdAlgorithm::addToCandidate(State& state, uint16_t strip, uint8_t adc) const { - float Noise = state.det().noise(strip); - if (adc < static_cast(Noise * ChannelThreshold) || state.det().bad(strip)) - return; - - if (state.candidateLacksSeed) - state.candidateLacksSeed = adc < static_cast(Noise * SeedThreshold); - if (state.ADCs.empty()) - state.lastStrip = strip - 1; // begin candidate - while (++state.lastStrip < strip) - state.ADCs.push_back(0); // pad holes - - if (state.ADCs.size() <= MaxClusterSize) - state.ADCs.push_back(adc); - state.noiseSquared += Noise * Noise; -} - -template -inline void ThreeThresholdAlgorithm::endCandidate(State& state, T& out) const { - if (candidateAccepted(state)) { - applyGains(state); - if (MaxAdjacentBad > 0) - appendBadNeighbors(state); - if (minGoodCharge <= 0 || - siStripClusterTools::chargePerCM(state.det().detId, state.ADCs.begin(), state.ADCs.end()) > minGoodCharge) - out.push_back(std::move(SiStripCluster(firstStrip(state), state.ADCs.begin(), state.ADCs.end()))); - } - clearCandidate(state); -} - -inline bool ThreeThresholdAlgorithm::candidateAccepted(State const& state) const { - return (!state.candidateLacksSeed && state.ADCs.size() <= MaxClusterSize && - state.noiseSquared * ClusterThresholdSquared <= - std::pow(float(std::accumulate(state.ADCs.begin(), state.ADCs.end(), int(0))), 2.f)); -} - -inline void ThreeThresholdAlgorithm::applyGains(State& state) const { - uint16_t strip = firstStrip(state); - for (auto& adc : state.ADCs) { -#ifdef EDM_ML_DEBUG - // if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) ); -#endif - // if(adc > 253) continue; //saturated, do not scale - auto charge = int(float(adc) * state.det().weight(strip++) + 0.5f); //adding 0.5 turns truncation into rounding - if (adc < 254) - adc = (charge > 1022 ? 255 : (charge > 253 ? 254 : charge)); - } -} - -inline void ThreeThresholdAlgorithm::appendBadNeighbors(State& state) const { - uint8_t max = MaxAdjacentBad; - while (0 < max--) { - if (state.det().bad(firstStrip(state) - 1)) { - state.ADCs.insert(state.ADCs.begin(), 0); - } - if (state.det().bad(state.lastStrip + 1)) { - state.ADCs.push_back(0); - state.lastStrip++; - } - } -} - void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet& digis, output_t::TSFastFiller& output) const { clusterizeDetUnit_(digis, output); } -void ThreeThresholdAlgorithm::clusterizeDetUnit(const edmNew::DetSet& digis, - output_t::TSFastFiller& output) const { - clusterizeDetUnit_(digis, output); -} void ThreeThresholdAlgorithm::stripByStripAdd(State& state, uint16_t strip, @@ -150,19 +36,6 @@ void ThreeThresholdAlgorithm::stripByStripAdd(State& state, addToCandidate(state, SiStripDigi(strip, adc)); } -void ThreeThresholdAlgorithm::stripByStripAdd(State& state, - uint16_t strip, - uint8_t adc, - output_t::TSFastFiller& out) const { - if (candidateEnded(state, strip)) - endCandidate(state, out); - addToCandidate(state, strip, adc); -} - void ThreeThresholdAlgorithm::stripByStripEnd(State& state, std::vector& out) const { endCandidate(state, out); } - -void ThreeThresholdAlgorithm::stripByStripEnd(State& state, output_t::TSFastFiller& out) const { - endCandidate(state, out); -} From 022301564fe562ff0f839fa629fe99eb54f06b1b Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Mon, 6 Jan 2025 15:51:59 -0800 Subject: [PATCH 3/4] preserve ability to use non-ThreeThresholdAlgorithm with templates --- .../interface/ThreeThresholdAlgorithm.h | 1 - .../plugins/ClustersFromRawProducer.cc | 83 ++++++++++++------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h index 2696b0da295b6..268aac8451306 100644 --- a/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h +++ b/RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h @@ -180,5 +180,4 @@ inline void ThreeThresholdAlgorithm::appendBadNeighbors(State& state) const { } } - #endif diff --git a/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc b/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc index 327b79744ff57..7a02ba9887df7 100644 --- a/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc +++ b/RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc @@ -89,10 +89,11 @@ namespace { return buffer; } + template class ClusterFiller final : public StripClusterizerAlgorithm::output_t::Getter { public: ClusterFiller(const FEDRawDataCollection& irawColl, - const ThreeThresholdAlgorithm& iclusterizer, + const AlgoT& iclusterizer, SiStripRawProcessingAlgorithms& irawAlgos, bool idoAPVEmulatorCheck, bool legacy, @@ -119,7 +120,7 @@ namespace { const FEDRawDataCollection& rawColl; - const ThreeThresholdAlgorithm& clusterizer; + const AlgoT& clusterizer; const SiStripClusterizerConditions& conditions; SiStripRawProcessingAlgorithms& rawAlgos; @@ -181,7 +182,7 @@ class SiStripClusterizerFromRaw final : public edm::stream::EDProducer<> { legacy_(conf.getParameter("LegacyUnpacker")), hybridZeroSuppressed_(conf.getParameter("HybridZeroSuppressed")) { productToken_ = consumes(conf.getParameter("ProductLabel")); - produces >(); + produces>(); assert(clusterizer_.get()); assert(rawAlgos_.get()); } @@ -193,17 +194,23 @@ class SiStripClusterizerFromRaw final : public edm::stream::EDProducer<> { edm::Handle rawData; ev.getByToken(productToken_, rawData); - std::unique_ptr > output( - onDemand ? new edmNew::DetSetVector( - std::shared_ptr::Getter>( - std::make_shared(*rawData, - dynamic_cast(*clusterizer_), - *rawAlgos_, - doAPVEmulatorCheck_, - legacy_, - hybridZeroSuppressed_)), - clusterizer_->conditions().allDetIds()) - : new edmNew::DetSetVector()); + const ThreeThresholdAlgorithm* clusterizer3 = dynamic_cast(clusterizer_.get()); + std::unique_ptr> output; + if (onDemand) { + if (clusterizer3 == nullptr) + output = std::make_unique>(edmNew::DetSetVector( + std::shared_ptr::Getter>( + std::make_shared>( + *rawData, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)), + clusterizer_->conditions().allDetIds())); + else + output = std::make_unique>(edmNew::DetSetVector( + std::shared_ptr::Getter>( + std::make_shared>( + *rawData, *clusterizer3, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)), + clusterizer_->conditions().allDetIds())); + } else + output = std::make_unique>(edmNew::DetSetVector()); if (onDemand) assert(output->onDemand()); @@ -271,25 +278,38 @@ void SiStripClusterizerFromRaw::initialize(const edm::EventSetup& es) { } void SiStripClusterizerFromRaw::run(const FEDRawDataCollection& rawColl, edmNew::DetSetVector& output) { - ClusterFiller filler(rawColl, - dynamic_cast(*clusterizer_), - *rawAlgos_, - doAPVEmulatorCheck_, - legacy_, - hybridZeroSuppressed_); + const ThreeThresholdAlgorithm* clusterizer3 = dynamic_cast(clusterizer_.get()); + if (clusterizer3 == nullptr) { + ClusterFiller filler( + rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_); - // loop over good det in cabling - for (auto idet : clusterizer_->conditions().allDetIds()) { - StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet); + // loop over good det in cabling + for (auto idet : clusterizer_->conditions().allDetIds()) { + StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet); - filler.fill(record); + filler.fill(record); - if (record.empty()) - record.abort(); - } // end loop over dets + if (record.empty()) + record.abort(); + } // end loop over dets + } else { + ClusterFiller filler( + rawColl, *clusterizer3, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_); + + // loop over good det in cabling + for (auto idet : clusterizer_->conditions().allDetIds()) { + StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet); + + filler.fill(record); + + if (record.empty()) + record.abort(); + } // end loop over dets + } } namespace { + template class StripByStripAdder { public: typedef std::output_iterator_tag iterator_category; @@ -298,7 +318,7 @@ namespace { typedef void pointer; typedef void reference; - StripByStripAdder(const ThreeThresholdAlgorithm& clusterizer, + StripByStripAdder(const AlgoT& clusterizer, StripClusterizerAlgorithm::State& state, StripClusterizerAlgorithm::output_t::TSFastFiller& record) : clusterizer_(clusterizer), state_(state), record_(record) {} @@ -313,7 +333,7 @@ namespace { StripByStripAdder& operator++(int) { return *this; } private: - const ThreeThresholdAlgorithm& clusterizer_; + const AlgoT& clusterizer_; StripClusterizerAlgorithm::State& state_; StripClusterizerAlgorithm::output_t::TSFastFiller& record_; }; @@ -336,7 +356,8 @@ namespace { }; } // namespace -void ClusterFiller::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& record) const { +template +void ClusterFiller::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& record) const { try { // edmNew::CapacityExaustedException incReady(); @@ -403,7 +424,7 @@ void ClusterFiller::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& reco using namespace sistrip; if LIKELY (fedchannelunpacker::isZeroSuppressed(mode, legacy_, lmode)) { - auto perStripAdder = StripByStripAdder(clusterizer, state, record); + auto perStripAdder = StripByStripAdder(clusterizer, state, record); const auto isNonLite = fedchannelunpacker::isNonLiteZS(mode, legacy_, lmode); const uint8_t pCode = (isNonLite ? buffer->packetCode(legacy_, fedCh) : 0); auto st_ch = fedchannelunpacker::StatusCode::SUCCESS; From 49e294beac0e90310001977ec2b7c31b86e3d765 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 8 Jan 2025 07:37:04 -0800 Subject: [PATCH 4/4] precompute strip noise and quality in SiStripClusterizerConditions --- .../interface/SiStripClusterizerConditions.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h b/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h index 35d07be8c8587..9323e81474f1a 100644 --- a/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h +++ b/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h @@ -14,18 +14,21 @@ class SiStripClusterizerConditions { struct Det { bool valid() const { return ind != invalidI; } - uint16_t rawNoise(const uint16_t strip) const { return SiStripNoises::getRawNoise(strip, noiseRange); } - float noise(const uint16_t strip) const { return SiStripNoises::getNoise(strip, noiseRange); } + uint16_t rawNoise(const uint16_t strip) const { return rawNoises[strip]; } + float noise(const uint16_t strip) const { return 0.1f * float(rawNoises[strip]); } float weight(const uint16_t strip) const { return m_weight[strip / 128]; } - bool bad(const uint16_t strip) const { return quality->IsStripBad(qualityRange, strip); } + bool bad(const uint16_t strip) const { return qualityBits[strip]; } bool allBadBetween(uint16_t L, const uint16_t& R) const { while (++L < R && bad(L)) { }; return L == R; } + static constexpr uint16_t kMaxStrips = 768; SiStripQuality const* quality; - SiStripNoises::Range noiseRange; SiStripQuality::Range qualityRange; + std::array qualityBits = {}; + SiStripNoises::Range noiseRange; + std::array rawNoises = {}; float m_weight[6]; uint32_t detId = 0; unsigned short ind = invalidI; @@ -72,7 +75,15 @@ class SiStripClusterizerConditions { auto& det = m_dets.emplace_back(); det.quality = m_quality; det.qualityRange = qualityRange; + for (uint16_t s = 0U; s < det.kMaxStrips; ++s) + det.qualityBits[s] = m_quality->IsStripBad(qualityRange, s); det.noiseRange = noiseRange; + auto maxRange8 = (noiseRange.second - noiseRange.first) * 8; + for (uint16_t s = 0U; s < det.kMaxStrips; ++s) { + if (9 * s >= maxRange8) + break; + det.rawNoises[s] = SiStripNoises::getRawNoise(s, noiseRange); + } for (uint32_t i = 0; i != invGains.size(); ++i) { det.m_weight[i] = invGains[i]; }