5 #include "TGraphSmooth.h" 19 m_LogLevel( ps.
get<
int>(
"LogLevel") ),
20 m_UseBasicROI( ps.
get<
bool>(
"UseBasicROI") ),
22 m_Pad( ps.
get<unsigned>(
"Pad") ),
23 m_MinFrac( ps.
get<
float>(
"MinFrac") ),
26 const string myname =
"BaselineDetrend::ctor: ";
29 cout<<myname<<
"Threshold to drop samples from average "<<
m_Thresh<<
endl;
30 cout<<myname<<
"Number of ticks to pad around signals above threshold "<<
m_Pad<<
endl;
31 cout<<myname<<
"Min fraction of pedestal samples for detrending "<<
m_MinFrac<<
endl;
32 cout<<myname<<
"LOWESS span parameter "<<
m_Span<<
endl;
35 m_GS =
new TGraphSmooth(
"smoother" );
48 vector<unsigned> pedidx;
52 for(
unsigned i=0; i<data.size(); ++i ){
53 if( sig[i] )
continue;
54 pedidx.push_back( i );
59 auto trend =
Smoother( data, pedidx );
62 for(
size_t i=0;i<data.size();++i){
75 const vector<unsigned> &pedidx )
const 77 const string myname =
"BaselineDetrend::Smoother: ";
81 if( !pedidx.empty() ){
86 for(
unsigned i = 0; i < data.size(); ++i ){
90 while( !idx.empty() ){
91 if( count >=
m_Pad )
break;
93 if( (
int)idx.back() != ((
int)i - (
int)
count) )
break;
100 for(
unsigned j = i+1; j < data.size(); ++j ){
102 if( count >=
m_Pad ) {
118 if( ((
float)idx.size())/data.size() <
m_MinFrac ){
120 cout<<myname<<
"number of baseline samples is too low\n";
126 TGraph gin( idx.size() );
127 for(
unsigned i=0; i<idx.size(); ++i ){
128 gin.SetPoint(i, idx[i], data[idx[i]] );
132 auto gout =
m_GS->SmoothLowess(&gin,
"",
m_Span);
135 gout->SetBit(TGraph::kIsSortedX);
138 unsigned nidx = idx.size();
139 for(
unsigned i = 0; i<nidx; ++i ){
140 unsigned ii = idx[i];
142 gout->GetPoint(i, x, y);
148 for(
unsigned j=0;j<ii;++j)
149 trend[j] = gout->Eval( j );
152 else if( i == nidx - 1 ) {
153 unsigned iii = data.size() - 1;
155 for(
unsigned j=ii;j<=iii;++j)
156 trend[j] = gout->Eval( j );
160 unsigned iii = idx[i-1];
161 if( (ii - iii ) > 1 ){
162 for(
unsigned j=iii;j<ii;++j)
163 trend[j] = gout->Eval( j );
DataMap update(AdcChannelData &acd) const override
AdcSignalVector Smoother(const AdcSignalVector &data, const std::vector< unsigned > &pedidx) const
~BaselineDetrend() override
BaselineDetrend(fhicl::ParameterSet const &ps)
static constexpr double ps
std::vector< AdcSignal > AdcSignalVector
auto const & get(AssnsNode< L, R, D > const &r)
QTextStream & endl(QTextStream &s)