Index: /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc
===================================================================
--- /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 8548)
+++ /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 8549)
@@ -124,5 +124,5 @@
 // The defaule for y is 0
 //
-Double_t MExtralgoSpline::FindY(Int_t i, Double_t y, Double_t min, Double_t max) const
+Double_t MExtralgoSpline::FindY(Int_t i, Bool_t downwards, Double_t y, Double_t min, Double_t max) const
 {
     // y = a*x^3 + b*x^2 + c*x + d'
@@ -144,13 +144,32 @@
     const Int_t rc = MMath::SolvePol3(a, b, c, d, x1, x2, x3);
 
-    Double_t x = -1;
-    if (rc>0 && x1>=min && x1<max && x1>x)
-        x = x1;
-    if (rc>1 && x2>=min && x2<max && x2>x)
-        x = x2;
-    if (rc>2 && x3>=min && x3<max && x3>x)
-        x = x3;
-
-    return x<0 ? -2 : x+i;
+    if (downwards==kTRUE)
+    {
+        Double_t x = -1;
+
+        if (rc>0 && x1>=min && x1<max && x1>x)
+            x = x1;
+        if (rc>1 && x2>=min && x2<max && x2>x)
+            x = x2;
+        if (rc>2 && x3>=min && x3<max && x3>x)
+            x = x3;
+
+        return x<0 ? -2 : x+i;
+    }
+    else
+    {
+        Double_t x = 2;
+
+        if (rc>0 && x1>min && x1<=max && x1<x)
+            x = x1;
+        if (rc>1 && x2>min && x2<=max && x2<x)
+            x = x2;
+        if (rc>2 && x3>min && x3<=max && x3<x)
+            x = x3;
+
+        return x>1 ? -2 : x+i;
+    }
+
+    return -2;
 }
 
@@ -166,7 +185,7 @@
 
     Int_t i = TMath::FloorNint(x);
-    Double_t rc = FindY(i, y, 0, x-i);
+    Double_t rc = FindY(i, kTRUE, y, 0, x-i);
     while (--i>=0 && rc<0)
-        rc = FindY(i, y);
+        rc = FindY(i, kTRUE, y);
 
     return rc;
@@ -179,7 +198,7 @@
 
     Int_t i = TMath::FloorNint(x);
-    Double_t rc = FindY(i, y, x-i, 1.);
+    Double_t rc = FindY(i, kFALSE, y, x-i, 1.);
     while (i++<fNum-1 && rc<0)
-        rc = FindY(i, y);
+        rc = FindY(i, kFALSE, y);
 
     return rc;
Index: /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
===================================================================
--- /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 8548)
+++ /trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 8549)
@@ -74,5 +74,5 @@
     }
 
-    Double_t FindY(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const;
+    Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const;
     Double_t SearchY(Float_t maxpos, Float_t y) const;
     Double_t SearchYup(Float_t maxpos, Float_t y) const;
