From 7ad80bacf775be3a979bef3c532d5d152d59a139 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 10 Jan 2025 14:23:36 -0800 Subject: [PATCH 1/4] fill charge_ and barycenter_ for all clusters; use another bit in firstStrip_ to signal it's an approximate cluster --- .../SiStripCluster/interface/SiStripCluster.h | 39 +++++++++++++++---- .../SiStripCluster/src/SiStripCluster.cc | 33 +--------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/DataFormats/SiStripCluster/interface/SiStripCluster.h b/DataFormats/SiStripCluster/interface/SiStripCluster.h index d95f379251036..c43d77f108520 100644 --- a/DataFormats/SiStripCluster/interface/SiStripCluster.h +++ b/DataFormats/SiStripCluster/interface/SiStripCluster.h @@ -14,8 +14,9 @@ class SiStripCluster { typedef std::vector::const_iterator SiStripDigiIter; typedef std::pair SiStripDigiRange; - static const uint16_t stripIndexMask = 0x7FFF; // The first strip index is in the low 15 bits of firstStrip_ + static const uint16_t stripIndexMask = 0x3FFF; // The first strip index is in the low 15 bits of firstStrip_ static const uint16_t mergedValueMask = 0x8000; // The merged state is given by the high bit of firstStrip_ + static const uint16_t approximateMask = 0x4000; // The approximate state is the high-1 bit of firstStrip_ /** Construct from a range of digis that form a cluster and from * a DetID. The range is assumed to be non-empty. @@ -26,16 +27,21 @@ class SiStripCluster { explicit SiStripCluster(const SiStripDigiRange& range); SiStripCluster(uint16_t firstStrip, std::vector&& data) - : amplitudes_(std::move(data)), firstStrip_(firstStrip) {} + : amplitudes_(std::move(data)), firstStrip_(firstStrip) { + initQB(); + } template - SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) {} + SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) { + initQB(); + } template SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end, bool merged) : amplitudes_(begin, end), firstStrip_(firstStrip) { if (merged) firstStrip_ |= mergedValueMask; // if this is a candidate merged cluster + initQB(); } SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips); @@ -44,6 +50,7 @@ class SiStripCluster { template void extend(Iter begin, Iter end) { amplitudes_.insert(amplitudes_.end(), begin, end); + initQB(); } /** The amplitudes of the strips forming the cluster. @@ -75,16 +82,16 @@ class SiStripCluster { /** The barycenter of the cluster, not corrected for Lorentz shift; * should not be used as position estimate for tracking. */ - float barycenter() const; + float barycenter() const { return barycenter_; } /** total charge * */ - int charge() const; + int charge() const { return charge_; } - bool filter() const; + bool filter() const { return filter_; } - bool isFromApprox() const; + bool isFromApprox() const { return (firstStrip_ & approximateMask) != 0; } /** Test (set) the merged status of the cluster * @@ -120,6 +127,8 @@ class SiStripCluster { // The CPE will check these errors and if they are not un-physical, // it will recognize the clusters as split and assign these (increased) // errors to the corresponding rechit. + + void initQB(); }; // Comparison operators @@ -134,4 +143,20 @@ inline bool operator<(const SiStripCluster& cluster, const uint16_t& firstStrip) inline bool operator<(const uint16_t& firstStrip, const SiStripCluster& cluster) { return firstStrip < cluster.firstStrip(); } + +inline void SiStripCluster::initQB() { + int sumx = 0; + int suma = 0; + auto asize = size(); + for (auto i = 0U; i < asize; ++i) { + sumx += i * amplitudes_[i]; + suma += amplitudes_[i]; + } + charge_ = suma; + + // strip centers are offset by half pitch w.r.t. strip numbers, + // so one has to add 0.5 to get the correct barycenter position. + // Need to mask off the high bit of firstStrip_, which contains the merged status. + barycenter_ = float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f; +} #endif // DATAFORMATS_SISTRIPCLUSTER_H diff --git a/DataFormats/SiStripCluster/src/SiStripCluster.cc b/DataFormats/SiStripCluster/src/SiStripCluster.cc index 9deb73b4c4a22..8586307a8e384 100644 --- a/DataFormats/SiStripCluster/src/SiStripCluster.cc +++ b/DataFormats/SiStripCluster/src/SiStripCluster.cc @@ -20,6 +20,7 @@ SiStripCluster::SiStripCluster(const SiStripDigiRange& range) : firstStrip_(rang v.push_back(i->adc()); } amplitudes_ = v; + initQB(); } SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips) : error_x(-99999.9) { @@ -36,35 +37,5 @@ SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const ui if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) { firstStrip_ = maxStrips - cluster.width(); } + firstStrip_ |= approximateMask; } - -int SiStripCluster::charge() const { - if (barycenter_ > 0) - return charge_; - return std::accumulate(begin(), end(), int(0)); -} - -float SiStripCluster::barycenter() const { - if (barycenter_ > 0) - return barycenter_; - - int sumx = 0; - int suma = 0; - auto asize = size(); - for (auto i = 0U; i < asize; ++i) { - sumx += i * amplitudes_[i]; - suma += amplitudes_[i]; - } - - // strip centers are offcet by half pitch w.r.t. strip numbers, - // so one has to add 0.5 to get the correct barycenter position. - // Need to mask off the high bit of firstStrip_, which contains the merged status. - return float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f; -} -bool SiStripCluster::filter() const { - if (barycenter_ > 0) - return filter_; - return false; -} - -bool SiStripCluster::isFromApprox() const { return (barycenter_ > 0); } From bc0d7c1c251d9b40789bc54bac540952f4bef5d8 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Tue, 14 Jan 2025 18:03:48 -0800 Subject: [PATCH 2/4] add ioread rules to fill barycenter_,charge_ for persisted data --- DataFormats/SiStripCluster/interface/SiStripCluster.h | 5 +++-- DataFormats/SiStripCluster/src/classes_def.xml | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DataFormats/SiStripCluster/interface/SiStripCluster.h b/DataFormats/SiStripCluster/interface/SiStripCluster.h index c43d77f108520..83ada6f6cfc1d 100644 --- a/DataFormats/SiStripCluster/interface/SiStripCluster.h +++ b/DataFormats/SiStripCluster/interface/SiStripCluster.h @@ -102,6 +102,8 @@ class SiStripCluster { float getSplitClusterError() const { return error_x; } void setSplitClusterError(float errx) { error_x = errx; } + void initQB(); + private: std::vector amplitudes_; @@ -127,8 +129,6 @@ class SiStripCluster { // The CPE will check these errors and if they are not un-physical, // it will recognize the clusters as split and assign these (increased) // errors to the corresponding rechit. - - void initQB(); }; // Comparison operators @@ -159,4 +159,5 @@ inline void SiStripCluster::initQB() { // Need to mask off the high bit of firstStrip_, which contains the merged status. barycenter_ = float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f; } + #endif // DATAFORMATS_SISTRIPCLUSTER_H diff --git a/DataFormats/SiStripCluster/src/classes_def.xml b/DataFormats/SiStripCluster/src/classes_def.xml index fa475a9e1ae50..a998138023cb0 100755 --- a/DataFormats/SiStripCluster/src/classes_def.xml +++ b/DataFormats/SiStripCluster/src/classes_def.xml @@ -1,12 +1,19 @@ - + + + + initQB();]]> + + + initQB(); } else { firstStrip_ |= SiStripCluster::approximateMask; }]]> + From c4350824f1c85a797023ee1611c31d5a2a9b32dd Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Wed, 15 Jan 2025 14:49:36 -0800 Subject: [PATCH 3/4] move verbose (and working) ioread rule --- DataFormats/SiStripCluster/src/classes_def.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DataFormats/SiStripCluster/src/classes_def.xml b/DataFormats/SiStripCluster/src/classes_def.xml index a998138023cb0..826ba2daa082c 100755 --- a/DataFormats/SiStripCluster/src/classes_def.xml +++ b/DataFormats/SiStripCluster/src/classes_def.xml @@ -8,11 +8,11 @@ - - initQB();]]> + + initQB();]]> - - initQB(); } else { firstStrip_ |= SiStripCluster::approximateMask; }]]> + + initQB(); } else { firstStrip_ |= SiStripCluster::approximateMask; }]]> From 77ad11b2054c2c61f9d825fb0fef48e37ed4cfff Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 16 Jan 2025 10:56:53 -0800 Subject: [PATCH 4/4] fix the pre-approx version range --- DataFormats/SiStripCluster/src/classes_def.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataFormats/SiStripCluster/src/classes_def.xml b/DataFormats/SiStripCluster/src/classes_def.xml index 826ba2daa082c..31ff33a914296 100755 --- a/DataFormats/SiStripCluster/src/classes_def.xml +++ b/DataFormats/SiStripCluster/src/classes_def.xml @@ -8,10 +8,10 @@ - + initQB();]]> - + initQB(); } else { firstStrip_ |= SiStripCluster::approximateMask; }]]>