Index: /trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc
===================================================================
--- /trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc	(revision 6535)
+++ /trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc	(revision 6536)
@@ -31,15 +31,4 @@
 #include "MRFEnergyEst.h"
 
-#include <TFile.h>
-#include <TList.h>
-
-#include <TH1F.h>
-#include <TH2F.h>
-#include <TStyle.h>
-#include <TCanvas.h>
-#include <TVector.h>
-
-#include "MHMatrix.h"
-
 #include "MLog.h"
 #include "MLogManip.h"
@@ -53,5 +42,11 @@
 #include "MRanForestGrow.h"
 #include "MData.h"
-#include "MEnergyEst.h"
+#include "TFile.h"
+#include "TList.h"
+
+#include "TH1F.h"
+#include "TH2F.h"
+#include "TStyle.h"
+#include "TCanvas.h"
 
 ClassImp(MRFEnergyEst);
@@ -274,6 +269,8 @@
     {
         Double_t e_true = (*mptr)(i,ncols-1);
-        Double_t e_est = -1;
-        Double_t hmax  = -1;
+        Double_t e_est = 0;
+        Double_t hmax  = 0;
+        Double_t hsum  = 0;
+
         for(Int_t j=0;j<nbins;j++)
         {
@@ -281,10 +278,14 @@
             Double_t h = ((MRanForest*) (fEForests[j]))->CalcHadroness(v);
             Double_t e = atof((fEForests[j])->GetTitle());
-            if(h>=hmax)
+            /*if(h>=hmax)
             {
                 hmax=h;
                 e_est=pow(10.,e);
-            }
+            }*/
+            hsum+=h;
+            e_est+=h*e;
         }
+        e_est/=hsum;
+        e_est=pow(10.,e_est);
 
         if(e_true>80.) hres.Fill((e_est-e_true)/e_true);
@@ -406,6 +407,7 @@
     *fData >> event;
 
-    Double_t e_est = -1;
-    Double_t hmax  = -1;
+    Double_t e_est = 0;
+    Double_t hmax  = 0;
+    Double_t hsum  = 0;
         
     for(Int_t j=0;j<fEForests.GetSize();j++)
@@ -413,10 +415,14 @@
         Double_t h = ((MRanForest*) (fEForests[j]))->CalcHadroness(event);
         Double_t e = atof((fEForests[j])->GetTitle());
-        if(h>=hmax)
+        /*if(h>=hmax)
         {
             hmax=h;
             e_est=pow(10.,e);
-        }
-    }
+        }*/
+        hsum+=h;
+        e_est+=h*e;
+    }
+    e_est/=hsum;
+    e_est=pow(10.,e_est);
 
     fEnergyEst->SetEnergy(e_est);
