CMS 3D CMS Logo

Phase2ITPixelCluster.h
Go to the documentation of this file.
1 #ifndef DataFormats_Phase2ITPixelCluster_Phase2ITPixelCluster_h
2 #define DataFormats_Phase2ITPixelCluster_Phase2ITPixelCluster_h
3 
4 //---------------------------------------------------------------------------
12 //---------------------------------------------------------------------------
13 
14 #include <vector>
16 
17 
18 #include <cstdint>
19 #include <cassert>
20 
21 class PixelDigi;
22 
24 public:
25 
26  class Pixel {
27  public:
28  constexpr Pixel() : x(0), y(0), adc(0){} // for root
29  constexpr Pixel(uint32_t pix_x, uint32_t pix_y, uint32_t pix_adc) :
30  x(pix_x), y(pix_y), adc(pix_adc) {}
31  uint32_t x;
32  uint32_t y;
33  uint32_t adc;
34  };
35 
36  //--- Integer shift in x and y directions.
37  class Shift {
38  public:
39  constexpr Shift( int dx, int dy) : dx_(dx), dy_(dy) {}
40  constexpr Shift() : dx_(0), dy_(0) {}
41  constexpr int dx() const { return dx_;}
42  constexpr int dy() const { return dy_;}
43  private:
44  int dx_;
45  int dy_;
46  };
47 
48  //--- Position of a SiPixel
49  class PixelPos {
50  public:
51  constexpr PixelPos() : row_(0), col_(0) {}
52  constexpr PixelPos(int row, int col) : row_(row) , col_(col) {}
53  constexpr uint32_t row() const { return row_;}
54  constexpr uint32_t col() const { return col_;}
56  return PixelPos( row() + shift.dx(), col() + shift.dy());
57  }
58  private:
59  uint32_t row_;
60  uint32_t col_;
61  };
62 
63  typedef std::vector<PixelDigi>::const_iterator PixelDigiIter;
64  typedef std::pair<PixelDigiIter,PixelDigiIter> PixelDigiRange;
65 
66  static constexpr unsigned int POSBITS=20;
67  static constexpr unsigned int SPANBITS=12;
68  static constexpr unsigned int MAXSPAN=255;
69  static constexpr unsigned int MAXPOS=2047;
70 
75  Phase2ITPixelCluster() : thePixelRow(MAXPOS), thePixelCol(MAXPOS), err_x(-99999.9), err_y(-99999.9) {} // needed by many....
76 
77  Phase2ITPixelCluster(unsigned int isize, uint32_t const * adcs,
78  uint32_t const * xpos, uint32_t const * ypos,
79  uint32_t const xmin, uint32_t const ymin) :
80  thePixelOffset(2*isize), thePixelADC(adcs,adcs+isize), err_x(-99999.9), err_y(-99999.9) {
81  uint32_t maxCol = 0;
82  uint32_t maxRow = 0;
83  for (unsigned int i=0; i!=isize; ++i) {
84  uint32_t xoffset = xpos[i]-xmin;
85  uint32_t yoffset = ypos[i]-ymin;
86  thePixelOffset[i*2] = std::min(uint32_t(MAXSPAN),xoffset);
87  thePixelOffset[i*2+1] = std::min(uint32_t(MAXSPAN),yoffset);
88  if (xoffset > maxRow) maxRow = xoffset;
89  if (yoffset > maxCol) maxCol = yoffset;
90  }
91  packRow(xmin,maxRow);
92  packCol(ymin,maxCol);
93  }
94 
95 
96  // obsolete (only for regression tests)
97  Phase2ITPixelCluster( const PixelPos& pix, uint32_t adc);
98  void add( const PixelPos& pix, uint32_t adc);
99 
100  // Analog linear average position (barycenter)
101  float x() const {
102  float qm = 0.0;
103  int isize = thePixelADC.size();
104  for (int i=0; i<isize; ++i)
105  qm += float(thePixelADC[i]) * (thePixelOffset[i*2] + minPixelRow() + 0.5f);
106  return qm/charge();
107  }
108 
109  float y() const {
110  float qm = 0.0;
111  int isize = thePixelADC.size();
112  for (int i=0; i<isize; ++i)
113  qm += float(thePixelADC[i]) * (thePixelOffset[i*2+1] + minPixelCol() + 0.5f);
114  return qm/charge();
115  }
116 
117  // Return number of pixels.
118  int size() const { return thePixelADC.size();}
119 
120  // Return cluster dimension in the x direction.
121  int sizeX() const {verifyVersion(); return rowSpan() +1;}
122 
123  // Return cluster dimension in the y direction.
124  int sizeY() const {verifyVersion(); return colSpan() +1;}
125 
126 
127  inline float charge() const {
128  float qm = 0.0;
129  int isize = thePixelADC.size();
130  for (int i=0; i<isize; ++i)
131  qm += float(thePixelADC[i]);
132  return qm;
133  } // Return total cluster charge.
134 
135  inline uint32_t minPixelRow() const { return thePixelRow&MAXPOS;} // The min x index.
136  inline uint32_t maxPixelRow() const { verifyVersion(); return minPixelRow() + rowSpan();} // The max x index.
137  inline uint32_t minPixelCol() const { return thePixelCol&MAXPOS;} // The min y index.
138  inline uint32_t maxPixelCol() const { verifyVersion(); return minPixelCol() + colSpan();} // The max y index.
139 
140 
141  const std::vector<uint16_t> & pixelOffset() const { return thePixelOffset;}
142  const std::vector<uint32_t> & pixelADC() const { return thePixelADC;}
143 
144  // obsolete, use single pixel access below
145  const std::vector<Pixel> pixels() const {
146  std::vector<Pixel> oldPixVector;
147  int isize = thePixelADC.size();
148  oldPixVector.reserve(isize);
149  for(int i=0; i<isize; ++i) {
150  oldPixVector.push_back(pixel(i));
151  }
152  return oldPixVector;
153  }
154 
155  // infinite faster than above...
156  Pixel pixel(int i) const {
157  return Pixel(minPixelRow() + thePixelOffset[i*2],
158  minPixelCol() + thePixelOffset[i*2+1],
159  thePixelADC[i]
160  );
161  }
162 
163 private:
164 
165  static int span_(uint32_t packed) { return packed >> POSBITS;}
166  static int overflow_(uint32_t packed) { return span_(packed)==uint32_t(MAXSPAN);}
167  static uint32_t pack_(uint32_t zmin, unsigned int zspan) {
168  zspan = std::min(zspan, uint32_t(MAXSPAN));
169  return (zspan<<POSBITS) | zmin;
170  }
171 public:
172 
173  int colSpan() const {return span_(thePixelCol); }
174 
175  int rowSpan() const { return span_(thePixelRow); }
176 
177 
178  bool overflowCol() const { return overflow_(thePixelCol); }
179 
180  bool overflowRow() const { return overflow_(thePixelRow); }
181 
182  bool overflow() const { return overflowCol() || overflowRow(); }
183 
184  void packCol(uint32_t ymin, uint32_t yspan) {
185  thePixelCol = pack_(ymin,yspan);
186  }
187  void packRow(uint32_t xmin, uint32_t xspan) {
188  thePixelRow = pack_(xmin,xspan);
189  }
190 
191 
192 
194  void verifyVersion() const {
195  if unlikely( thePixelRow<MAXPOS && thePixelCol<MAXPOS)
196  const_cast<Phase2ITPixelCluster*>(this)->computeMax();
197  }
198 
200  void computeMax() {
201  int maxRow = 0;
202  int maxCol = 0;
203  int isize = thePixelADC.size();
204  for (int i=0; i!=isize; ++i) {
205  int xsize = thePixelOffset[i*2];
206  if (xsize > maxRow) maxRow = xsize;
207  int ysize = thePixelOffset[i*2+1] ;
208  if (ysize > maxCol) maxCol = ysize;
209  }
210  // assume minimum is correct
211  uint32_t minCol= minPixelCol();
212  packCol(minCol,maxCol);
213  uint32_t minRow= minPixelRow();
214  packRow(minRow,maxRow);
215  }
216 
217  // Getters and setters for the newly added data members (err_x and err_y). See below.
218  void setSplitClusterErrorX( float errx ) { err_x = errx; }
219  void setSplitClusterErrorY( float erry ) { err_y = erry; }
220  float getSplitClusterErrorX() const { return err_x; }
221  float getSplitClusterErrorY() const { return err_y; }
222 
223 
224 private:
225 
226  std::vector<uint16_t> thePixelOffset;
227  std::vector<uint32_t> thePixelADC;
228 
229 
230  uint32_t thePixelRow; // Minimum and span pixel index in the x direction (low edge).
231  uint32_t thePixelCol; // Minimum and span pixel index in the y direction (left edge).
232  // Need 10 bits for Position information. the other 6 used for span
233 
234  // A rechit from a split cluster should have larger errors than rechits from normal clusters.
235  // However, when presented with a cluster, the CPE does not know if the cluster comes
236  // from a splitting procedure or not. That's why we have to instruct the CPE to use
237  // appropriate errors for split clusters.
238  float err_x;
239  float err_y;
240 
241 };
242 
243 // Comparison operators (no clue...)
245  if ( one.minPixelRow() < other.minPixelRow() ) {
246  return true;
247  } else if ( one.minPixelRow() > other.minPixelRow() ) {
248  return false;
249  } else if ( one.minPixelCol() < other.minPixelCol() ) {
250  return true;
251  } else {
252  return false;
253  }
254 }
255 
260 
265 
268 #endif
std::vector< uint32_t > thePixelADC
uint32_t minPixelRow() const
std::pair< PixelDigiIter, PixelDigiIter > PixelDigiRange
static unsigned int SPANBITS
void verifyVersion() const
mostly to be compatible for <610
void setSplitClusterErrorX(float errx)
edm::DetSetVector< Phase2ITPixelCluster > Phase2ITPixelClusterCollection
void setSplitClusterErrorY(float erry)
void computeMax()
moslty to be compatible for <610
uint32_t maxPixelCol() const
edm::Ref< Phase2ITPixelClusterCollectionNew, Phase2ITPixelCluster > Phase2ITPixelClusterRefNew
void packRow(uint32_t xmin, uint32_t xspan)
const Int_t ysize
#define constexpr
edm::DetSetRefVector< Phase2ITPixelCluster > Phase2ITPixelClusterRefVector
const std::vector< uint32_t > & pixelADC() const
#define unlikely(x)
float getSplitClusterErrorX() const
void add(const PixelPos &pix, uint32_t adc)
static unsigned int POSBITS
uint32_t maxPixelRow() const
const std::vector< uint16_t > & pixelOffset() const
static int span_(uint32_t packed)
static unsigned int MAXPOS
const std::vector< Pixel > pixels() const
T min(T a, T b)
Definition: MathUtil.h:58
uint32_t minPixelCol() const
void packCol(uint32_t ymin, uint32_t yspan)
static uint32_t pack_(uint32_t zmin, unsigned int zspan)
float getSplitClusterErrorY() const
bool operator<(const Phase2ITPixelCluster &one, const Phase2ITPixelCluster &other)
Pixel cluster – collection of neighboring pixels above threshold.
edm::RefProd< Phase2ITPixelClusterCollection > Phase2ITPixelClusterRefProd
PixelPos operator+(const Shift &shift) const
edm::Ref< Phase2ITPixelClusterCollection, Phase2ITPixelCluster > Phase2ITPixelClusterRef
std::vector< uint16_t > thePixelOffset
static unsigned int MAXSPAN
Pixel(uint32_t pix_x, uint32_t pix_y, uint32_t pix_adc)
Phase2ITPixelCluster(unsigned int isize, uint32_t const *adcs, uint32_t const *xpos, uint32_t const *ypos, uint32_t const xmin, uint32_t const ymin)
static int overflow_(uint32_t packed)
col
Definition: cuy.py:1008
static unsigned int const shift
edmNew::DetSetVector< Phase2ITPixelCluster > Phase2ITPixelClusterCollectionNew
const Int_t xsize
std::vector< PixelDigi >::const_iterator PixelDigiIter
Pixel pixel(int i) const