CSPadPixCoords/src/PixCoordsQuad.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class PixCoordsQuad...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "CSPadPixCoords/PixCoordsQuad.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <math.h>
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
00025 //-------------------------------
00026 #include <boost/math/constants/constants.hpp>
00027 
00028 
00029 //-----------------------------------------------------------------------
00030 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00031 //-----------------------------------------------------------------------
00032 
00033 using namespace std;
00034 
00035 //              ----------------------------------------
00036 //              -- Public Function Member Definitions --
00037 //              ----------------------------------------
00038 
00039 namespace CSPadPixCoords {
00040 
00041 //----------------
00042 // Constructors --
00043 //----------------
00044 PixCoordsQuad::PixCoordsQuad ( PixCoords2x1 *pix_coords_2x1,  PSCalib::CSPadCalibPars *cspad_calibpar, bool tiltIsApplied )
00045   : m_pix_coords_2x1(pix_coords_2x1)
00046   , m_cspad_calibpar(cspad_calibpar)
00047   , m_tiltIsApplied (tiltIsApplied)
00048 {
00049   //cout << "PixCoordsQuad" << endl;
00050   //m_pix_coords_2x1 -> print_member_data(); 
00051   //m_cspad_calibpar -> printCalibPars();
00052 
00053   XCOOR = CSPadPixCoords::PixCoords2x1::X;
00054   YCOOR = CSPadPixCoords::PixCoords2x1::Y;
00055   ZCOOR = CSPadPixCoords::PixCoords2x1::Z;
00056 
00057   fillAllQuads();
00058   setConstXYMinMax();
00059 }
00060 
00061 //--------------
00062 
00063 void PixCoordsQuad::fillAllQuads()
00064 {
00065         for (uint32_t quad=0; quad < NQuadsInCSPad; ++quad)
00066           {
00067             //cout << "\n quad=" << quad << ":\n" ;
00068 
00069             m_coor_x_min[quad] = 1e5;
00070             m_coor_x_max[quad] = 0;
00071             m_coor_y_min[quad] = 1e5;
00072             m_coor_y_max[quad] = 0;
00073 
00074             m_degToRad = 3.14159265359 / 180.; 
00075 
00076             fillOneQuad(quad);
00077           }
00078 }
00079 
00080 //--------------
00081 
00082 void PixCoordsQuad::fillOneQuad(uint32_t quad)
00083 {
00084         double pixSize_um = PSCalib::CSPadCalibPars::getRowSize_um();
00085 
00086         for (uint32_t sect=0; sect < N2x1InQuad; ++sect)
00087           {
00088             //bool bitIsOn = roiMask & (1<<sect);
00089             //if( !bitIsOn ) continue;
00090 
00091             double xcenter  = m_cspad_calibpar -> getQuadMargX  ()
00092                            + m_cspad_calibpar -> getCenterX    (quad,sect)
00093                            + m_cspad_calibpar -> getCenterCorrX(quad,sect);
00094 
00095             double ycenter  = m_cspad_calibpar -> getQuadMargY  ()
00096                            + m_cspad_calibpar -> getCenterY    (quad,sect)
00097                            + m_cspad_calibpar -> getCenterCorrY(quad,sect);
00098 
00099             double zcenter  = m_cspad_calibpar -> getQuadMargZ  ()
00100                            + m_cspad_calibpar -> getCenterZ    (quad,sect)
00101                            + m_cspad_calibpar -> getCenterCorrZ(quad,sect);
00102 
00103             double rotation = m_cspad_calibpar -> getRotation   (quad,sect);
00104 
00105             double tilt     = m_cspad_calibpar -> getTilt       (quad,sect);
00106 
00107 
00108             xcenter *= pixSize_um;
00109             ycenter *= pixSize_um;
00110 
00111             if (m_tiltIsApplied) fillOneSectionTiltedInQuad(quad, sect, xcenter, ycenter, zcenter, rotation, tilt);
00112             else                 fillOneSectionInQuad(quad, sect, xcenter, ycenter, zcenter, rotation);
00113 
00114             //cout << " sect=" << sect;
00115           }
00116         //cout << endl;
00117 
00118 }
00119 
00120 //--------------
00121 
00122 void PixCoordsQuad::fillOneSectionInQuad(uint32_t quad, uint32_t sect, double xcenter, double ycenter, double zcenter, double rotation)
00123 {
00124   // cout << "PixCoordsQuad::fillOneSectionInQuad" << endl;
00125   // cout << " sect=" << sect;
00126   // if (sect != 0) return;
00127 
00128             PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00129 
00130             double xmin = xcenter - m_pix_coords_2x1->getXCenterOffset_um(orient);
00131             double ymin = ycenter - m_pix_coords_2x1->getYCenterOffset_um(orient);
00132 
00133             for (uint32_t col=0; col<NCols2x1; col++) {
00134             for (uint32_t row=0; row<NRows2x1; row++) {
00135 
00136                double coor_x = xmin + m_pix_coords_2x1->getPixCoorRotN90_um (orient, XCOOR, row, col);
00137                double coor_y = ymin + m_pix_coords_2x1->getPixCoorRotN90_um (orient, YCOOR, row, col);
00138                m_coor_x[quad][sect][col][row] = coor_x;
00139                m_coor_y[quad][sect][col][row] = coor_y;
00140 
00141                if ( coor_x < m_coor_x_min[quad] ) m_coor_x_min[quad] = coor_x;
00142                if ( coor_x > m_coor_x_max[quad] ) m_coor_x_max[quad] = coor_x;
00143                if ( coor_y < m_coor_y_min[quad] ) m_coor_y_min[quad] = coor_y;
00144                if ( coor_y > m_coor_y_max[quad] ) m_coor_y_max[quad] = coor_y;
00145             }
00146             }
00147 }
00148 
00149 //--------------
00150 
00151 void PixCoordsQuad::fillOneSectionTiltedInQuad(uint32_t quad, uint32_t sect, double xcenter, double ycenter, double zcenter, double rotation, double tilt)
00152 {
00153   //cout << "PixCoordsQuad::fillOneSectionInQuad: " << endl;
00154 
00155     PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00156   
00157     double xhalf  = m_pix_coords_2x1->getXCenterOffset_um(orient);
00158     double yhalf  = m_pix_coords_2x1->getYCenterOffset_um(orient);
00159 
00160     double tiltrad = tilt*m_degToRad;
00161 
00162     double sintilt = sin(tiltrad);
00163     double costilt = cos(tiltrad);
00164 
00165     // Calculate the corner-center offset due to the tilt
00166 
00167     double radius = sqrt(xhalf*xhalf + yhalf*yhalf);
00168     double sinPhi = yhalf / radius;
00169     double cosPhi = xhalf / radius;
00170 
00171     double rdPhi  = radius * tiltrad; // fabs(tiltrad) ?
00172     double dxOff  =  rdPhi * sinPhi;
00173     double dyOff  = -rdPhi * cosPhi;
00174 
00175     double xmin   = xcenter - xhalf + dxOff;
00176     double ymin   = ycenter - yhalf + dyOff;
00177 
00178     /*
00179     cout << " sect="      << sect 
00180          << " rotation="  << rotation
00181          << " tilt="      << tilt
00182          << " sin(tilt)=" << sintilt
00183          << " cos(tilt)=" << costilt
00184          << endl;
00185     */
00186 
00187     for (uint32_t col=0; col<NCols2x1; col++) {
00188     for (uint32_t row=0; row<NRows2x1; row++) {
00189 
00190        double x_in_sec = m_pix_coords_2x1->getPixCoorRotN90_um (orient, XCOOR, row, col);
00191        double y_in_sec = m_pix_coords_2x1->getPixCoorRotN90_um (orient, YCOOR, row, col);
00192 
00193        double x_tilted =  x_in_sec * costilt - y_in_sec * sintilt;
00194        double y_tilted =  x_in_sec * sintilt + y_in_sec * costilt; 
00195 
00196        double coor_x = xmin + x_tilted;
00197        double coor_y = ymin + y_tilted;
00198 
00199        m_coor_x[quad][sect][col][row] = coor_x;
00200        m_coor_y[quad][sect][col][row] = coor_y;
00201 
00202        if ( coor_x < m_coor_x_min[quad] ) m_coor_x_min[quad] = coor_x;
00203        if ( coor_x > m_coor_x_max[quad] ) m_coor_x_max[quad] = coor_x;
00204        if ( coor_y < m_coor_y_min[quad] ) m_coor_y_min[quad] = coor_y;
00205        if ( coor_y > m_coor_y_max[quad] ) m_coor_y_max[quad] = coor_y;
00206     }
00207     }
00208 }
00209 
00210 //--------------
00211 
00212 void PixCoordsQuad::setConstXYMinMax()
00213 {
00214         double pixSize_um = PSCalib::CSPadCalibPars::getRowSize_um();
00215 
00216             for (uint32_t q=0; q<NQuadsInCSPad; q++) {
00217               m_coor_x_min[q] = 0;
00218               m_coor_y_min[q] = 0;
00219               m_coor_x_max[q] = 850*pixSize_um;
00220               m_coor_y_max[q] = 850*pixSize_um;
00221             }
00222 }
00223 
00224 //--------------
00225 
00226 double PixCoordsQuad::getPixCoorRot000_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00227 {
00228   switch (icoor)
00229     {
00230     case CSPadPixCoords::PixCoords2x1::X : return m_coor_x[quad][sect][col][row] - m_coor_x_min[quad];
00231     case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y[quad][sect][col][row] - m_coor_y_min[quad];
00232     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00233     default: return 0;
00234     }
00235 }
00236 
00237 //--------------
00238 
00239 double PixCoordsQuad::getPixCoorRot090_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00240 {
00241   switch (icoor)
00242     {
00243     case CSPadPixCoords::PixCoords2x1::X : return m_coor_y_max[quad] - m_coor_y[quad][sect][col][row];
00244     case CSPadPixCoords::PixCoords2x1::Y : return m_coor_x[quad][sect][col][row] - m_coor_x_min[quad];
00245     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00246     default: return 0;
00247     }
00248 }
00249 
00250 //--------------
00251 
00252 double PixCoordsQuad::getPixCoorRot180_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00253 {
00254   switch (icoor)
00255     {
00256     case CSPadPixCoords::PixCoords2x1::X : return m_coor_x_max[quad] - m_coor_x[quad][sect][col][row];
00257     case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y_max[quad] - m_coor_y[quad][sect][col][row];
00258     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00259     default: return 0;
00260     }
00261 }
00262 
00263 //--------------
00264 
00265 double PixCoordsQuad::getPixCoorRot270_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00266 {
00267   switch (icoor)
00268     {
00269     case CSPadPixCoords::PixCoords2x1::X : return m_coor_y[quad][sect][col][row] - m_coor_y_min[quad];
00270     case CSPadPixCoords::PixCoords2x1::Y : return m_coor_x_max[quad] - m_coor_x[quad][sect][col][row];
00271     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00272     default: return 0;
00273     }
00274 }
00275 
00276 //--------------
00277 //--------------
00278 //--------------
00279 //--------------
00280 
00281 double PixCoordsQuad::getPixCoorRot000_pix (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00282 {
00283   switch (icoor)
00284     {
00285     case CSPadPixCoords::PixCoords2x1::X : return getPixCoorRot000_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getRowUmToPix();
00286     case CSPadPixCoords::PixCoords2x1::Y : return getPixCoorRot000_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getColUmToPix();
00287     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00288     default: return 0;
00289     }
00290 }
00291 
00292 //--------------
00293 
00294 double PixCoordsQuad::getPixCoorRot090_pix (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00295 {
00296   switch (icoor)
00297     {
00298     case CSPadPixCoords::PixCoords2x1::X : return getPixCoorRot090_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getColUmToPix();
00299     case CSPadPixCoords::PixCoords2x1::Y : return getPixCoorRot090_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getRowUmToPix();
00300     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00301     default: return 0;
00302     }
00303 }
00304 
00305 //--------------
00306 
00307 double PixCoordsQuad::getPixCoorRot180_pix (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00308 {
00309   switch (icoor)
00310     {
00311     case CSPadPixCoords::PixCoords2x1::X : return getPixCoorRot180_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getRowUmToPix();
00312     case CSPadPixCoords::PixCoords2x1::Y : return getPixCoorRot180_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getColUmToPix();
00313     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00314     default: return 0;
00315     }
00316 }
00317 
00318 //--------------
00319 
00320 double PixCoordsQuad::getPixCoorRot270_pix (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00321 {
00322   switch (icoor)
00323     {
00324     case CSPadPixCoords::PixCoords2x1::X : return getPixCoorRot270_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getColUmToPix();
00325     case CSPadPixCoords::PixCoords2x1::Y : return getPixCoorRot270_um (icoor, quad, sect, row, col) * PSCalib::CSPadCalibPars::getRowUmToPix();
00326     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00327     default: return 0;
00328     }
00329 }
00330 
00331 //--------------
00332 
00333 double PixCoordsQuad::getPixCoorRotN90_um (CSPadPixCoords::PixCoords2x1::ORIENTATION n90, 
00334                                           CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00335 {
00336   switch (n90)
00337     {
00338     case CSPadPixCoords::PixCoords2x1::R000 : return getPixCoorRot000_um (icoor, quad, sect, row, col);
00339     case CSPadPixCoords::PixCoords2x1::R090 : return getPixCoorRot090_um (icoor, quad, sect, row, col);
00340     case CSPadPixCoords::PixCoords2x1::R180 : return getPixCoorRot180_um (icoor, quad, sect, row, col);
00341     case CSPadPixCoords::PixCoords2x1::R270 : return getPixCoorRot270_um (icoor, quad, sect, row, col);
00342     default   : return 0;
00343     }
00344 }
00345 
00346 //--------------
00347 
00348 double PixCoordsQuad::getPixCoorRotN90_pix(CSPadPixCoords::PixCoords2x1::ORIENTATION n90, 
00349                                           CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00350 {
00351   switch (n90)
00352     {
00353     case CSPadPixCoords::PixCoords2x1::R000 : return getPixCoorRot000_pix (icoor, quad, sect, row, col);
00354     case CSPadPixCoords::PixCoords2x1::R090 : return getPixCoorRot090_pix (icoor, quad, sect, row, col);
00355     case CSPadPixCoords::PixCoords2x1::R180 : return getPixCoorRot180_pix (icoor, quad, sect, row, col);
00356     case CSPadPixCoords::PixCoords2x1::R270 : return getPixCoorRot270_pix (icoor, quad, sect, row, col);
00357     default   : return 0;
00358     }
00359 }
00360 
00361 //--------------
00362 
00363 double PixCoordsQuad::getPixCoorRotN90 ( CSPadPixCoords::PixCoords2x1::UNITS units, 
00364                                         CSPadPixCoords::PixCoords2x1::ORIENTATION n90, 
00365                                         CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned quad, unsigned sect, unsigned row, unsigned col)
00366 {
00367   switch (units)
00368     {
00369     case  CSPadPixCoords::PixCoords2x1::UM  : return getPixCoorRotN90_um  (n90, icoor, quad, sect, row, col);
00370     case  CSPadPixCoords::PixCoords2x1::PIX : return getPixCoorRotN90_pix (n90, icoor, quad, sect, row, col);
00371     default   : return 0;
00372     }
00373 }
00374 
00375 //--------------
00376 // Destructor --
00377 //--------------
00378 
00379 PixCoordsQuad::~PixCoordsQuad ()
00380 {
00381 }
00382 
00383 } // namespace CSPadPixCoords

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7