preco_algo_base.cc

Go to the documentation of this file.
00001 #ifndef PRECO_ALGO_BASE_CC
00002 #define PRECO_ALGO_BASE_CC
00003 
00004 #include "preco_algo_base.hh"
00005 
00006 //***************************************************************
00007 bool check_index(const std::vector<UShort_t> *wf, const size_t &begin, size_t &end)
00008 //***************************************************************
00009 {
00010   if(begin >= wf->size() || end >= wf->size() || begin > end){
00011 
00012     Message::send(MSG::ERROR,__FUNCTION__,
00013           Form("Invalid arguments: waveform length = %zu, begin = %zu, end = %zu!",
00014                wf->size(), begin, end));
00015     return false;
00016 
00017   }
00018 
00019   if(!end) end = wf->size() - 1;
00020 
00021   return true;
00022 }
00023 
00024 //***************************************************************
00025 preco_algo_base::preco_algo_base() : decoder_base(), _pulse()
00026 //***************************************************************
00027 {
00028 
00029   _name = "preco_algo_base";
00030   
00031   _ped_mean = _ped_rms = -1;
00032 
00033   reset();
00034 
00035 }
00036 
00037 void preco_algo_base::reset(){
00038 
00039   _pulse.reset_param();
00040 
00041   _pulse_v.clear();
00042 
00043   _pulse_v.reserve(3);
00044   
00045 }
00046 
00047 //***************************************************************
00048 const pulse_param* preco_algo_base::get_pulse(size_t index) const
00049 //***************************************************************
00050 {
00051 
00052   if(index >= _pulse_v.size()) return 0;
00053 
00054   else return &(_pulse_v.at(index));
00055 
00056 }
00057 
00058 //***************************************************************
00059 bool preco_algo_base::integral(const std::vector<UShort_t> *wf,
00060                    double &result,
00061                    size_t begin,
00062                    size_t end) const
00063 //***************************************************************
00064 {
00065   
00066   if(!check_index(wf,begin,end)) return false;
00067   
00068   std::vector<UShort_t>::const_iterator begin_iter(wf->begin());
00069   
00070   std::vector<UShort_t>::const_iterator end_iter(wf->begin());
00071 
00072   begin_iter = begin_iter + begin;
00073 
00074   end_iter = end_iter + end + 1;
00075   
00076   result = (double)(std::accumulate(begin_iter, end_iter, 0));
00077 
00078   return true;
00079 }
00080 
00081 //***************************************************************
00082 bool preco_algo_base::derivative(const std::vector<UShort_t> *wf,
00083                  std::vector<int32_t> &diff,
00084                  size_t begin,
00085                  size_t end) const 
00086 //***************************************************************
00087 {
00088 
00089   if(check_index(wf,begin,end)){
00090     
00091     diff.clear();
00092     diff.reserve(end - begin);
00093 
00094     for(size_t index = begin ; index <= end ; ++index)
00095       
00096       diff.push_back(wf->at(index+1) - wf->at(index));
00097 
00098     return true;
00099   }
00100 
00101   return false;
00102 
00103 }
00104 
00105 //***************************************************************
00106 size_t preco_algo_base::max(const std::vector<UShort_t> *wf,
00107                 double &result,
00108                 size_t begin,
00109                 size_t end) const
00110 //***************************************************************
00111 {
00112 
00113   size_t target_index = wf->size() + 1;
00114 
00115   result = 0;
00116 
00117   if(check_index(wf,begin,end)) {
00118 
00119     for(size_t index = begin; index <= end; ++index)
00120       
00121       if( result < wf->at(index)) { target_index = index; result = (double)(wf->at(index)); }
00122     
00123   }
00124 
00125   return target_index;
00126 
00127 }
00128 
00129 //***************************************************************
00130 size_t preco_algo_base::min(const std::vector<UShort_t> *wf,
00131                 double &result,
00132                 size_t begin,
00133                 size_t end) const
00134 //***************************************************************
00135 {
00136 
00137   size_t target_index = wf->size() + 1;
00138 
00139   result = 4096;
00140 
00141   if(check_index(wf,begin,end)) {
00142 
00143     for(size_t index = begin; index <= end; ++index)
00144       
00145       if( result > wf->at(index)) { target_index = index; result = (double)(wf->at(index)); }
00146     
00147   }
00148 
00149   return target_index;
00150 
00151 }
00152 
00153 #endif

Generated on Mon Apr 7 15:35:12 2014 for MyProject by  doxygen 1.4.7