/** * @file SChannel.cpp * @author Dan Saunders & Mathieu Labare, on behalf of the SoLid collaboration. * @date 16 Feb 2016 */ #include "SChannel.h" #include //============================================================================== //! Constructor just setting passed values. /*! Default values are set to -2, since -1 is used in the DAQ. */ SChannel::SChannel(unsigned int safChanIndex, int xLoc, int yLoc, int zLoc, float xGlob, float yGlob, float zGlob) : m_safChanIndex(safChanIndex), m_xLoc(xLoc), m_yLoc(yLoc), m_zLoc(zLoc), m_xGlob(xGlob), m_yGlob(yGlob), m_zGlob(zGlob), m_baseline(-1), m_masked(false), m_sampleWidthNs(25), m_findBaselinesAuto(false) {} //============================================================================== //! Function to empty containers per block process. void SChannel::clear() { m_waveforms.clear(); m_peaks.clear(); } //============================================================================== //! Adds a waveform, and estimates baseline waveforms if 'auto' flag set. void SChannel::addWaveform(SWaveform * w) { m_waveforms.push_back(w); if (m_baseline == -1 && m_findBaselinesAuto) findBaseline(w); } //============================================================================== //! Estimates baseline from single waveform. Take median of the waveform. void SChannel::findBaseline(SWaveform * w) { // Just stolen from google. // Start by making a copy of the waveform samples (to sort). std::vector m_samplesCopy(*w->samples()); std::sort(m_samplesCopy.begin(), m_samplesCopy.end()); auto size = m_samplesCopy.size(); if (size % 2 == 0) m_baseline = 0.5*(m_samplesCopy[size/2 - 1] + m_samplesCopy[size/2]); else m_baseline = m_samplesCopy[size/2]; std::cout<<"[Note]: baseline set automatically, at (channel, baseline): ("<