PSCalib/include/CSPadCalibPars.h

Go to the documentation of this file.
00001 #ifndef PSCALIB_CSPADCALIBPARS_H
00002 #define PSCALIB_CSPADCALIBPARS_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: CSPadCalibPars.h 8295 2014-05-28 18:28:22Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // $Revision: 8295 $
00009 //------------------------------------------------------------------------
00010 
00011 //-----------------
00012 // C/C++ Headers --
00013 //-----------------
00014 #include <iostream>
00015 #include <string>
00016 #include <vector>
00017 #include <map>
00018 #include <fstream>  // open, close etc.
00019 
00020 //-------------------------------
00021 // Collaborating Class Headers --
00022 //-------------------------------
00023 #include "psddl_psana/cspad.ddl.h"
00024 #include "pdsdata/xtc/Src.hh"
00025 
00026 #include "pdscalibdata/CalibParsCenterV1.h"      
00027 #include "pdscalibdata/CalibParsCenterCorrV1.h"  
00028 #include "pdscalibdata/CalibParsMargGapShiftV1.h"
00029 #include "pdscalibdata/CalibParsOffsetV1.h"      
00030 #include "pdscalibdata/CalibParsOffsetCorrV1.h"  
00031 #include "pdscalibdata/CalibParsRotationV1.h"    
00032 #include "pdscalibdata/CalibParsTiltV1.h"        
00033 #include "pdscalibdata/CalibParsQuadRotationV1.h"
00034 #include "pdscalibdata/CalibParsQuadTiltV1.h"    
00035 #include "pdscalibdata/CsPadBeamVectorV1.h"    
00036 #include "pdscalibdata/CsPadBeamIntersectV1.h"    
00037 #include "pdscalibdata/CsPadCenterGlobalV1.h"      
00038 #include "pdscalibdata/CsPadRotationGlobalV1.h"    
00039 
00040 //-----------------------------
00041 
00042 namespace PSCalib {
00043 
00044 /**
00045  *  @version $Id: CSPadCalibPars.h 8295 2014-05-28 18:28:22Z dubrovin@SLAC.STANFORD.EDU $
00046  *
00047  *  @author Mikhail S. Dubrovin
00048  */
00049 
00050 ///  @addtogroup PSCalib PSCalib
00051  
00052 /**
00053  *
00054  *  @ingroup PSCalib
00055  *
00056  *  @brief CSPadCalibPars class loads/holds/provides access to the CSPad
00057  *  geometry calibration parameters.
00058  *
00059  *  This software was developed for the LCLS project. If you use all or 
00060  *  part of it, please give an appropriate acknowledgment.
00061  *
00062  *  @anchor interface
00063  *  @par<interface> Interface Description
00064  * 
00065  *  @li  Include and typedef
00066  *  @code
00067  *  #include "PSCalib/CSPadCalibPars.h"
00068  *  typedef PSCalib::CSPadCalibPars CALIB;
00069  *  @endcode
00070  *
00071  *  @li Instatiation
00072  *  \n
00073  *  For default constructor:
00074  *  @code
00075  *  CALIB *calibpars = new CALIB();  
00076  *  @endcode
00077  *  \n
00078  *  For regular constructor:
00079  *  @code
00080  *  const std::string calibDir   = "/reg/d/psdm/cxi/cxitut13/calib";
00081  *  const std::string groupName  = "CsPad::CalibV1";
00082  *  unsigned long     runNumber  = 10;
00083  *  Pds::Src src; env.get(...,&src);
00084  *  CALIB *calibpars = new CALIB(calibDir, groupName, src, runNumber);  
00085  *  @endcode
00086  *  \n
00087  *  For explicit constructor (depricated):
00088  *  @code
00089  *  const std::string calibDir   = "/reg/d/psdm/cxi/cxitut13/calib";
00090  *  const std::string groupName  = "CsPad::CalibV1";
00091  *  const std::string source     = "CxiDs1.0:Cspad.0";
00092  *  unsigned long     runNumber  = 10;
00093  *  CALIB *calibpars = new CALIB(calibDir, groupName, source, runNumber);  
00094  *  @endcode
00095  *
00096  *  @li Printing methods
00097  *  @code
00098  *  calibpars -> printInputPars();
00099  *  calibpars -> printCalibPars();
00100  *  calibpars -> printCalibParsStatus();
00101  *  @endcode
00102  *
00103  *  @li Access methods
00104  *  @code
00105  *  size_t quad=1, sect=7; // for example...
00106  *  int status  = calibpars -> getCalibTypeStatus("center_global") // Returns status: 0-default, 1-loaded from file
00107  *  double xc   = calibpars -> getCenterX(quad, sect);
00108  *  double xcg  = calibpars -> getCenterGlobalX(quad, sect);
00109  *  double tilt = calibpars -> getTilt(quad, sect);
00110  *  ... etc. for all other access methods
00111  *  @endcode
00112  *
00113  *  @see CalibFileFinder
00114  *
00115  */
00116 
00117 //----------------
00118 
00119 class CSPadCalibPars  {
00120 public:
00121 
00122   /**
00123    *  @brief Default and test constructor
00124    *  @param[in] isTestMode - flag of the test mode; if =true then parameters are loaded from the test directory.
00125    */ 
00126   CSPadCalibPars ( bool isTestMode = false ) ;
00127 
00128   /**
00129    *  @brief DEPRICATED constructor, which gets the source as a string\&. It is preserved for backward compatability.
00130    *  @param[in] calibDir       Calibration directory for current experiment, for example "/reg/d/psdm/cxi/cxitut13/calib";
00131    *  @param[in] typeGroupName  Data type and group names, for example "CsPad::CalibV1";
00132    *  @param[in] source         The name of the data source, for example "CxiDs1.0:Cspad.0";
00133    *  @param[in] runNumber      Run number to search the valid file name, for example  =10;
00134    *  @param[in] print_bits     Verbosity bits;
00135    */ 
00136   CSPadCalibPars ( const std::string&   calibDir,     
00137                    const std::string&   typeGroupName,
00138                    const std::string&   source,       
00139                    const unsigned long& runNumber,
00140                    const unsigned&      print_bits=0 ) ; 
00141   /**
00142    *  @brief RECOMMENDED constructor, which gets the source as a \c const \c Pds::Src\& parameter.
00143    *  @param[in] calibDir       Calibration directory for current experiment, for example "/reg/d/psdm/cxi/cxitut13/calib";
00144    *  @param[in] typeGroupName  Data type and group names, for example "CsPad::CalibV1";
00145    *  @param[in] src            The name of the data source, for example Pds::Src m_src; defined in the env.get(...,&m_src)
00146    *  @param[in] runNumber      Run number to search the valid file name, for example  =10;
00147    *  @param[in] print_bits     Verbosity bits;
00148    */ 
00149   CSPadCalibPars ( const std::string&   calibDir,     
00150                    const std::string&   typeGroupName,
00151                    const Pds::Src&      src,          
00152                    const unsigned long& runNumber,
00153                    const unsigned&      print_bits=0 ) ; 
00154 
00155   /// Destructor
00156   virtual ~CSPadCalibPars () ;
00157 
00158   // Returns the number of rows in 2x1 (185)          
00159   //size_t   getNRows          (){ return m_nrows; };
00160 
00161   // Returns the number of columns in 2x1 (388)
00162   //size_t   getNCols          (){ return m_ncols; };
00163 
00164   /// Prints status for all calibration parameters: 0-default, 1-loaded from file
00165   void printCalibParsStatus  ();
00166 
00167   /// Prints all calibration parameters
00168   void printCalibPars        ();
00169 
00170   /// Prints input parameters
00171   void printInputPars        ();
00172 
00173 
00174 
00175   /// Returns x-coordinate [pix] of the 2x1 section center in specified quad.
00176   double getCenterX(size_t quad, size_t sect){ return m_center -> getCenterX(quad,sect); };
00177 
00178   /// Returns y-coordinate [pix] of the 2x1 section center in specified quad.
00179   double getCenterY(size_t quad, size_t sect){ return m_center -> getCenterY(quad,sect); };
00180 
00181   /// Returns z-coordinate [pix] of the 2x1 section center in specified quad.
00182   double getCenterZ(size_t quad, size_t sect){ return m_center -> getCenterZ(quad,sect); };
00183 
00184 
00185 
00186   /// Returns x-coordinate correction [pix] of the 2x1 section center in specified quad.
00187   double getCenterCorrX(size_t quad, size_t sect){ return m_center_corr -> getCenterCorrX(quad,sect); };
00188 
00189   /// Returns y-coordinate correction [pix] of the 2x1 section center in specified quad.
00190   double getCenterCorrY(size_t quad, size_t sect){ return m_center_corr -> getCenterCorrY(quad,sect); };
00191 
00192   /// Returns z-coordinate correction [pix] of the 2x1 section center in specified quad.
00193   double getCenterCorrZ(size_t quad, size_t sect){ return m_center_corr -> getCenterCorrZ(quad,sect); };
00194 
00195 
00196 
00197   /// Returns x-margine of all 2x1s in quad from calibration type marg_gap_shift
00198   double getQuadMargX () { return m_marg_gap_shift -> getQuadMargX (); };
00199 
00200   /// Returns y-margine of all 2x1s in quad from calibration type marg_gap_shift
00201   double getQuadMargY () { return m_marg_gap_shift -> getQuadMargY (); };
00202 
00203   /// Returns z-margine of all 2x1s in quad from calibration type marg_gap_shift
00204   double getQuadMargZ () { return m_marg_gap_shift -> getQuadMargZ (); };
00205 
00206 
00207 
00208   /// Returns x-margine of all quads in the detector from calibration type marg_gap_shift
00209   double getMargX () { return m_marg_gap_shift -> getMargX (); };
00210 
00211   /// Returns y-margine of all quads in the detector from calibration type marg_gap_shift
00212   double getMargY () { return m_marg_gap_shift -> getMargY (); };
00213 
00214   /// Returns z-margine of all quads in the detector from calibration type marg_gap_shift
00215   double getMargZ () { return m_marg_gap_shift -> getMargZ (); };
00216                                                          
00217 
00218 
00219   /// Returns x-gap between quads in the detector from calibration type marg_gap_shift
00220   double getGapX  () { return m_marg_gap_shift -> getGapX  (); };
00221 
00222   /// Returns y-gap between quads in the detector from calibration type marg_gap_shift
00223   double getGapY  () { return m_marg_gap_shift -> getGapY  (); };
00224 
00225   /// Returns z-gap between quads in the detector from calibration type marg_gap_shift
00226   double getGapZ  () { return m_marg_gap_shift -> getGapZ  (); };
00227 
00228 
00229                                                          
00230   /// Returns x-shift between quads in the detector from calibration type marg_gap_shift
00231   double getShiftX() { return m_marg_gap_shift -> getShiftX(); };
00232                                                          
00233   /// Returns y-shift between quads in the detector from calibration type marg_gap_shift
00234   double getShiftY() { return m_marg_gap_shift -> getShiftY(); };
00235                                                          
00236   /// Returns z-shift between quads in the detector from calibration type marg_gap_shift
00237   double getShiftZ() { return m_marg_gap_shift -> getShiftZ(); };
00238 
00239 
00240 
00241   /// Returns x-offset of quads in the detector from calibration type offset
00242   double getOffsetX(size_t quad) { return m_offset -> getOffsetX(quad); };
00243 
00244   /// Returns y-offset of quads in the detector from calibration type offset
00245   double getOffsetY(size_t quad) { return m_offset -> getOffsetY(quad); };
00246 
00247   /// Returns z-offset of quads in the detector from calibration type offset
00248   double getOffsetZ(size_t quad) { return m_offset -> getOffsetZ(quad); };
00249 
00250 
00251 
00252   /// Returns x-offset correction of quads in the detector from calibration type offset_corr
00253   double getOffsetCorrX(size_t quad) { return m_offset_corr -> getOffsetCorrX(quad); };
00254 
00255   /// Returns y-offset correction of quads in the detector from calibration type offset_corr
00256   double getOffsetCorrY(size_t quad) { return m_offset_corr -> getOffsetCorrY(quad); };
00257 
00258   /// Returns z-offset correction of quads in the detector from calibration type offset_corr
00259   double getOffsetCorrZ(size_t quad) { return m_offset_corr -> getOffsetCorrZ(quad); };
00260 
00261 
00262 
00263   /// Returns the 2x1 tile rotation angle (in units of n*90 degrees) from calibration type rotation 
00264   double getRotation(size_t quad, size_t sect) { return m_rotation -> getRotation(quad,sect); };
00265 
00266   /// Returns the 2x1 tile tilt angle (in units of n*90 degrees) from calibration type tilt 
00267   double getTilt    (size_t quad, size_t sect) { return m_tilt     -> getTilt    (quad,sect); };
00268 
00269 
00270 
00271   /// Returns the quad rotation angle (in units of n*90 degrees) from calibration type quad_rotation 
00272   double getQuadRotation(size_t quad) { return m_quad_rotation -> getQuadRotation(quad); };
00273 
00274   /// Returns the quad tilt angle (in units of n*90 degrees) from calibration type quad_tilt
00275   double getQuadTilt    (size_t quad) { return m_quad_tilt     -> getQuadTilt    (quad); };
00276 
00277 
00278 
00279   /// Returns pointer to the beam_vector from calibration type beam_vector 
00280   double* getBeamVector   ()         { return  m_beam_vector    -> getVector(); };
00281 
00282   /// Returns component of the beam_vector from calibration type beam_vector 
00283   double  getBeamVector   (size_t i) { return  m_beam_vector    -> getVectorEl(i); };
00284 
00285 
00286 
00287   /// Returns pointer to the beam_intersect from calibration type beam_intersect 
00288   double* getBeamIntersect()         { return  m_beam_intersect -> getVector(); };
00289 
00290   /// Returns component of the beam_intersect from calibration type beam_intersect 
00291   double  getBeamIntersect(size_t i) { return  m_beam_intersect -> getVectorEl(i); };
00292 
00293 
00294 
00295   /// Returns the pixel size of the row in um                                           
00296   static double getRowSize_um()   { return 109.92; }
00297 
00298   /// Returns the pixel size of the column in um                                        
00299   static double getColSize_um()   { return 109.92; }  
00300 
00301   /// Returns the pixel size of the gap column in um
00302   static double getGapRowSize_um(){ return 274.80; }
00303 
00304   /// Returns the pixel size of the total gap in um 
00305   static double getGapSize_um()   { return 2*getGapRowSize_um() - getRowSize_um(); }
00306 
00307   /// Returns the pixel size of the ortogonal dimension in um                                        
00308   static double getOrtSize_um()   { return 500.00; }
00309 
00310   /// Returns the conversion factor of um to pixels for rows
00311   static double getRowUmToPix()   { return 1./getRowSize_um(); }
00312  
00313   /// Returns the conversion factor of um to pixels for columns 
00314   static double getColUmToPix()   { return 1./getColSize_um(); }
00315 
00316   /// Returns the conversion factor of um to pixels for ort.
00317   static double getOrtUmToPix()   { return 1.; }                
00318 
00319   /// Returns x-coordinate [pix] of the 2x1 section center for specified quad in the detector frame.
00320   double getCenterGlobalX(size_t quad, size_t sect){ return m_center_global -> getCenterX(quad,sect); };
00321 
00322   /// Returns y-coordinate [pix] of the 2x1 section center for specified quad in the detector frame.
00323   double getCenterGlobalY(size_t quad, size_t sect){ return m_center_global -> getCenterY(quad,sect); };
00324 
00325   /// Returns z-coordinate [pix] of the 2x1 section center for specified quad in the detector frame.
00326   double getCenterGlobalZ(size_t quad, size_t sect){ return m_center_global -> getCenterZ(quad,sect); };
00327 
00328   /// Returns rotation angle of the 2x1 section for specified quad in the detector frame.
00329   double getRotationGlobal(size_t quad, size_t sect) { return m_rotation_global -> getRotation(quad,sect); };
00330 
00331   /// Returns status of the calibration constants, 0-default, 1-loaded from file
00332   int getCalibTypeStatus(const std::string&  type) { return m_calibtype_status[type]; };
00333 
00334 
00335 protected:
00336 
00337   /// Makes member data vector with all supported calibration types such as center, center_corr, off_gap_shift, offset, offset_corr, rotation, tilt, ...
00338   void fillCalibNameVector   ();
00339 
00340   /// Define the path to the calibration file based on input parameters
00341   void getCalibFileName      ();
00342 
00343   /// Load all known calibration parameters
00344   void loadCalibPars         ();
00345 
00346   /// Open calibration file
00347   void openCalibFile         ();
00348 
00349   /// Close calibration file
00350   void closeCalibFile        ();
00351 
00352   /// Read parameters from calibration file to vector
00353   void readCalibPars         ();
00354 
00355   /// Fill calibration parameters from vector
00356   void fillCalibParsV1       ();
00357 
00358   /// Fill default calibration parameters
00359   void fillDefaultCalibParsV1();
00360 
00361   /// Generate error message in the log and abort
00362   void fatalMissingFileName  ();
00363 
00364   /// Generate warning message in the log
00365   void msgUseDefault         ();
00366 
00367 
00368 private:
00369 
00370   /// Copy constructor
00371   CSPadCalibPars ( const CSPadCalibPars& ) ;
00372   /// Assignment operator
00373   CSPadCalibPars operator = ( const CSPadCalibPars& ) ;
00374 
00375 //------------------
00376 // Static Members --
00377 //------------------
00378 
00379   // Data members for TEST constructor       
00380   //std::string m_expdir;       // /reg/d/psdm/CXI/cxi35711 
00381   //std::string m_calibtype;    // CsPad::CalibV1 
00382   //std::string m_calibsrc;     // CxiDs1.0:Cspad.0 
00383   std::string m_calibdir;       // /reg/neh/home/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi35711-r0009-det
00384   std::string m_calibfilename;  // 1-20.data
00385 
00386 
00387   // Data members for regular constructor // /reg/d/psdm/CXI/cxi35711/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/pedestals/1-20.data
00388   std::string   m_calibDir;
00389   std::string   m_typeGroupName;
00390   std::string   m_source;
00391   Pds::Src      m_src;
00392   std::string   m_dataType;
00393   unsigned long m_runNumber;
00394 
00395   std::vector<std::string> v_calibname; // center, center_corr, off_gap_shift, offset, offset_corr, rotation, tilt, ...
00396   std::vector<double>      v_parameters;
00397 
00398   std::map<std::string, int> m_calibtype_status; // =0-default, =1-from file
00399 
00400   std::string m_cur_calibname;  
00401   std::string m_fname;
00402 
00403   bool m_isTestMode;
00404   unsigned m_print_bits;
00405 
00406   //size_t m_nrows; 
00407   //size_t m_ncols; 
00408 
00409   std::ifstream m_file;
00410 
00411   pdscalibdata::CalibParsCenterV1       *m_center;
00412   pdscalibdata::CalibParsCenterCorrV1   *m_center_corr;
00413   pdscalibdata::CalibParsMargGapShiftV1 *m_marg_gap_shift;
00414   pdscalibdata::CalibParsOffsetV1       *m_offset;
00415   pdscalibdata::CalibParsOffsetCorrV1   *m_offset_corr;
00416   pdscalibdata::CalibParsRotationV1     *m_rotation;    
00417   pdscalibdata::CalibParsTiltV1         *m_tilt;   
00418   pdscalibdata::CalibParsQuadRotationV1 *m_quad_rotation;    
00419   pdscalibdata::CalibParsQuadTiltV1     *m_quad_tilt;   
00420   pdscalibdata::CsPadBeamVectorV1       *m_beam_vector;   
00421   pdscalibdata::CsPadBeamIntersectV1    *m_beam_intersect;   
00422   pdscalibdata::CsPadCenterGlobalV1     *m_center_global;
00423   pdscalibdata::CsPadRotationGlobalV1   *m_rotation_global;    
00424 
00425 };
00426 
00427 } // namespace PSCalib
00428 
00429 #endif // PSCALIB_CSPADCALIBPARS_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7