File indexing completed on 2025-01-21 01:39:40
0001 #ifndef DATAFORMATS_SISTRIPCLUSTER_H
0002 #define DATAFORMATS_SISTRIPCLUSTER_H
0003
0004 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0005 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0006 #include <vector>
0007 #include <numeric>
0008 #include <iostream>
0009
0010 class SiStripApproximateCluster;
0011
0012 class SiStripCluster {
0013 public:
0014 typedef std::vector<SiStripDigi>::const_iterator SiStripDigiIter;
0015 typedef std::pair<SiStripDigiIter, SiStripDigiIter> SiStripDigiRange;
0016
0017 static const uint16_t stripIndexMask = 0x3FFF;
0018 static const uint16_t mergedValueMask = 0x8000;
0019 static const uint16_t approximateMask = 0x4000;
0020
0021
0022
0023
0024
0025 SiStripCluster() {}
0026
0027 explicit SiStripCluster(const SiStripDigiRange& range);
0028
0029 SiStripCluster(uint16_t firstStrip, std::vector<uint8_t>&& data)
0030 : amplitudes_(std::move(data)), firstStrip_(firstStrip) {
0031 initQB();
0032 }
0033
0034 template <typename Iter>
0035 SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) {
0036 initQB();
0037 }
0038
0039 template <typename Iter>
0040 SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end, bool merged)
0041 : amplitudes_(begin, end), firstStrip_(firstStrip) {
0042 if (merged)
0043 firstStrip_ |= mergedValueMask;
0044 initQB();
0045 }
0046
0047 SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips);
0048
0049
0050 template <typename Iter>
0051 void extend(Iter begin, Iter end) {
0052 amplitudes_.insert(amplitudes_.end(), begin, end);
0053 initQB();
0054 }
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 auto size() const { return amplitudes_.size(); }
0068 auto const* begin() const { return amplitudes_.data(); }
0069 auto const* end() const { return begin() + size(); }
0070 auto operator[](int i) const { return *(begin() + i); }
0071 bool empty() const { return amplitudes_.empty(); }
0072 bool full() const { return false; }
0073
0074 SiStripCluster const& amplitudes() const { return *this; }
0075
0076
0077
0078
0079 uint16_t firstStrip() const { return firstStrip_ & stripIndexMask; }
0080 uint16_t endStrip() const { return firstStrip() + size(); }
0081
0082
0083
0084
0085 float barycenter() const { return barycenter_; }
0086
0087
0088
0089
0090 int charge() const { return charge_; }
0091
0092 bool filter() const { return filter_; }
0093
0094 bool isFromApprox() const { return (firstStrip_ & approximateMask) != 0; }
0095
0096
0097
0098
0099 bool isMerged() const { return (firstStrip_ & mergedValueMask) != 0; }
0100 void setMerged(bool mergedState) { mergedState ? firstStrip_ |= mergedValueMask : firstStrip_ &= stripIndexMask; }
0101
0102 float getSplitClusterError() const { return error_x; }
0103 void setSplitClusterError(float errx) { error_x = errx; }
0104
0105 void initQB();
0106
0107 private:
0108 std::vector<uint8_t> amplitudes_;
0109
0110 uint16_t firstStrip_ = 0;
0111
0112
0113 float barycenter_ = 0;
0114 int charge_ = 0;
0115 bool filter_ = false;
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 float error_x = -99999.9;
0126
0127
0128
0129
0130
0131
0132 };
0133
0134
0135 inline bool operator<(const SiStripCluster& one, const SiStripCluster& other) {
0136 return one.firstStrip() < other.firstStrip();
0137 }
0138
0139 inline bool operator<(const SiStripCluster& cluster, const uint16_t& firstStrip) {
0140 return cluster.firstStrip() < firstStrip;
0141 }
0142
0143 inline bool operator<(const uint16_t& firstStrip, const SiStripCluster& cluster) {
0144 return firstStrip < cluster.firstStrip();
0145 }
0146
0147 inline void SiStripCluster::initQB() {
0148 int sumx = 0;
0149 int suma = 0;
0150 auto asize = size();
0151 for (auto i = 0U; i < asize; ++i) {
0152 sumx += i * amplitudes_[i];
0153 suma += amplitudes_[i];
0154 }
0155 charge_ = suma;
0156
0157
0158
0159
0160 barycenter_ = float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
0161 }
0162
0163 #endif