Index: fact/tools/rootmacros/discriminator.C
===================================================================
--- fact/tools/rootmacros/discriminator.C	(revision 12169)
+++ fact/tools/rootmacros/discriminator.C	(revision 12169)
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <iostream>
+
+
+// this function reads a (hopefully smoothed, and baseline corrected) DRS pipeline and produces 
+// three vectors 
+// 1. start of 'over threshold'
+// 2. end of 'over threshold'
+// 3. max within this 'over threshold' region
+//
+// it needs a threshold and the length of the falling edge 
+
+typedef struct
+{
+	int begin;
+	int maxPos;
+	int end;
+	float maxVal;
+}
+DiscOut;
+
+vector<DiscOut> * discriminator(
+		vector<float>& input, 			// vector of floats, the discriminator acts on
+		float thr = 5., 						// threshold
+		int fallingEdge = 100	)			// number of slices, after the maximum, which should be discarded...
+{
+
+	vector<DiscOut> result;
+	DiscOut disc;
+	disc.begin = 0;
+	disc.end = 0;
+	disc.maxPos = 0;
+	disc.maxVal = 0.;
+	bool start_under_thr = false;
+	bool over_thr_found = false;
+
+
+	bool debug = true; // switch to true in order to generate some output.
+
+	// chech if by chance the first slice is already over thr
+	if ( input[0] > thr )
+		start_under_thr = false;
+	else
+		start_under_thr = true;
+		
+
+	
+	for ( int sl = 1; sl < input.size() ; sl++ ){
+
+		// normal case
+	//	if ( start_under_thr )
+		{
+			if ( input[sl] > thr ) {
+				
+				if ( !over_thr_found ) {
+					over_thr_found = true;
+					disc.begin = sl;
+				}
+
+				if ( input[sl] > disc.maxVal) {
+					disc.maxVal = input[sl];
+					disc.maxPos = sl;
+				}
+			}
+			if ( input[sl] < thr ) {
+				if ( over_thr_found ) {
+					over_thr_found = false;
+					disc.end = sl;
+				
+					result.push_back(disc);
+					disc.begin = 0;
+					disc.end = 0;
+					disc.maxPos = 0;
+					disc.maxVal = 0.;
+
+				}
+			}		
+		} 
+//		else  // if we were already over thr, when starting.
+		{
+
+		}
+
+	} // end of for llop over all slices
+		if (debug){  // output the vector
+			for (int p=0; p<result.size(); p++ ){
+				cout << p << ":\t"; 
+				cout << result[p].begin << "\t";
+				cout << result[p].end << "\t";
+				cout << result[p].maxPos << "\t";
+				cout << result[p].maxVal << endl;
+			}
+		}
+
+return NULL;
+
+} // end of function - discriminator
