00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "PSCalib/SegGeometryCspad2x1V1.h"
00017
00018
00019
00020
00021 #include <math.h>
00022 #include <iostream>
00023
00024
00025
00026
00027
00028 using namespace std;
00029
00030
00031
00032
00033 #include "PSCalib/CSPadCalibPars.h"
00034
00035
00036
00037
00038
00039 namespace PSCalib {
00040
00041
00042
00043
00044
00045 const size_t SegGeometryCspad2x1V1::ROWS;
00046 const size_t SegGeometryCspad2x1V1::COLS;
00047 const size_t SegGeometryCspad2x1V1::COLSHALF;
00048 const size_t SegGeometryCspad2x1V1::SIZE;
00049 const size_t SegGeometryCspad2x1V1::NCORNERS;
00050
00051 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::PIX_SCALE_SIZE = 109.92;
00052 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::PIX_SIZE_COLS = PIX_SCALE_SIZE;
00053 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::PIX_SIZE_ROWS = PIX_SCALE_SIZE;
00054 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::PIX_SIZE_WIDE = 274.80;
00055 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::PIX_SIZE_DEPTH = 400.;
00056 const double SegGeometryCspad2x1V1::UM_TO_PIX = 1./PIX_SCALE_SIZE;
00057
00058 const size_t SegGeometryCspad2x1V1::IND_CORNER[NCORNERS] = {0, COLS-1, (ROWS-1)*COLS, ROWS*COLS-1};
00059 const size_t SegGeometryCspad2x1V1::ARR_SHAPE[2] = {ROWS, COLS};
00060
00061
00062
00063
00064
00065
00066
00067 SegGeometry* SegGeometryCspad2x1V1::m_pInstance = NULL;
00068
00069
00070 SegGeometry* SegGeometryCspad2x1V1::instance(const bool& use_wide_pix_center)
00071 {
00072 if( !m_pInstance ) m_pInstance = new SegGeometryCspad2x1V1(use_wide_pix_center);
00073 return m_pInstance;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 SegGeometryCspad2x1V1::SegGeometryCspad2x1V1 (const bool& use_wide_pix_center)
00085 : PSCalib::SegGeometry()
00086 , m_use_wide_pix_center(use_wide_pix_center)
00087 , m_done_bits(0)
00088 {
00089
00090
00091 make_pixel_coord_arrs();
00092 }
00093
00094
00095
00096
00097
00098 SegGeometryCspad2x1V1::~SegGeometryCspad2x1V1 ()
00099 {
00100 }
00101
00102
00103
00104 void SegGeometryCspad2x1V1::make_pixel_coord_arrs()
00105 {
00106
00107 SegGeometry::pixel_coord_t x_offset = PIX_SIZE_WIDE - PIX_SIZE_COLS / 2;
00108 for (size_t c=0; c<COLSHALF; c++) m_x_rhs_um[c] = c * PIX_SIZE_COLS + x_offset;
00109 if (m_use_wide_pix_center) m_x_rhs_um[0] = PIX_SIZE_WIDE / 2;
00110 for (size_t c=0; c<COLSHALF; c++) { m_x_arr_um[c] = -m_x_rhs_um[COLSHALF-1-c];
00111 m_x_arr_um[COLSHALF + c] = m_x_rhs_um[c]; }
00112
00113
00114 SegGeometry::pixel_coord_t y_offset = (ROWS-1) * PIX_SIZE_ROWS / 2;
00115 for (size_t r=0; r<ROWS; r++) m_y_arr_um[r] = y_offset - r * PIX_SIZE_ROWS;
00116
00117 for (size_t r=0; r<ROWS; r++) {
00118 for (size_t c=0; c<COLS; c++) {
00119 m_x_pix_coord_um [r][c] = m_x_arr_um [c];
00120 m_y_pix_coord_um [r][c] = m_y_arr_um [r];
00121 }
00122 }
00123
00124 std::fill_n(&m_z_pix_coord_um[0][0], int(SIZE), SegGeometry::pixel_coord_t(0));
00125 m_done_bits ^= 1;
00126 }
00127
00128
00129
00130 void SegGeometryCspad2x1V1::make_pixel_size_arrs()
00131 {
00132 if (m_done_bits & 2) return;
00133
00134 std::fill_n(&m_x_pix_size_um[0][0], int(SIZE), PIX_SIZE_COLS);
00135 std::fill_n(&m_y_pix_size_um[0][0], int(SIZE), PIX_SIZE_ROWS);
00136 std::fill_n(&m_z_pix_size_um[0][0], int(SIZE), PIX_SIZE_DEPTH);
00137 std::fill_n(&m_pix_area_arr [0][0], int(SIZE), SegGeometry::pixel_area_t(1));
00138
00139 SegGeometry::pixel_area_t arr_wide = PIX_SIZE_WIDE/PIX_SIZE_COLS;
00140
00141
00142 for (size_t r=0; r<ROWS; r++) {
00143 m_x_pix_size_um[r][COLSHALF-1] = PIX_SIZE_WIDE;
00144 m_x_pix_size_um[r][COLSHALF] = PIX_SIZE_WIDE;
00145 m_pix_area_arr [r][COLSHALF-1] = arr_wide;
00146 m_pix_area_arr [r][COLSHALF] = arr_wide;
00147 }
00148
00149 m_done_bits ^= 2;
00150 }
00151
00152
00153
00154 void SegGeometryCspad2x1V1::print_member_data()
00155 {
00156 cout << "SegGeometryCspad2x1V1::print_member_data():"
00157 << "\n ROWS " << ROWS
00158 << "\n COLS " << COLS
00159 << "\n COLSHALF " << COLSHALF
00160 << "\n PIX_SIZE_COLS " << PIX_SIZE_COLS
00161 << "\n PIX_SIZE_ROWS " << PIX_SIZE_ROWS
00162 << "\n PIX_SIZE_WIDE " << PIX_SIZE_WIDE
00163 << "\n PIX_SIZE_UM " << PIX_SCALE_SIZE
00164 << "\n UM_TO_PIX " << UM_TO_PIX
00165 << "\n m_use_wide_pix_center " << m_use_wide_pix_center
00166 << "\n";
00167 }
00168
00169
00170
00171 void SegGeometryCspad2x1V1::print_coord_arrs()
00172 {
00173 cout << "\nSegGeometryCspad2x1V1::print_coord_arrs\n";
00174
00175 cout << "m_x_arr_um:\n";
00176 for (unsigned counter=0, c=0; c<COLS; c++) {
00177 cout << " " << m_x_arr_um[c];
00178 if (++counter > 19) { counter=0; cout << "\n"; }
00179 }
00180 cout << "\n";
00181
00182 cout << "m_y_arr_um:\n";
00183 for (unsigned counter=0, r=0; r<ROWS; r++) {
00184 cout << " " << m_y_arr_um[r];
00185 if (++counter > 19) { counter=0; cout << "\n"; }
00186 }
00187 cout << "\n";
00188 }
00189
00190
00191
00192 void SegGeometryCspad2x1V1::print_min_max_coords()
00193 {
00194 cout << " 2x1 coordinate map limits:"
00195 << "\n xmin = " << pixel_coord_min (AXIS_X)
00196 << "\n xmax = " << pixel_coord_max (AXIS_X)
00197 << "\n ymin = " << pixel_coord_min (AXIS_Y)
00198 << "\n ymax = " << pixel_coord_max (AXIS_Y)
00199 << "\n zmin = " << pixel_coord_min (AXIS_Z)
00200 << "\n zmax = " << pixel_coord_max (AXIS_Z)
00201 << "\n";
00202 }
00203
00204
00205
00206
00207
00208 void SegGeometryCspad2x1V1::print_seg_info(const unsigned& pbits)
00209 {
00210 if (pbits & 1) print_member_data();
00211 if (pbits & 2) print_coord_arrs();
00212 if (pbits & 4) print_min_max_coords();
00213 }
00214
00215
00216
00217 const SegGeometry::pixel_area_t* SegGeometryCspad2x1V1::pixel_area_array()
00218 {
00219 make_pixel_size_arrs();
00220
00221 return &m_pix_area_arr[0][0];
00222 }
00223
00224
00225
00226 const SegGeometry::pixel_coord_t* SegGeometryCspad2x1V1::pixel_size_array(AXIS axis)
00227 {
00228 make_pixel_size_arrs();
00229
00230 if (axis == AXIS_X) return &m_x_pix_size_um [0][0];
00231 else if (axis == AXIS_Y) return &m_y_pix_size_um [0][0];
00232 else if (axis == AXIS_Z) return &m_z_pix_size_um [0][0];
00233 else return &m_y_pix_size_um [0][0];
00234 }
00235
00236
00237
00238 const SegGeometry::pixel_coord_t* SegGeometryCspad2x1V1::pixel_coord_array (AXIS axis)
00239 {
00240 if (axis == AXIS_X) return &m_x_pix_coord_um [0][0];
00241 else if (axis == AXIS_Y) return &m_y_pix_coord_um [0][0];
00242 else if (axis == AXIS_Z) return &m_z_pix_coord_um [0][0];
00243 else return &m_x_pix_coord_um [0][0];
00244 }
00245
00246
00247
00248 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::pixel_coord_min (AXIS axis)
00249 {
00250 const SegGeometry::pixel_coord_t* arr = pixel_coord_array (axis);
00251 SegGeometry::pixel_coord_t corner_coords[NCORNERS];
00252 for (size_t i=0; i<NCORNERS; ++i) { corner_coords[i] = arr[IND_CORNER[i]]; }
00253 return PSCalib::min_of_arr(corner_coords, NCORNERS);
00254 }
00255
00256
00257
00258 const SegGeometry::pixel_coord_t SegGeometryCspad2x1V1::pixel_coord_max (AXIS axis)
00259 {
00260 const SegGeometry::pixel_coord_t* arr = pixel_coord_array (axis);
00261 SegGeometry::pixel_coord_t corner_coords[NCORNERS];
00262 for (size_t i=0; i<NCORNERS; ++i) { corner_coords[i] = arr[IND_CORNER[i]]; }
00263 return PSCalib::max_of_arr(corner_coords, NCORNERS);
00264 }
00265
00266
00267
00268 const SegGeometry::pixel_mask_t* SegGeometryCspad2x1V1::pixel_mask_array(const unsigned& mbits)
00269 {
00270
00271
00272
00273 std::fill_n(&m_pix_mask_arr[0][0], int(SIZE), SegGeometry::pixel_mask_t(1));
00274
00275 size_t h = COLSHALF;
00276
00277 if(mbits & 1) {
00278
00279 for (size_t r=0; r<ROWS; r++) {
00280 m_pix_mask_arr[r][0] = 0;
00281 m_pix_mask_arr[r][COLS-1] = 0;
00282 }
00283
00284 for (size_t c=0; c<COLS; c++) {
00285 m_pix_mask_arr[0][c] = 0;
00286 m_pix_mask_arr[ROWS-1][c] = 0;
00287 }
00288 }
00289
00290 if(mbits & 2) {
00291
00292 for (size_t r=0; r<ROWS; r++) {
00293 m_pix_mask_arr[r][h-1] = 0;
00294 m_pix_mask_arr[r][h] = 0;
00295 }
00296 }
00297
00298 if(mbits & 4) {
00299
00300 for (size_t p=0; p<ROWS; p+=10) {
00301
00302 m_pix_mask_arr[p][p] = 0;
00303 m_pix_mask_arr[p][p+h] = 0;
00304
00305 if(mbits & 8) {
00306
00307 if(p==0) {
00308 m_pix_mask_arr[1][0] = 0;
00309 m_pix_mask_arr[0][1] = 0;
00310 m_pix_mask_arr[1][0+h] = 0;
00311 m_pix_mask_arr[0][1+h] = 0;
00312 }
00313 else {
00314 m_pix_mask_arr[p-1][p] = 0;
00315 m_pix_mask_arr[p+1][p] = 0;
00316 m_pix_mask_arr[p][p-1] = 0;
00317 m_pix_mask_arr[p][p+1] = 0;
00318
00319 m_pix_mask_arr[p-1][p+h] = 0;
00320 m_pix_mask_arr[p+1][p+h] = 0;
00321 m_pix_mask_arr[p][p+h-1] = 0;
00322 m_pix_mask_arr[p][p+h+1] = 0;
00323 }
00324 }
00325 }
00326 }
00327
00328 return &m_pix_mask_arr[0][0];
00329 }
00330
00331
00332
00333
00334
00335
00336
00337 }
00338
00339