File indexing completed on 2024-04-06 12:05:12
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 = 0x7FFF;
0018 static const uint16_t mergedValueMask = 0x8000;
0019
0020
0021
0022
0023
0024 SiStripCluster() {}
0025
0026 explicit SiStripCluster(const SiStripDigiRange& range);
0027
0028 SiStripCluster(uint16_t firstStrip, std::vector<uint8_t>&& data)
0029 : amplitudes_(std::move(data)), firstStrip_(firstStrip) {}
0030
0031 template <typename Iter>
0032 SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) {}
0033
0034 template <typename Iter>
0035 SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end, bool merged)
0036 : amplitudes_(begin, end), firstStrip_(firstStrip) {
0037 if (merged)
0038 firstStrip_ |= mergedValueMask;
0039 }
0040
0041 SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips);
0042
0043
0044 template <typename Iter>
0045 void extend(Iter begin, Iter end) {
0046 amplitudes_.insert(amplitudes_.end(), begin, end);
0047 }
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 auto size() const { return amplitudes_.size(); }
0061 auto const* begin() const { return amplitudes_.data(); }
0062 auto const* end() const { return begin() + size(); }
0063 auto operator[](int i) const { return *(begin() + i); }
0064 bool empty() const { return amplitudes_.empty(); }
0065 bool full() const { return false; }
0066
0067 SiStripCluster const& amplitudes() const { return *this; }
0068
0069
0070
0071
0072 uint16_t firstStrip() const { return firstStrip_ & stripIndexMask; }
0073 uint16_t endStrip() const { return firstStrip() + size(); }
0074
0075
0076
0077
0078 float barycenter() const;
0079
0080
0081
0082
0083 int charge() const;
0084
0085 bool filter() const;
0086
0087 bool isFromApprox() const;
0088
0089
0090
0091
0092 bool isMerged() const { return (firstStrip_ & mergedValueMask) != 0; }
0093 void setMerged(bool mergedState) { mergedState ? firstStrip_ |= mergedValueMask : firstStrip_ &= stripIndexMask; }
0094
0095 float getSplitClusterError() const { return error_x; }
0096 void setSplitClusterError(float errx) { error_x = errx; }
0097
0098 private:
0099 std::vector<uint8_t> amplitudes_;
0100
0101 uint16_t firstStrip_ = 0;
0102
0103
0104 float barycenter_ = 0;
0105 int charge_ = 0;
0106 bool filter_ = false;
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 float error_x = -99999.9;
0117
0118
0119
0120
0121
0122
0123 };
0124
0125
0126 inline bool operator<(const SiStripCluster& one, const SiStripCluster& other) {
0127 return one.firstStrip() < other.firstStrip();
0128 }
0129
0130 inline bool operator<(const SiStripCluster& cluster, const uint16_t& firstStrip) {
0131 return cluster.firstStrip() < firstStrip;
0132 }
0133
0134 inline bool operator<(const uint16_t& firstStrip, const SiStripCluster& cluster) {
0135 return firstStrip < cluster.firstStrip();
0136 }
0137 #endif