Diana Software
QTriggerThreshold.cc
Go to the documentation of this file.
1 #include "QTriggerThreshold.hh"
2 #include "QReader.hh"
3 #include <vector>
4 
5 ClassImp(Diana::QTriggerThreshold);
6 using std::cout;
7 using std::endl;
8 
10 
12  if(reader==0){
13  cout<<"NO READER PASSED TO TRIGGER"<<endl;
14  exit(-1);
15  }
16 
17  SetCFGParameters(reader->GetDouble(("ThresholdTrigLVL"+triggerLabel).c_str(),600.),reader->GetBool(("SubtractBaseline"+triggerLabel).c_str(),false));
18 }
19 
20 void QTriggerThreshold::TriggerStream(const vector<double>& stream){
21  if (!read_parameters){
23  }
24  //empty triggers
25  triggers.clear();
26  triggerHeights.clear();
27 
28  if(samplingFrequency ==0 or windowsize==0)cout<<"Sampling frequecy "<< samplingFrequency<<"\tWindow Size = "<<windowsize<<endl;
29 
30  size_t first_trig=stream.size()+1;
31  size_t prev_trig=first_trig;
32  double height =0;
33  int sample;
34  double baseline=0;
35  int samps=0;
36  filteredStream=stream;
38  for(size_t i =0;(double) i<0.1*(double) windowsize and i<stream.size();i++){
39  samps++;
40  baseline +=stream[i];
41  }
42  baseline/=samps;
43  }else{
44  samps=1;
45  }
46  for(size_t i=0; i<stream.size();i++){
47  if(stream[i]-baseline/samps>=triggerLevel){//If sample triggers
48  if(first_trig==stream.size()+1){//first trigger point in chunk
49  first_trig = i;
50  prev_trig = i;
51  }else if (i==prev_trig+1){//same peak
52  prev_trig=i;
53  }else if(i>prev_trig+1){//new peak
54  first_trig=i;
55  prev_trig=i;
56  }
57  }
58 
59  if((i==prev_trig+1 and stream[i]<triggerLevel) or(i == stream.size()-1 and i ==prev_trig)){//as soon as the peak ends or if the peak is ongoing and we are at the end of the stream
61  baseline = stream[i];
62  samps=1;
63  }
64  if(triggers.size()==0){//if first trigger
65  for(size_t j =first_trig; j<=prev_trig;j++){
66  if(j==first_trig){
67  height=stream[j];
68  sample=(int)j;
69  }else{
70  if(height<stream[j]){
71  height=stream[j];
72  sample=(int)j;
73  }
74  }
75  }
76  size_t min = first_trig -1;
77  if(min<0){
78  min = i;
79  }
80  if(min >= stream.size()){
81  min = first_trig;
82  }
83  triggers.push_back(sample);
84  triggerHeights.push_back(height-stream[min]);
85  }else{
87  baseline += stream[i];
88  samps++;
89  }
90  if((double)((int)first_trig-triggers[triggers.size()-1]) >= (double)debounce){//don't trigger if trigger is too near the previous one
91  for(size_t j =first_trig; j<=prev_trig;j++){
92  if(j==first_trig){
93  height=stream[j];
94  sample=(int)j;
95  }else{
96  if(height<stream[j]){
97  height=stream[j];
98  sample=(int)j;
99  }
100  }
101  }
102  triggers.push_back(sample);
103  size_t min = first_trig -1;
104  if(min<0){
105  min = i;
106  }
107  if(min >= stream.size()){
108  min = first_trig;
109  }
110  triggerHeights.push_back(height-stream[min]);
111  }
112  }
113  }
114  }
115 }
116 
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
ClassImp(Diana::QTriggerThreshold)
double min(const Diana::QVector &v)
Definition: QVector.cc:878
double GetDouble(const std::string &parname, double defVal, bool warnCfg=true) const
Get a double parameter from config file.
Definition: QBaseModule.cc:184
bool GetBool(const std::string &parname, bool defVal, bool warnCfg=true) const
Get a bool parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:256
void TriggerStream(const vector< double > &stream)
void SetCFGParameters(double trigLevl=5., bool baselinesub=false)
int windowsize
Definition: QTrigger.hh:104
vector< int > triggers
Definition: QTrigger.hh:98
double samplingFrequency
Definition: QTrigger.hh:102
string triggerLabel
Definition: QTrigger.hh:112
vector< double > triggerHeights
Definition: QTrigger.hh:99
vector< double > filteredStream
Definition: QTrigger.hh:100
int debounce
Definition: QTrigger.hh:106
const QBaseModule * reader
Definition: QTrigger.hh:110