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

#include <TriggerPrimitiveFinderPass1.h>

Inheritance diagram for TriggerPrimitiveFinderPass1:
TriggerPrimitiveFinderTool TriggerPrimitiveFinderPass2

Public Member Functions

 TriggerPrimitiveFinderPass1 (fhicl::ParameterSet const &p)
 
virtual std::vector< TriggerPrimitiveFinderTool::HitfindHits (const std::vector< unsigned int > &channel_numbers, const std::vector< std::vector< short >> &collection_samples)
 
- Public Member Functions inherited from TriggerPrimitiveFinderTool
virtual ~TriggerPrimitiveFinderTool ()=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)
 
void hitFinding (const std::vector< short > &waveform, std::vector< TriggerPrimitiveFinderTool::Hit > &hits, int channel)
 

Protected Attributes

unsigned int m_threshold
 
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
 

Detailed Description

Definition at line 10 of file TriggerPrimitiveFinderPass1.h.

Constructor & Destructor Documentation

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

Definition at line 18 of file TriggerPrimitiveFinderPass1_tool.cc.

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

Member Function Documentation

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

Definition at line 37 of file TriggerPrimitiveFinderPass1_tool.cc.

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 > TriggerPrimitiveFinderPass1::filter ( const std::vector< short > &  orig)
protected

Definition at line 68 of file TriggerPrimitiveFinderPass1_tool.cc.

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

Implements TriggerPrimitiveFinderTool.

Reimplemented in TriggerPrimitiveFinderPass2.

Definition at line 125 of file TriggerPrimitiveFinderPass1_tool.cc.

127 {
128  auto hits=std::vector<TriggerPrimitiveFinderTool::Hit>();
129  std::cout << "findHits called with " << collection_samples.size()
130  << " channels. First chan has " << collection_samples[0].size() << " samples" << std::endl;
131  // std::cout << "First few samples: ";
132  // for(int i=0; i<10; ++i) std::cout << collection_samples[0][i] << " ";
133  // std::cout << std::endl;
134 
135  for(size_t ich=0; ich<collection_samples.size(); ++ich){
136  const std::vector<short>& waveformOrig=collection_samples[ich];
137 
138  std::vector<short> waveform=downSample(waveformOrig);
139 
140  std::vector<short> pedestal=findPedestal(waveform);
141  std::vector<short> pedsub(waveform.size(), 0);
142  for(size_t i=0; i<pedsub.size(); ++i){
143  pedsub[i]=waveform[i]-pedestal[i];
144  }
145 
146  std::vector<short> filtered=filter(pedsub);
147  hitFinding(filtered, hits, channel_numbers[ich]);
148  }
149  std::cout << "Returning " << hits.size() << " hits" << std::endl;
150  std::cout << "hits/channel=" << float(hits.size())/collection_samples.size() << std::endl;
151  std::cout << "hits/tick=" << float(hits.size())/collection_samples[0].size() << std::endl;
152  return hits;
153 }
void hitFinding(const std::vector< short > &waveform, std::vector< TriggerPrimitiveFinderTool::Hit > &hits, int channel)
std::vector< short > downSample(const std::vector< short > &orig)
std::vector< short > findPedestal(const std::vector< short > &orig)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< short > filter(const std::vector< short > &orig)
QTextStream & endl(QTextStream &s)
std::vector< short > TriggerPrimitiveFinderPass1::findPedestal ( const std::vector< short > &  orig)
protected

Definition at line 54 of file TriggerPrimitiveFinderPass1_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 TriggerPrimitiveFinderPass1::hitFinding ( const std::vector< short > &  waveform,
std::vector< TriggerPrimitiveFinderTool::Hit > &  hits,
int  channel 
)
protected

Definition at line 89 of file TriggerPrimitiveFinderPass1_tool.cc.

92 {
93  //---------------------------------------------
94  // Hit finding
95  //---------------------------------------------
96  bool is_hit=false;
97  bool was_hit=false;
99  for(size_t isample=0; isample<waveform.size()-1; ++isample){
100  // if(ich>11510) std::cout << isample << " " << std::flush;
101  int sample_time=isample*m_downsampleFactor;
102  short adc=waveform[isample];
103  is_hit=adc>(short)m_threshold;
104  if(is_hit && !was_hit){
105  // We just started a hit. Set the start time
106  hit.startTime=sample_time;
107  hit.charge=adc;
108  hit.timeOverThreshold=m_downsampleFactor;
109  }
110  if(is_hit && was_hit){
111  hit.charge+=adc*m_downsampleFactor;
112  hit.timeOverThreshold+=m_downsampleFactor;
113  }
114  if(!is_hit && was_hit){
115  // The hit is over. Push it to the output vector
116  hit.charge/=m_multiplier;
117  hits.push_back(hit);
118  }
119  was_hit=is_hit;
120  }
121 }
int16_t adc
Definition: CRTFragment.hh:202
uint8_t channel
Definition: CRTFragment.hh:201
Detector simulation of raw signals on wires.

Member Data Documentation

bool TriggerPrimitiveFinderPass1::m_doFiltering
protected

Definition at line 36 of file TriggerPrimitiveFinderPass1.h.

unsigned int TriggerPrimitiveFinderPass1::m_downsampleFactor
protected

Definition at line 38 of file TriggerPrimitiveFinderPass1.h.

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

Definition at line 39 of file TriggerPrimitiveFinderPass1.h.

short TriggerPrimitiveFinderPass1::m_frugalNContig
protected

Definition at line 34 of file TriggerPrimitiveFinderPass1.h.

int TriggerPrimitiveFinderPass1::m_multiplier
protected

Definition at line 40 of file TriggerPrimitiveFinderPass1.h.

short TriggerPrimitiveFinderPass1::m_signalKillLookahead
protected

Definition at line 30 of file TriggerPrimitiveFinderPass1.h.

short TriggerPrimitiveFinderPass1::m_signalKillNContig
protected

Definition at line 32 of file TriggerPrimitiveFinderPass1.h.

short TriggerPrimitiveFinderPass1::m_signalKillThreshold
protected

Definition at line 31 of file TriggerPrimitiveFinderPass1.h.

unsigned int TriggerPrimitiveFinderPass1::m_threshold
protected

Definition at line 27 of file TriggerPrimitiveFinderPass1.h.

bool TriggerPrimitiveFinderPass1::m_useSignalKill
protected

Definition at line 29 of file TriggerPrimitiveFinderPass1.h.


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