AdcTimingMitigator_tool.cc
Go to the documentation of this file.
1 // AdcTimingMitigator_tool.cc
2 
3 #include "AdcTimingMitigator.h"
4 #include <iostream>
5 
6 using std::string;
7 using std::cout;
8 using std::endl;
9 
10 using Index = unsigned int;
11 
12 //**********************************************************************
13 // Class methods.
14 //**********************************************************************
15 
17 : m_LogLevel(ps.get<int>("LogLevel")),
18  m_SamplingRatio(ps.get<float>("SamplingRatio")),
19  m_SamplingOffset(ps.get<float>("SamplingOffset")),
20  m_FEMBs(ps.get<IndexVector>("FEMBs")) {
21  const string myname = "AdcTimingMitigator::ctor: ";
22  for ( Index ifmb : m_FEMBs ) m_fembSet.insert(ifmb);
23  if ( m_LogLevel >= 1 ) {
24  cout << myname << "Configuration parameters:" << endl;
25  cout << myname << " LogLevel: " << m_LogLevel << endl;
26  cout << myname << " SamplingRatio: " << m_SamplingRatio << endl;
27  cout << myname << " SamplingOffset: " << m_SamplingOffset << endl;
28  cout << myname << " FEMBs: [";
29  bool first = true;
30  for ( Index ifmb : m_fembSet ) {
31  if ( first ) first = false;
32  else cout << ", ";
33  cout << ifmb;
34  }
35  cout << "]" << endl;
36  }
37 }
38 
39 //**********************************************************************
40 
42  const string myname = "AdcTimingMitigator::update: ";
43  DataMap ret;
44  if ( m_fembSet.count(acd.fembID()) == 0 ) {
45  if ( m_LogLevel >= 2 ) {
46  cout << myname << "Skipping channel " << acd.channel() << " in FEMB " << acd.fembID() << endl;
47  }
48  return ret;
49  }
50  Index nsam = acd.samples.size();
51  if ( nsam == 0 ) {
52  if ( m_LogLevel >= 2 ) {
53  cout << myname << "Skipping channel " << acd.channel() << " with no samples." << endl;
54  }
55  return ret;
56  }
57  if ( m_SamplingRatio < 0.01 ) return ret;
58  AdcSignalVector newsams;
59  newsams.reserve(nsam/m_SamplingRatio+1);
60  // Loop over indices for new sample.
61  if ( m_LogLevel >= 3 ) {
62  cout << myname << "Updating samples for channel " << acd.channel() << "." << endl;
63  }
64  for ( Index j=0; ; ++j ) {
65  double xj = j*m_SamplingRatio - m_SamplingOffset;
66  double yj = acd.samples[0];
67  if ( xj > 0.0 ) {
68  Index i1 = xj;
69  Index i2 = i1 + 1;
70  if ( i2 >= acd.samples.size() ) break;
71  double y1 = acd.samples[i1];
72  double y2 = acd.samples[i2];
73  yj = (y2 - y1)*(xj - i1) + y1;
74  if ( m_LogLevel >= 3 ) {
75  cout << myname << " " << j << ": " << y1 << " , " << y2 << " ==> " << yj << endl;
76  }
77  } else {
78  if ( m_LogLevel >= 3 ) {
79  cout << myname << " " << j << ": " << " Keeping first sample: " << yj << endl;
80  }
81  }
82  newsams.push_back(yj);
83  }
84  if ( m_LogLevel >= 2 ) {
85  cout << myname << "Updating samples for channel " << acd.channel() << ": size "
86  << nsam << " --> " << newsams.size() << endl;
87  }
88  acd.samples = newsams;
89  acd.signal.clear();
90  acd.rois.clear();
91  return ret;
92 }
93 
94 //**********************************************************************
95 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int Index
std::string string
Definition: nybbler.cc:12
unsigned int Index
AdcTimingMitigator(fhicl::ParameterSet const &ps)
Index fembID() const
std::vector< Index > IndexVector
AdcRoiVector rois
static constexpr double ps
Definition: Units.h:99
Channel channel() const
AdcFilterVector signal
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
DataMap update(AdcChannelData &acd) const override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)