Index: fact/tools/rootmacros/discriminator.C
===================================================================
--- fact/tools/rootmacros/discriminator.C	(revision 12194)
+++ fact/tools/rootmacros/discriminator.C	(revision 12195)
@@ -11,12 +11,5 @@
 // it needs a threshold and the length of the falling edge 
 
-typedef struct
-{
-	int begin;
-	int maxPos;
-	int end;
-	float maxVal;
-}
-DiscOut;
+#include "discriminator.h"
 
 vector<DiscOut> * discriminator(
@@ -26,5 +19,5 @@
 {
 
-	vector<DiscOut> result;
+	vector<DiscOut> * result = new vector<DiscOut>;
 	DiscOut disc;
 	disc.begin = 0;
@@ -36,19 +29,9 @@
 
 
-	bool debug = true; // switch to true in order to generate some output.
+	bool debug = false; // 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 = 0; sl < input.size() ; sl++ ){
 
-	
-	for ( int sl = 1; sl < input.size() ; sl++ ){
 
-		// normal case
-	//	if ( start_under_thr )
-		{
 			if ( input[sl] > thr ) {
 				
@@ -68,5 +51,5 @@
 					disc.end = sl;
 				
-					result.push_back(disc);
+					result->push_back(disc);
 					disc.begin = 0;
 					disc.end = 0;
@@ -76,22 +59,58 @@
 				}
 			}		
-		} 
-//		else  // if we were already over thr, when starting.
-		{
+	} // end of for llop over all slices
 
-		}
-
-	} // end of for llop over all slices
 		if (debug){  // output the vector
-			for (int p=0; p<result.size(); p++ ){
+			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;
+				cout << result->at(p).begin << "\t";
+				cout << result->at(p).end << "\t";
+				cout << result->at(p).maxPos << "\t";
+				cout << result->at(p).maxVal << endl;
 			}
 		}
 
-return NULL;
+DiscOut last;
+vector<DiscOut> * realresult = new vector<DiscOut>;
+	
+if (result->size() > 0) {	
+	while (!result->empty()){
+
+		last.begin = result->back().begin;
+		last.end = result->back().end;
+		last.maxPos = result->back().maxPos;
+		last.maxVal = result->back().maxVal;
+		result->pop_back();
+
+		if (result->empty()){
+			if (last.maxPos > 0)
+				realresult->push_back(last);
+			break;
+		}
+		if (last.maxPos - result->back().maxPos > fallingEdge)
+			realresult->push_back(last);
+	}
+}
+/*
+	vector<vector<DiscOut>::iterator> toBeDeleted;
+
+	for (vector<DiscOut>::iterator it=result->begin(); it != result->end()-1; ++it ){
+		if ( (*it).begin==0 ){
+				toBeDeleted.push_back(it);
+		}
+		if ( ((*(it+1)).maxPos - (*it).maxPos) < fallingEdge ){
+			toBeDeleted.push_back(it);
+			}
+	}		
+
+	for (int i=0; i<toBeDeleted.size(); i++) {
+		result->erase(toBeDeleted[i]);
+		if (debug)
+			cout << "erased peak at:" << (*toBeDeleted[i]).maxPos << endl;
+	}
+*/
+
+delete result;
+return realresult;
 
 } // end of function - discriminator
Index: fact/tools/rootmacros/discriminator.h
===================================================================
--- fact/tools/rootmacros/discriminator.h	(revision 12195)
+++ fact/tools/rootmacros/discriminator.h	(revision 12195)
@@ -0,0 +1,16 @@
+
+	#ifndef __DISCRIMINATOR_H
+	#define __DISCRIMINATOR_H
+
+	typedef struct
+	{
+		int begin;
+	  int maxPos;
+	  int end;
+	  float maxVal;
+	}
+	DiscOut;
+	
+
+	#endif
+
