Go to the documentation of this file.00001 #ifndef DataFormats_SiPixel_Cluster_SiPixelCluster_h
00002 #define DataFormats_SiPixel_Cluster_SiPixelCluster_h
00003
00004
00016
00017
00018 #include <vector>
00019 #include "boost/cstdint.hpp"
00020
00021 class PixelDigi;
00022
00023 class SiPixelCluster {
00024 public:
00025
00026 class Pixel {
00027 public:
00028 Pixel() {}
00029 Pixel(int pix_x, int pix_y, int pix_adc) :
00030 x(pix_x), y(pix_y), adc(pix_adc) {}
00031 unsigned char x;
00032 unsigned short y;
00033 unsigned short adc;
00034 };
00035
00036
00037 class Shift {
00038 public:
00039 Shift( int dx, int dy) : dx_(dx), dy_(dy) {}
00040 Shift() : dx_(0), dy_(0) {}
00041 int dx() const { return dx_;}
00042 int dy() const { return dy_;}
00043 private:
00044 int dx_;
00045 int dy_;
00046 };
00047
00048
00049 class PixelPos {
00050 public:
00051 PixelPos() : row_(0), col_(0) {}
00052 PixelPos(int row, int col) : row_(row) , col_(col) {}
00053 int row() const { return row_;}
00054 int col() const { return col_;}
00055 PixelPos operator+( const Shift& shift) {
00056 return PixelPos( row() + shift.dx(), col() + shift.dy());
00057 }
00058 private:
00059 int row_;
00060 int col_;
00061 };
00062
00063 typedef std::vector<PixelDigi>::const_iterator PixelDigiIter;
00064 typedef std::pair<PixelDigiIter,PixelDigiIter> PixelDigiRange;
00065
00070
00071 SiPixelCluster() : detId_(0), err_x(-99999.9), err_y(-99999.9) {}
00072
00073
00074 SiPixelCluster( const PixelPos& pix, int adc);
00075
00076 void add( const PixelPos& pix, int adc);
00077
00078
00079 float x() const {
00080 float qm = 0.0;
00081 int isize = thePixelADC.size();
00082 for (int i=0; i<isize; ++i)
00083 qm += float(thePixelADC[i]) * (thePixelOffset[i*2] + theMinPixelRow + 0.5);
00084 return qm/charge();
00085 }
00086 float y() const {
00087 float qm = 0.0;
00088 int isize = thePixelADC.size();
00089 for (int i=0; i<isize; ++i)
00090 qm += float(thePixelADC[i]) * (thePixelOffset[i*2+1] + theMinPixelCol + 0.5);
00091 return qm/charge();
00092 }
00093
00094
00095 int size() const { return thePixelADC.size();}
00096
00097
00098 int sizeX() const {return maxPixelRow() - theMinPixelRow +1;}
00099
00100
00101 int sizeY() const {return maxPixelCol() - theMinPixelCol +1;}
00102
00103
00104
00105
00106
00107
00108 inline float charge() const {
00109 float qm = 0.0;
00110 int isize = thePixelADC.size();
00111 for (int i=0; i<isize; ++i)
00112 qm += float(thePixelADC[i]);
00113 return qm;
00114 }
00115
00116 inline int minPixelRow() const { return theMinPixelRow;}
00117 inline int minPixelCol() const { return theMinPixelCol & 511;}
00118
00119 inline int maxPixelRow() const {
00120 int maxRow = 0;
00121 int isize = thePixelADC.size();
00122 for (int i=0; i<isize; ++i) {
00123 int xsize = thePixelOffset[i*2];
00124 if (xsize > maxRow) maxRow = xsize;
00125 }
00126 return maxRow + theMinPixelRow;
00127 }
00128
00129 inline int maxPixelCol() const {
00130 int maxCol = 0;
00131 int isize = thePixelADC.size();
00132 for (int i=0; i<isize; ++i) {
00133 int ysize = thePixelOffset[i*2+1] ;
00134 if (ysize > maxCol) maxCol = ysize;
00135 }
00136 return maxCol + theMinPixelCol;
00137 }
00138
00139 const std::vector<uint8_t> & pixelOffset() const { return thePixelOffset;}
00140 const std::vector<uint16_t> & pixelADC() const { return thePixelADC;}
00141
00142 const std::vector<Pixel> pixels() const {
00143 std::vector<Pixel> oldPixVector;
00144 int isize = thePixelADC.size();
00145 oldPixVector.reserve(isize);
00146 for(int i=0; i<isize; ++i) {
00147 int x = theMinPixelRow + (thePixelOffset[i*2] );
00148 int y = theMinPixelCol + (thePixelOffset[i*2+1] );
00149 oldPixVector.push_back(Pixel(x,y,thePixelADC[i]));
00150 }
00151 return oldPixVector;
00152 }
00153
00154
00158 unsigned int geographicalId() const {return detId_;}
00159
00160
00161
00162
00163
00164
00165
00166 void setSplitClusterErrorX( float errx ) { err_x = errx; }
00167 void setSplitClusterErrorY( float erry ) { err_y = erry; }
00168 float getSplitClusterErrorX() const { return err_x; }
00169 float getSplitClusterErrorY() const { return err_y; }
00170
00171
00172 private:
00173 unsigned int detId_;
00174
00175 std::vector<uint8_t> thePixelOffset;
00176 std::vector<uint16_t> thePixelADC;
00177
00178
00179
00180
00181
00182
00183
00184 uint8_t theMinPixelRow;
00185 uint16_t theMinPixelCol;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 float err_x;
00198 float err_y;
00199
00200 };
00201
00202
00203 inline bool operator<( const SiPixelCluster& one, const SiPixelCluster& other) {
00204 if ( one.geographicalId() < other.geographicalId() ) {
00205 return true;
00206 } else if ( one.geographicalId() > other.geographicalId() ) {
00207 return false;
00208 } else if ( one.minPixelRow() < other.minPixelRow() ) {
00209 return true;
00210 } else if ( one.minPixelRow() > other.minPixelRow() ) {
00211 return false;
00212 } else if ( one.minPixelCol() < other.minPixelCol() ) {
00213 return true;
00214 } else {
00215 return false;
00216 }
00217 }
00218
00219 #include "DataFormats/Common/interface/DetSetVector.h"
00220 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00221 #include "DataFormats/Common/interface/Ref.h"
00222 #include "DataFormats/Common/interface/DetSetRefVector.h"
00223
00224 typedef edm::DetSetVector<SiPixelCluster> SiPixelClusterCollection;
00225 typedef edm::Ref<SiPixelClusterCollection, SiPixelCluster> SiPixelClusterRef;
00226 typedef edm::DetSetRefVector<SiPixelCluster> SiPixelClusterRefVector;
00227 typedef edm::RefProd<SiPixelClusterCollection> SiPixelClusterRefProd;
00228
00229 typedef edmNew::DetSetVector<SiPixelCluster> SiPixelClusterCollectionNew;
00230 typedef edm::Ref<SiPixelClusterCollectionNew, SiPixelCluster> SiPixelClusterRefNew;
00231 #endif