ThresholdNoiseRemovalService_service.cc
Go to the documentation of this file.
1 // ThresholdNoiseRemovalService_service.cc
2 
4 #include <iostream>
5 #include <sstream>
6 #include <iomanip>
7 #include <algorithm>
11 
12 using std::vector;
13 using std::string;
14 using std::ostream;
15 using std::cout;
16 using std::endl;
17 using std::ostringstream;
18 using std::setw;
19 using art::ServiceHandle;
20 
21 //**********************************************************************
22 
25 : m_LogLevel(1) {
26  const string myname = "ThresholdNoiseRemovalService::ctor: ";
27  pset.get_if_present<int>("LogLevel", m_LogLevel);
28  m_Threshold = pset.get<AdcSignal>("Threshold");
29  print(cout, myname);
30 }
31 
32 //**********************************************************************
33 
35  const string myname = "ThresholdNoiseRemovalService:update: ";
36  AdcSignalVector& sigs = data.samples;
37  AdcFlagVector& flags = data.flags;
38  if ( sigs.size() == 0 ) {
39  cout << myname << "WARNING: No data found." << endl;
40  return 1;
41  }
42  if ( flags.size() == 0 ) flags.resize(sigs.size(), AdcGood );
43  if ( flags.size() != sigs.size() ) {
44  cout << myname << "ERROR: samples and flags vectors have different sizes." << endl;
45  return 2;
46  }
47  AdcIndex count = 0;
48  for ( unsigned int isig=0; isig<sigs.size(); ++isig ) {
49  AdcSignal& sig = sigs[isig];
50  if ( fabs(sig) < m_Threshold ) {
51  sig = 0.0;
52  flags[isig] = AdcSetFixed;
53  ++count;
54  }
55  }
56  if ( m_LogLevel >= 2 ) cout << myname << "Suppressed " << count << " of "
57  << sigs.size() << " ticks." << endl;
58  return 0;
59 }
60 
61 //**********************************************************************
62 
64 print(ostream& out, string prefix) const {
65  out << prefix << "ThresholdNoiseRemovalService:" << endl;
66  out << prefix << " LogLevel: " << m_LogLevel << endl;
67  out << prefix << " Threshold: " << m_Threshold << endl;
68  return out;
69 }
70 
71 //**********************************************************************
72 
74 
75 //**********************************************************************
std::string string
Definition: nybbler.cc:12
ThresholdNoiseRemovalService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
float AdcSignal
Definition: AdcTypes.h:21
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
struct vector vector
const AdcFlag AdcSetFixed
Definition: AdcTypes.h:41
art framework interface to geometry description
const AdcFlag AdcGood
Definition: AdcTypes.h:32
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
T get(std::string const &key) const
Definition: ParameterSet.h:271
unsigned int AdcIndex
Definition: AdcTypes.h:15
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)