Legacy35tZeroSuppressService_service.cc
Go to the documentation of this file.
1 // Legacy35tZeroSuppressService.cxx
2 
5 #include <cmath>
8 
9 using std::string;
10 using std::ostream;
11 using std::endl;
12 
13 namespace {
14 
15 string sbool(bool arg) {
16  if ( arg ) return "true";
17  return "false";
18 }
19 
20 } // end unnamed namespace.
21 
22 typedef unsigned int Index;
23 
24 //**********************************************************************
25 
28  m_AdcThreshold = pset.get<float>("AdcThreshold");
29  m_TickRange = pset.get<unsigned int>("TickRange");
30  m_MinTickGap = pset.get<unsigned int>("MinTickGap");
31  m_SuppressStickyBits = pset.get<bool>("SuppressStickyBits");
32 }
33 
34 //**********************************************************************
35 
37 Legacy35tZeroSuppressService(float aAdcThreshold,
38  unsigned int aTickRange,
39  unsigned int aMinTickGap,
40  bool aSuppressStickyBits)
41 : m_AdcThreshold(aAdcThreshold),
42  m_TickRange(aTickRange),
43  m_MinTickGap(aMinTickGap),
44  m_SuppressStickyBits(aSuppressStickyBits) { }
45 
46 //**********************************************************************
47 
49 filter(const AdcCountVector& sigs, Channel, AdcPedestal ped, AdcFilterVector& keep) const {
50  const unsigned int nsig = sigs.size();
51  keep.clear();
52  keep.resize(nsig, false);
53  if ( nsig == 0 ) return 0;
54  AdcCodeHelper ach(64);
55  for ( unsigned int isig=0; isig<nsig; ++isig ) {
56  AdcCount rawsig = sigs[isig];
57  AdcSignal pedsig = ach.subtract(ped, rawsig);
58  if ( m_SuppressStickyBits ) {
59  if ( ach.hasStickyBits(rawsig) && ach.isSmall(pedsig) ) {
60  std::cout << "Legacy35tZeroSuppressService::filter: Suppressing sticky ADC value " << pedsig
61  << " (raw=" << rawsig << ", ped=" << ped << ")" << endl;
62  pedsig = 0.0;
63  }
64  }
65  if ( fabs(pedsig) > m_AdcThreshold ) {
66  Index isig1 = 0;
67  if ( m_TickRange < isig ) isig1 = isig - m_TickRange;
68  Index isig2 = isig + m_TickRange;
69  if ( isig2 > nsig ) isig2 = nsig;
70  for ( Index jsig=isig1; jsig<=isig2; ++jsig ) keep[jsig] = true;
71  }
72  }
73  // Make gaps between unsupressed blocks < MinTickGap.
74  bool inGap = false;
75  unsigned int jsig1 = 0; // Start of gap.
76  unsigned int jsig2 = 0; // End of gap.
77  for ( unsigned int isig=0; isig<nsig; ++isig ) {
78  // End of a gap;
79  if ( inGap && (isig+1==nsig || keep[isig]) ) {
80  inGap = false;
81  if ( (jsig2 - jsig1 + 1) < m_MinTickGap ) {
82  for ( unsigned int jsig=jsig1; jsig<=jsig2; ++jsig ) {
83  keep[jsig] = true;
84  }
85  }
86  // In a gap.
87  } else if ( inGap ) {
88  jsig2 = isig;
89  // Start of gap.
90  } else if ( !inGap && !keep[isig] ) {
91  inGap = true;
92  jsig1 = isig;
93  jsig2 = jsig1;
94  }
95  }
96  return 0;
97 }
98 
99 //**********************************************************************
100 
101 ostream& Legacy35tZeroSuppressService::print(ostream& out, string prefix) const {
102  out << prefix << "Legacy35tZeroSuppressService:" << endl;
103  out << prefix << " AdcThreshold: " << m_AdcThreshold << endl;
104  out << prefix << " MinTickGap: " << m_MinTickGap << endl;
105  out << prefix << " TickRange: " << m_TickRange << endl;
106  out << prefix << " SuppressStickyBits: " << sbool(m_SuppressStickyBits);
107  return out;
108 }
109 
110 //**********************************************************************
111 
113 
114 //**********************************************************************
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
AdcSignal subtract(AdcCount sig, AdcSignal ped) const
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
bool isSmall(AdcCount sig, AdcSignal ped=0.0)
std::vector< bool > AdcFilterVector
Definition: AdcTypes.h:27
float AdcPedestal
Definition: AdcTypes.h:25
bool hasStickyBits(AdcCount sig)
Legacy35tZeroSuppressService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
short AdcCount
Definition: AdcTypes.h:18
int filter(const AdcCountVector &sigs, Channel chan, AdcPedestal ped, AdcFilterVector &keep) const
QTextStream & endl(QTextStream &s)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)