source: fact/tools/rootmacros/discriminator.C@ 13029

Last change on this file since 13029 was 12259, checked in by neise, 13 years ago
discriminator does now return vector<Region>
File size: 5.5 KB
Line 
1#include <stdio.h>
2#include <iostream>
3
4
5// this function reads a (hopefully smoothed, and baseline corrected) DRS pipeline and produces
6// The DRs pipiline is given as a vector<float>.
7//
8// the Output is a vector of Over-Threshold-Regions, which are described by
9// * the index of its start
10// * the index of its Maximum
11// * the index of its end
12// * the height of its Maximum
13//
14// it needs a threshold and the length of the falling edge
15
16#include "discriminator.h"
17
18vector<Region> * discriminator(
19 vector<float>& input, // vector of floats, the discriminator acts on
20 float thr, // threshold
21 bool clean, // choose here, if the discriminator should already discard Regions, which are assumend to sit on the predessesors falling edge
22 int fallingEdge, // number of slices, after the maximum, which should be discarded...
23 bool debug
24){ //----- start of function discrimnator--------
25
26 // this vector will contain the Region, found by the simple
27 // discriminator
28 vector<Region> * uncleaned = new vector<Region>;
29
30 // The former vector will be cleaned, by checking the distance of the
31 // position of the Maxima .... Maxima, sitting on
32 // falling edges of other pulses, should be discarded.
33 vector<Region> * Cleaned = new vector<Region>;
34
35 Region currentRegion;
36 currentRegion.begin = 0;
37 currentRegion.end = 0;
38 currentRegion.maxPos = 0;
39 currentRegion.maxVal = 0.;
40 bool over_thr_found = false;
41
42 for ( unsigned int sl = 0; sl < input.size() ; sl++ ){
43 if ( input[sl] > thr ) {
44 // mark as -start-
45 if ( !over_thr_found ) {
46 over_thr_found = true;
47 currentRegion.begin = sl;
48 }
49
50 // Find the -Maximum- in this Region
51 if ( input[sl] > currentRegion.maxVal) {
52 currentRegion.maxVal = input[sl];
53 currentRegion.maxPos = sl;
54 }
55
56 } else if ( input[sl] < thr ) {
57
58 // mark the -end-
59 if ( over_thr_found ) {
60 over_thr_found = false;
61 currentRegion.end = sl;
62 // store the region in a vector.
63 uncleaned->push_back(currentRegion);
64 currentRegion.begin = 0;
65 currentRegion.end = 0;
66 currentRegion.maxPos = 0;
67 currentRegion.maxVal = 0.;
68 }
69 }
70 } // end of for loop over all slices
71
72 if (debug){ // output the vector
73 cout << "------------Discriminator Debug Output:"
74 <<"----------------" << endl;
75 cout << "\t uncleaned Over Threshold Regions found: "
76 << uncleaned->size() << endl;
77 for (unsigned int p=0 ; p < uncleaned->size() ; p++ ){
78 cout << p << ":\t";
79 cout << uncleaned->at(p).begin << "\t";
80 cout << uncleaned->at(p).end << "\t";
81 cout << uncleaned->at(p).maxPos << "\t";
82 cout << uncleaned->at(p).maxVal << endl;
83 }
84 }
85
86 if (clean){
87 cleanRegionsOnFallingEdge ( *Cleaned, *uncleaned, fallingEdge, debug);
88 delete uncleaned;
89 return Cleaned;
90 } else
91 return uncleaned;
92
93
94
95
96} // end of function - discriminator
97///////////////////////////////////////////////////////////////////////////////////////
98
99
100
101
102////////// Cleaning Funcs ////////////
103
104int cleanRegionsOnFallingEdge (
105 vector<Region> &dest,
106 vector<Region> &src,
107 int fallingEdgeLen,
108 bool debug
109){
110 // This function scans the src-vector for Maxima, sitting on its predesessors falling edge.
111 // the out vector is cleaned from these regions.
112 // note: the cleaned regions are appended to the dest-vector.
113 //
114 //
115 // note further: in case pulses pile up to form a broad Region over threshold
116 // the maximum of this region is caused by pile up, even though is is far away from the next region.
117 // TODO
118 // write another cleaning function - or implement into this function a check,
119 // if the maximum the first of all local maxima in the region.
120 // maybe the search for the maximum should be oursourced and not be done in the first
121 // discrimnator loop in line 51ff...
122
123 if (dest.size() > 0 && debug)
124 cout << "discriminator::cleanRegionsOnFallingEdge: destination vector.size()=" << dest.size() << endl;
125
126 // if nothing to do
127 if (src.size() == 0){
128 if (debug)
129 cout << "discriminator::cleanRegionsOnFallingEdge: src vector empty" << endl;
130 return -1;
131 }
132
133 // local copy of source
134 vector<Region> localSrc(src);
135 // last Region in (local)-src
136 Region last;
137 while (!localSrc.empty()){
138 last = localSrc.back();
139 localSrc.pop_back();
140 // last.begin = result->back().begin;
141 // last.end = result->back().end;
142 // last.maxPos = result->back().maxPos;
143 // last.maxVal = result->back().maxVal;
144
145 // if localSrc is _now_ empty, then there was no predecessor
146 if (localSrc.empty()){
147 dest.push_back(last);
148 break;
149 }
150 if (last.maxPos - localSrc.back().maxPos > fallingEdgeLen)
151 dest.push_back(last);
152 }
153
154 if (debug){ // output the vector
155 cout << "------------Discriminator::CleanRegionsOnFallingEdge - Debug Output:----------------" << endl;
156 cout << "\t Cleaned Regions found: " << dest.size() << endl;
157 for (unsigned int p=0 ; p < dest.size() ; p++ ){
158 cout << p << ":\t";
159 cout << dest.at(p).begin << "\t";
160 cout << dest.at(p).end << "\t";
161 cout << dest.at(p).maxPos << "\t";
162 cout << dest.at(p).maxVal << endl;
163 }
164 }
165
166return 0;
167}
168
169////// alternative loop, but it didn't work ////////////////
170/*
171 vector<vector<DiscOut>::iterator> toBeDeleted;
172
173 for (vector<DiscOut>::iterator it=result->begin(); it != result->end()-1; ++it ){
174 if ( (*it).begin==0 ){
175 toBeDeleted.push_back(it);
176 }
177 if ( ((*(it+1)).maxPos - (*it).maxPos) < fallingEdge ){
178 toBeDeleted.push_back(it);
179 }
180 }
181
182 for (int i=0; i<toBeDeleted.size(); i++) {
183 result->erase(toBeDeleted[i]);
184 if (debug)
185 cout << "erased peak at:" << (*toBeDeleted[i]).maxPos << endl;
186 }
187*/
188
189
190
Note: See TracBrowser for help on using the repository browser.