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