File indexing completed on 2024-04-06 12:04:01
0001 #ifndef DataFormats_CTPPS_CTPPSPixelCluster_h
0002 #define DataFormats_CTPPS_CTPPSPixelCluster_h
0003
0004
0005
0006
0007
0008
0009
0010 #include <vector>
0011 #include <cstdint>
0012 #include <cassert>
0013
0014 class CTPPSPixelCluster {
0015 public:
0016 CTPPSPixelCluster() {}
0017 static constexpr uint8_t MAXSPAN = 255;
0018 static constexpr uint8_t MAXCOL = 155;
0019 static constexpr uint8_t MAXROW = 159;
0020
0021 CTPPSPixelCluster(uint16_t isize, uint16_t* adcs, uint8_t const* rowpos, uint8_t const* colpos)
0022 : thePixelOffset(
0023 2 *
0024 isize),
0025 thePixelADC(adcs, adcs + isize) {
0026 uint8_t maxCol = 0;
0027 uint8_t maxRow = 0;
0028 uint8_t rowmin = MAXROW;
0029 uint8_t colmin = MAXCOL;
0030 for (unsigned int j = 0; j != isize; ++j) {
0031 rowmin = std::min(rowpos[j], rowmin);
0032 colmin = std::min(colpos[j], colmin);
0033 }
0034 for (unsigned int i = 0; i != isize; ++i) {
0035 uint8_t rowoffset = rowpos[i] - rowmin;
0036 uint8_t coloffset = colpos[i] - colmin;
0037 thePixelOffset[i * 2] = std::min(MAXSPAN, rowoffset);
0038 thePixelOffset[i * 2 + 1] = std::min(MAXSPAN, coloffset);
0039 if (rowoffset > maxRow)
0040 maxRow = rowoffset;
0041 if (coloffset > maxCol)
0042 maxCol = coloffset;
0043 }
0044
0045 theMinPixelRow = rowmin;
0046 thePixelRowSpan = std::min(maxRow, MAXSPAN);
0047
0048 theMinPixelCol = colmin;
0049 thePixelColSpan = std::min(maxCol, MAXSPAN);
0050 }
0051
0052
0053
0054 float avg_row() const {
0055 float qm = 0.0;
0056 unsigned int isize = thePixelADC.size();
0057 for (unsigned int i = 0; i < isize; ++i)
0058 qm += float(thePixelADC[i]) * (thePixelOffset[i * 2] + theMinPixelRow + 0.5f);
0059 return qm / charge();
0060 }
0061
0062 float avg_col() const {
0063 float qm = 0.0;
0064 unsigned int isize = thePixelADC.size();
0065 for (unsigned int i = 0; i < isize; ++i)
0066 qm += float(thePixelADC[i]) * (thePixelOffset[i * 2 + 1] + theMinPixelCol + 0.5f);
0067 return qm / charge();
0068 }
0069
0070
0071
0072 inline float charge() const {
0073 float qm = 0.0;
0074 unsigned int isize = thePixelADC.size();
0075 for (unsigned int i = 0; i < isize; ++i)
0076 qm += float(thePixelADC[i]);
0077 return qm;
0078 }
0079
0080
0081 unsigned int size() const { return thePixelADC.size(); }
0082
0083
0084 unsigned int sizeRow() const { return thePixelRowSpan + 1; }
0085
0086
0087 unsigned int sizeCol() const { return thePixelColSpan + 1; }
0088
0089 inline unsigned int minPixelRow() const { return theMinPixelRow; }
0090 inline unsigned int minPixelCol() const { return theMinPixelCol; }
0091
0092 inline unsigned int colSpan() const { return thePixelColSpan; }
0093 inline unsigned int rowSpan() const { return thePixelRowSpan; }
0094
0095 const std::vector<uint8_t>& pixelOffset() const { return thePixelOffset; }
0096 const std::vector<uint16_t>& pixelADC() const { return thePixelADC; }
0097
0098 unsigned int pixelRow(unsigned int i) const { return theMinPixelRow + thePixelOffset[i * 2]; }
0099 unsigned int pixelCol(unsigned int i) const { return theMinPixelCol + thePixelOffset[i * 2 + 1]; }
0100 unsigned int pixelADC(unsigned int i) const { return thePixelADC[i]; }
0101
0102 private:
0103 std::vector<uint8_t> thePixelOffset;
0104 std::vector<uint16_t> thePixelADC;
0105
0106 uint8_t theMinPixelRow = MAXROW;
0107 uint8_t theMinPixelCol = MAXCOL;
0108 uint8_t thePixelRowSpan = 0;
0109 uint8_t thePixelColSpan = 0;
0110 };
0111
0112 inline bool operator<(const CTPPSPixelCluster& one, const CTPPSPixelCluster& two) {
0113 if (one.minPixelRow() < two.minPixelRow()) {
0114 return true;
0115 } else if (one.minPixelRow() > two.minPixelRow()) {
0116 return false;
0117 } else if (one.minPixelCol() < two.minPixelCol()) {
0118 return true;
0119 } else {
0120 return false;
0121 }
0122 }
0123
0124 #endif