ImgAlgos/include/ImgSpectra.h

Go to the documentation of this file.
00001 #ifndef IMGALGOS_IMGSPECTRA_H
00002 #define IMGALGOS_IMGSPECTRA_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: ImgSpectra.h 8035 2014-04-19 00:56:24Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class ImgSpectra.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 
00017 //----------------------
00018 // Base Class Headers --
00019 //----------------------
00020 #include "psana/Module.h"
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "PSEvt/Source.h"
00026 #include "MsgLogger/MsgLogger.h"
00027 
00028 //------------------------------------
00029 // Collaborating Class Declarations --
00030 //------------------------------------
00031 
00032 //              ---------------------
00033 //              -- Class Interface --
00034 //              ---------------------
00035 
00036 namespace ImgAlgos {
00037 
00038 /// @addtogroup ImgAlgos
00039 
00040 /**
00041  *  @ingroup ImgAlgos
00042  *
00043  *  @brief ImgSpectra extracts two spectra from image and evaluate their relative difference.
00044  *
00045  *  ImgSpectra psana module:
00046  *  - gets the image object from event,
00047  *  - selects two spectral band regions and integrates amplitudes for each column,
00048  *  - saves two spectra, f_sig and f_ref and their relative difference 
00049  *    as a ndarray<double,2> object in the event. 
00050  * 
00051  *  This software was developed for the LCLS project. If you use all or 
00052  *  part of it, please give an appropriate acknowledgment.
00053  *
00054  *  @see CSPadImageProducer
00055  *
00056  *  @version \$Id: ImgSpectra.h 8035 2014-04-19 00:56:24Z dubrovin@SLAC.STANFORD.EDU $
00057  *
00058  *  @author Mikhail S. Dubrovin
00059  */
00060 
00061 class ImgSpectra : public Module {
00062 public:
00063 
00064   // Default constructor
00065   ImgSpectra (const std::string& name) ;
00066 
00067   // Destructor
00068   virtual ~ImgSpectra () ;
00069 
00070   /// Method which is called once at the beginning of the job
00071   virtual void beginJob(Event& evt, Env& env);
00072   
00073   /// Method which is called at the beginning of the run
00074   virtual void beginRun(Event& evt, Env& env);
00075   
00076   /// Method which is called at the beginning of the calibration cycle
00077   virtual void beginCalibCycle(Event& evt, Env& env);
00078   
00079   /// Method which is called with event data, this is the only required 
00080   /// method, all other methods are optional
00081   virtual void event(Event& evt, Env& env);
00082   
00083   /// Method which is called at the end of the calibration cycle
00084   virtual void endCalibCycle(Event& evt, Env& env);
00085 
00086   /// Method which is called at the end of the run
00087   virtual void endRun(Event& evt, Env& env);
00088 
00089   /// Method which is called once at the end of the job
00090   virtual void endJob(Event& evt, Env& env);
00091 
00092   void printInputParameters();
00093   void printEventRecord(Event& evt, std::string=std::string());
00094   void procEvent(Event& evt);
00095   //void getSpectrum(float rowc, float tilt, unsigned width, unsigned ind);
00096   void difSpectrum();
00097   void printSpectra(Event& evt);
00098 
00099 private:
00100 
00101   Pds::Src    m_src;
00102   Source      m_str_src;     // i.e. Opal:
00103   std::string m_key_in;      // input key
00104   std::string m_key_out;     // output key
00105   float       m_sig_rowc;    // signal    band row center coordinate
00106   float       m_ref_rowc;    // reference ...
00107   float       m_sig_tilt;    // signal    band tilt angle
00108   float       m_ref_tilt;    // reference ...
00109   unsigned    m_sig_width;   // signal    band width in number of rows
00110   unsigned    m_ref_width;   // signal    ...
00111   unsigned    m_print_bits;
00112   long        m_count;
00113 
00114   unsigned    m_cols;
00115   ndarray<double, 2> m_data;
00116 
00117 protected:
00118 
00119 //--------------------
00120 
00121     template <typename T>
00122     void getSpectrum(const T* img_data, float rowc, float tilt, unsigned width, unsigned ind)
00123     {
00124       for( unsigned c=0; c<m_cols; c++ ) {
00125         int row_min = int(rowc - tilt * c - 0.5*width);
00126         int row_max = row_min + width + 1;
00127 
00128         for( int r=row_min; r<row_max; r++ ) {
00129 
00130           m_data[ind][c] += img_data[r*m_cols + c];
00131         }
00132       }
00133     }
00134 
00135 //--------------------
00136 
00137     template <typename T>
00138     void retrieveSpectra(const ndarray<const T,2>& sp_ndarr, bool print_msg=false)
00139       {
00140         const T* img_data = sp_ndarr.data();               // Access to entire image
00141         unsigned rows = sp_ndarr.shape()[0];
00142         m_cols = sp_ndarr.shape()[1];
00143         if(print_msg) MsgLog( name(), info, "Image shape =" << rows << ", " << m_cols);
00144 
00145         if(m_data.empty()) {
00146           m_data = make_ndarray<double>(3, m_cols); // memory allocation for output array of spectra
00147         }
00148 
00149         std::fill_n(m_data.begin(), m_data.size(), double(0));
00150 
00151         getSpectrum(img_data, m_sig_rowc, m_sig_tilt, m_sig_width, 0);
00152         getSpectrum(img_data, m_ref_rowc, m_ref_tilt, m_ref_width, 1);  
00153         difSpectrum();  
00154       }
00155 
00156 //--------------------
00157 //--------------------
00158 //--------------------
00159 };
00160 
00161 } // namespace ImgAlgos
00162 
00163 #endif // IMGALGOS_IMGSPECTRA_H

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7