Changeset 12259 for fact/tools/rootmacros/discriminator.C
- Timestamp:
- 10/25/11 13:52:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/discriminator.C
r12195 r12259 4 4 5 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 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 10 13 // 11 14 // it needs a threshold and the length of the falling edge … … 13 16 #include "discriminator.h" 14 17 15 vector<DiscOut> * discriminator( 16 vector<float>& input, // vector of floats, the discriminator acts on 17 float thr = 5., // threshold 18 int fallingEdge = 100 ) // number of slices, after the maximum, which should be discarded... 19 { 18 vector<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-------- 20 25 21 vector<DiscOut> * result = new vector<DiscOut>; 22 DiscOut disc; 23 disc.begin = 0; 24 disc.end = 0; 25 disc.maxPos = 0; 26 disc.maxVal = 0.; 27 bool start_under_thr = false; 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.; 28 40 bool over_thr_found = false; 29 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 } 30 49 31 bool debug = false; // switch to true in order to generate some output. 50 // Find the -Maximum- in this Region 51 if ( input[sl] > currentRegion.maxVal) { 52 currentRegion.maxVal = input[sl]; 53 currentRegion.maxPos = sl; 54 } 32 55 33 for ( int sl = 0; sl < input.size() ; sl++ ){56 } else if ( input[sl] < thr ) { 34 57 35 36 if ( input[sl] > thr ) { 37 38 if ( !over_thr_found ) { 39 over_thr_found = true; 40 disc.begin = sl; 41 } 42 43 if ( input[sl] > disc.maxVal) { 44 disc.maxVal = input[sl]; 45 disc.maxPos = sl; 46 } 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.; 47 68 } 48 if ( input[sl] < thr ) { 49 if ( over_thr_found ) { 50 over_thr_found = false; 51 disc.end = sl; 52 53 result->push_back(disc); 54 disc.begin = 0; 55 disc.end = 0; 56 disc.maxPos = 0; 57 disc.maxVal = 0.; 58 59 } 60 } 61 } // end of for llop over all slices 69 } 70 } // end of for loop over all slices 62 71 63 72 if (debug){ // output the vector 64 for (int p=0; p<result->size(); p++ ){ 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++ ){ 65 78 cout << p << ":\t"; 66 cout << result->at(p).begin << "\t";67 cout << result->at(p).end << "\t";68 cout << result->at(p).maxPos << "\t";69 cout << result->at(p).maxVal << endl;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; 70 83 } 71 84 } 72 85 73 DiscOut last; 74 vector<DiscOut> * realresult = new vector<DiscOut>; 75 76 if (result->size() > 0) { 77 while (!result->empty()){ 86 if (clean){ 87 cleanRegionsOnFallingEdge ( *Cleaned, *uncleaned, fallingEdge, debug); 88 delete uncleaned; 89 return Cleaned; 90 } else 91 return uncleaned; 78 92 79 last.begin = result->back().begin;80 last.end = result->back().end;81 last.maxPos = result->back().maxPos;82 last.maxVal = result->back().maxVal;83 result->pop_back();84 93 85 if (result->empty()){ 86 if (last.maxPos > 0) 87 realresult->push_back(last); 94 95 96 } // end of function - discriminator 97 /////////////////////////////////////////////////////////////////////////////////////// 98 99 100 101 102 ////////// Cleaning Funcs //////////// 103 104 int 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); 88 148 break; 89 149 } 90 if (last.maxPos - result->back().maxPos > fallingEdge)91 realresult->push_back(last);150 if (last.maxPos - localSrc.back().maxPos > fallingEdgeLen) 151 dest.push_back(last); 92 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 166 return 0; 93 167 } 168 169 ////// alternative loop, but it didn't work //////////////// 94 170 /* 95 171 vector<vector<DiscOut>::iterator> toBeDeleted; … … 111 187 */ 112 188 113 delete result;114 return realresult;115 189 116 } // end of function - discriminator 190
Note:
See TracChangeset
for help on using the changeset viewer.