00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CSPadPixCoords/PixCoordsCSPad.h"
00017 #include "CSPadPixCoords/PixCoordsCSPadV2.h"
00018
00019
00020
00021
00022 #include <math.h>
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 using namespace std;
00033
00034 typedef CSPadPixCoords::PixCoordsCSPadV2 PCV2;
00035
00036
00037
00038
00039
00040 namespace CSPadPixCoords {
00041
00042
00043
00044
00045 PixCoordsCSPad::PixCoordsCSPad ( PixCoordsQuad *pix_coords_quad, PSCalib::CSPadCalibPars *cspad_calibpar, bool tiltIsApplied )
00046 : m_pix_coords_quad(pix_coords_quad)
00047 , m_cspad_calibpar (cspad_calibpar)
00048 , m_tiltIsApplied (tiltIsApplied)
00049 {
00050
00051
00052
00053
00054 XCOOR = CSPadPixCoords::PixCoords2x1::X;
00055 YCOOR = CSPadPixCoords::PixCoords2x1::Y;
00056 ZCOOR = CSPadPixCoords::PixCoords2x1::Z;
00057
00058
00059 if (m_cspad_calibpar -> getCalibTypeStatus("center_global") == 1) {
00060
00061
00062 fillArrsOfCSPadPixCoordsFromCenterGlobal();
00063
00064 } else {
00065
00066 fillAllQuadCoordsInCSPad();
00067 fillArrsOfCSPadPixCoords();
00068 }
00069 }
00070
00071
00072
00073 void PixCoordsCSPad::fillAllQuadCoordsInCSPad()
00074 {
00075 m_degToRad = 3.14159265359 / 180.;
00076
00077 m_coor_x_min = 1e5;
00078 m_coor_x_max = 0;
00079 m_coor_y_min = 1e5;
00080 m_coor_y_max = 0;
00081
00082 double pixSize_um = PSCalib::CSPadCalibPars::getRowSize_um();
00083
00084 double margX = m_cspad_calibpar -> getMargX ();
00085 double margY = m_cspad_calibpar -> getMargY ();
00086 double gapX = m_cspad_calibpar -> getGapX ();
00087 double gapY = m_cspad_calibpar -> getGapY ();
00088 double shiftX = m_cspad_calibpar -> getShiftX ();
00089 double shiftY = m_cspad_calibpar -> getShiftY ();
00090
00091 double dx[] = {margX-gapX+shiftX, margX-gapX-shiftX, margX+gapX-shiftX, margX+gapX+shiftX};
00092 double dy[] = {margY-gapY-shiftY, margY+gapY-shiftY, margY+gapY+shiftY, margY-gapY+shiftY};
00093
00094 for (uint32_t q=0; q < NQuadsInCSPad; ++q)
00095 {
00096
00097
00098 m_xmin_quad [q] = m_cspad_calibpar -> getOffsetX (q)
00099 + m_cspad_calibpar -> getOffsetCorrX(q)
00100 + dx[q];
00101
00102 m_ymin_quad [q] = m_cspad_calibpar -> getOffsetY (q)
00103 + m_cspad_calibpar -> getOffsetCorrY(q)
00104 + dy[q];
00105
00106 m_xmin_quad [q] *= pixSize_um;
00107 m_ymin_quad [q] *= pixSize_um;
00108
00109
00110
00111
00112
00113 if (m_tiltIsApplied) fillOneQuadTiltedCoordsInCSPad(q);
00114 else fillOneQuadCoordsInCSPad(q);
00115 }
00116 }
00117
00118
00119
00120 void PixCoordsCSPad::fillOneQuadCoordsInCSPad(uint32_t quad)
00121 {
00122 double rotation = m_cspad_calibpar -> getQuadRotation(quad);
00123
00124
00125 CSPadPixCoords::PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00126
00127 for (uint32_t sect=0; sect<N2x1InQuad; ++sect) {
00128 for (uint32_t row=0; row<NRows2x1; row++) {
00129 for (uint32_t col=0; col<NCols2x1; col++) {
00130
00131 double coor_x = m_xmin_quad[quad] + m_pix_coords_quad->getPixCoorRotN90_um (orient, XCOOR, quad, sect, row, col);
00132 double coor_y = m_ymin_quad[quad] + m_pix_coords_quad->getPixCoorRotN90_um (orient, YCOOR, quad, sect, row, col);
00133
00134 m_coor_x[quad][sect][col][row] = coor_x;
00135 m_coor_y[quad][sect][col][row] = coor_y;
00136
00137 if ( coor_x < m_coor_x_min ) m_coor_x_min = coor_x;
00138 if ( coor_x > m_coor_x_max ) m_coor_x_max = coor_x;
00139 if ( coor_y < m_coor_y_min ) m_coor_y_min = coor_y;
00140 if ( coor_y > m_coor_y_max ) m_coor_y_max = coor_y;
00141
00142 }
00143 }
00144 }
00145
00146 }
00147
00148
00149
00150 void PixCoordsCSPad::fillOneQuadTiltedCoordsInCSPad(uint32_t quad)
00151 {
00152 double rotation = m_cspad_calibpar -> getQuadRotation(quad);
00153 double tilt = m_cspad_calibpar -> getQuadTilt(quad);
00154 CSPadPixCoords::PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00155
00156
00157
00158
00159
00160
00161 double tiltrad = tilt * m_degToRad;
00162 double sintilt = sin(tiltrad);
00163 double costilt = cos(tiltrad);
00164
00165 for (uint32_t sect=0; sect<N2x1InQuad; ++sect) {
00166 for (uint32_t row=0; row<NRows2x1; row++) {
00167 for (uint32_t col=0; col<NCols2x1; col++) {
00168
00169 double x_in_quad = m_pix_coords_quad->getPixCoorRotN90_um (orient, XCOOR, quad, sect, row, col);
00170 double y_in_quad = m_pix_coords_quad->getPixCoorRotN90_um (orient, YCOOR, quad, sect, row, col);
00171
00172 double x_tilted = x_in_quad * costilt - y_in_quad * sintilt;
00173 double y_tilted = x_in_quad * sintilt + y_in_quad * costilt;
00174
00175 double coor_x = m_xmin_quad[quad] + x_tilted;
00176 double coor_y = m_ymin_quad[quad] + y_tilted;
00177
00178 m_coor_x[quad][sect][col][row] = coor_x;
00179 m_coor_y[quad][sect][col][row] = coor_y;
00180
00181 if ( coor_x < m_coor_x_min ) m_coor_x_min = coor_x;
00182 if ( coor_x > m_coor_x_max ) m_coor_x_max = coor_x;
00183 if ( coor_y < m_coor_y_min ) m_coor_y_min = coor_y;
00184 if ( coor_y > m_coor_y_max ) m_coor_y_max = coor_y;
00185
00186 }
00187 }
00188 }
00189
00190 }
00191
00192
00193
00194 void PixCoordsCSPad::setConstXYMinMax()
00195 {
00196 m_coor_x_min = 0;
00197 m_coor_y_min = 0;
00198 m_coor_x_max = NX_CSPAD * PSCalib::CSPadCalibPars::getRowSize_um();
00199 m_coor_y_max = NY_CSPAD * PSCalib::CSPadCalibPars::getColSize_um();
00200 }
00201
00202
00203
00204 void PixCoordsCSPad::fillArrsOfCSPadPixCoords()
00205 {
00206 for (uint32_t quad=0; quad<NQuadsInCSPad; quad++) {
00207 for (uint32_t sect=0; sect<N2x1InQuad; sect++) {
00208 for (uint32_t row=0; row<NRows2x1; row++) {
00209 for (uint32_t col=0; col<NCols2x1; col++) {
00210
00211 double coor_x_um = m_coor_x[quad][sect][col][row] - m_coor_x_min;
00212 double coor_y_um = m_coor_y[quad][sect][col][row] - m_coor_y_min;
00213
00214 m_coor_x [quad][sect][col][row] = coor_x_um;
00215 m_coor_y [quad][sect][col][row] = coor_y_um;
00216
00217 m_coor_x_pix [quad][sect][col][row] = coor_x_um * PSCalib::CSPadCalibPars::getRowUmToPix();
00218 m_coor_y_pix [quad][sect][col][row] = coor_y_um * PSCalib::CSPadCalibPars::getColUmToPix();
00219
00220 m_coor_x_int [quad][sect][col][row] = int (m_coor_x_pix [quad][sect][col][row] + 0.25);
00221 m_coor_y_int [quad][sect][col][row] = int (m_coor_y_pix [quad][sect][col][row] + 0.25);
00222 }
00223 }
00224 }
00225 }
00226 }
00227
00228
00229
00230 void PixCoordsCSPad::fillArrsOfCSPadPixCoordsFromCenterGlobal()
00231 {
00232 PCV2 *pix_coords_v2 = new PCV2(m_cspad_calibpar);
00233
00234 for (uint32_t quad=0; quad<NQuadsInCSPad; quad++) {
00235 for (uint32_t sect=0; sect<N2x1InQuad; sect++) {
00236
00237 uint32_t s = quad * N2x1InQuad + sect;
00238
00239 for (uint32_t row=0; row<NRows2x1; row++) {
00240 for (uint32_t col=0; col<NCols2x1; col++) {
00241
00242 double coor_x_um = pix_coords_v2 -> getPixCoor_um(PCV2::AXIS_X, s, col, row);
00243 double coor_y_um = pix_coords_v2 -> getPixCoor_um(PCV2::AXIS_Y, s, col, row);
00244
00245 m_coor_x [quad][sect][col][row] = coor_x_um;
00246 m_coor_y [quad][sect][col][row] = coor_y_um;
00247
00248 m_coor_x_pix [quad][sect][col][row] = coor_x_um * PSCalib::CSPadCalibPars::getRowUmToPix();
00249 m_coor_y_pix [quad][sect][col][row] = coor_y_um * PSCalib::CSPadCalibPars::getColUmToPix();
00250
00251 m_coor_x_int [quad][sect][col][row] = int (m_coor_x_pix [quad][sect][col][row] + 0.25);
00252 m_coor_y_int [quad][sect][col][row] = int (m_coor_y_pix [quad][sect][col][row] + 0.25);
00253 }
00254 }
00255 }
00256 }
00257 }
00258
00259
00260
00261 double PixCoordsCSPad::getPixCoor_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00262 {
00263 switch (icoor)
00264 {
00265 case CSPadPixCoords::PixCoords2x1::X : return m_coor_x [quad][sect][col][row];
00266 case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y [quad][sect][col][row];
00267 case CSPadPixCoords::PixCoords2x1::Z : return 0;
00268 default: return 0;
00269 }
00270 }
00271
00272
00273
00274 double PixCoordsCSPad::getPixCoor_pix(CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00275 {
00276 switch (icoor)
00277 {
00278 case CSPadPixCoords::PixCoords2x1::X : return m_coor_x_pix [quad][sect][col][row];
00279 case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y_pix [quad][sect][col][row];
00280 case CSPadPixCoords::PixCoords2x1::Z : return 0;
00281 default: return 0;
00282 }
00283 }
00284
00285
00286
00287 double PixCoordsCSPad::getPixCoor_int(CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00288 {
00289 switch (icoor)
00290 {
00291 case CSPadPixCoords::PixCoords2x1::X : return m_coor_x_int [quad][sect][col][row];
00292 case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y_int [quad][sect][col][row];
00293 case CSPadPixCoords::PixCoords2x1::Z : return 0;
00294 default: return 0;
00295 }
00296 }
00297
00298
00299
00300
00301
00302
00303 PixCoordsCSPad::~PixCoordsCSPad ()
00304 {
00305 }
00306
00307 }