Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RunningSumTPFinderPass4 Class Reference

#include <RunningSumTPFinderPass4.h>

Inheritance diagram for RunningSumTPFinderPass4:
RunningSumTPFinderTool

Public Member Functions

 RunningSumTPFinderPass4 (fhicl::ParameterSet const &p)
 
virtual std::vector< RunningSumTPFinderTool::HitfindHits (const std::vector< unsigned int > &channel_numbers, const std::vector< std::vector< short >> &collection_samples)
 
- Public Member Functions inherited from RunningSumTPFinderTool
virtual ~RunningSumTPFinderTool ()=default
 

Protected Member Functions

std::vector< short > downSample (const std::vector< short > &orig)
 
std::vector< short > findPedestal (const std::vector< short > &orig)
 
std::vector< short > filter (const std::vector< short > &orig)
 
std::vector< short > runSum (const std::vector< short > &orig)
 
void hitFinding (const std::vector< short > &waveform, const std::vector< short > &iqr, std::vector< RunningSumTPFinderTool::Hit > &hits, int channel)
 

Protected Attributes

bool m_useSignalKill
 
short m_signalKillLookahead
 
short m_signalKillThreshold
 
short m_signalKillNContig
 
short m_frugalNContig
 
bool m_doFiltering
 
unsigned int m_downsampleFactor
 
std::vector< short > m_filterTaps
 
int m_multiplier
 
float m_sigmaThreshold
 

Detailed Description

Definition at line 10 of file RunningSumTPFinderPass4.h.

Constructor & Destructor Documentation

RunningSumTPFinderPass4::RunningSumTPFinderPass4 ( fhicl::ParameterSet const &  p)
explicit

Definition at line 18 of file RunningSumTPFinderPass4_tool.cc.

19  : m_useSignalKill (p.get<bool> ("UseSignalKill" , true)),
20  m_signalKillLookahead(p.get<short> ("SignalKillLookahead" , 5)),
21  m_signalKillThreshold(p.get<short> ("SignalKillThreshold" , 15)),
22  m_signalKillNContig (p.get<short> ("SignalKillNContig" , 1)),
23  m_frugalNContig (p.get<short> ("FrugalPedestalNContig", 10)),
24  m_doFiltering (p.get<bool> ("DoFiltering" , true)),
25  m_downsampleFactor (p.get<unsigned int> ("DownsampleFactor" , 1)),
26  m_filterTaps (p.get<std::vector<short>>("FilterCoeffs" , {2, 9, 23, 31, 23, 9, 2})),
27  m_multiplier (std::accumulate(m_filterTaps.begin(), m_filterTaps.end(), 0)),
28  m_sigmaThreshold (p.get<float> ("SigmaThreshold" , 5))
29  // Default filter taps calculated by:
30  // np.round(scipy.signal.firwin(7, 0.1)*100)
31  // Initialize member data here.
32 {
33  std::cout << "Sigma Threshold = " << m_sigmaThreshold << std::endl;
34 }
std::vector< short > m_filterTaps
p
Definition: test.py:223
QTextStream & endl(QTextStream &s)

Member Function Documentation

std::vector< short > RunningSumTPFinderPass4::downSample ( const std::vector< short > &  orig)
protected

Definition at line 36 of file RunningSumTPFinderPass4_tool.cc.

36  {
37 
38  //---------------------------------------------
39  // Do the downsampling
40  //---------------------------------------------
41  if (m_downsampleFactor==1) {
42  return orig;
43  }
44  else {
45  std::vector<short> waveform;
46  for(size_t i=0; i<orig.size(); i+=m_downsampleFactor) {
47  waveform.push_back(orig[i]);
48  }
49  return waveform;
50  }
51 }
std::vector< short > RunningSumTPFinderPass4::filter ( const std::vector< short > &  orig)
protected

Definition at line 67 of file RunningSumTPFinderPass4_tool.cc.

67  {
68 
69  //---------------------------------------------
70  // Filtering
71  //---------------------------------------------
72  const size_t ntaps = m_filterTaps.size();
73  const short* taps = m_filterTaps.data();
74 
75  std::vector<short> filtered(m_doFiltering ?
76  apply_fir_filter(pedsub, ntaps, taps) :
77  pedsub);
78  if (!m_doFiltering) {
79  std::transform(filtered.begin(), filtered.end(),
80  filtered.begin(),
81  [=](short a) { return a*m_multiplier; });
82  }
83  return filtered;
84 }
std::vector< short > m_filterTaps
const double a
std::vector< short > apply_fir_filter(const std::vector< short > &input, const size_t ntaps, const short *taps)
Definition: AlgParts.h:104
std::vector< RunningSumTPFinderTool::Hit > RunningSumTPFinderPass4::findHits ( const std::vector< unsigned int > &  channel_numbers,
const std::vector< std::vector< short >> &  collection_samples 
)
virtual

Implements RunningSumTPFinderTool.

Definition at line 120 of file RunningSumTPFinderPass4_tool.cc.

