00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "PSCalib/GeometryObject.h"
00018 #include "PSCalib/GeometryAccess.h"
00019
00020 #include "ImgAlgos/GlobalMethods.h"
00021 #include "pdscalibdata/NDArrIOV1.h"
00022
00023 #include <string>
00024 #include <iostream>
00025 #include <iomanip>
00026
00027
00028
00029
00030 using namespace std;
00031
00032
00033
00034
00035
00036 void test_cspad2x2 (int argc, char* argv[])
00037 {
00038
00039 string basedir = "/reg/g/psdm/detector/alignment/cspad2x2/calib-cspad2x2-01-2013-02-13/";
00040 string fname_geometry = basedir + "calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.1/geometry/0-end.data";
00041 string fname_data = basedir + "cspad2x2.1-ndarr-ave-meca6113-r0028.dat";
00042
00043 typedef pdscalibdata::NDArrIOV1<double,3> NDAIO;
00044 unsigned shape[] = {185,388,2};
00045 NDAIO* arrio = new NDAIO(fname_data, shape, 0, 0);
00046
00047
00048 PSCalib::GeometryAccess geometry(fname_geometry, 0);
00049 geometry.print_list_of_geos_children();
00050
00051 cout << "\n\ntest_cspad2x2(...):\n";
00052
00053 const unsigned * iX;
00054 const unsigned * iY;
00055 unsigned isize;
00056 geometry.get_pixel_coord_indexes(iX, iY, isize);
00057
00058 ndarray<PSCalib::GeometryAccess::image_t, 2> img =
00059 PSCalib::GeometryAccess::img_from_pixel_arrays(iX, iY, arrio->get_ndarray().data(), isize);
00060 cout << img << "\n";
00061
00062 string fname_img("cspad2x2-img-test.txt");
00063 cout << " argc=" << argc << ", if (argc>1) - save image in text file " << fname_img << '\n';
00064 if (argc>1) ImgAlgos::save2DArrayInFile<PSCalib::GeometryAccess::image_t>(fname_img.c_str(), img, true);
00065 }
00066
00067
00068
00069
00070 int main (int argc, char* argv[])
00071 {
00072 std::string pname("SOME_PARENT");
00073 unsigned pindex=1;
00074 std::string oname("SENS2X1:V1");
00075 unsigned oindex=2;
00076 double x0=3;
00077 double y0=4;
00078 double z0=5;
00079 double rot_z=6;
00080 double rot_y=7;
00081 double rot_x=8;
00082 double tilt_z=9;
00083 double tilt_y=10;
00084 double tilt_x=11;
00085
00086
00087 cout << "Run " << argv[0] << '\n';
00088 cout << "\n\nTest of PSCalib::GeometryObject\n";
00089 PSCalib::GeometryObject* geo = new PSCalib::GeometryObject(pname,
00090 pindex,
00091 oname,
00092 oindex,
00093 x0,
00094 y0,
00095 z0,
00096 rot_z,
00097 rot_y,
00098 rot_x,
00099 tilt_z,
00100 tilt_y,
00101 tilt_x );
00102
00103 geo->print_geo();
00104
00105 cout << "Size of geo: " << geo->get_size_geo_array() << "\n";
00106
00107
00108 cout << "\n\nTest of PSCalib::GeometryAccess\n";
00109
00110
00111
00112
00113
00114 string basedir = "/reg/g/psdm/detector/alignment/cspad/calib-cxi-ds1-2014-05-15/";
00115 string fname_geometry = basedir + "calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/geometry/2-end.data";
00116 string fname_data = basedir + "cspad-arr-cxid2714-r0023-lysozyme-rings.txt";
00117
00118
00119
00120
00121
00122
00123
00124 unsigned print_bits = 0;
00125 PSCalib::GeometryAccess geometry(fname_geometry, print_bits);
00126
00127
00128 cout << "\n\nTest of print_list_of_geos():\n";
00129 geometry.print_list_of_geos();
00130
00131
00132 cout << "\n\nTest of print_list_of_geos_children():\n";
00133 geometry.print_list_of_geos_children();
00134
00135
00136 cout << "\n\nTest of print_comments_from_dict():\n";
00137 geometry.print_comments_from_dict();
00138
00139
00140 cout << "\n\nTest of get_geo(...):\n";
00141 geometry.get_geo("QUAD:V1", 1)->print_geo_children();
00142
00143
00144 cout << "\n\nTest of get_top_geo():\n";
00145 geometry.get_top_geo()->print_geo_children();
00146
00147
00148 cout << "\n\nTest of print_pixel_coords(...) for quad:\n";
00149 geometry.print_pixel_coords("QUAD:V1", 1);
00150 cout << "\n\nTest of print_pixel_coords(...) for CSPAD:\n";
00151 geometry.print_pixel_coords();
00152
00153
00154 cout << "\n\nTest of get_pixel_coords(...):\n";
00155 const double* X;
00156 const double* Y;
00157 const double* Z;
00158 unsigned size;
00159 geometry.get_pixel_coords(X,Y,Z,size);
00160
00161 cout << "size=" << size << '\n' << std::fixed << std::setprecision(1);
00162 cout << "X: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << X[i] << ", "; cout << "...\n";
00163 cout << "Y: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << Y[i] << ", "; cout << "...\n";
00164 cout << "Z: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << Z[i] << ", "; cout << "...\n";
00165
00166
00167 cout << "\n\nTest of get_pixel_coord_indexes(...):\n";
00168 const unsigned * iX;
00169 const unsigned * iY;
00170 unsigned isize;
00171
00172 const std::string ioname = "QUAD:V1";
00173 const unsigned ioindex = 1;
00174 const double pix_scale_size_um = 109.92;
00175 const int xy0_off_pix[] = {200,200};
00176 geometry.get_pixel_coord_indexes(iX, iY, isize, ioname, ioindex, pix_scale_size_um, xy0_off_pix);
00177
00178 cout << "QUAD size=" << isize << '\n' << std::fixed << std::setprecision(1);
00179 cout << "iX: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << iX[i] << ", "; cout << "...\n";
00180 cout << "iY: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << iY[i] << ", "; cout << "...\n";
00181
00182 geometry.get_pixel_coord_indexes(iX, iY, isize);
00183
00184 cout << "CSPAD size=" << isize << '\n' << std::fixed << std::setprecision(1);
00185 cout << "iX: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << iX[i] << ", "; cout << "...\n";
00186 cout << "iY: "; for(unsigned i=0; i<10; ++i) cout << std::setw(10) << iY[i] << ", "; cout << "...\n";
00187
00188
00189
00190 cout << "\n\nTest of PSCalib::img_from_pixel_arrays(...):\n";
00191 ndarray<PSCalib::GeometryAccess::image_t, 2> img =
00192 PSCalib::GeometryAccess::img_from_pixel_arrays(iX, iY, 0, isize);
00193 cout << img << "\n";
00194 cout << " argc=" << argc << ", if (argc>1) - save image in text file.\n";
00195 if (argc>1) ImgAlgos::save2DArrayInFile<PSCalib::GeometryAccess::image_t>("cspad-img-test.txt", img, true);
00196
00197
00198 cout << "\n\nTest of get_pixel_areas(...):\n";
00199 const double* A;
00200 geometry.get_pixel_areas(A,size);
00201
00202 cout << "size=" << size << '\n' << std::fixed << std::setprecision(1);
00203 cout << "Areas: "; for(unsigned i=190; i<200; ++i) cout << std::setw(10) << A[i] << ", "; cout << "...\n";
00204
00205
00206 cout << "\n\nTest of get_pixel_mask(...):\n";
00207 const int* mask;
00208 unsigned mbits = 077;
00209 geometry.get_pixel_mask(mask, size, std::string(), 0, mbits);
00210
00211 cout << "size=" << size << '\n' << std::fixed << std::setprecision(1);
00212 cout << "Mask[row=0]: "; for(unsigned i=190; i<200; ++i) cout << std::setw(10) << mask[i] << ", "; cout << "...\n";
00213 cout << "Mask[row=1]: "; for(unsigned i=190; i<200; ++i) cout << std::setw(10) << mask[i+388] << ", "; cout << "...\n";
00214
00215
00216 cout << "\n\nTest of get_size_geo_array(...) for";
00217 cout << "\nQuad : " << geometry.get_geo("QUAD:V1", 1)->get_size_geo_array();
00218 cout << "\nCSPAD: " << geometry.get_top_geo()->get_size_geo_array();
00219
00220
00221 cout << "\n\nTest of get_pixel_scale_size() for" << std::setprecision(2);
00222 cout << "\nQuad : " << geometry.get_geo("QUAD:V1", 1)->get_pixel_scale_size();
00223 cout << "\nCSPAD : " << geometry.get_top_geo()->get_pixel_scale_size();
00224 cout << "\ngeometry : " << geometry.get_pixel_scale_size();
00225
00226
00227 cout << "\n\nTest of get_dict_of_comments():\n";
00228 std::map<int, std::string>& dict = geometry.get_dict_of_comments();
00229 cout << "dict[0] = " << dict[0] << '\n';
00230
00231
00232
00233 cout << "\n\nTest of save_pars_in_file(path):\n";
00234 geometry.save_pars_in_file("test.txt");
00235
00236
00237 cout << "\n\nTest of save_pars_in_file(path):\n";
00238
00239 const std::string fname_test("test.txt");
00240 geometry.set_print_bits(1+64);
00241 geometry.save_pars_in_file(fname_test);
00242
00243
00244 cout << "\n\nTest of load_pars_from_file(path):\n";
00245 geometry.set_print_bits(1);
00246 geometry.load_pars_from_file(fname_test);
00247 geometry.print_list_of_geos();
00248
00249
00250
00251 cout << "\n\nTest cspad2x2:\n";
00252 test_cspad2x2(argc, argv);
00253
00254
00255 cout << "End of " << argv[0] << '\n';
00256 return 0;
00257 }
00258
00259