1 | #include <stdio.h>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 |
|
---|
5 | // this function reads a (hopefully smoothed, and baseline corrected) DRS pipeline and produces
|
---|
6 | // three vectors
|
---|
7 | // 1. start of 'over threshold'
|
---|
8 | // 2. end of 'over threshold'
|
---|
9 | // 3. max within this 'over threshold' region
|
---|
10 | //
|
---|
11 | // it needs a threshold and the length of the falling edge
|
---|
12 |
|
---|
13 | typedef struct
|
---|
14 | {
|
---|
15 | int begin;
|
---|
16 | int maxPos;
|
---|
17 | int end;
|
---|
18 | float maxVal;
|
---|
19 | }
|
---|
20 | DiscOut;
|
---|
21 |
|
---|
22 | vector<DiscOut> * discriminator(
|
---|
23 | vector<float>& input, // vector of floats, the discriminator acts on
|
---|
24 | float thr = 5., // threshold
|
---|
25 | int fallingEdge = 100 ) // number of slices, after the maximum, which should be discarded...
|
---|
26 | {
|
---|
27 |
|
---|
28 | vector<DiscOut> result;
|
---|
29 | DiscOut disc;
|
---|
30 | disc.begin = 0;
|
---|
31 | disc.end = 0;
|
---|
32 | disc.maxPos = 0;
|
---|
33 | disc.maxVal = 0.;
|
---|
34 | bool start_under_thr = false;
|
---|
35 | bool over_thr_found = false;
|
---|
36 |
|
---|
37 |
|
---|
38 | bool debug = true; // switch to true in order to generate some output.
|
---|
39 |
|
---|
40 | // chech if by chance the first slice is already over thr
|
---|
41 | if ( input[0] > thr )
|
---|
42 | start_under_thr = false;
|
---|
43 | else
|
---|
44 | start_under_thr = true;
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | for ( int sl = 1; sl < input.size() ; sl++ ){
|
---|
49 |
|
---|
50 | // normal case
|
---|
51 | // if ( start_under_thr )
|
---|
52 | {
|
---|
53 | if ( input[sl] > thr ) {
|
---|
54 |
|
---|
55 | if ( !over_thr_found ) {
|
---|
56 | over_thr_found = true;
|
---|
57 | disc.begin = sl;
|
---|
58 | }
|
---|
59 |
|
---|
60 | if ( input[sl] > disc.maxVal) {
|
---|
61 | disc.maxVal = input[sl];
|
---|
62 | disc.maxPos = sl;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | if ( input[sl] < thr ) {
|
---|
66 | if ( over_thr_found ) {
|
---|
67 | over_thr_found = false;
|
---|
68 | disc.end = sl;
|
---|
69 |
|
---|
70 | result.push_back(disc);
|
---|
71 | disc.begin = 0;
|
---|
72 | disc.end = 0;
|
---|
73 | disc.maxPos = 0;
|
---|
74 | disc.maxVal = 0.;
|
---|
75 |
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | // else // if we were already over thr, when starting.
|
---|
80 | {
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | } // end of for llop over all slices
|
---|
85 | if (debug){ // output the vector
|
---|
86 | for (int p=0; p<result.size(); p++ ){
|
---|
87 | cout << p << ":\t";
|
---|
88 | cout << result[p].begin << "\t";
|
---|
89 | cout << result[p].end << "\t";
|
---|
90 | cout << result[p].maxPos << "\t";
|
---|
91 | cout << result[p].maxVal << endl;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | return NULL;
|
---|
96 |
|
---|
97 | } // end of function - discriminator
|
---|