Public Member Functions | Private Attributes | List of all members
InterpolatingAdcMitigationService Class Reference

#include <InterpolatingAdcMitigationService.h>

Inheritance diagram for InterpolatingAdcMitigationService:
AdcMitigationService

Public Member Functions

 InterpolatingAdcMitigationService (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
int update (AdcChannelData &data) const
 
std::ostream & print (std::ostream &out=std::cout, std::string prefix="") const
 
- Public Member Functions inherited from AdcMitigationService
virtual ~AdcMitigationService ()=default
 

Private Attributes

int m_LogLevel
 
bool m_SkipUnderflows
 
bool m_SkipOverflows
 
int m_MaxConsecutiveSamples
 
int m_MaxConsecutiveFlag
 

Detailed Description

Definition at line 35 of file InterpolatingAdcMitigationService.h.

Constructor & Destructor Documentation

InterpolatingAdcMitigationService::InterpolatingAdcMitigationService ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry  
)

Definition at line 15 of file InterpolatingAdcMitigationService_service.cc.

16 : m_LogLevel(1) {
17  const string myname = "InterpolatingAdcMitigationService::ctor: ";
18  pset.get_if_present<int>("LogLevel", m_LogLevel);
19  m_SkipUnderflows = pset.get<bool>("SkipUnderflows");
20  m_SkipOverflows = pset.get<bool>("SkipOverflows");
21  m_MaxConsecutiveSamples = pset.get<int>("MaxConsecutiveSamples");
22  m_MaxConsecutiveFlag = pset.get<int>("MaxConsecutiveFlag");
23  print(cout, myname);
24 }
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const

Member Function Documentation

std::ostream & InterpolatingAdcMitigationService::print ( std::ostream &  out = std::cout,
std::string  prefix = "" 
) const
virtual

Implements AdcMitigationService.

Definition at line 112 of file InterpolatingAdcMitigationService_service.cc.

112  {
113  out << prefix << "InterpolatingAdcMitigationService:" << endl;
114  out << prefix << " LogLevel: " << m_LogLevel << endl;
115  out << prefix << " SkipUnderflows: " << m_SkipUnderflows << endl;
116  out << prefix << " SkipOverflows: " << m_SkipOverflows << endl;
117  out << prefix << " MaxConsecutiveSamples: " << m_MaxConsecutiveSamples << endl;
118  out << prefix << " MaxConsecutiveFlag: " << m_MaxConsecutiveFlag << endl;
119  return out;
120 }
QTextStream & endl(QTextStream &s)
int InterpolatingAdcMitigationService::update ( AdcChannelData data) const
virtual

Implements AdcMitigationService.

Definition at line 29 of file InterpolatingAdcMitigationService_service.cc.

29  {
30  const string myname = "InterpolatingAdcMitigationService:update: ";
31  if ( m_LogLevel >= 3 ) {
32  cout << myname << "Entering..." << endl;
33  cout << myname << " Channel: " << data.channel() << endl;
34  cout << myname << "Input vector size: " << data.samples.size() << endl;
35  }
36  AdcSignalVector& sigs = data.samples;
37  AdcFlagVector& flags = data.flags;
38  unsigned int isigFirst = sigs.size(); // First sample in the bad sample sequence.
39  bool useMax = m_MaxConsecutiveSamples >= 0;
40  unsigned int maxsig = m_MaxConsecutiveSamples;
41  unsigned int nupdated = 0;
42  // Loop over samples.
43  for ( unsigned int isig=0; isig<sigs.size(); ++isig ) {
44  AdcFlag flag = flags[isig];
45  unsigned int isLast = isig == sigs.size()-1;
46  // Set isBad which indicates if this is value that is flagged to be updated.
47  bool isBad = false;
48  if ( flag != AdcGood ) {
49  isBad = true;
50  if ( m_SkipUnderflows && flag == AdcUnderflow ) isBad = false;
51  else if ( m_SkipOverflows && flag == AdcOverflow ) isBad = false;
52  }
53  // Record if this is the first sample in a new bad sequence.
54  if ( isBad && isigFirst > isig ) isigFirst = isig;
55  // Check if we have found the end of a sequence of bad samples.
56  // This is indicated with a nonzero value for isigLast.
57  // We will update samples in the range [isigFirst, isigLast].
58  bool endBadSequence = false;
59  unsigned int isigLast = 0;
60  if ( !isBad && isigFirst < isig ) {
61  endBadSequence = true;
62  isigLast = isig - 1;
63  }
64  if ( isLast && isBad ) {
65  endBadSequence = true;
66  isigLast = isig;
67  }
68  // Update the current sequence of bad samples.
69  if ( endBadSequence ) {
70  unsigned int nsig = isigLast - isigFirst + 1;
71  bool tooMany = useMax && nsig > maxsig;
72  if ( m_LogLevel > 2 ) {
73  cout << myname << " Updating at sample " << isig << ":"
74  << " range=[" << isigFirst << "," << isigLast << "],"
75  << " tooMany=" << tooMany << ", isLast=" << isLast << endl;
76  }
77  // For too many samples or beginning or end of data, use MaxConsecutiveFlag.
78  if ( tooMany || isigFirst == 0 || isLast ) {
79  if ( m_MaxConsecutiveFlag == 1 ) {
80  for ( unsigned isig=isigFirst; isig<=isigLast; ++isig ) {
81  sigs[isig] = 0.0;
82  flags[isig] = AdcSetFixed;
83  ++nupdated;
84  }
85  }
86  // Otherwise, interpolate: sig_i = a*i + b
87  } else {
88  unsigned int isig1 = isigFirst - 1;
89  unsigned int isig2 = isigLast + 1;
90  double sig1 = sigs[isig1];
91  double sig2 = sigs[isigLast+1];
92  double fac = 1.0/(isig2 - isig1);
93  double a = fac*(sig2 - sig1);
94  double b = fac*(isig2*sig1 - isig1*sig2);
95  for ( unsigned isig=isigFirst; isig<=isigLast; ++isig ) {
96  sigs[isig] = a*isig + b;
97  flags[isig] = AdcInterpolated;
98  ++nupdated;
99  }
100  }
101  isigFirst = sigs.size();
102  }
103  }
104  if ( m_LogLevel >= 2 ) cout << myname << "Channel " << data.channel()
105  << ": # updated/total = " << nupdated << "/" << sigs.size() << endl;
106  return 0;
107 }
short AdcFlag
Definition: AdcTypes.h:29
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
const AdcFlag AdcSetFixed
Definition: AdcTypes.h:41
const AdcFlag AdcGood
Definition: AdcTypes.h:32
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
const double a
Channel channel() const
const AdcFlag AdcInterpolated
Definition: AdcTypes.h:42
static bool * b
Definition: config.cpp:1043
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags

Member Data Documentation

int InterpolatingAdcMitigationService::m_LogLevel
private

Definition at line 48 of file InterpolatingAdcMitigationService.h.

int InterpolatingAdcMitigationService::m_MaxConsecutiveFlag
private

Definition at line 52 of file InterpolatingAdcMitigationService.h.

int InterpolatingAdcMitigationService::m_MaxConsecutiveSamples
private

Definition at line 51 of file InterpolatingAdcMitigationService.h.

bool InterpolatingAdcMitigationService::m_SkipOverflows
private

Definition at line 50 of file InterpolatingAdcMitigationService.h.

bool InterpolatingAdcMitigationService::m_SkipUnderflows
private

Definition at line 49 of file InterpolatingAdcMitigationService.h.


The documentation for this class was generated from the following files: