CSPadPixCoords/include/CSPadInterpolImageProducer.h

Go to the documentation of this file.
00001 #ifndef CSPADPIXCOORDS_CSPADINTERPOLIMAGEPRODUCER_H
00002 #define CSPADPIXCOORDS_CSPADINTERPOLIMAGEPRODUCER_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: CSPadInterpolImageProducer.h 8040 2014-04-19 01:00:36Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class CSPadInterpolImageProducer.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 #include <ostream>
00017 
00018 //----------------------
00019 // Base Class Headers --
00020 //----------------------
00021 #include "psana/Module.h"
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
00025 //-------------------------------
00026 #include "PSCalib/CSPadCalibPars.h"
00027 
00028 #include "CSPadPixCoords/QuadParameters.h"
00029 #include "CSPadPixCoords/PixCoords2x1.h"
00030 #include "CSPadPixCoords/PixCoordsQuad.h"
00031 #include "CSPadPixCoords/PixCoordsCSPad.h"
00032 
00033 //------------------------------------
00034 // Collaborating Class Declarations --
00035 //------------------------------------
00036 
00037 #include "PSEvt/Source.h"
00038 
00039 
00040 //              ---------------------
00041 //              -- Class Interface --
00042 //              ---------------------
00043 
00044 namespace CSPadPixCoords {
00045 
00046 /// @addtogroup CSPadPixCoords
00047 
00048 /**
00049  *  @ingroup CSPadPixCoords
00050  *
00051  *  @brief CSPadInterpolImageProducer produces the CSPad image for each event and add it to the event in psana framework.
00052  *
00053  *  CSPadInterpolImageProducer works in psana framework. It does a few operation as follows:
00054  *  1) get the pixel coordinates from PixCoords2x1, PixCoordsQuad, and PixCoordsCSPad classes,
00055  *  2) get data from the event,
00056  *  3) produce the Image2D object with CSPad image for each event,
00057  *  4) add the Image2D object in the event for further modules.
00058  *
00059  *  Time consumed to fill the CSPad image array (currently [1750][1750]) 
00060  *  is measured to be about 40 msec/event on psana0105. 
00061  *
00062  *  This class should not be used directly in the code of users modules. 
00063  *  Instead, it should be added as a module in the psana.cfg file with appropriate parameters.
00064  *  Then, the produced Image2D object can be extracted from event and used in other modules.
00065  *
00066  *  This software was developed for the LCLS project.  If you use all or 
00067  *  part of it, please give an appropriate acknowledgment.
00068  *
00069  *  @see PixCoords2x1, PixCoordsQuad, PixCoordsCSPad, CSPadImageGetTest
00070  *
00071  *  @version \$Id: CSPadInterpolImageProducer.h 8040 2014-04-19 01:00:36Z dubrovin@SLAC.STANFORD.EDU $
00072  *
00073  *  @author Mikhail S. Dubrovin
00074  */
00075 
00076 /**
00077   * Array address descriptor for CSPad pixel
00078   */
00079 
00080 struct ArrAddr {
00081     int quad;
00082     int sect;
00083     int row;
00084     int col;
00085 };
00086 
00087 std::ostream& operator<< (std::ostream& s, const ArrAddr& a) ;
00088 bool areEqual( const ArrAddr& a1, const ArrAddr& a2 ) ;
00089 
00090 class CSPadInterpolImageProducer : public Module {
00091 public:
00092 
00093   enum { NQuadsMax    = Psana::CsPad::MaxQuadsPerSensor  };  // 4
00094   enum { N2x1         = Psana::CsPad::SectorsPerQuad     };  // 8
00095   enum { NCols2x1     = Psana::CsPad::ColumnsPerASIC     };  // 185
00096   enum { NRows2x1     = Psana::CsPad::MaxRowsPerASIC * 2 };  // 388
00097   enum { SizeOf2x1Arr = NRows2x1 * NCols2x1              };  // 185*388;
00098 
00099   // Default constructor
00100   CSPadInterpolImageProducer (const std::string& name) ;
00101 
00102   // Destructor
00103   virtual ~CSPadInterpolImageProducer () ;
00104 
00105   /// Method which is called once at the beginning of the job
00106   virtual void beginJob(Event& evt, Env& env);
00107   
00108   /// Method which is called at the beginning of the run
00109   virtual void beginRun(Event& evt, Env& env);
00110   
00111   /// Method which is called at the beginning of the calibration cycle
00112   virtual void beginCalibCycle(Event& evt, Env& env);
00113   
00114   /// Method which is called with event data, this is the only required 
00115   /// method, all other methods are optional
00116   virtual void event(Event& evt, Env& env);
00117   
00118   /// Method which is called at the end of the calibration cycle
00119   virtual void endCalibCycle(Event& evt, Env& env);
00120 
00121   /// Method which is called at the end of the run
00122   virtual void endRun(Event& evt, Env& env);
00123 
00124   /// Method which is called once at the end of the job
00125   virtual void endJob(Event& evt, Env& env);
00126 
00127 protected:
00128 
00129   void init_address_table_1();
00130   void fill_address_table_1();
00131   void init_address_and_weights_of_4_neighbors();
00132   void fill_address_and_weights_of_4_neighbors();
00133   void get_address_of_4_neighbors(unsigned ix, unsigned iy);
00134   void get_weight_of_4_neighbors(unsigned ix, unsigned iy);
00135 
00136   void getConfigPars(Env& env);
00137   void cspad_image_init();
00138   void cspad_image_save_in_file(const std::string &filename = "cspad_image.txt");
00139   void cspad_image_add_in_event(Event& evt);
00140   //void cspad_image_interpolated_fill (int16_t* data[], QuadParameters* quadpars[], bool quadIsAvailable[]);
00141   void cspad_image_interpolated_fill (ndarray<const int16_t, 3> data[], QuadParameters* quadpars[], bool quadIsAvailable[]);
00142 
00143 private:
00144 
00145   // Data members, this is for example purposes only
00146 
00147   std::string m_calibDir;       // i.e. ./calib
00148   std::string m_typeGroupName;  // i.e. CsPad::CalibV1
00149   std::string m_source;         // i.e. CxiDs1.0:Cspad.0
00150    
00151   Source      m_src;            // Data source set from config file
00152   Pds::Src    m_actualSrc;
00153   std::string m_inkey;          // i.e. "" or "calibrated"
00154   std::string m_imgkey;         // i.e. "CSPad:Image"
00155   unsigned    m_maxEvents;
00156   bool        m_filter;
00157   bool        m_tiltIsApplied;
00158   unsigned    m_print_bits;
00159   long        m_count;
00160 
00161   uint32_t m_roiMask        [4];
00162   uint32_t m_numAsicsStored [4];
00163 
00164   CSPadPixCoords::PixCoords2x1::COORDINATE XCOOR;
00165   CSPadPixCoords::PixCoords2x1::COORDINATE YCOOR;
00166   CSPadPixCoords::PixCoords2x1::COORDINATE ZCOOR;
00167 
00168   PSCalib::CSPadCalibPars        *m_cspad_calibpar;
00169   CSPadPixCoords::PixCoords2x1   *m_pix_coords_2x1;
00170   CSPadPixCoords::PixCoordsQuad  *m_pix_coords_quad;
00171   CSPadPixCoords::PixCoordsCSPad *m_pix_coords_cspad;
00172 
00173   uint32_t  m_cspad_ind;
00174   double   *m_coor_x_pix;
00175   double   *m_coor_y_pix;
00176   uint32_t *m_coor_x_int;
00177   uint32_t *m_coor_y_int;
00178 
00179   enum{ NX_QUAD=850, 
00180         NY_QUAD=850 };
00181 
00182   enum{ NX_CSPAD=1750, 
00183         NY_CSPAD=1750 };
00184   double m_arr_cspad_image [NX_CSPAD][NY_CSPAD];
00185 
00186   ArrAddr m_addr_empty;
00187   ArrAddr m_address_table_1[NX_CSPAD][NY_CSPAD];
00188   ArrAddr m_address        [NX_CSPAD][NY_CSPAD][4];
00189   double  m_weight         [NX_CSPAD][NY_CSPAD][4];
00190 
00191 };
00192 
00193 } // namespace CSPadPixCoords
00194 
00195 #endif // CSPADPIXCOORDS_CSPADINTERPOLIMAGEPRODUCER_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7