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 
11 #include <vector>
12 #include <cstdint>
13 #include <cassert>
14 
15 
17 
18 public:
19 
21  static constexpr uint8_t MAXSPAN=255;
22  static constexpr uint8_t MAXCOL=155;
23  static constexpr uint8_t MAXROW=159;
24 
25 
26 CTPPSPixelCluster(uint16_t isize, uint16_t * adcs,
27  uint8_t const * rowpos, uint8_t const * colpos ) :
28  thePixelOffset(2*isize), // the pixel offset is the pixel position inside the cluster wrt rowmin (even positions) and colmin (odd positions)
29  thePixelADC(adcs, adcs+isize)
30  {
31 
32  uint8_t maxCol = 0;
33  uint8_t maxRow = 0;
34  uint8_t rowmin = MAXROW;
35  uint8_t colmin = MAXCOL;
36  for (unsigned int j=0; j!=isize; ++j) {
37  rowmin = std::min(rowpos[j],rowmin);
38  colmin = std::min(colpos[j],colmin);
39  }
40  for (unsigned int i=0; i!=isize; ++i) {
41  uint8_t rowoffset = rowpos[i]-rowmin;
42  uint8_t coloffset = colpos[i]-colmin;
43  thePixelOffset[i*2] = std::min(MAXSPAN, rowoffset);
44  thePixelOffset[i*2+1] = std::min(MAXSPAN, coloffset);
45  if (rowoffset > maxRow) maxRow = rowoffset;
46  if (coloffset > maxCol) maxCol = coloffset;
47  }
48 
49 
50  theMinPixelRow = rowmin;
51  thePixelRowSpan = std::min(maxRow, MAXSPAN);
52 
53  theMinPixelCol = colmin;
54  thePixelColSpan = std::min(maxCol, MAXSPAN);
55  }
56 
57 // barycenter
58 
59  float avg_row() const {
60  float qm = 0.0;
61  unsigned int isize = thePixelADC.size();
62  for (unsigned int i=0; i<isize; ++i)
63  qm += float(thePixelADC[i]) * (thePixelOffset[i*2] + theMinPixelRow + 0.5f);
64  return qm/charge();
65  }
66 
67  float avg_col() const {
68  float qm = 0.0;
69  unsigned int isize = thePixelADC.size();
70  for (unsigned int i=0; i<isize; ++i)
71  qm += float(thePixelADC[i]) * (thePixelOffset[i*2+1] + theMinPixelCol + 0.5f);
72  return qm/charge();
73  }
74 
75 //cluster charge
76 
77  inline float charge() const {
78  float qm = 0.0;
79  unsigned int isize = thePixelADC.size();
80  for (unsigned int i=0; i<isize; ++i)
81  qm += float(thePixelADC[i]);
82  return qm;
83  }
84 
85  // Return number of pixels.
86  unsigned int size() const { return thePixelADC.size();}
87 
88  // Return cluster dimension in rows
89  unsigned int sizeRow() const { return thePixelRowSpan +1;}
90 
91  // Return cluster dimension in columns
92  unsigned int sizeCol() const { return thePixelColSpan +1;}
93 
94  inline unsigned int minPixelRow() const { return theMinPixelRow;}
95  inline unsigned int minPixelCol() const { return theMinPixelCol;}
96 
97 
98  inline unsigned int colSpan() const {return thePixelColSpan; }
99  inline unsigned int rowSpan() const { return thePixelRowSpan; }
100 
101  const std::vector<uint8_t> & pixelOffset() const { return thePixelOffset;}
102  const std::vector<uint16_t> & pixelADC() const { return thePixelADC;}
103 
104  unsigned int pixelRow(unsigned int i) const {
105  return theMinPixelRow + thePixelOffset[i*2];
106  }
107  unsigned int pixelCol(unsigned int i) const {
108  return theMinPixelCol + thePixelOffset[i*2+1];
109  }
110  unsigned int pixelADC(unsigned int i) const {
111  return thePixelADC[i];
112  }
113 
114 private:
115 
116  std::vector<uint8_t> thePixelOffset;
117  std::vector<uint16_t> thePixelADC;
118 
119 
122  uint8_t thePixelRowSpan=0;
123  uint8_t thePixelColSpan=0;
124 
125 };
126 
127 inline bool operator<( const CTPPSPixelCluster& one, const CTPPSPixelCluster& two) {
128  if ( one.minPixelRow() < two.minPixelRow() ) {
129  return true;
130  } else if ( one.minPixelRow() > two.minPixelRow() ) {
131  return false;
132  } else if ( one.minPixelCol() < two.minPixelCol() ) {
133  return true;
134  } else {
135  return false;
136  }
137 }
138 
139 #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
#define constexpr
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
unsigned int pixelCol(unsigned int i) const
float avg_row() const