All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawDigitBinAverageAlg.cxx
Go to the documentation of this file.
1 
3 
4 #include "messagefacility/MessageLogger/MessageLogger.h"
5 
6 #include <cmath>
7 #include <algorithm>
8 
9 namespace caldata
10 {
11 
12 //----------------------------------------------------------------------------
13 /// Constructor.
14 ///
15 /// Arguments:
16 ///
17 /// pset - Fcl parameters.
18 ///
19 RawDigitBinAverageAlg::RawDigitBinAverageAlg(fhicl::ParameterSet const & pset)
20 {
21  // Report.
22  mf::LogInfo("RawDigitBinAverageAlg") << "RawDigitBinAverageAlg configured\n";
23 }
24 
25 //----------------------------------------------------------------------------
26 /// Destructor.
28 {}
29 
31  size_t binsToAverage) const
32 {
33  size_t halfBinsToAverage(binsToAverage/2);
34 
35  float runningSum(0.);
36 
37  for(size_t idx = 0; idx < halfBinsToAverage; idx++) runningSum += dataVec[idx];
38 
39  // Declare erosion vector
40  std::vector<float> meanVec;
41 
42  meanVec.resize(dataVec.size(), 0);
43  std::vector<float>::iterator meanVecItr = meanVec.begin();
44 
45  // First pass through to build the erosion vector
46  for(RawDigitVector::iterator dataItr = dataVec.begin(); dataItr != dataVec.end(); dataItr++)
47  {
48  size_t startOffset = std::distance(dataVec.begin(),dataItr);
49  size_t stopOffset = std::distance(dataItr,dataVec.end());
50  size_t count = std::min(2 * halfBinsToAverage, std::min(startOffset + halfBinsToAverage + 1, halfBinsToAverage + stopOffset - 1));
51 
52  if (startOffset >= halfBinsToAverage) runningSum -= *(dataItr - halfBinsToAverage);
53  if (stopOffset > halfBinsToAverage) runningSum += *(dataItr + halfBinsToAverage);
54 
55  *meanVecItr++ = runningSum / float(count);
56  }
57 
58  std::transform(meanVec.begin(),meanVec.end(),dataVec.begin(),[](const float& val){return std::round(val);});
59 
60  return;
61 }
62 
64 {
65  // This should be a straightforward transform
66  std::transform(dataVec.begin(),dataVec.end()-1,dataVec.begin()+1,dataVec.begin(),[](const short& first, const short& last){return std::round(float(first+last)/2.);});
67 
68  return;
69 }
70 
71 }
static constexpr Sample_t transform(Sample_t sample)
raw::RawDigit::ADCvector_t RawDigitVector
RawDigitBinAverageAlg(fhicl::ParameterSet const &pset)
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
void doTwoBinAverage(RawDigitVector &) const
void doBinAverage(RawDigitVector &, size_t) const
std::size_t count(Cont const &cont)
process_name can override from command line with o or output caldata
Definition: pid.fcl:40