121  {
122 
123  auto hits = std::vector<RunningSumTPFinderTool::Hit>();
124  std::cout << "findHits called with " << collection_samples.size()
125  << " channels. First chan has " << collection_samples[0].size() << " samples" << std::endl;
126 
127  for(size_t ich=0; ich<collection_samples.size(); ++ich){
128  const std::vector<short>& waveformOrig = collection_samples[ich];
129 
130  std::vector<short> waveform = downSample (waveformOrig);
131  std::vector<short> pedestal = findPedestal(waveform );
132  std::vector<short> pedsub(waveform.size(), 0);
133  for(size_t i=0; i<pedsub.size(); ++i)
134  pedsub[i]=waveform[i]-pedestal[i];
135  std::vector<short> iqr=frugal_iqr(waveform, pedestal, m_frugalNContig);
136  std::vector<short> filtered = filter(pedsub);
137  hitFinding(filtered, iqr, hits, channel_numbers[ich]);
138  }
139  std::cout << "Returning " << hits.size() << " hits" << std::endl;
140  std::cout << "hits/channel=" << float(hits.size())/collection_samples .size() << std::endl;
141  std::cout << "hits/tick=" << float(hits.size())/collection_samples[0].size() << std::endl;
142  return hits;
143 }
std::vector< short > findPedestal(const std::vector< short > &orig)
std::vector< short > downSample(const std::vector< short > &orig)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
void hitFinding(const std::vector< short > &waveform, const std::vector< short > &iqr, std::vector< RunningSumTPFinderTool::Hit > &hits, int channel)
std::vector< short > frugal_iqr(const std::vector< short > &raw_in, const std::vector< short > &median, const int ncontig)
Definition: AlgParts.h:59
QTextStream & endl(QTextStream &s)
std::vector< short > filter(const std::vector< short > &orig)
std::vector< short > RunningSumTPFinderPass4::findPedestal ( const std::vector< short > &  orig)
protected

Definition at line 53 of file RunningSumTPFinderPass4_tool.cc.

54 {
55  //---------------------------------------------
56  // Pedestal subtraction
57  //---------------------------------------------
58  const std::vector<short>& pedestal=m_useSignalKill ?
59  frugal_pedestal_sigkill(waveform,
64  return pedestal;
65 }
std::vector< short > frugal_pedestal_sigkill(const std::vector< short > &raw_in, const int lookahead, const int threshold, const int ncontig)
Definition: AlgParts.h:21
std::vector< short > frugal_pedestal(const std::vector< short > &raw_in, const int ncontig)
Definition: AlgParts.h:86
void RunningSumTPFinderPass4::hitFinding ( const std::vector< short > &  waveform,
const std::vector< short > &  iqr,
std::vector< RunningSumTPFinderTool::Hit > &  hits,
int  channel 
)
protected

Definition at line 87 of file RunningSumTPFinderPass4_tool.cc.

90  {
91 
92  //---------------------------------------------
93  // Hit finding
94  //---------------------------------------------
95  bool is_hit = false;
96  bool was_hit = false;
98  for(size_t isample=0; isample<waveform.size()-1; ++isample){
99  int sample_time = isample * m_downsampleFactor;
100  short adc = waveform[isample];
101  is_hit = (float)adc > 100*m_sigmaThreshold*iqr[isample];
102  if(is_hit && !was_hit) {
103  hit.startTime = sample_time;
104  hit.charge = adc;
105  hit.timeOverThreshold = m_downsampleFactor;
106  }
107  if(is_hit && was_hit) {
108  hit.charge += adc*m_downsampleFactor;
109  hit.timeOverThreshold += m_downsampleFactor;
110  }
111  if(!is_hit && was_hit) {
112  hit.charge /= m_multiplier;
113  hits.push_back(hit);
114  }
115  was_hit = is_hit;
116  }
117 }
int16_t adc
Definition: CRTFragment.hh:202
uint8_t channel
Definition: CRTFragment.hh:201
Detector simulation of raw signals on wires.
std::vector<short> RunningSumTPFinderPass4::runSum ( const std::vector< short > &  orig)
protected

Member Data Documentation

bool RunningSumTPFinderPass4::m_doFiltering
protected

Definition at line 36 of file RunningSumTPFinderPass4.h.

unsigned int RunningSumTPFinderPass4::m_downsampleFactor
protected

Definition at line 37 of file RunningSumTPFinderPass4.h.

std::vector<short> RunningSumTPFinderPass4::m_filterTaps
protected

Definition at line 38 of file RunningSumTPFinderPass4.h.

short RunningSumTPFinderPass4::m_frugalNContig
protected

Definition at line 35 of file RunningSumTPFinderPass4.h.

int RunningSumTPFinderPass4::m_multiplier
protected

Definition at line 39 of file RunningSumTPFinderPass4.h.

float RunningSumTPFinderPass4::m_sigmaThreshold
protected

Definition at line 40 of file RunningSumTPFinderPass4.h.

short RunningSumTPFinderPass4::m_signalKillLookahead
protected

Definition at line 32 of file RunningSumTPFinderPass4.h.

short RunningSumTPFinderPass4::m_signalKillNContig
protected

Definition at line 34 of file RunningSumTPFinderPass4.h.

short RunningSumTPFinderPass4::m_signalKillThreshold
protected

Definition at line 33 of file RunningSumTPFinderPass4.h.

bool RunningSumTPFinderPass4::m_useSignalKill
protected

Definition at line 31 of file RunningSumTPFinderPass4.h.


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