Skip to content

Commit 6ffa77a

Browse files
authored
Merge pull request #47810 from slava77/CMSSW_15_0_X_2025-04-06-0000/revert-47061
revert "speedup SiStripClusterizer(FromRaw) using ThreeThresholdAlgorithm"
2 parents a4fc072 + 5e79aee commit 6ffa77a

File tree

4 files changed

+139
-184
lines changed

4 files changed

+139
-184
lines changed

CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h

+4-15
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ class SiStripClusterizerConditions {
1414

1515
struct Det {
1616
bool valid() const { return ind != invalidI; }
17-
uint16_t rawNoise(const uint16_t strip) const { return rawNoises[strip]; }
18-
float noise(const uint16_t strip) const { return 0.1f * float(rawNoises[strip]); }
17+
uint16_t rawNoise(const uint16_t strip) const { return SiStripNoises::getRawNoise(strip, noiseRange); }
18+
float noise(const uint16_t strip) const { return SiStripNoises::getNoise(strip, noiseRange); }
1919
float weight(const uint16_t strip) const { return m_weight[strip / 128]; }
20-
bool bad(const uint16_t strip) const { return qualityBits[strip]; }
20+
bool bad(const uint16_t strip) const { return quality->IsStripBad(qualityRange, strip); }
2121
bool allBadBetween(uint16_t L, const uint16_t& R) const {
2222
while (++L < R && bad(L)) {
2323
};
2424
return L == R;
2525
}
26-
static constexpr uint16_t kMaxStrips = 768;
2726
SiStripQuality const* quality;
28-
SiStripQuality::Range qualityRange;
29-
std::array<bool, kMaxStrips> qualityBits = {};
3027
SiStripNoises::Range noiseRange;
31-
std::array<uint16_t, kMaxStrips> rawNoises = {};
28+
SiStripQuality::Range qualityRange;
3229
float m_weight[6];
3330
uint32_t detId = 0;
3431
unsigned short ind = invalidI;
@@ -75,15 +72,7 @@ class SiStripClusterizerConditions {
7572
auto& det = m_dets.emplace_back();
7673
det.quality = m_quality;
7774
det.qualityRange = qualityRange;
78-
for (uint16_t s = 0U; s < det.kMaxStrips; ++s)
79-
det.qualityBits[s] = m_quality->IsStripBad(qualityRange, s);
8075
det.noiseRange = noiseRange;
81-
auto maxRange8 = (noiseRange.second - noiseRange.first) * 8;
82-
for (uint16_t s = 0U; s < det.kMaxStrips; ++s) {
83-
if (9 * s >= maxRange8)
84-
break;
85-
det.rawNoises[s] = SiStripNoises::getRawNoise(s, noiseRange);
86-
}
8776
for (uint32_t i = 0; i != invGains.size(); ++i) {
8877
det.m_weight[i] = invGains[i];
8978
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
#ifndef RecoLocalTracker_SiStripClusterizer_ThreeThresholdAlgorithm_h
22
#define RecoLocalTracker_SiStripClusterizer_ThreeThresholdAlgorithm_h
3-
4-
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
5-
#include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h"
6-
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
7-
#include "FWCore/MessageLogger/interface/MessageLogger.h"
83
#include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithm.h"
94
#include "RecoLocalTracker/SiStripClusterizer/interface/SiStripApvShotCleaner.h"
105

11-
#include <cmath>
12-
#include <numeric>
13-
146
class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm {
157
friend class StripClusterizerAlgorithmFactory;
168

@@ -72,112 +64,4 @@ class ThreeThresholdAlgorithm final : public StripClusterizerAlgorithm {
7264
float minGoodCharge;
7365
};
7466

75-
template <class digiDetSet>
76-
inline void ThreeThresholdAlgorithm::clusterizeDetUnit_(const digiDetSet& digis, output_t::TSFastFiller& output) const {
77-
const auto& cond = conditions();
78-
if (cond.isModuleBad(digis.detId()))
79-
return;
80-
81-
auto const& det = cond.findDetId(digis.detId());
82-
if (!det.valid())
83-
return;
84-
85-
#ifdef EDM_ML_DEBUG
86-
if (!cond.isModuleUsable(digis.detId()))
87-
edm::LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
88-
#endif
89-
90-
typename digiDetSet::const_iterator scan(digis.begin()), end(digis.end());
91-
92-
SiStripApvShotCleaner ApvCleaner;
93-
if (RemoveApvShots) {
94-
ApvCleaner.clean(digis, scan, end);
95-
}
96-
97-
output.reserve(16);
98-
State state(det);
99-
while (scan != end) {
100-
while (scan != end && !candidateEnded(state, scan->strip()))
101-
addToCandidate(state, *scan++);
102-
endCandidate(state, output);
103-
}
104-
}
105-
106-
inline bool ThreeThresholdAlgorithm::candidateEnded(State const& state, const uint16_t& testStrip) const {
107-
uint16_t holes = testStrip - state.lastStrip - 1;
108-
return (((!state.ADCs.empty()) & // a candidate exists, and
109-
(holes > MaxSequentialHoles) // too many holes if not all are bad strips, and
110-
) &&
111-
(holes > MaxSequentialBad || // (too many bad strips anyway, or
112-
!state.det().allBadBetween(state.lastStrip, testStrip) // not all holes are bad strips)
113-
));
114-
}
115-
116-
inline void ThreeThresholdAlgorithm::addToCandidate(State& state, uint16_t strip, uint8_t adc) const {
117-
float Noise = state.det().noise(strip);
118-
if (adc < static_cast<uint8_t>(Noise * ChannelThreshold) || state.det().bad(strip))
119-
return;
120-
121-
if (state.candidateLacksSeed)
122-
state.candidateLacksSeed = adc < static_cast<uint8_t>(Noise * SeedThreshold);
123-
if (state.ADCs.empty())
124-
state.lastStrip = strip - 1; // begin candidate
125-
while (++state.lastStrip < strip)
126-
state.ADCs.push_back(0); // pad holes
127-
128-
if (state.ADCs.size() <= MaxClusterSize)
129-
state.ADCs.push_back(adc);
130-
state.noiseSquared += Noise * Noise;
131-
}
132-
133-
inline void ThreeThresholdAlgorithm::clusterizeDetUnit(const edmNew::DetSet<SiStripDigi>& digis,
134-
output_t::TSFastFiller& output) const {
135-
clusterizeDetUnit_(digis, output);
136-
}
137-
138-
template <class T>
139-
inline void ThreeThresholdAlgorithm::endCandidate(State& state, T& out) const {
140-
if (candidateAccepted(state)) {
141-
applyGains(state);
142-
if (MaxAdjacentBad > 0)
143-
appendBadNeighbors(state);
144-
if (minGoodCharge <= 0 ||
145-
siStripClusterTools::chargePerCM(state.det().detId, state.ADCs.begin(), state.ADCs.end()) > minGoodCharge)
146-
out.push_back(std::move(SiStripCluster(firstStrip(state), state.ADCs.begin(), state.ADCs.end())));
147-
}
148-
clearCandidate(state);
149-
}
150-
151-
inline bool ThreeThresholdAlgorithm::candidateAccepted(State const& state) const {
152-
return (!state.candidateLacksSeed && state.ADCs.size() <= MaxClusterSize &&
153-
state.noiseSquared * ClusterThresholdSquared <=
154-
std::pow(float(std::accumulate(state.ADCs.begin(), state.ADCs.end(), int(0))), 2.f));
155-
}
156-
157-
inline void ThreeThresholdAlgorithm::applyGains(State& state) const {
158-
uint16_t strip = firstStrip(state);
159-
for (auto& adc : state.ADCs) {
160-
#ifdef EDM_ML_DEBUG
161-
// if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
162-
#endif
163-
// if(adc > 253) continue; //saturated, do not scale
164-
auto charge = int(float(adc) * state.det().weight(strip++) + 0.5f); //adding 0.5 turns truncation into rounding
165-
if (adc < 254)
166-
adc = (charge > 1022 ? 255 : (charge > 253 ? 254 : charge));
167-
}
168-
}
169-
170-
inline void ThreeThresholdAlgorithm::appendBadNeighbors(State& state) const {
171-
uint8_t max = MaxAdjacentBad;
172-
while (0 < max--) {
173-
if (state.det().bad(firstStrip(state) - 1)) {
174-
state.ADCs.insert(state.ADCs.begin(), 0);
175-
}
176-
if (state.det().bad(state.lastStrip + 1)) {
177-
state.ADCs.push_back(0);
178-
state.lastStrip++;
179-
}
180-
}
181-
}
182-
18367
#endif

RecoLocalTracker/SiStripClusterizer/plugins/ClustersFromRawProducer.cc

+21-53
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingFactory.h"
55

66
#include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithm.h"
7-
#include "RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h"
87
#include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingAlgorithms.h"
98

109
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
@@ -90,11 +89,10 @@ namespace {
9089
return buffer;
9190
}
9291

93-
template <class AlgoT>
9492
class ClusterFiller final : public StripClusterizerAlgorithm::output_t::Getter {
9593
public:
9694
ClusterFiller(const FEDRawDataCollection& irawColl,
97-
const AlgoT& iclusterizer,
95+
StripClusterizerAlgorithm& iclusterizer,
9896
SiStripRawProcessingAlgorithms& irawAlgos,
9997
bool idoAPVEmulatorCheck,
10098
bool legacy,
@@ -121,7 +119,7 @@ namespace {
121119

122120
const FEDRawDataCollection& rawColl;
123121

124-
const AlgoT& clusterizer;
122+
StripClusterizerAlgorithm& clusterizer;
125123
const SiStripClusterizerConditions& conditions;
126124
SiStripRawProcessingAlgorithms& rawAlgos;
127125

@@ -183,7 +181,7 @@ class SiStripClusterizerFromRaw final : public edm::stream::EDProducer<> {
183181
legacy_(conf.getParameter<bool>("LegacyUnpacker")),
184182
hybridZeroSuppressed_(conf.getParameter<bool>("HybridZeroSuppressed")) {
185183
productToken_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("ProductLabel"));
186-
produces<edmNew::DetSetVector<SiStripCluster>>();
184+
produces<edmNew::DetSetVector<SiStripCluster> >();
187185
assert(clusterizer_.get());
188186
assert(rawAlgos_.get());
189187
}
@@ -195,23 +193,12 @@ class SiStripClusterizerFromRaw final : public edm::stream::EDProducer<> {
195193
edm::Handle<FEDRawDataCollection> rawData;
196194
ev.getByToken(productToken_, rawData);
197195

198-
const ThreeThresholdAlgorithm* clusterizer3 = dynamic_cast<const ThreeThresholdAlgorithm*>(clusterizer_.get());
199-
std::unique_ptr<edmNew::DetSetVector<SiStripCluster>> output;
200-
if (onDemand) {
201-
if (clusterizer3 == nullptr)
202-
output = std::make_unique<edmNew::DetSetVector<SiStripCluster>>(edmNew::DetSetVector<SiStripCluster>(
203-
std::shared_ptr<edmNew::DetSetVector<SiStripCluster>::Getter>(
204-
std::make_shared<ClusterFiller<StripClusterizerAlgorithm>>(
205-
*rawData, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)),
206-
clusterizer_->conditions().allDetIds()));
207-
else
208-
output = std::make_unique<edmNew::DetSetVector<SiStripCluster>>(edmNew::DetSetVector<SiStripCluster>(
209-
std::shared_ptr<edmNew::DetSetVector<SiStripCluster>::Getter>(
210-
std::make_shared<ClusterFiller<ThreeThresholdAlgorithm>>(
211-
*rawData, *clusterizer3, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)),
212-
clusterizer_->conditions().allDetIds()));
213-
} else
214-
output = std::make_unique<edmNew::DetSetVector<SiStripCluster>>(edmNew::DetSetVector<SiStripCluster>());
196+
std::unique_ptr<edmNew::DetSetVector<SiStripCluster> > output(
197+
onDemand ? new edmNew::DetSetVector<SiStripCluster>(
198+
std::shared_ptr<edmNew::DetSetVector<SiStripCluster>::Getter>(std::make_shared<ClusterFiller>(
199+
*rawData, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)),
200+
clusterizer_->conditions().allDetIds())
201+
: new edmNew::DetSetVector<SiStripCluster>());
215202

216203
if (onDemand)
217204
assert(output->onDemand());
@@ -279,38 +266,20 @@ void SiStripClusterizerFromRaw::initialize(const edm::EventSetup& es) {
279266
}
280267

281268
void SiStripClusterizerFromRaw::run(const FEDRawDataCollection& rawColl, edmNew::DetSetVector<SiStripCluster>& output) {
282-
const ThreeThresholdAlgorithm* clusterizer3 = dynamic_cast<const ThreeThresholdAlgorithm*>(clusterizer_.get());
283-
if (clusterizer3 == nullptr) {
284-
ClusterFiller<StripClusterizerAlgorithm> filler(
285-
rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_);
269+
ClusterFiller filler(rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_);
286270

287-
// loop over good det in cabling
288-
for (auto idet : clusterizer_->conditions().allDetIds()) {
289-
StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet);
271+
// loop over good det in cabling
272+
for (auto idet : clusterizer_->conditions().allDetIds()) {
273+
StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet);
290274

291-
filler.fill(record);
275+
filler.fill(record);
292276

293-
if (record.empty())
294-
record.abort();
295-
} // end loop over dets
296-
} else {
297-
ClusterFiller<ThreeThresholdAlgorithm> filler(
298-
rawColl, *clusterizer3, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_);
299-
300-
// loop over good det in cabling
301-
for (auto idet : clusterizer_->conditions().allDetIds()) {
302-
StripClusterizerAlgorithm::output_t::TSFastFiller record(output, idet);
303-
304-
filler.fill(record);
305-
306-
if (record.empty())
307-
record.abort();
308-
} // end loop over dets
309-
}
277+
if (record.empty())
278+
record.abort();
279+
} // end loop over dets
310280
}
311281

312282
namespace {
313-
template <class AlgoT>
314283
class StripByStripAdder {
315284
public:
316285
typedef std::output_iterator_tag iterator_category;
@@ -319,7 +288,7 @@ namespace {
319288
typedef void pointer;
320289
typedef void reference;
321290

322-
StripByStripAdder(const AlgoT& clusterizer,
291+
StripByStripAdder(StripClusterizerAlgorithm& clusterizer,
323292
StripClusterizerAlgorithm::State& state,
324293
StripClusterizerAlgorithm::output_t::TSFastFiller& record)
325294
: clusterizer_(clusterizer), state_(state), record_(record) {}
@@ -334,7 +303,7 @@ namespace {
334303
StripByStripAdder& operator++(int) { return *this; }
335304

336305
private:
337-
const AlgoT& clusterizer_;
306+
StripClusterizerAlgorithm& clusterizer_;
338307
StripClusterizerAlgorithm::State& state_;
339308
StripClusterizerAlgorithm::output_t::TSFastFiller& record_;
340309
};
@@ -357,8 +326,7 @@ namespace {
357326
};
358327
} // namespace
359328

360-
template <class AlgoT>
361-
void ClusterFiller<AlgoT>::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& record) const {
329+
void ClusterFiller::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& record) const {
362330
try { // edmNew::CapacityExaustedException
363331
incReady();
364332

@@ -425,7 +393,7 @@ void ClusterFiller<AlgoT>::fill(StripClusterizerAlgorithm::output_t::TSFastFille
425393

426394
using namespace sistrip;
427395
if LIKELY (fedchannelunpacker::isZeroSuppressed(mode, legacy_, lmode)) {
428-
auto perStripAdder = StripByStripAdder<AlgoT>(clusterizer, state, record);
396+
auto perStripAdder = StripByStripAdder(clusterizer, state, record);
429397
const auto isNonLite = fedchannelunpacker::isNonLiteZS(mode, legacy_, lmode);
430398
const uint8_t pCode = (isNonLite ? buffer->packetCode(legacy_, fedCh) : 0);
431399
auto st_ch = fedchannelunpacker::StatusCode::SUCCESS;

0 commit comments

Comments
 (0)