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

#include <RunningSumTPFinderPass3.h>

Inheritance diagram for RunningSumTPFinderPass3:
RunningSumTPFinderTool

Public Member Functions

 RunningSumTPFinderPass3 (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
 
short m_runningSumAlpha
 
float m_sigmaThreshold
 

Detailed Description

Definition at line 10 of file RunningSumTPFinderPass3.h.

Constructor & Destructor Documentation

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

Definition at line 18 of file RunningSumTPFinderPass3_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_runningSumAlpha (p.get<short> ("RunningSumAlpha" , 97)),
29  m_sigmaThreshold (p.get<float> ("SigmaThreshold" , 5))
30  // Default filter taps calculated by:
31  // np.round(scipy.signal.firwin(7, 0.1)*100)
32  // Initialize member data here.
33 {
34 
35 }
std::vector< short > m_filterTaps
p
Definition: test.py:223

Member Function Documentation

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

Definition at line 37 of file RunningSumTPFinderPass3_tool.cc.

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

Definition at line 68 of file RunningSumTPFinderPass3_tool.cc.

68  {
69 
70  //---------------------------------------------
71  // Filtering
72  //---------------------------------------------
73  const size_t ntaps = m_filterTaps.size();
74  const short* taps = m_filterTaps.data();
75 
76  std::vector<short> filtered(m_doFiltering ?
77  apply_fir_filter(pedsub, ntaps, taps) :
78  pedsub);
79  if (!m_doFiltering) {
80  std::transform(filtered.begin(), filtered.end(),
81  filtered.begin(),
82  [=](short a) { return a*m_multiplier; });
83  }
84  return filtered;
85 }
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 > RunningSumTPFinderPass3::findHits ( const std::vector< unsigned int > &  channel_numbers,
const std::vector< std::vector< short >> &  collection_samples 
)
virtual

Implements RunningSumTPFinderTool.

Definition at line 137 of file RunningSumTPFinderPass3_tool.cc.

138  {
139 
140  auto hits = std::vector<RunningSumTPFinderTool::Hit>();
141  std::cout << "findHits called with " << collection_samples.size()
142  << " channels. First chan has " << collection_samples[0].size() << " samples" << std::endl;
143 
144  for(size_t ich=0; ich<collection_samples.size(); ++ich){
145  const std::vector<short>& waveformOrig = collection_samples[ich];
146 
147  std::vector<short> waveform = downSample (waveformOrig);
148  std::vector<short> pedestal = findPedestal(waveform );
149  std::vector<short> pedsub(waveform.size(), 0);
150  for(size_t i=0; i<pedsub.size(); ++i)
151  pedsub[i]=waveform[i]-pedestal[i];
152  std::vector<short> iqr=frugal_iqr(waveform, pedestal, m_frugalNContig);
153  std::vector<short> filtered = filter(pedsub);
154  std::vector<short> runingSum = runSum(filtered);
155  hitFinding(runingSum, iqr, hits, channel_numbers[ich]);
156  }
157  std::cout << "Returning " << hits.size() << " hits" << std::endl;
158  std::cout << "hits/channel=" << float(hits.size())/collection_samples .size() << std::endl;
159  std::cout << "hits/tick=" << float(hits.size())/collection_samples[0].size() << std::endl;
160  return hits;
161 }
std::vector< short > filter(const std::vector< short > &orig)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< short > findPedestal(const std::vector< short > &orig)
std::vector< short > downSample(const std::vector< short > &orig)
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 > runSum(const std::vector< short > &orig)
std::vector< short > RunningSumTPFinderPass3::findPedestal ( const std::vector< short > &  orig)
protected

Definition at line 54 of file RunningSumTPFinderPass3_tool.cc.

55 {
56  //---------------------------------------------
57  // Pedestal subtraction
58  //---------------------------------------------
59  const std::vector<short>& pedestal=m_useSignalKill ?
60  frugal_pedestal_sigkill(waveform,
65  return pedestal;
66 }
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 RunningSumTPFinderPass3::hitFinding ( const std::vector< short > &  waveform,
const std::vector< short > &  iqr,
std::vector< RunningSumTPFinderTool::Hit > &  hits,
int  channel 
)
protected

Definition at line 104 of file RunningSumTPFinderPass3_tool.cc.

107  {
108 
109  //---------------------------------------------
110  // Hit finding
111  //---------------------------------------------
112  bool is_hit = false;
113  bool was_hit = false;
115  for(size_t isample=0; isample<waveform.size()-1; ++isample){
116  int sample_time = isample * m_downsampleFactor;
117  short adc = waveform[isample];
118  is_hit = (float)adc > m_sigmaThreshold*iqr[isample];
119  if(is_hit && !was_hit) {
120  hit.startTime = sample_time;
121  hit.charge = adc;
122  hit.timeOverThreshold = m_downsampleFactor;
123  }
124  if(is_hit && was_hit) {
125  hit.charge += adc*m_downsampleFactor;
126  hit.timeOverThreshold += m_downsampleFactor;
127  }
128  if(!is_hit && was_hit) {
129  hit.charge /= m_multiplier;
130  hits.push_back(hit);
131  }
132  was_hit = is_hit;
133  }
134 }
int16_t adc
Definition: CRTFragment.hh:202
uint8_t channel
Definition: CRTFragment.hh:201
Detector simulation of raw signals on wires.
std::vector< short > RunningSumTPFinderPass3::runSum ( const std::vector< short > &  orig)
protected

Definition at line 87 of file RunningSumTPFinderPass3_tool.cc.

87  {
88 
89  //---------------------------------------------
90  // Running Sum
91  //---------------------------------------------
92  std::vector<short> runningSum(filtered.size(), 0); runningSum[0] = 0;
93  for (size_t i=0; i<filtered.size(); ++i) {
94  short sumValue = (filtered[i]/10) + ((runningSum[i-1]/10)*m_runningSumAlpha);
95  sumValue /= 10;
96  if (sumValue < 0) runningSum[i] = 0;
97  else runningSum[i] = sumValue;
98  }
99  return runningSum;
100 }

Member Data Documentation

bool RunningSumTPFinderPass3::m_doFiltering
protected

Definition at line 36 of file RunningSumTPFinderPass3.h.

unsigned int RunningSumTPFinderPass3::m_downsampleFactor
protected

Definition at line 37 of file RunningSumTPFinderPass3.h.

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

Definition at line 38 of file RunningSumTPFinderPass3.h.

short RunningSumTPFinderPass3::m_frugalNContig
protected

Definition at line 35 of file RunningSumTPFinderPass3.h.

int RunningSumTPFinderPass3::m_multiplier
protected

Definition at line 39 of file RunningSumTPFinderPass3.h.

short RunningSumTPFinderPass3::m_runningSumAlpha
protected

Definition at line 40 of file RunningSumTPFinderPass3.h.

float RunningSumTPFinderPass3::m_sigmaThreshold
protected

Definition at line 41 of file RunningSumTPFinderPass3.h.

short RunningSumTPFinderPass3::m_signalKillLookahead
protected

Definition at line 32 of file RunningSumTPFinderPass3.h.

short RunningSumTPFinderPass3::m_signalKillNContig
protected

Definition at line 34 of file RunningSumTPFinderPass3.h.

short RunningSumTPFinderPass3::m_signalKillThreshold
protected

Definition at line 33 of file RunningSumTPFinderPass3.h.

bool RunningSumTPFinderPass3::m_useSignalKill
protected

Definition at line 31 of file RunningSumTPFinderPass3.h.


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