CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //---------------------------------------------------------------------------
16 //---------------------------------------------------------------------------
17 
18 #include <vector>
19 #include "boost/cstdint.hpp"
20 
21 class PixelDigi;
22 
24  public:
25 
26  class Pixel {
27  public:
28  Pixel() {} // for root
29  Pixel(int pix_x, int pix_y, int pix_adc) :
30  x(pix_x), y(pix_y), adc(pix_adc) {}
31  unsigned char x;
32  unsigned short y;
33  unsigned short adc;
34  };
35 
36  //--- Integer shift in x and y directions.
37  class Shift {
38  public:
39  Shift( int dx, int dy) : dx_(dx), dy_(dy) {}
40  Shift() : dx_(0), dy_(0) {}
41  int dx() const { return dx_;}
42  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  PixelPos() : row_(0), col_(0) {}
52  PixelPos(int row, int col) : row_(row) , col_(col) {}
53  int row() const { return row_;}
54  int col() const { return col_;}
56  return PixelPos( row() + shift.dx(), col() + shift.dy());
57  }
58  private:
59  int row_;
60  int col_;
61  };
62 
63  typedef std::vector<PixelDigi>::const_iterator PixelDigiIter;
64  typedef std::pair<PixelDigiIter,PixelDigiIter> PixelDigiRange;
65 
70  // &&& Decide the fate of the two strip-like constructors below:
71  SiPixelCluster() : detId_(0), err_x(-99999.9), err_y(-99999.9) {} // needed by vector::push_back()!
72  // SiPixelCluster( unsigned int detid, const PixelDigiRange& range)
73 
74  SiPixelCluster( const PixelPos& pix, int adc);
75 
76  void add( const PixelPos& pix, int adc);
77 
78  // Analog linear average position (barycenter)
79  float x() const {
80  float qm = 0.0;
81  int isize = thePixelADC.size();
82  for (int i=0; i<isize; ++i)
83  qm += float(thePixelADC[i]) * (thePixelOffset[i*2] + theMinPixelRow + 0.5);
84  return qm/charge();
85  }
86  float y() const {
87  float qm = 0.0;
88  int isize = thePixelADC.size();
89  for (int i=0; i<isize; ++i)
90  qm += float(thePixelADC[i]) * (thePixelOffset[i*2+1] + theMinPixelCol + 0.5);
91  return qm/charge();
92  }
93 
94  // Return number of pixels.
95  int size() const { return thePixelADC.size();}
96 
97  // Return cluster dimension in the x direction.
98  int sizeX() const {return maxPixelRow() - theMinPixelRow +1;}
99 
100  // Return cluster dimension in the y direction.
101  int sizeY() const {return maxPixelCol() - theMinPixelCol +1;}
102 
103  // Detect clusters at the edge of the detector.
104  // NOTE: Moved to RectangularPixelTopology class
105  // bool edgeHitX() const;
106  // bool edgeHitY() const;
107 
108  inline float charge() const {
109  float qm = 0.0;
110  int isize = thePixelADC.size();
111  for (int i=0; i<isize; ++i)
112  qm += float(thePixelADC[i]);
113  return qm;
114  } // Return total cluster charge.
115 
116  inline int minPixelRow() const { return theMinPixelRow;} // The min x index.
117  inline int minPixelCol() const { return theMinPixelCol & 511;} // The min y index.
118 
119  inline int maxPixelRow() const {
120  int maxRow = 0;
121  int isize = thePixelADC.size();
122  for (int i=0; i<isize; ++i) {
123  int xsize = thePixelOffset[i*2];
124  if (xsize > maxRow) maxRow = xsize;
125  }
126  return maxRow + theMinPixelRow; // The max x index.
127  }
128 
129  inline int maxPixelCol() const {
130  int maxCol = 0;
131  int isize = thePixelADC.size();
132  for (int i=0; i<isize; ++i) {
133  int ysize = thePixelOffset[i*2+1] ;
134  if (ysize > maxCol) maxCol = ysize;
135  }
136  return maxCol + theMinPixelCol; // The max y index.
137  }
138 
139  const std::vector<uint8_t> & pixelOffset() const { return thePixelOffset;}
140  const std::vector<uint16_t> & pixelADC() const { return thePixelADC;}
141 
142  const std::vector<Pixel> pixels() const {
143  std::vector<Pixel> oldPixVector;
144  int isize = thePixelADC.size();
145  oldPixVector.reserve(isize);
146  for(int i=0; i<isize; ++i) {
147  int x = theMinPixelRow + (thePixelOffset[i*2] );
148  int y = theMinPixelCol + (thePixelOffset[i*2+1] );
149  oldPixVector.push_back(Pixel(x,y,thePixelADC[i]));
150  }
151  return oldPixVector;
152  }
153  //--- Cloned fom Strips:
154 
158  unsigned int geographicalId() const {return detId_;}
159 
160  // &&& Decide if we still need these two:
161  // typedef vector<Digi::ChannelType> ChannelContainer;
162  // ChannelContainer channels() const;
163 
164  // ggiurgiu@fnal.gov, 01/05/12
165  // Getters and setters for the newly added data members (err_x and err_y). See below.
166  void setSplitClusterErrorX( float errx ) { err_x = errx; }
167  void setSplitClusterErrorY( float erry ) { err_y = erry; }
168  float getSplitClusterErrorX() const { return err_x; }
169  float getSplitClusterErrorY() const { return err_y; }
170 
171 
172  private:
173  unsigned int detId_;
174 
175  std::vector<uint8_t> thePixelOffset;
176  std::vector<uint16_t> thePixelADC;
177 
178  /* float theSumX; // Sum of charge weighted pixel positions.
179  float theSumY;
180  float theCharge; // Total charge
181  uint8_t theMaxPixelRow; // Maximum pixel index in the x direction (top edge).
182  uint16_t theMaxPixelCol; // Maximum pixel index in the y direction (right edge).
183  */
184  uint8_t theMinPixelRow; // Minimum pixel index in the x direction (low edge).
185  uint16_t theMinPixelCol; // Minimum pixel index in the y direction (left edge).
186  // Need 9 bits for Col information. Use 1 bit for whether larger
187  // cluster than 9x33. Other 6 bits for quality information.
188 
189  // ggiurgiu@fnal.gov, 01/05/12
190  // Add cluster errors to be used by rechits from split clusters.
191  // A rechit from a split cluster has larger errors than rechits from normal clusters.
192  // However, when presented with a cluster, the CPE does not know if the cluster comes
193  // from a splitting procedure or not. That's why we have to instruct the CPE to use
194  // appropriate errors for split clusters.
195  // To avoid increase of data size on disk,these new data members are set as transient in:
196  // DataFormats/SiPixelCluster/src/classes_def.xml
197  float err_x;
198  float err_y;
199 
200 };
201 
202 // Comparison operators
203 inline bool operator<( const SiPixelCluster& one, const SiPixelCluster& other) {
204  if ( one.geographicalId() < other.geographicalId() ) {
205  return true;
206  } else if ( one.geographicalId() > other.geographicalId() ) {
207  return false;
208  } else if ( one.minPixelRow() < other.minPixelRow() ) {
209  return true;
210  } else if ( one.minPixelRow() > other.minPixelRow() ) {
211  return false;
212  } else if ( one.minPixelCol() < other.minPixelCol() ) {
213  return true;
214  } else {
215  return false;
216  }
217 }
218 
223 
228 
231 #endif
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
float charge() const
int minPixelCol() const
void setSplitClusterErrorY(float erry)
PixelPos(int row, int col)
std::vector< PixelDigi >::const_iterator PixelDigiIter
unsigned int geographicalId() const
edm::RefProd< SiPixelClusterCollection > SiPixelClusterRefProd
int maxPixelRow() const
std::vector< uint16_t > thePixelADC
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
int minPixelRow() const
edm::Ref< SiPixelClusterCollection, SiPixelCluster > SiPixelClusterRef
void add(const PixelPos &pix, int adc)
edm::DetSetRefVector< SiPixelCluster > SiPixelClusterRefVector
const std::vector< uint8_t > & pixelOffset() const
const std::vector< uint16_t > & pixelADC() const
std::vector< uint8_t > thePixelOffset
void setSplitClusterErrorX(float errx)
float getSplitClusterErrorY() const
edm::DetSetVector< SiPixelCluster > SiPixelClusterCollection
Shift(int dx, int dy)
edm::Ref< SiPixelClusterCollectionNew, SiPixelCluster > SiPixelClusterRefNew
Pixel(int pix_x, int pix_y, int pix_adc)
int maxPixelCol() const
uint8_t theMinPixelRow
edmNew::DetSetVector< SiPixelCluster > SiPixelClusterCollectionNew
int sizeY() const
uint16_t theMinPixelCol
Pixel cluster – collection of neighboring pixels above threshold.
unsigned int detId_
PixelPos operator+(const Shift &shift)
float getSplitClusterErrorX() const
static unsigned int const shift
float y() const
unsigned short adc
int sizeX() const
std::pair< PixelDigiIter, PixelDigiIter > PixelDigiRange
float x() const
const std::vector< Pixel > pixels() const
int size() const