CSPadPixCoords/src/PixCoordsCSPad2x2.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class PixCoordsCSPad2x2...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "CSPadPixCoords/PixCoordsCSPad2x2.h"
00017 #include "MsgLogger/MsgLogger.h"
00018 
00019 //-----------------
00020 // C/C++ Headers --
00021 //-----------------
00022 #include <math.h>
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include <boost/math/constants/constants.hpp>
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 const char logger[] = "PixCoordsCSPad2x2";
00042 
00043 //----------------
00044 // Constructors --
00045 //----------------
00046   PixCoordsCSPad2x2::PixCoordsCSPad2x2 (PixCoords2x1 *pix_coords_2x1, bool tiltIsApplied)
00047   : m_pix_coords_2x1(pix_coords_2x1)
00048   , m_cspad2x2_calibpars(0)
00049   , m_tiltIsApplied (tiltIsApplied)
00050 {
00051   XCOOR = CSPadPixCoords::PixCoords2x1::X;
00052   YCOOR = CSPadPixCoords::PixCoords2x1::Y;
00053   ZCOOR = CSPadPixCoords::PixCoords2x1::Z;
00054 
00055   fillPixelCoordinateArrays();
00056   resetXYOriginAndMinMax();
00057   printXYLimits();
00058 }
00059 
00060 //--------------
00061 
00062 PixCoordsCSPad2x2::PixCoordsCSPad2x2 (PixCoords2x1 *pix_coords_2x1,  PSCalib::CSPad2x2CalibPars *cspad2x2_calibpars, bool tiltIsApplied)
00063   : m_pix_coords_2x1(pix_coords_2x1)
00064   , m_cspad2x2_calibpars(cspad2x2_calibpars)
00065   , m_tiltIsApplied (tiltIsApplied)
00066 {
00067   XCOOR = CSPadPixCoords::PixCoords2x1::X;
00068   YCOOR = CSPadPixCoords::PixCoords2x1::Y;
00069   ZCOOR = CSPadPixCoords::PixCoords2x1::Z;
00070 
00071   fillPixelCoordinateArrays();
00072   resetXYOriginAndMinMax();
00073   printXYLimits();
00074 }
00075 
00076 //--------------
00077 
00078 void PixCoordsCSPad2x2::fillPixelCoordinateArrays()
00079 {
00080         m_coor_x_min = 1e5;
00081         m_coor_x_max = 0;
00082         m_coor_y_min = 1e5;
00083         m_coor_y_max = 0;
00084 
00085         m_degToRad = 3.14159265359 / 180.; 
00086 
00087         // Approximate geometry for constructor w/o alignment parameters, where *cspad2x2_calibpars = 0;
00088         double xcenter_pix [] = {200,200};
00089         double ycenter_pix [] = { 95,308};
00090         double zcenter_pix [] = {  0,  0};
00091         double tilt_2x1    [] = {  0,  0};
00092         double rotation_2x1[] = {180,180}; // ...Just because of conventions in this code...
00093 
00094         double pixSize_um = PSCalib::CSPad2x2CalibPars::getRowSize_um();
00095         double xcenter, ycenter, zcenter, rotation, tilt;
00096 
00097         for (uint32_t sect=0; sect < N2x1InDet; ++sect)
00098           {
00099             if (m_cspad2x2_calibpars) {
00100               xcenter  = m_cspad2x2_calibpars -> getCenterX (sect);
00101               ycenter  = m_cspad2x2_calibpars -> getCenterY (sect);
00102               zcenter  = m_cspad2x2_calibpars -> getCenterZ (sect);
00103               tilt     = m_cspad2x2_calibpars -> getTilt    (sect);
00104             } else {
00105               xcenter  = xcenter_pix [sect];
00106               ycenter  = ycenter_pix [sect];
00107               zcenter  = zcenter_pix [sect];
00108               tilt     = tilt_2x1    [sect];
00109             }
00110 
00111             xcenter *= pixSize_um;
00112             ycenter *= pixSize_um;
00113             rotation = rotation_2x1[sect];
00114 
00115             if (m_tiltIsApplied) fillOneSectionTiltedInDet(sect, xcenter, ycenter, zcenter, rotation, tilt);
00116             else                 fillOneSectionInDet      (sect, xcenter, ycenter, zcenter, rotation);
00117 
00118             //cout << " sect=" << sect;
00119           }
00120         //cout << endl;
00121 }
00122 
00123 //--------------
00124 
00125 void PixCoordsCSPad2x2::fillOneSectionInDet(uint32_t sect, double xcenter, double ycenter, double zcenter, double rotation)
00126 {
00127             PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00128 
00129             double xmin = xcenter - m_pix_coords_2x1->getXCenterOffset_um(orient);
00130             double ymin = ycenter - m_pix_coords_2x1->getYCenterOffset_um(orient);
00131 
00132             for (uint32_t col=0; col<NCols2x1; col++) {
00133             for (uint32_t row=0; row<NRows2x1; row++) {
00134 
00135                double coor_x = xmin + m_pix_coords_2x1->getPixCoorRotN90_um (orient, XCOOR, row, col);
00136                double coor_y = ymin + m_pix_coords_2x1->getPixCoorRotN90_um (orient, YCOOR, row, col);
00137                m_coor_x[col][row][sect] = coor_x;
00138                m_coor_y[col][row][sect] = coor_y;
00139 
00140                if ( coor_x < m_coor_x_min ) m_coor_x_min = coor_x;
00141                if ( coor_x > m_coor_x_max ) m_coor_x_max = coor_x;
00142                if ( coor_y < m_coor_y_min ) m_coor_y_min = coor_y;
00143                if ( coor_y > m_coor_y_max ) m_coor_y_max = coor_y;
00144             }
00145             }
00146 }
00147 
00148 //--------------
00149 
00150 void PixCoordsCSPad2x2::fillOneSectionTiltedInDet(uint32_t sect, double xcenter, double ycenter, double zcenter, double rotation, double tilt)
00151 {
00152   //cout << "PixCoordsCSPad2x2::fillOneSectionInQuad: " << endl;
00153 
00154     PixCoords2x1::ORIENTATION orient = PixCoords2x1::getOrientation(rotation);
00155   
00156     double xhalf  = m_pix_coords_2x1->getXCenterOffset_um(orient);
00157     double yhalf  = m_pix_coords_2x1->getYCenterOffset_um(orient);
00158 
00159     double tiltrad = tilt*m_degToRad;
00160 
00161     double sintilt = sin(tiltrad);
00162     double costilt = cos(tiltrad);
00163 
00164     // Calculate the corner-center offset due to the tilt
00165 
00166     double radius = sqrt(xhalf*xhalf + yhalf*yhalf);
00167     double sinPhi = yhalf / radius;
00168     double cosPhi = xhalf / radius;
00169 
00170     double rdPhi  = radius * tiltrad; // fabs(tiltrad) ?
00171     double dxOff  =  rdPhi * sinPhi;
00172     double dyOff  = -rdPhi * cosPhi;
00173 
00174     double xmin   = xcenter - xhalf + dxOff;
00175     double ymin   = ycenter - yhalf + dyOff;
00176 
00177     /*
00178     cout << " sect="      << sect 
00179          << " rotation="  << rotation
00180          << " tilt="      << tilt
00181          << " sin(tilt)=" << sintilt
00182          << " cos(tilt)=" << costilt
00183          << endl;
00184     */
00185 
00186     for (uint32_t col=0; col<NCols2x1; col++) {
00187     for (uint32_t row=0; row<NRows2x1; row++) {
00188 
00189        double x_in_sec = m_pix_coords_2x1->getPixCoorRotN90_um (orient, XCOOR, row, col);
00190        double y_in_sec = m_pix_coords_2x1->getPixCoorRotN90_um (orient, YCOOR, row, col);
00191 
00192        double x_tilted =  x_in_sec * costilt - y_in_sec * sintilt;
00193        double y_tilted =  x_in_sec * sintilt + y_in_sec * costilt; 
00194 
00195        double coor_x = xmin + x_tilted;
00196        double coor_y = ymin + y_tilted;
00197 
00198        m_coor_x[col][row][sect] = coor_x;
00199        m_coor_y[col][row][sect] = coor_y;
00200 
00201        if ( coor_x < m_coor_x_min ) m_coor_x_min = coor_x;
00202        if ( coor_x > m_coor_x_max ) m_coor_x_max = coor_x;
00203        if ( coor_y < m_coor_y_min ) m_coor_y_min = coor_y;
00204        if ( coor_y > m_coor_y_max ) m_coor_y_max = coor_y;
00205     }
00206     }
00207 }
00208 
00209 //--------------
00210 
00211 void PixCoordsCSPad2x2::resetXYOriginAndMinMax()
00212 {
00213     for (uint32_t col=0; col<NCols2x1;  col++) {
00214     for (uint32_t row=0; row<NRows2x1;  row++) {
00215     for (uint32_t sec=0; sec<N2x1InDet; sec++) {
00216 
00217        m_coor_x[col][row][sec] -= m_coor_x_min;
00218        m_coor_y[col][row][sec] -= m_coor_y_min;
00219     }
00220     }
00221     }
00222 
00223     //double pixSize_um = PSCalib::CSPad2x2CalibPars::getRowSize_um();
00224     //m_coor_x_max = 400*pixSize_um;
00225     //m_coor_y_max = 400*pixSize_um;
00226     m_coor_x_max -= m_coor_x_min;
00227     m_coor_y_max -= m_coor_y_min;
00228     m_coor_x_min = 0;
00229     m_coor_y_min = 0;
00230 }
00231 
00232 //--------------
00233 
00234 void PixCoordsCSPad2x2::printXYLimits()
00235 {
00236   MsgLog(logger, info, "  Xmin: " << m_coor_x_min << "  Xmax: " << m_coor_x_max
00237                     << "  Ymin: " << m_coor_y_min << "  Ymax: " << m_coor_y_max );
00238 }
00239 
00240 //--------------
00241 
00242 double PixCoordsCSPad2x2::getPixCoor_um (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned sect, unsigned row, unsigned col)
00243 {
00244   switch (icoor)
00245     {
00246     case CSPadPixCoords::PixCoords2x1::X : return m_coor_x[col][row][sect];
00247     case CSPadPixCoords::PixCoords2x1::Y : return m_coor_y[col][row][sect];
00248     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00249     default: return 0;
00250     }
00251 }
00252 
00253 //--------------
00254 //--------------
00255 //--------------
00256 //--------------
00257 
00258 double PixCoordsCSPad2x2::getPixCoor_pix (CSPadPixCoords::PixCoords2x1::COORDINATE icoor, unsigned sect, unsigned row, unsigned col)
00259 {
00260   switch (icoor)
00261     {
00262     case CSPadPixCoords::PixCoords2x1::X : return getPixCoor_um (icoor, sect, row, col) * PSCalib::CSPad2x2CalibPars::getRowUmToPix();
00263     case CSPadPixCoords::PixCoords2x1::Y : return getPixCoor_um (icoor, sect, row, col) * PSCalib::CSPad2x2CalibPars::getColUmToPix();
00264     case CSPadPixCoords::PixCoords2x1::Z : return 0;
00265     default: return 0;
00266     }
00267 }
00268 
00269 //--------------
00270 // Destructor --
00271 //--------------
00272 
00273 PixCoordsCSPad2x2::~PixCoordsCSPad2x2 ()
00274 {
00275 }
00276 
00277 } // namespace CSPadPixCoords

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7