CMS 3D CMS Logo

SiPixelCluster.h
Go to the documentation of this file.
1 #ifndef DataFormats_SiPixel_Cluster_SiPixelCluster_h
2 #define DataFormats_SiPixel_Cluster_SiPixelCluster_h
3 
4 //---------------------------------------------------------------------------
19 //---------------------------------------------------------------------------
20 
21 #include <vector>
22 #include <cstdint>
23 #include <cassert>
24 #include <limits>
25 
26 class PixelDigi;
27 
29 public:
30  // FIXME make it POD
31  class Pixel {
32  public:
33  constexpr Pixel() : x(0), y(0), adc(0) {} // for root
34  constexpr Pixel(int pix_x, int pix_y, int pix_adc) : x(pix_x), y(pix_y), adc(pix_adc) {}
35  uint16_t x;
36  uint16_t y;
37  uint16_t adc;
38  };
39 
40  //--- Integer shift in x and y directions.
41  // FIXME make it POD
42  class Shift {
43  public:
44  constexpr Shift(int dx, int dy) : dx_(dx), dy_(dy) {}
45  constexpr Shift() : dx_(0), dy_(0) {}
46  constexpr int dx() const { return dx_; }
47  constexpr int dy() const { return dy_; }
48 
49  private:
50  int dx_;
51  int dy_;
52  };
53 
54  //--- Position of a SiPixel
55  // FIXME make it POD
56  class PixelPos {
57  public:
58  constexpr PixelPos() : row_(0), col_(0) {}
59  constexpr PixelPos(int row, int col) : row_(row), col_(col) {}
60  constexpr int row() const { return row_; }
61  constexpr int col() const { return col_; }
62  constexpr PixelPos operator+(const Shift& shift) const { return PixelPos(row() + shift.dx(), col() + shift.dy()); }
63 
64  private:
65  int row_;
66  int col_;
67  };
68 
69  typedef std::vector<PixelDigi>::const_iterator PixelDigiIter;
70  typedef std::pair<PixelDigiIter, PixelDigiIter> PixelDigiRange;
71 
72  static constexpr unsigned int MAXSPAN = 255;
73  static constexpr unsigned int MAXPOS = 2047;
74 
76 
81  SiPixelCluster() = default;
82  ~SiPixelCluster() = default;
83  SiPixelCluster(SiPixelCluster const&) = default;
84  SiPixelCluster(SiPixelCluster&&) = default;
85  SiPixelCluster& operator=(SiPixelCluster const&) = default;
87 
88  SiPixelCluster(unsigned int isize,
89  uint16_t const* adcs,
90  uint16_t const* xpos,
91  uint16_t const* ypos,
92  uint16_t xmin,
93  uint16_t ymin,
94  uint16_t id = invalidClusterId)
95  : thePixelOffset(2 * isize), thePixelADC(adcs, adcs + isize), theOriginalClusterId(id) {
96  uint16_t maxCol = 0;
97  uint16_t maxRow = 0;
98  for (unsigned int i = 0; i < isize; ++i) {
99  uint16_t xoffset = xpos[i] - xmin;
100  uint16_t yoffset = ypos[i] - ymin;
101  thePixelOffset[i * 2] = std::min(uint16_t(MAXSPAN), xoffset);
102  thePixelOffset[i * 2 + 1] = std::min(uint16_t(MAXSPAN), yoffset);
103  if (xoffset > maxRow)
104  maxRow = xoffset;
105  if (yoffset > maxCol)
106  maxCol = yoffset;
107  }
108  packRow(xmin, maxRow);
109  packCol(ymin, maxCol);
110  }
111 
112  // obsolete (only for regression tests)
113  SiPixelCluster(const PixelPos& pix, int adc);
114  void add(const PixelPos& pix, int adc);
115 
116  // Analog linear average position (barycenter)
117  float x() const {
118  float qm = 0.0;
119  int isize = thePixelADC.size();
120  for (int i = 0; i < isize; ++i)
121  qm += float(thePixelADC[i]) * (thePixelOffset[i * 2] + minPixelRow() + 0.5f);
122  return qm / charge();
123  }
124 
125  float y() const {
126  float qm = 0.0;
127  int isize = thePixelADC.size();
128  for (int i = 0; i < isize; ++i)
129  qm += float(thePixelADC[i]) * (thePixelOffset[i * 2 + 1] + minPixelCol() + 0.5f);
130  return qm / charge();
131  }
132 
133  // Return number of pixels.
134  int size() const { return thePixelADC.size(); }
135 
136  // Return cluster dimension in the x direction.
137  int sizeX() const { return rowSpan() + 1; }
138 
139  // Return cluster dimension in the y direction.
140  int sizeY() const { return colSpan() + 1; }
141 
142  inline int charge() const {
143  int qm = 0;
144  int isize = thePixelADC.size();
145  for (int i = 0; i < isize; ++i)
146  qm += thePixelADC[i];
147  return qm;
148  } // Return total cluster charge.
149 
150  inline int minPixelRow() const { return theMinPixelRow; } // The min x index.
151  inline int maxPixelRow() const { return minPixelRow() + rowSpan(); } // The max x index.
152  inline int minPixelCol() const { return theMinPixelCol; } // The min y index.
153  inline int maxPixelCol() const { return minPixelCol() + colSpan(); } // The max y index.
154 
155  const std::vector<uint8_t>& pixelOffset() const { return thePixelOffset; }
156  const std::vector<uint16_t>& pixelADC() const { return thePixelADC; }
157 
158  // obsolete, use single pixel access below
159  const std::vector<Pixel> pixels() const {
160  std::vector<Pixel> oldPixVector;
161  int isize = thePixelADC.size();
162  oldPixVector.reserve(isize);
163  for (int i = 0; i < isize; ++i) {
164  oldPixVector.push_back(pixel(i));
165  }
166  return oldPixVector;
167  }
168 
169  // infinite faster than above...
170  Pixel pixel(int i) const {
171  return Pixel(minPixelRow() + thePixelOffset[i * 2], minPixelCol() + thePixelOffset[i * 2 + 1], thePixelADC[i]);
172  }
173 
174 private:
175  static int overflow_(uint16_t span) { return span == uint16_t(MAXSPAN); }
176 
177 public:
178  int colSpan() const { return thePixelColSpan; }
179 
180  int rowSpan() const { return thePixelRowSpan; }
181 
182  bool overflowCol() const { return overflow_(thePixelColSpan); }
183 
184  bool overflowRow() const { return overflow_(thePixelRowSpan); }
185 
186  bool overflow() const { return overflowCol() || overflowRow(); }
187 
188  void packCol(uint16_t ymin, uint16_t yspan) {
190  thePixelColSpan = std::min(yspan, uint16_t(MAXSPAN));
191  }
192  void packRow(uint16_t xmin, uint16_t xspan) {
194  thePixelRowSpan = std::min(xspan, uint16_t(MAXSPAN));
195  }
196 
197  // ggiurgiu@fnal.gov, 01/05/12
198  // Getters and setters for the newly added data members (err_x and err_y). See below.
199  void setSplitClusterErrorX(float errx) { err_x = errx; }
200  void setSplitClusterErrorY(float erry) { err_y = erry; }
201  float getSplitClusterErrorX() const { return err_x; }
202  float getSplitClusterErrorY() const { return err_y; }
203 
204  // the original id (they get sorted)
205  auto originalId() const { return theOriginalClusterId; }
206  void setOriginalId(uint16_t id) { theOriginalClusterId = id; }
207 
208 private:
209  std::vector<uint8_t> thePixelOffset;
210  std::vector<uint16_t> thePixelADC;
211 
212  uint16_t theMinPixelRow = MAXPOS; // Minimum pixel index in the x direction (low edge).
213  uint16_t theMinPixelCol = MAXPOS; // Minimum pixel index in the y direction (left edge).
214  uint8_t thePixelRowSpan = 0; // Span pixel index in the x direction (low edge).
215  uint8_t thePixelColSpan = 0; // Span pixel index in the y direction (left edge).
216 
218 
219  float err_x = -99999.9f;
220  float err_y = -99999.9f;
221 };
222 
223 // Comparison operators (needed by DetSetVector)
224 inline bool operator<(const SiPixelCluster& one, const SiPixelCluster& other) {
225  if (one.minPixelRow() < other.minPixelRow()) {
226  return true;
227  } else if (one.minPixelRow() > other.minPixelRow()) {
228  return false;
229  } else if (one.minPixelCol() < other.minPixelCol()) {
230  return true;
231  } else {
232  return false;
233  }
234 }
235 
240 
245 
248 #endif
edm::RefProd
Definition: EDProductfwd.h:25
edm::DetSetVector
Definition: DetSetVector.h:61
SiPixelCluster::theMinPixelRow
uint16_t theMinPixelRow
Definition: SiPixelCluster.h:212
SiPixelCluster::minPixelCol
int minPixelCol() const
Definition: SiPixelCluster.h:152
EcalSCDynamicDPhiParametersESProducer_cfi.yoffset
yoffset
Definition: EcalSCDynamicDPhiParametersESProducer_cfi.py:10
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
SiPixelCluster::invalidClusterId
static constexpr uint16_t invalidClusterId
Definition: SiPixelCluster.h:75
SiPixelCluster::PixelPos::PixelPos
constexpr PixelPos()
Definition: SiPixelCluster.h:58
SiPixelCluster::packCol
void packCol(uint16_t ymin, uint16_t yspan)
Definition: SiPixelCluster.h:188
SiPixelCluster::overflowRow
bool overflowRow() const
Definition: SiPixelCluster.h:184
min
T min(T a, T b)
Definition: MathUtil.h:58
EcalSCDynamicDPhiParametersESProducer_cfi.xoffset
xoffset
Definition: EcalSCDynamicDPhiParametersESProducer_cfi.py:12
SiPixelClusterCollectionNew
edmNew::DetSetVector< SiPixelCluster > SiPixelClusterCollectionNew
Definition: SiPixelCluster.h:246
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
SiPixelCluster::y
float y() const
Definition: SiPixelCluster.h:125
SiPixelCluster::operator=
SiPixelCluster & operator=(SiPixelCluster const &)=default
SiPixelCluster::maxPixelCol
int maxPixelCol() const
Definition: SiPixelCluster.h:153
PixelDigi
Definition: PixelDigi.h:14
SiPixelCluster::PixelPos::col_
int col_
Definition: SiPixelCluster.h:66
SiPixelCluster::maxPixelRow
int maxPixelRow() const
Definition: SiPixelCluster.h:151
operator<
bool operator<(const SiPixelCluster &one, const SiPixelCluster &other)
Definition: SiPixelCluster.h:224
SiPixelCluster::rowSpan
int rowSpan() const
Definition: SiPixelCluster.h:180
SiPixelCluster::MAXSPAN
static constexpr unsigned int MAXSPAN
Definition: SiPixelCluster.h:72
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
SiPixelCluster::Shift::Shift
constexpr Shift(int dx, int dy)
Definition: SiPixelCluster.h:44
SiPixelClusterRef
edm::Ref< SiPixelClusterCollection, SiPixelCluster > SiPixelClusterRef
Definition: SiPixelCluster.h:242
SiPixelCluster::theOriginalClusterId
uint16_t theOriginalClusterId
Definition: SiPixelCluster.h:217
SiPixelCluster::theMinPixelCol
uint16_t theMinPixelCol
Definition: SiPixelCluster.h:213
SiPixelCluster::PixelDigiRange
std::pair< PixelDigiIter, PixelDigiIter > PixelDigiRange
Definition: SiPixelCluster.h:70
SiPixelCluster::Pixel
Definition: SiPixelCluster.h:31
DetSetRefVector.h
edm::Ref
Definition: AssociativeIterator.h:58
SiPixelCluster::overflowCol
bool overflowCol() const
Definition: SiPixelCluster.h:182
SiPixelCluster::colSpan
int colSpan() const
Definition: SiPixelCluster.h:178
SiPixelCluster::getSplitClusterErrorX
float getSplitClusterErrorX() const
Definition: SiPixelCluster.h:201
SiPixelCluster::sizeY
int sizeY() const
Definition: SiPixelCluster.h:140
SiPixelCluster::overflow
bool overflow() const
Definition: SiPixelCluster.h:186
SiPixelCluster::Pixel::adc
uint16_t adc
Definition: SiPixelCluster.h:37
SiPixelCluster::add
void add(const PixelPos &pix, int adc)
Definition: SiPixelCluster.cc:25
SiPixelClusterRefVector
edm::DetSetRefVector< SiPixelCluster > SiPixelClusterRefVector
Definition: SiPixelCluster.h:243
SiPixelCluster::PixelDigiIter
std::vector< PixelDigi >::const_iterator PixelDigiIter
Definition: SiPixelCluster.h:69
SiPixelCluster::thePixelColSpan
uint8_t thePixelColSpan
Definition: SiPixelCluster.h:215
SiPixelCluster::overflow_
static int overflow_(uint16_t span)
Definition: SiPixelCluster.h:175
SiPixelCluster::minPixelRow
int minPixelRow() const
Definition: SiPixelCluster.h:150
SiPixelCluster::Shift::dx
constexpr int dx() const
Definition: SiPixelCluster.h:46
SiPixelCluster::SiPixelCluster
SiPixelCluster(unsigned int isize, uint16_t const *adcs, uint16_t const *xpos, uint16_t const *ypos, uint16_t xmin, uint16_t ymin, uint16_t id=invalidClusterId)
Definition: SiPixelCluster.h:88
SiPixelCluster::thePixelRowSpan
uint8_t thePixelRowSpan
Definition: SiPixelCluster.h:214
SiPixelCluster::err_y
float err_y
Definition: SiPixelCluster.h:220
trackingPlots.other
other
Definition: trackingPlots.py:1464
SiPixelCluster::PixelPos::operator+
constexpr PixelPos operator+(const Shift &shift) const
Definition: SiPixelCluster.h:62
SiPixelCluster::pixelADC
const std::vector< uint16_t > & pixelADC() const
Definition: SiPixelCluster.h:156
SiPixelCluster::setSplitClusterErrorX
void setSplitClusterErrorX(float errx)
Definition: SiPixelCluster.h:199
SiPixelCluster::err_x
float err_x
Definition: SiPixelCluster.h:219
SiPixelCluster::Pixel::Pixel
constexpr Pixel(int pix_x, int pix_y, int pix_adc)
Definition: SiPixelCluster.h:34
SiPixelCluster::thePixelADC
std::vector< uint16_t > thePixelADC
Definition: SiPixelCluster.h:210
SiPixelCluster::Shift::dy
constexpr int dy() const
Definition: SiPixelCluster.h:47
SiPixelCluster::x
float x() const
Definition: SiPixelCluster.h:117
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiPixelCluster::PixelPos::PixelPos
constexpr PixelPos(int row, int col)
Definition: SiPixelCluster.h:59
SiPixelCluster::Shift::dy_
int dy_
Definition: SiPixelCluster.h:51
SiPixelCluster::getSplitClusterErrorY
float getSplitClusterErrorY() const
Definition: SiPixelCluster.h:202
SiPixelCluster::Shift
Definition: SiPixelCluster.h:42
SiPixelCluster::Pixel::y
uint16_t y
Definition: SiPixelCluster.h:36
SiPixelCluster::setOriginalId
void setOriginalId(uint16_t id)
Definition: SiPixelCluster.h:206
SiPixelCluster::thePixelOffset
std::vector< uint8_t > thePixelOffset
Definition: SiPixelCluster.h:209
SiPixelCluster::size
int size() const
Definition: SiPixelCluster.h:134
SiPixelCluster::pixel
Pixel pixel(int i) const
Definition: SiPixelCluster.h:170
DetSetVector.h
SiPixelCluster::MAXPOS
static constexpr unsigned int MAXPOS
Definition: SiPixelCluster.h:73
SiPixelCluster::packRow
void packRow(uint16_t xmin, uint16_t xspan)
Definition: SiPixelCluster.h:192
SiPixelCluster::PixelPos::row_
int row_
Definition: SiPixelCluster.h:65
SiPixelCluster::setSplitClusterErrorY
void setSplitClusterErrorY(float erry)
Definition: SiPixelCluster.h:200
SiPixelClusterRefProd
edm::RefProd< SiPixelClusterCollection > SiPixelClusterRefProd
Definition: SiPixelCluster.h:244
edmNew::DetSetVector
Definition: DetSetNew.h:13
Ref.h
L1TOccupancyClient_cfi.ymin
ymin
Definition: L1TOccupancyClient_cfi.py:43
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
edm::DetSetRefVector
Definition: DetSetRefVector.h:50
SiPixelCluster::~SiPixelCluster
~SiPixelCluster()=default
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
SiPixelClusterCollection
edm::DetSetVector< SiPixelCluster > SiPixelClusterCollection
Definition: SiPixelCluster.h:241
SiPixelCluster::PixelPos::row
constexpr int row() const
Definition: SiPixelCluster.h:60
SiPixelCluster::Shift::Shift
constexpr Shift()
Definition: SiPixelCluster.h:45
SiPixelCluster::charge
int charge() const
Definition: SiPixelCluster.h:142
align::Pixel
Definition: StructureType.h:68
SiPixelCluster::pixelOffset
const std::vector< uint8_t > & pixelOffset() const
Definition: SiPixelCluster.h:155
SiPixelCluster::pixels
const std::vector< Pixel > pixels() const
Definition: SiPixelCluster.h:159
SiPixelCluster::Pixel::x
uint16_t x
Definition: SiPixelCluster.h:35
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10
SiPixelCluster::originalId
auto originalId() const
Definition: SiPixelCluster.h:205
SiPixelCluster::SiPixelCluster
SiPixelCluster()=default
SiPixelCluster::sizeX
int sizeX() const
Definition: SiPixelCluster.h:137
SiPixelCluster::PixelPos
Definition: SiPixelCluster.h:56
DetSetVectorNew.h
SiPixelClusterRefNew
edm::Ref< SiPixelClusterCollectionNew, SiPixelCluster > SiPixelClusterRefNew
Definition: SiPixelCluster.h:247
SiPixelCluster::Pixel::Pixel
constexpr Pixel()
Definition: SiPixelCluster.h:33
SiPixelCluster::PixelPos::col
constexpr int col() const
Definition: SiPixelCluster.h:61
SiPixelCluster::Shift::dx_
int dx_
Definition: SiPixelCluster.h:50