AdcRangeSampleScaler_tool.cc
Go to the documentation of this file.
1 // AdcRangeSampleScaler_tool.cc
2 
3 #include "AdcRangeSampleScaler.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_RangeLimits(ps.get<IndexVector>("RangeLimits")),
19  m_RangeModulus(ps.get<Index>("RangeModulus")),
20  m_ScaleFactors(ps.get<FloatVector>("ScaleFactors")) {
21  const string myname = "AdcRangeSampleScaler::ctor: ";
22  if ( m_LogLevel >= 1 ) {
23  cout << myname << "Parameters:" << endl;
24  cout << myname << " LogLevel: " << m_LogLevel << endl;
25  Index imin = 0;
26  cout << myname << " Modulus: " << m_RangeModulus << endl;
27  cout << myname << " Range: Scale: " << endl;
28  Index imod = m_RangeModulus;
29  for ( Index iran=0; ; ++iran ) {
30  // No more ranges.
31  // Unless protected with a modulus, we need one more scale factor.
32  Index imax = 0;
33  bool haveMax = true;
34  if ( iran >= m_RangeLimits.size() ) {
35  if ( imod && imin >= imod ) {
36  break;
37  }
38  haveMax = false;
39  } else {
40  imax = m_RangeLimits[iran];
41  if ( imod > 0 && imax >= imod ) {
42  cout << myname << "WARNING: Index exceeds modulus: " << imax << " >= " << imod << endl;
43  break;
44  }
45  }
46  if ( m_ScaleFactors.size() < iran + 1 ) {
47  cout << myname << "ERROR: Too few scale factors." << endl;
48  break;
49  }
50  float sfac = m_ScaleFactors[iran];
51  cout << myname << " [" << imin << ", ";
52  if ( haveMax ) cout << imax;
53  else cout << "...";
54  cout << "): " << sfac << endl;
55  if ( haveMax ) imin = imax;
56  else break;
57  }
58 
59  }
60 }
61 
62 //**********************************************************************
63 
65  const string myname = "AdcRangeSampleScaler::update: ";
66  if ( m_LogLevel >= 2 ) cout << "Processing run " << acd.run() << " event " << acd.event()
67  << " channel " << acd.channel() << endl;
68  DataMap ret;
69 
70  // Find the index for the scale factor.
71  if ( acd.channel() == AdcChannelData::badIndex() ) {
72  cout << myname << "ERROR: Invalid channel." << endl;
73  return ret.setStatus(1);
74  }
75  Index icha = acd.channel();
76  Index ichaMod = m_RangeModulus ? icha%m_RangeModulus : icha;
77  Index iran = 0;
78  for ( iran=0; iran<m_RangeLimits.size(); ++iran ) {
79  Index imax = m_RangeLimits[iran];
80  if ( ichaMod < imax ) {
81  break;
82  }
83  }
84 
85  if ( iran >= m_ScaleFactors.size() ) {
86  cout << myname << "ERROR: No scale factor for channel " << icha;
87  if ( ichaMod != icha ) cout << " (" << ichaMod << ")";
88  cout << endl;
89  return ret.setStatus(2);
90  }
91  float sfac = m_ScaleFactors[iran];
92 
93  // Scale samples.
94  for ( float& sam : acd.samples ) sam *= sfac;
95 
96  ret.setFloat("arssScaleFactor", sfac);
97 
98  return ret;
99 }
100 
101 //**********************************************************************
102 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
void setFloat(Name name, float val)
Definition: DataMap.h:133
unsigned int Index
DataMap & setStatus(int stat)
Definition: DataMap.h:130
std::string string
Definition: nybbler.cc:12
DataMap update(AdcChannelData &acd) const override
unsigned int Index
AdcRangeSampleScaler(fhicl::ParameterSet const &ps)
AdcIndex run() const
AdcIndex event() const
static constexpr double ps
Definition: Units.h:99
std::vector< Index > IndexVector
Channel channel() const
std::vector< float > FloatVector
int imax
Definition: tracks.py:195
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
static Index badIndex()
AdcSignalVector samples
QTextStream & endl(QTextStream &s)