DuneAdcSignalFinder_tool.cc
Go to the documentation of this file.
1 // DuneAdcSignalFinder_tool.cc
2 
3 #include "DuneAdcSignalFinder.h"
4 #include <iostream>
5 #include <iomanip>
6 
7 using std::string;
8 using std::cout;
9 using std::endl;
10 using std::setw;
11 
12 //**********************************************************************
13 // Class methods.
14 //**********************************************************************
15 
17 : m_LogLevel(ps.get<int>("LogLevel")),
18  m_NoiseSigma(ps.get<float>("NoiseSigma")),
19  m_NSigmaStart(ps.get<float>("NSigmaStart")),
20  m_NSigmaEnd(ps.get<float>("NSigmaEnd")),
21  m_TicksBefore(ps.get<AdcIndex>("TicksBefore")),
22  m_TicksAfter(ps.get<AdcIndex>("TicksAfter"))
23 {
24  const string myname = "DuneAdcSignalFinder::ctor: ";
25  if ( m_LogLevel >= 1 ) {
26  cout << myname << "Configuration parameters:" << endl;
27  cout << myname << " LogLevel: " << m_LogLevel << endl;
28  cout << myname << " NoiseSigma: " << m_NoiseSigma << endl;
29  cout << myname << " NSigmaStart: " << m_NSigmaStart << endl;
30  cout << myname << " NSigmaEnd: " << m_NSigmaEnd << endl;
31  cout << myname << " TicksBefore: " << m_TicksBefore << endl;
32  cout << myname << " TicksAfter: " << m_TicksAfter << endl;
33  }
34 }
35 
36 //**********************************************************************
37 
39  const string myname = "DuneAdcSignalFinder::update: ";
40  DataMap ret;
41  if ( m_LogLevel >= 2 ) {
42  cout << myname << "Finding ROIs for channel " << acd.channel() << endl;
43  }
44  AdcIndex nsam = acd.samples.size();
45  if ( nsam == 0 ) {
46  cout << myname << "ERROR: No samples found in channel " << acd.channel() << endl;
47  acd.signal.clear();
48  acd.rois.clear();
49  return ret.setStatus(1);
50  }
51  AdcSignal sigma = m_NoiseSigma > 0 ? m_NoiseSigma : acd.sampleNoise;
52  if ( sigma <= 0 ) {
53  cout << myname << "ERROR: Unable to determine noise level." << endl;
54  return ret.setStatus(2);
55  }
56  if ( m_LogLevel >= 3 ) cout << myname << "Noise level: " << sigma << endl;
57  // Build ROIS before padding and merging.
58  const AdcSignalVector& sams = acd.samples;
59  AdcFilterVector& signal = acd.signal;
60  AdcRoiVector& rois = acd.rois;
61  signal.clear();
62  signal.resize(sams.size(), false);
63  bool inroi = false;
64  AdcSignal siglow = m_NSigmaEnd*sigma;
65  AdcSignal sighigh = m_NSigmaStart*sigma;
66  for ( AdcIndex isam=0; isam<nsam; ++isam ) {
67  AdcSignal sig = sams[isam];
68  if ( inroi ) {
69  if ( sig > siglow ) {
70  signal[isam] = true;
71  } else {
72  inroi = false;
73  }
74  } else {
75  if ( sig > sighigh ) {
76  signal[isam] = true;
77  inroi = true;
78  }
79  }
80  }
81  // Fill the unpadded ROIs.
82  acd.roisFromSignal();
83  if ( rois.size() == 0 ) {
84  if ( m_LogLevel >= 3 ) cout << myname << " No ROIs found." << endl;
85  } else {
86  // Display ROIs before padding and merging.
87  if ( m_LogLevel >= 3 ) {
88  cout << myname << " ROIs before merge (size = " << rois.size() << "):" << endl;
89  for ( const AdcRoi& roi : rois ) {
90  cout << myname << setw(8) << roi.first << " " << setw(8) << roi.second << endl;
91  }
92  } else if ( m_LogLevel >= 2 ) {
93  cout << myname << " ROI count before merge: " << acd.rois.size() << endl;
94  }
95  // Pad ROIs.
96  unsigned int isam1 = 0;
97  unsigned int isam2 = 0;
98  for ( AdcRoi roi : rois ) {
99  isam2 = roi.first;
100  isam1 = isam2 > m_TicksBefore ? isam2 - m_TicksBefore : 0;
101  for ( unsigned int isam=isam1; isam<isam2; ++isam ) signal[isam] = true;
102  isam1 = roi.second + 1;
103  isam2 = isam1 + m_TicksAfter;
104  if ( isam2 > nsam ) isam2 = nsam;
105  for ( unsigned int isam=isam1; isam<isam2; ++isam ) signal[isam] = true;
106  }
107  // Fill the final ROIs.
108  acd.roisFromSignal();
109  // Display final ROIs.
110  if ( m_LogLevel >= 3 ) {
111  cout << myname << " ROIs after merge (size = " << rois.size() << "):" << endl;
112  for ( const AdcRoi& roi : rois ) {
113  cout << myname << setw(8) << roi.first << " " << setw(8) << roi.second << endl;
114  }
115  } else if ( m_LogLevel >= 2 ) {
116  cout << myname << " ROI count after merge: " << acd.rois.size() << endl;
117  }
118  }
119  ret.setInt("nroi", acd.rois.size());
120  return ret;
121 }
122 
123 //**********************************************************************
124 
126  AdcChannelData acdtmp;
127  acdtmp.samples = acd.samples;
128  return update(acdtmp);
129 }
130 
131 //**********************************************************************
132 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
DataMap & setStatus(int stat)
Definition: DataMap.h:130
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
DuneAdcSignalFinder(fhicl::ParameterSet const &ps)
AdcSignal sampleNoise
AdcRoiVector rois
void setInt(Name name, int val)
Definition: DataMap.h:131
static constexpr double ps
Definition: Units.h:99
unsigned int AdcIndex
Definition: AdcTypes.h:15
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< AdcRoi > AdcRoiVector
Definition: AdcTypes.h:55
DataMap view(const AdcChannelData &acd) const override
Channel channel() const
AdcFilterVector signal
std::vector< bool > AdcFilterVector
Definition: AdcTypes.h:27
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
DataMap update(AdcChannelData &acd) const override