DuneRoiBuildingService_service.cc
Go to the documentation of this file.
1 // DuneRoiBuildingService_service.cc
2 
4 #include <iostream>
5 #include <sstream>
6 #include <iomanip>
10 
11 using std::vector;
12 using std::string;
13 using std::ostream;
14 using std::cout;
15 using std::endl;
16 using std::setw;
17 using art::ServiceHandle;
18 
19 //**********************************************************************
20 
23 : m_LogLevel(1) {
24  const string myname = "DuneRoiBuildingService::ctor: ";
25  pset.get_if_present<int>("LogLevel", m_LogLevel);
26  m_NSigmaStart = pset.get<AdcSignal>("NSigmaStart");
27  m_NSigmaEnd = pset.get<AdcSignal>("NSigmaEnd");
28  m_PadLow = pset.get<AdcSignal>("PadLow");
29  m_PadHigh = pset.get<AdcSignal>("PadHigh");
30  if ( m_LogLevel > 0 ) print(cout, myname);
31 }
32 
33 
34 //**********************************************************************
35 
37  const string myname = "DuneRoiBuildingService:build: ";
38  if ( m_LogLevel >= 2 ) cout << myname << "Building ROIs for channel "
39  << data.channel() << "." << endl;
40  data.rois.clear();
41  // Get signal shaping service.
43  AdcSignal sigma = hsss->GetDeconNoise(data.channel());
44  if ( m_LogLevel >= 3 ) {
45  cout << myname << " Noise level: " << sigma << " " << data.sampleUnit << endl;
46  }
47  const AdcSignalVector& sigs = data.samples;
48  // Build ROIS before padding and merging.
49  AdcFilterVector& signal = data.signal;
50  AdcRoiVector& rois = data.rois;
51  signal.clear();
52  signal.resize(sigs.size(), false);
53  bool inroi = false;
54  AdcSignal siglow = m_NSigmaEnd*sigma;
55  AdcSignal sighigh = m_NSigmaStart*sigma;
56  AdcIndex nsig = sigs.size();
57  if ( nsig < 1 ) {
58  if ( m_LogLevel >= 2 ) cout << myname << "Channel " << data.channel()
59  << " has no samples." << endl;
60  return 0;
61  }
62  for ( AdcIndex isig=0; isig<sigs.size(); ++isig ) {
63  AdcSignal sig = sigs[isig];
64  if ( inroi ) {
65  if ( sig > siglow ) {
66  signal[isig] = true;
67  } else {
68  inroi = false;
69  }
70  } else {
71  if ( sig > sighigh ) {
72  signal[isig] = true;
73  inroi = true;
74  }
75  }
76  }
77  // Fill the unpadded ROIs.
78  data.roisFromSignal();
79  // Display ROIs before padding and merging.
80  if ( m_LogLevel >= 3 ) {
81  cout << myname << " ROIs before merge (size = " << rois.size() << "):" << endl;
82  for ( const AdcRoi& roi : rois ) {
83  cout << myname << setw(8) << roi.first << " " << setw(8) << roi.second << endl;
84  }
85  } else if ( m_LogLevel >= 2 ) {
86  cout << myname << " ROI count before merge: " << data.rois.size() << endl;
87  }
88  if ( rois.size() == 0 ) return 0;
89  // Pad ROIs.
90  unsigned int isig1 = 0;
91  unsigned int isig2 = 0;
92  for ( AdcRoi roi : rois ) {
93  isig2 = roi.first;
94  isig1 = isig2 > m_PadLow ? isig2 - m_PadLow : 0;
95  for ( unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] = true;
96  isig1 = roi.second + 1;
97  isig2 = isig1 + m_PadHigh;
98  if ( isig2 > nsig ) isig2 = nsig;
99  for ( unsigned int isig=isig1; isig<isig2; ++isig ) signal[isig] = true;
100  }
101  // Fill the final ROIs.
102  data.roisFromSignal();
103  // Display final ROIs.
104  if ( m_LogLevel >= 3 ) {
105  cout << myname << " ROIs after merge (size = " << rois.size() << "):" << endl;
106  for ( const AdcRoi& roi : rois ) {
107  cout << myname << setw(8) << roi.first << " " << setw(8) << roi.second << endl;
108  }
109  } else if ( m_LogLevel >= 2 ) {
110  cout << myname << " ROI count after merge: " << data.rois.size() << endl;
111  }
112  return 0;
113 }
114 
115 //**********************************************************************
116 
118 print(ostream& out, string prefix) const {
119  out << prefix << "DuneRoiBuildingService:" << endl;
120  out << prefix << " LogLevel: " << m_LogLevel << endl;
121  out << prefix << " NSigmaStart: " << m_NSigmaStart << endl;
122  out << prefix << " NSigmaEnd: " << m_NSigmaEnd << endl;
123  out << prefix << " PadLow: " << m_PadLow << endl;
124  out << prefix << " PadHigh: " << m_PadHigh << endl;
125  return out;
126 }
127 
128 //**********************************************************************
129 
131 
132 //**********************************************************************
int build(AdcChannelData &data) const
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
DuneRoiBuildingService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
struct vector vector
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
double GetDeconNoise(Channel channel) const override
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
AdcRoiVector rois
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::vector< AdcRoi > AdcRoiVector
Definition: AdcTypes.h:55
Channel channel() 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)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)