Index: trunk/SophyaLib/HiStats/hist2err.cc
===================================================================
--- trunk/SophyaLib/HiStats/hist2err.cc	(revision 3136)
+++ trunk/SophyaLib/HiStats/hist2err.cc	(revision 3147)
@@ -19,5 +19,5 @@
 : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.)
 , ymin_(1.), ymax_(-1.), ny_(0), dy_(0.)
-, mCorrel(0)
+, mMean(0)
 {
 }
@@ -33,5 +33,5 @@
 /*! Constructeur par copie */
 Histo2DErr::Histo2DErr(const Histo2DErr& H)
-: mCorrel(0)
+: mMean(0)
 {
  if(H.nx_<=0 || H.ny_<=0) return;
@@ -40,5 +40,5 @@
  err2_  = H.err2_; 
  ndata_ = H.ndata_; 
- mCorrel = H.mCorrel;
+ mMean = H.mMean;
 }
 
@@ -47,5 +47,5 @@
 Histo2DErr::~Histo2DErr(void)
 {
- mCorrel = 0;
+ mMean = 0;
 }
 
@@ -63,5 +63,5 @@
     dy_ = (ymax_-ymin_)/ny_;
   }
-  mCorrel = 0;
+  mMean = 0;
 }
 
@@ -113,14 +113,14 @@
 /********* Methode *********/
 /*!
-  Compute the correlation histogram.
-  Each bin content is divided by the number of entries in that bin.
-  Each squared error is divided by the number of entries in that bin.
-  The number of entries by bin is NOT set to 1 (calling ToCorrel
-    many time will change the histogram !)
-*/
-void Histo2DErr::ToCorrel(void)
+  Compute the mean histogram.
+  Each bin content is divided by the number of entries in the bin.
+  Each squared error is divided by the number of entries in the bin.
+  The number of entries by bin is NOT set to 1
+  (calling ToMean many time will change the histogram !)
+*/
+void Histo2DErr::ToMean(void)
 {
  if(nx_<1 || ny_<1) return;
- mCorrel++;
+ mMean++;
  for(int_4 i=0;i<nx_;i++) {
    for(int_4 j=0;j<ny_;j++) {
@@ -135,10 +135,10 @@
 /********* Methode *********/
 /*!
- Recompute back the original Histo2DErr before ToCorrel action
-*/
-void Histo2DErr::FromCorrel(void)
+ Recompute back the original Histo2DErr after ToMean action
+*/
+void Histo2DErr::FromMean(void)
 {
  if(nx_<1 || ny_<1) return;
- mCorrel--;
+ mMean--;
  for(int_4 i=0;i<nx_;i++) {
    for(int_4 j=0;j<ny_;j++) {
@@ -146,4 +146,47 @@
      data_(i,j) *= ndata_(i,j);
      err2_(i,j) *= ndata_(i,j);
+   }
+ }
+ return;
+}
+
+/********* Methode *********/
+/*!
+  Compute the mean histogram and replace the "error table" by the variance.
+  This should be done if Add(x,w,w) has been used.
+  The "value table" is divided by the number of entries to get the mean
+  The "error table" is replace by the variance
+  The number of entries by bin is NOT set to 1 
+  (calling ToMean many time will change the histogram !)
+  Mixing ToMean and ToVariance leads to unpredictable results
+*/
+void Histo2DErr::ToVariance(void)
+{
+ if(nx_<1 || ny_<1) return;
+ mMean++;
+ for(int_4 i=0;i<nx_;i++) {
+   for(int_4 j=0;j<ny_;j++) {
+     if(ndata_(i,j)<1.) continue;
+     data_(i,j) /= ndata_(i,j);
+     err2_(i,j) = err2_(i,j)/ndata_(i,j) - data_(i,j)*data_(i,j);
+   }
+ }
+ return;
+}
+
+/********* Methode *********/
+/*!
+ Recompute back the original HistoErr after ToVariance action
+  Mixing FromMean and FromVariance leads to unpredictable results
+*/
+void Histo2DErr::FromVariance(void)
+{
+ if(nx_<1 || ny_<1) return;
+ mMean--;
+ for(int_4 i=0;i<nx_;i++) {
+   for(int_4 j=0;j<ny_;j++) {
+     if(ndata_(i,j)<1.) continue;
+     err2_(i,j) = ndata_(i,j)*(err2_(i,j) + data_(i,j)*data_(i,j));
+     data_(i,j) *= ndata_(i,j);
    }
  }
@@ -172,5 +215,5 @@
    }
  }
- mCorrel = hfrom.mCorrel;
+ mMean = hfrom.mMean;
 
 }
@@ -187,5 +230,5 @@
   err2_  = h.err2_;
   ndata_ = h.ndata_;
-  mCorrel = h.mCorrel;
+  mMean = h.mMean;
   return *this;
 }
@@ -213,5 +256,5 @@
 void Histo2DErr::Show(ostream & os) const
 {
-  os <<"Histo2DErr(ncorrel="<<mCorrel<<")"<<endl
+  os <<"Histo2DErr(nmean="<<mMean<<")"<<endl
      <<"          nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl
      <<"          ny="<<ny_<<" ["<<ymin_<<","<<ymax_<<"] dy="<<dy_<<endl;
@@ -234,6 +277,6 @@
 is.GetStr(strg);
 
-// Nombre d'appels a ToCorrel/FromCorrel
-is.Get(dobj->mCorrel);
+// Nombre d'appels a ToMean/FromMean
+is.Get(dobj->mMean);
 
 // Lecture des parametres Histo2DErr
@@ -267,6 +310,6 @@
 os.PutStr(strg);
 
-// Nombre d'appels a ToCorrel/FromCorrel
-os.Put(dobj->mCorrel);
+// Nombre d'appels a ToMean/FromMean
+os.Put(dobj->mMean);
 
 // Ecriture des parametres Histo2DErr
