00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CSPadPixCoords/PixCoords2x1V2.h"
00017
00018
00019
00020
00021 #include <math.h>
00022
00023
00024 #include <iostream>
00025
00026
00027 using namespace std;
00028
00029
00030
00031
00032
00033 #include "PSCalib/CSPadCalibPars.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 namespace CSPadPixCoords {
00044
00045
00046
00047
00048
00049
00050 void rotation(const double* x, const double* y, unsigned size, double angle_deg, double* xrot, double* yrot)
00051 {
00052 const double angle_rad = angle_deg * DEG_TO_RAD;
00053 const double C = cos(angle_rad);
00054 const double S = sin(angle_rad);
00055 rotation(x, y, size, C, S, xrot, yrot);
00056 }
00057
00058
00059
00060 void rotation(const double* x, const double* y, unsigned size, double C, double S, double* xrot, double* yrot)
00061 {
00062 for (unsigned i=0; i<size; i++, xrot++, yrot++, *x++, *y++) {
00063 *xrot = *x *C - *y *S;
00064 *yrot = *y *C + *x *S;
00065 }
00066 }
00067
00068
00069
00070 double min_of_array(const double* arr, unsigned size)
00071 {
00072 double min=arr[0]; for(unsigned i=1; i<size; ++i) { if(arr[i] < min) min=arr[i]; }
00073 return min;
00074 }
00075
00076
00077
00078 double max_of_array(const double* arr, unsigned size)
00079 {
00080 double max=arr[0]; for(unsigned i=1; i<size; ++i) { if(arr[i] > max) max=arr[i]; }
00081 return max;
00082 }
00083
00084
00085
00086
00087
00088
00089 PixCoords2x1V2::PixCoords2x1V2 (bool use_wide_pix_center)
00090 {
00091
00092
00093 m_use_wide_pix_center = use_wide_pix_center;
00094 m_angle_deg = 123456;
00095
00096 make_maps_of_2x1_pix_coordinates();
00097 }
00098
00099
00100
00101
00102
00103 PixCoords2x1V2::~PixCoords2x1V2 ()
00104 {
00105 }
00106
00107
00108
00109
00110 const unsigned PixCoords2x1V2::IND_CORNER[NCORNERS] = {0, COLS2X1-1, (ROWS2X1-1)*COLS2X1, ROWS2X1*COLS2X1-1};
00111
00112
00113
00114 void PixCoords2x1V2::make_maps_of_2x1_pix_coordinates()
00115 {
00116
00117 double x_offset = PIX_SIZE_WIDE - PIX_SIZE_COLS / 2;
00118 for (unsigned c=0; c<COLS2X1HALF; c++) m_x_rhs[c] = c * PIX_SIZE_COLS + x_offset;
00119 if (m_use_wide_pix_center) m_x_rhs[0] = PIX_SIZE_WIDE / 2;
00120 for (unsigned c=0; c<COLS2X1HALF; c++) { m_x_arr_um[c] = -m_x_rhs[COLS2X1HALF-1-c];
00121 m_x_arr_um[COLS2X1HALF + c] = m_x_rhs[c]; }
00122
00123
00124 double y_offset = (ROWS2X1-1) * PIX_SIZE_ROWS / 2;
00125 for (unsigned r=0; r<ROWS2X1; r++) m_y_arr_um[r] = y_offset - r * PIX_SIZE_ROWS;
00126
00127 for (unsigned c=0; c<COLS2X1; c++) { m_x_arr_pix[c] = m_x_arr_um[c] / PIX_SIZE_COLS; }
00128 for (unsigned r=0; r<ROWS2X1; r++) { m_y_arr_pix[r] = m_y_arr_um[r] / PIX_SIZE_ROWS; }
00129
00130 for (unsigned r=0; r<ROWS2X1; r++) {
00131 for (unsigned c=0; c<COLS2X1; c++) {
00132 m_x_map_2x1_um [r][c] = m_x_arr_um [c];
00133 m_y_map_2x1_um [r][c] = m_y_arr_um [r];
00134 m_x_map_2x1_pix[r][c] = m_x_arr_pix[c];
00135 m_y_map_2x1_pix[r][c] = m_y_arr_pix[r];
00136 }
00137 }
00138
00139 std::fill_n(&m_z_map_2x1[0][0], int(SIZE2X1), double(0));
00140 }
00141
00142
00143
00144 void PixCoords2x1V2::print_member_data()
00145 {
00146 cout << "PixCoords2x1V2::print_member_data():"
00147 << "\n ROWS2X1 " << ROWS2X1
00148 << "\n COLS2X1 " << COLS2X1
00149 << "\n COLS2X1HALF " << COLS2X1HALF
00150 << "\n PIX_SIZE_COLS " << PIX_SIZE_COLS
00151 << "\n PIX_SIZE_ROWS " << PIX_SIZE_ROWS
00152 << "\n PIX_SIZE_WIDE " << PIX_SIZE_WIDE
00153 << "\n PIX_SIZE_UM " << PIX_SIZE_UM
00154 << "\n UM_TO_PIX " << UM_TO_PIX
00155 << "\n m_use_wide_pix_center " << m_use_wide_pix_center
00156 << "\n m_angle_deg " << m_angle_deg
00157
00158 << "\n";
00159 }
00160
00161
00162
00163 void PixCoords2x1V2::print_map_min_max(UNITS units, const double& angle_deg)
00164 {
00165 cout << " 2x1 coordinate map limits for units: " << units << " and angle(deg): " << angle_deg << "\n";
00166 cout << " xmin = " << get_min_of_coord_map_2x1 (AXIS_X, units, angle_deg) << "\n";
00167 cout << " xmax = " << get_max_of_coord_map_2x1 (AXIS_X, units, angle_deg) << "\n";
00168 cout << " ymin = " << get_min_of_coord_map_2x1 (AXIS_Y, units, angle_deg) << "\n";
00169 cout << " ymax = " << get_max_of_coord_map_2x1 (AXIS_Y, units, angle_deg) << "\n";
00170 cout << " zmin = " << get_min_of_coord_map_2x1 (AXIS_Z, units, angle_deg) << "\n";
00171 cout << " zmax = " << get_max_of_coord_map_2x1 (AXIS_Z, units, angle_deg) << "\n";
00172 }
00173
00174
00175
00176 void PixCoords2x1V2::print_coord_arrs_2x1()
00177 {
00178 cout << "\nPixCoords2x1V2::print_coord_arrs_2x1\n";
00179
00180 cout << "m_x_arr_pix:\n";
00181 for (unsigned counter=0, c=0; c<COLS2X1; c++) {
00182 cout << " " << m_x_arr_pix[c];
00183 if (++counter > 19) { counter=0; cout << "\n"; }
00184 }
00185 cout << "\n";
00186
00187 cout << "m_y_arr_pix:\n";
00188 for (unsigned counter=0, r=0; r<ROWS2X1; r++) {
00189 cout << " " << m_y_arr_pix[r];
00190 if (++counter > 19) { counter=0; cout << "\n"; }
00191 }
00192 cout << "\n";
00193 }
00194
00195
00196
00197 double* PixCoords2x1V2::get_coord_map_2x1 (AXIS axis, UNITS units, const double& angle_deg)
00198 {
00199 if(axis == AXIS_Z) return &m_z_map_2x1[0][0];
00200
00201 if(angle_deg != m_angle_deg or units != m_units) {
00202 m_angle_deg = angle_deg;
00203 m_units = units;
00204
00205 const double* x;
00206 const double* y;
00207
00208 switch (units)
00209 {
00210 case PIX :
00211 x = &m_x_map_2x1_pix[0][0];
00212 y = &m_y_map_2x1_pix[0][0];
00213 break;
00214
00215 default :
00216 x = &m_x_map_2x1_um [0][0];
00217 y = &m_y_map_2x1_um [0][0];
00218 }
00219 CSPadPixCoords::rotation(x, y, SIZE2X1, angle_deg, &m_x_map_2x1_rot[0][0], &m_y_map_2x1_rot[0][0]);
00220 }
00221
00222 switch (axis)
00223 {
00224 case AXIS_X : return &m_x_map_2x1_rot [0][0];
00225 case AXIS_Y : return &m_y_map_2x1_rot [0][0];
00226 default : return &m_x_map_2x1_rot [0][0];
00227 }
00228 }
00229
00230
00231
00232 double PixCoords2x1V2::get_min_of_coord_map_2x1 (AXIS axis, UNITS units, const double& angle_deg)
00233 {
00234 double* arr = get_coord_map_2x1 (axis, units, angle_deg);
00235 double corner_coords[NCORNERS];
00236 for (unsigned i=0; i<NCORNERS; ++i) corner_coords[i] = arr[IND_CORNER[i]];
00237 return CSPadPixCoords::min_of_array(corner_coords, NCORNERS);
00238 }
00239
00240
00241
00242 double PixCoords2x1V2::get_max_of_coord_map_2x1 (AXIS axis, UNITS units, const double& angle_deg)
00243 {
00244 double* arr = get_coord_map_2x1 (axis, units, angle_deg);
00245 double corner_coords[NCORNERS];
00246 for (unsigned i=0; i<NCORNERS; ++i) corner_coords[i] = arr[IND_CORNER[i]];
00247 return CSPadPixCoords::max_of_array(corner_coords, NCORNERS);
00248 }
00249
00250
00251
00252
00253
00254
00255 }
00256
00257