CMS 3D CMS Logo

CTPPSPixelCluster.h
Go to the documentation of this file.
1 #ifndef DataFormats_CTPPS_CTPPSPixelCluster_h
2 #define DataFormats_CTPPS_CTPPSPixelCluster_h
3 
4 /*
5  \class CTPPSPixelCluster
6  \brief CTPPSPixelCluster stores the information of CTPPS Tracker clusters of 3D pixels
7  Author: F.Ferro - INFN Genova - 2016
8 */
9 
10 #include <vector>
11 #include <cstdint>
12 #include <cassert>
13 
15 public:
17  static constexpr uint8_t MAXSPAN = 255;
18  static constexpr uint8_t MAXCOL = 155;
19  static constexpr uint8_t MAXROW = 159;
20 
21  CTPPSPixelCluster(uint16_t isize, uint16_t* adcs, uint8_t const* rowpos, uint8_t const* colpos)
23  2 *
24  isize), // the pixel offset is the pixel position inside the cluster wrt rowmin (even positions) and colmin (odd positions)
25  thePixelADC(adcs, adcs + isize) {
26  uint8_t maxCol = 0;
27  uint8_t maxRow = 0;
28  uint8_t rowmin = MAXROW;
29  uint8_t colmin = MAXCOL;
30  for (unsigned int j = 0; j != isize; ++j) {
31  rowmin = std::min(rowpos[j], rowmin);
32  colmin = std::min(colpos[j], colmin);
33  }
34  for (unsigned int i = 0; i != isize; ++i) {
35  uint8_t rowoffset = rowpos[i] - rowmin;
36  uint8_t coloffset = colpos[i] - colmin;
37  thePixelOffset[i * 2] = std::min(MAXSPAN, rowoffset);
38  thePixelOffset[i * 2 + 1] = std::min(MAXSPAN, coloffset);
39  if (rowoffset > maxRow)
40  maxRow = rowoffset;
41  if (coloffset > maxCol)
42  maxCol = coloffset;
43  }
44 
45  theMinPixelRow = rowmin;
46  thePixelRowSpan = std::min(maxRow, MAXSPAN);
47 
48  theMinPixelCol = colmin;
49  thePixelColSpan = std::min(maxCol, MAXSPAN);
50  }
51 
52  // barycenter
53 
54  float avg_row() const {
55  float qm = 0.0;
56  unsigned int isize = thePixelADC.size();
57  for (unsigned int i = 0; i < isize; ++i)
58  qm += float(thePixelADC[i]) * (thePixelOffset[i * 2] + theMinPixelRow + 0.5f);
59  return qm / charge();
60  }
61 
62  float avg_col() const {
63  float qm = 0.0;
64  unsigned int isize = thePixelADC.size();
65  for (unsigned int i = 0; i < isize; ++i)
66  qm += float(thePixelADC[i]) * (thePixelOffset[i * 2 + 1] + theMinPixelCol + 0.5f);
67  return qm / charge();
68  }
69 
70  //cluster charge
71 
72  inline float charge() const {
73  float qm = 0.0;
74  unsigned int isize = thePixelADC.size();
75  for (unsigned int i = 0; i < isize; ++i)
76  qm += float(thePixelADC[i]);
77  return qm;
78  }
79 
80  // Return number of pixels.
81  unsigned int size() const { return thePixelADC.size(); }
82 
83  // Return cluster dimension in rows
84  unsigned int sizeRow() const { return thePixelRowSpan + 1; }
85 
86  // Return cluster dimension in columns
87  unsigned int sizeCol() const { return thePixelColSpan + 1; }
88 
89  inline unsigned int minPixelRow() const { return theMinPixelRow; }
90  inline unsigned int minPixelCol() const { return theMinPixelCol; }
91 
92  inline unsigned int colSpan() const { return thePixelColSpan; }
93  inline unsigned int rowSpan() const { return thePixelRowSpan; }
94 
95  const std::vector<uint8_t>& pixelOffset() const { return thePixelOffset; }
96  const std::vector<uint16_t>& pixelADC() const { return thePixelADC; }
97 
98  unsigned int pixelRow(unsigned int i) const { return theMinPixelRow + thePixelOffset[i * 2]; }
99  unsigned int pixelCol(unsigned int i) const { return theMinPixelCol + thePixelOffset[i * 2 + 1]; }
100  unsigned int pixelADC(unsigned int i) const { return thePixelADC[i]; }
101 
102 private:
103  std::vector<uint8_t> thePixelOffset;
104  std::vector<uint16_t> thePixelADC;
105 
108  uint8_t thePixelRowSpan = 0;
109  uint8_t thePixelColSpan = 0;
110 };
111 
112 inline bool operator<(const CTPPSPixelCluster& one, const CTPPSPixelCluster& two) {
113  if (one.minPixelRow() < two.minPixelRow()) {
114  return true;
115  } else if (one.minPixelRow() > two.minPixelRow()) {
116  return false;
117  } else if (one.minPixelCol() < two.minPixelCol()) {
118  return true;
119  } else {
120  return false;
121  }
122 }
123 
124 #endif
float charge() const
unsigned int rowSpan() const
std::vector< uint16_t > thePixelADC
std::vector< uint8_t > thePixelOffset
unsigned int size() const
unsigned int colSpan() const
unsigned int minPixelCol() const
const std::vector< uint16_t > & pixelADC() const
unsigned int pixelRow(unsigned int i) const
unsigned int sizeCol() const
T min(T a, T b)
Definition: MathUtil.h:58
unsigned int minPixelRow() const
const std::vector< uint8_t > & pixelOffset() const
CTPPSPixelCluster(uint16_t isize, uint16_t *adcs, uint8_t const *rowpos, uint8_t const *colpos)
static constexpr uint8_t MAXROW
float avg_col() const
static constexpr uint8_t MAXCOL
unsigned int sizeRow() const
bool operator<(const CTPPSPixelCluster &one, const CTPPSPixelCluster &two)
static constexpr uint8_t MAXSPAN
unsigned int pixelADC(unsigned int i) const
#define constexpr
unsigned int pixelCol(unsigned int i) const
float avg_row() const