diff --git a/DataFormats/SiStripCluster/interface/SiStripCluster.h b/DataFormats/SiStripCluster/interface/SiStripCluster.h index d95f379251036..83ada6f6cfc1d 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 * @@ -95,6 +102,8 @@ class SiStripCluster { float getSplitClusterError() const { return error_x; } void setSplitClusterError(float errx) { error_x = errx; } + void initQB(); + private: std::vector amplitudes_; @@ -134,4 +143,21 @@ 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); } diff --git a/DataFormats/SiStripCluster/src/classes_def.xml b/DataFormats/SiStripCluster/src/classes_def.xml index fa475a9e1ae50..31ff33a914296 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; }]]> +