00001 #ifndef IMGALGOS_IMGSPECTRA_H
00002 #define IMGALGOS_IMGSPECTRA_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "psana/Module.h"
00021
00022
00023
00024
00025 #include "PSEvt/Source.h"
00026 #include "MsgLogger/MsgLogger.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 namespace ImgAlgos {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class ImgSpectra : public Module {
00062 public:
00063
00064
00065 ImgSpectra (const std::string& name) ;
00066
00067
00068 virtual ~ImgSpectra () ;
00069
00070
00071 virtual void beginJob(Event& evt, Env& env);
00072
00073
00074 virtual void beginRun(Event& evt, Env& env);
00075
00076
00077 virtual void beginCalibCycle(Event& evt, Env& env);
00078
00079
00080
00081 virtual void event(Event& evt, Env& env);
00082
00083
00084 virtual void endCalibCycle(Event& evt, Env& env);
00085
00086
00087 virtual void endRun(Event& evt, Env& env);
00088
00089
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
00096 void difSpectrum();
00097 void printSpectra(Event& evt);
00098
00099 private:
00100
00101 Pds::Src m_src;
00102 Source m_str_src;
00103 std::string m_key_in;
00104 std::string m_key_out;
00105 float m_sig_rowc;
00106 float m_ref_rowc;
00107 float m_sig_tilt;
00108 float m_ref_tilt;
00109 unsigned m_sig_width;
00110 unsigned m_ref_width;
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();
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);
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 }
00162
00163 #endif // IMGALGOS_IMGSPECTRA_H