MedianPedestalService_service.cc
Go to the documentation of this file.
1 // MedianPedestalService_service.cc
2 
4 #include <iostream>
5 #include <sstream>
6 #include <iomanip>
9 
10 using std::vector;
11 using std::string;
12 using std::ostream;
13 using std::cout;
14 using std::endl;
15 using std::ostringstream;
16 using std::setw;
17 using art::ServiceHandle;
18 
19 //**********************************************************************
20 
23 : m_LogLevel(1),
24  m_SkipFlaggedSamples(false),
25  m_SkipSignals(false) {
26  const string myname = "MedianPedestalService::ctor: ";
27  pset.get_if_present<int>("LogLevel", m_LogLevel);
28  m_UseMean = pset.get<bool>("UseMean");
29  m_SkipFlaggedSamples = pset.get<bool>("SkipFlaggedSamples");
30  m_SkipSignals = pset.get<bool>("SkipSignals");
31  print(cout, myname);
32 }
33 
34 //**********************************************************************
35 
38  AdcSignal* ppederr, AdcSignal* prmserr) const {
39  const string myname = "MedianPedestalService::evaluate: ";
40  AdcSignal ped = 0.0;
41  AdcSignal rms = 0.0;
42  AdcSignal pederr = 0.0;
43  AdcSignal rmserr = 0.0;
44  const AdcSignalVector sigsin = data.samples;
45  const AdcFlagVector flags = data.flags;
46  const AdcFilterVector signal = data.signal;
47  if ( sigsin.size() == 0 ) return 0;
48  AdcSignalVector sigs;
49  unsigned int nsig = sigsin.size();
50  double sigsum = 0.0;
51  unsigned int nsigout = 0;
52  for ( unsigned int isig=0; isig<nsig; ++isig ) {
53  AdcSignal sig = sigsin[isig];
54  if ( m_SkipFlaggedSamples && flags.size() ) {
55  AdcFlag flag = flags[isig];
56  bool skip = flag != AdcGood;
57  if ( skip ) continue;
58  }
59  if ( m_SkipSignals && signal.size() ) {
60  bool isSignal = signal[isig];
61  if ( isSignal ) continue;
62  }
63  if ( m_UseMean ) sigsum += sig;
64  else sigs.push_back(sig);
65  ++nsigout;
66  }
67  if ( nsigout ) {
68  if ( m_UseMean ) {
69  ped = sigsum/nsigout;
70  } else {
71  sort(sigs.begin(), sigs.end());
72  unsigned int isig = sigs.size()/2;
73  bool isodd = sigs.size()%2;
74  ped = isodd ? sigs[isig-1] : 0.5*(sigs[isig-1] + sigs[isig]);
75  }
76  }
77  if ( pped != nullptr ) *pped = ped;
78  if ( prms != nullptr ) *prms = rms;
79  if ( ppederr != nullptr ) *ppederr = pederr;
80  if ( prmserr != nullptr ) *prmserr = rmserr;
81  return 0;
82 }
83 
84 //**********************************************************************
85 
87 print(ostream& out, string prefix) const {
88  out << prefix << "MedianPedestalService:" << endl;
89  out << prefix << " LogLevel: " << m_LogLevel << endl;
90  out << prefix << " SkipFlaggedSamples: " << m_SkipFlaggedSamples << endl;
91  out << prefix << " SkipSignals: " << m_SkipSignals << endl;
92  return out;
93 }
94 
95 //**********************************************************************
96 
98 
99 //**********************************************************************
short AdcFlag
Definition: AdcTypes.h:29
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
struct vector vector
int evaluate(const AdcChannelData &data, AdcSignal *pped=nullptr, AdcSignal *prms=nullptr, AdcSignal *ppederr=nullptr, AdcSignal *prmserr=nullptr) const
const AdcFlag AdcGood
Definition: AdcTypes.h:32
MedianPedestalService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
T get(std::string const &key) const
Definition: ParameterSet.h:271
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
AdcFilterVector signal
std::vector< bool > AdcFilterVector
Definition: AdcTypes.h:27
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)