PSCalib/src/SegGeometryEpix100V1.cpp

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

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7