ImgAlgos/src/AlgSmearing.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: AlgSmearing.cpp 9478 2015-01-13 20:07:05Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class AlgSmearing
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "ImgAlgos/AlgSmearing.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <math.h>    // for exp
00022 #include <iomanip>   // for std::setw
00023 #include <sstream>   // for stringstream
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 #include "MsgLogger/MsgLogger.h"
00029 
00030 //-----------------------------------------------------------------------
00031 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00032 //-----------------------------------------------------------------------
00033 
00034 //              ----------------------------------------
00035 //              -- Public Function Member Definitions --
00036 //              ----------------------------------------
00037 
00038 namespace ImgAlgos {
00039 
00040 //----------------
00041 // Constructors --
00042 //----------------
00043 //template <typename T>
00044 //AlgSmearing<T>::AlgSmearing(const double& sigma, const int& nsm) 
00045 
00046 AlgSmearing::AlgSmearing( const double& sigma
00047                         , const int& nsm
00048                         , const double& thr_low
00049                         , const unsigned& opt
00050                         , const unsigned& pbits
00051                         , const size_t&   seg
00052                         , const size_t& rowmin
00053                         , const size_t& rowmax
00054                         , const size_t& colmin
00055                         , const size_t& colmax
00056                         , const double& value
00057                         )
00058   : m_sigma(sigma)
00059   , m_nsm(nsm)
00060   , m_nsm1(nsm+1)
00061   , m_thr_low(thr_low)
00062   , m_opt(opt)
00063   , m_pbits(pbits)
00064   , m_seg(seg)
00065   , m_rowmin(rowmin)
00066   , m_rowmax(rowmax)
00067   , m_colmin(colmin)
00068   , m_colmax(colmax)
00069   , m_value(value)
00070 {
00071   if(m_pbits & 1) printInputPars();
00072   evaluateWeights();
00073   if(m_pbits & 2) printWeights();
00074 }
00075 
00076 //--------------------
00077 // Define smearing weighting matrix
00078 void 
00079 AlgSmearing::evaluateWeights()
00080 {
00081   m_weights = make_ndarray<double>(m_nsm1, m_nsm1);
00082 
00083   //std::cout << "In AlgSmearing::evaluateWeights()\n";
00084 
00085   if ( m_sigma == 0 ) { 
00086     if(m_pbits) MsgLog(_name(), info, "Smearing is turned OFF by sigma = " << m_sigma); 
00087     std::fill_n(m_weights.data(), int(m_weights.size()*sizeof(double)), double(0));
00088     m_weights[0][0] = 1;
00089     return;
00090   }
00091 
00092   double norm = -0.5/(m_sigma*m_sigma);
00093   for (int r = 0; r < m_nsm1; r++) {
00094     for (int c = 0; c < m_nsm1; c++) {
00095       m_weights[r][c] = exp( norm * (r*r+c*c) );
00096     }
00097   }
00098 }
00099 
00100 //--------------------
00101 // Print smearing weighting matrix
00102 void 
00103 AlgSmearing::printWeights()
00104 {
00105   // if ( m_sigma == 0 ) { MsgLog(_name(), info, "Smearing is turned OFF by sigma =" << m_sigma ); }
00106 
00107     std::stringstream ss; ss << "printWeights() - Weights for smearing";
00108     ss << "\n   cols :   ";
00109     for (int c = 0; c < m_nsm1; c++) ss << std::left << std::setw(10) << c;
00110     for (int r = 0; r < m_nsm1; r++) {
00111       ss << "\n   row=" << r << ": " << fixed; 
00112       for (int c = 0; c < m_nsm1; c++) {
00113         ss << "  " << std::left << std::setw(8) << m_weights[r][c];
00114       }
00115     }
00116     MsgLog(_name(), info, ss.str()); 
00117 }
00118 
00119 //--------------------
00120 // Print member data and matrix of weights
00121 void 
00122 AlgSmearing::printInputPars()
00123 {
00124   std::stringstream ss; 
00125   ss << "\nsigma   : " << m_sigma
00126      << "\nnsm     : " << m_nsm
00127      << "\nnsm1    : " << m_nsm1
00128      << "\nthr_low : " << m_thr_low
00129      << "\nopt     : " << m_opt
00130      << "\nseg     : " << m_seg
00131      << "\nrowmin  : " << m_rowmin
00132      << "\nrowmax  : " << m_rowmax
00133      << "\ncolmin  : " << m_colmin
00134      << "\ncolmax  : " << m_colmax  
00135      << "\nvalue   : " << m_value  
00136      << '\n';
00137   MsgLog(_name(), info, ss.str()); 
00138 }
00139 
00140 //--------------------
00141 
00142 //template class ImgAlgos::AlgSmearing<int16_t>;
00143 //template class ImgAlgos::AlgSmearing<int>;
00144 //template class ImgAlgos::AlgSmearing<float>;
00145 //template class ImgAlgos::AlgSmearing<double>;
00146 
00147 //--------------------
00148 
00149 } // namespace ImgAlgos

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7