Smoother.cc
00001 #include "Smoother.hh"
00002 #include "SumChannels.hh"
00003 #include "ProcessedPlotter.hh"
00004 #include "ConvertData.hh"
00005 #include "EventHandler.hh"
00006 #include "intarray.hh"
00007 #include "RootWriter.hh"
00008 #include <algorithm>
00009 Smoother::Smoother() :
00010 ChannelModule(GetDefaultName(),
00011 "Smooth each channel's waveform using a moving average window")
00012 {
00013 RegisterParameter("pre_samples", pre_samples = 2,
00014 "Number of samples to include in the average before the current one");
00015 RegisterParameter("post_samples", post_samples = 2,
00016 "Number of samples to include in the average after the current one");
00017
00018 AddDependency<ConvertData>();
00019 }
00020
00021 Smoother::~Smoother()
00022 {}
00023
00024 int Smoother::Initialize()
00025 {
00026 return 0;
00027 }
00028
00029 int Smoother::Finalize()
00030 { return 0; }
00031
00032 int Smoother::Process(ChannelData* chdata)
00033 {
00034 const int nsamps = chdata->nsamps;
00035 chdata->smoothed_data.resize(nsamps);
00036 double* smoothdata = &(chdata->smoothed_data[0]);
00037
00038 double* wave = chdata->GetWaveform();
00039 double running_sum = 0;
00040 double samps_in_sum = post_samples;
00041 for(int j = 0; j<post_samples && j<nsamps; j++)
00042 running_sum += wave[j];
00043 for(int samp = 0; samp < nsamps; samp++){
00044 if(samp < nsamps - post_samples){
00045 running_sum += wave[samp+post_samples];
00046 samps_in_sum++;
00047 }
00048 if(samp > pre_samples){
00049 running_sum -= wave[samp-pre_samples-1];
00050 samps_in_sum--;
00051 }
00052 smoothdata[samp] = running_sum / samps_in_sum;
00053 }
00054 chdata->smoothed_min = *std::min_element(smoothdata, smoothdata+nsamps);
00055 chdata->smoothed_max = *std::max_element(smoothdata, smoothdata+nsamps);
00056
00057 return 0;
00058 }