Public Member Functions | Private Member Functions | Private Attributes | List of all members
BaselineDetrend Class Reference

#include <BaselineDetrend.h>

Inheritance diagram for BaselineDetrend:
TpcDataTool AdcChannelTool

Public Member Functions

 BaselineDetrend (fhicl::ParameterSet const &ps)
 
 ~BaselineDetrend () override
 
DataMap update (AdcChannelData &acd) const override
 
- Public Member Functions inherited from TpcDataTool
virtual DataMap updateTpcData (TpcData &) const
 
virtual DataMap viewTpcData (const TpcData &) const
 
virtual int forwardTpcData () const
 
- Public Member Functions inherited from AdcChannelTool
virtual ~AdcChannelTool ()=default
 
virtual DataMap view (const AdcChannelData &acd) const
 
virtual DataMap updateMap (AdcChannelDataMap &acds) const
 
virtual DataMap viewMap (const AdcChannelDataMap &acds) const
 
virtual bool updateWithView () const
 
virtual bool viewWithUpdate () const
 
virtual DataMap beginEvent (const DuneEventInfo &) const
 
virtual DataMap endEvent (const DuneEventInfo &) const
 
virtual DataMap close (const DataMap *dmin=nullptr)
 

Private Member Functions

AdcSignalVector Smoother (const AdcSignalVector &data, const std::vector< unsigned > &pedidx) const
 

Private Attributes

int m_LogLevel
 
bool m_UseBasicROI
 
float m_Thresh
 
unsigned m_Pad
 
float m_MinFrac
 
float m_Span
 
TGraphSmooth * m_GS
 

Additional Inherited Members

- Public Types inherited from AdcChannelTool
using Index = unsigned int
 
- Static Public Member Functions inherited from AdcChannelTool
static int interfaceNotImplemented ()
 

Detailed Description

Definition at line 45 of file BaselineDetrend.h.

Constructor & Destructor Documentation

BaselineDetrend::BaselineDetrend ( fhicl::ParameterSet const &  ps)

Definition at line 18 of file BaselineDetrend_tool.cc.

18  :
19  m_LogLevel( ps.get<int>("LogLevel") ),
20  m_UseBasicROI( ps.get<bool>("UseBasicROI") ),
21  m_Thresh( ps.get<float>("Thresh") ),
22  m_Pad( ps.get<unsigned>("Pad") ),
23  m_MinFrac( ps.get<float>("MinFrac") ),
24  m_Span( ps.get<float>("Span") )
25 {
26  const string myname = "BaselineDetrend::ctor: ";
27  if( m_LogLevel >= 1 ){
28  cout<<myname<<"Use basic ROI "<<m_UseBasicROI<<endl;
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;
33  }
34 
35  m_GS = new TGraphSmooth( "smoother" );
36 }
static constexpr double ps
Definition: Units.h:99
TGraphSmooth * m_GS
QTextStream & endl(QTextStream &s)
BaselineDetrend::~BaselineDetrend ( )
override

Definition at line 39 of file BaselineDetrend_tool.cc.

39  {
40  m_GS->Delete();
41 }
TGraphSmooth * m_GS

Member Function Documentation

AdcSignalVector BaselineDetrend::Smoother ( const AdcSignalVector data,
const std::vector< unsigned > &  pedidx 
) const
private

Definition at line 74 of file BaselineDetrend_tool.cc.

76 {
77  const string myname = "BaselineDetrend::Smoother: ";
78  AdcSignalVector trend( data.size(), 0 );
79 
80  vector<unsigned> idx;
81  if( !pedidx.empty() ){
82  idx = pedidx;
83  }
84  else { // simple ROI threshold finder
85 
86  for( unsigned i = 0; i < data.size(); ++i ){
87  if( data[i] > m_Thresh ) {
88  unsigned count = 1;
89  // remove last elements from the vector
90  while( !idx.empty() ){
91  if( count >= m_Pad ) break;
92  //
93  if( (int)idx.back() != ((int)i - (int)count) ) break;
94  idx.pop_back();
95  count++;
96  }
97 
98  // move forward until we are below threshold + num of samples to skip after
99  count = 0;
100  for( unsigned j = i+1; j < data.size(); ++j ){
101  if( data[j] > m_Thresh ) continue;
102  if( count >= m_Pad ) {
103  i = j;
104  break;
105  }
106  count++;
107  }
108 
109  continue;
110  }
111 
112  //
113  idx.push_back( i );
114  }
115  } // simple roi finder
116 
117  // do nothing if we have only a limited number of ped samples
118  if( ((float)idx.size())/data.size() < m_MinFrac ){
119  if( m_LogLevel >= 2 ){
120  cout<<myname<<"number of baseline samples is too low\n";
121  }
122  return trend;
123  }
124 
125  //
126  TGraph gin( idx.size() );
127  for( unsigned i=0; i<idx.size(); ++i ){
128  gin.SetPoint(i, idx[i], data[idx[i]] );
129  }
130 
131  // do smoothing
132  auto gout = m_GS->SmoothLowess(&gin,"", m_Span);
133 
134  // our graph data are sorted in ticks
135  gout->SetBit(TGraph::kIsSortedX);
136 
137  // compute detranding function interpolating inside ROIs
138  unsigned nidx = idx.size();
139  for( unsigned i = 0; i<nidx; ++i ){
140  unsigned ii = idx[i];
141  double x, y;
142  gout->GetPoint(i, x, y);
143  trend[ii] = y;
144 
145  //
146  if( i == 0 ){
147  if( ii != 0 ){
148  for(unsigned j=0;j<ii;++j)
149  trend[j] = gout->Eval( j );
150  }
151  }
152  else if( i == nidx - 1 ) {
153  unsigned iii = data.size() - 1;
154  if( ii != iii){
155  for(unsigned j=ii;j<=iii;++j)
156  trend[j] = gout->Eval( j );
157  }
158  }
159  else {
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 );
164  }
165  }
166 
167  }
168 
169  return trend;
170 }
TGraphSmooth * m_GS
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
list x
Definition: train.py:276
DataMap BaselineDetrend::update ( AdcChannelData acd) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 44 of file BaselineDetrend_tool.cc.

44  {
45  DataMap ret;
47 
48  vector<unsigned> pedidx;
49  if( !m_UseBasicROI ){
50  // use info from ROI search already performed
51  auto sig = acd.signal;
52  for( unsigned i=0; i<data.size(); ++i ){
53  if( sig[i] ) continue;
54  pedidx.push_back( i );
55  }
56  }
57 
58  // computed baseline trend
59  auto trend = Smoother( data, pedidx );
60 
61  // detrending
62  for(size_t i=0;i<data.size();++i){
63  data[i] -= trend[i];
64  }
65 
66  // finished
67  return ret;
68 }
AdcSignalVector Smoother(const AdcSignalVector &data, const std::vector< unsigned > &pedidx) const
AdcFilterVector signal
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples

Member Data Documentation

TGraphSmooth* BaselineDetrend::m_GS
private

Definition at line 64 of file BaselineDetrend.h.

int BaselineDetrend::m_LogLevel
private

Definition at line 55 of file BaselineDetrend.h.

float BaselineDetrend::m_MinFrac
private

Definition at line 59 of file BaselineDetrend.h.

unsigned BaselineDetrend::m_Pad
private

Definition at line 58 of file BaselineDetrend.h.

float BaselineDetrend::m_Span
private

Definition at line 60 of file BaselineDetrend.h.

float BaselineDetrend::m_Thresh
private

Definition at line 57 of file BaselineDetrend.h.

bool BaselineDetrend::m_UseBasicROI
private

Definition at line 56 of file BaselineDetrend.h.


The documentation for this class was generated from the following files: