Index: trunk/SophyaLib/HiStats/histerr.cc
===================================================================
--- trunk/SophyaLib/HiStats/histerr.cc	(revision 3136)
+++ trunk/SophyaLib/HiStats/histerr.cc	(revision 3147)
@@ -18,5 +18,5 @@
 HistoErr::HistoErr(void)
 : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.)
-, mCorrel(0)
+, mMean(0)
 {
 }
@@ -25,5 +25,5 @@
 /*! Constructeur d'un histo */
 HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx)
-: mCorrel(0)
+: mMean(0)
 {
   CreateOrResize(xmin,xmax,nx);
@@ -33,5 +33,5 @@
 /*! Constructeur par copie */
 HistoErr::HistoErr(const HistoErr& H)
-: mCorrel(H.mCorrel)
+: mMean(H.mMean)
 {
  if(H.nx_<=0) return;
@@ -46,5 +46,5 @@
 HistoErr::~HistoErr(void)
 {
- mCorrel = 0;
+ mMean = 0;
 }
 
@@ -60,5 +60,5 @@
     dx_ = (xmax_-xmin_)/nx_;
   }
-  mCorrel = 0;
+  mMean = 0;
 }
 
@@ -95,14 +95,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 HistoErr::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 HistoErr::ToMean(void)
 {
  if(nx_<1) return;
- mCorrel++;
+ mMean++;
  for(int_4 i=0;i<nx_;i++) {
    if(ndata_(i)<1.) continue;
@@ -115,14 +115,53 @@
 /********* Methode *********/
 /*!
- Recompute back the original HistoErr before ToCorrel action
-*/
-void HistoErr::FromCorrel(void)
+ Recompute back the original HistoErr after ToMean action
+*/
+void HistoErr::FromMean(void)
 {
  if(nx_<1) return;
- mCorrel--;
+ mMean--;
  for(int_4 i=0;i<nx_;i++) {
    if(ndata_(i)<1.) continue;
    data_(i) *= ndata_(i);
    err2_(i) *= ndata_(i);
+ }
+ 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 HistoErr::ToVariance(void)
+{
+ if(nx_<1) return;
+ mMean++;
+ for(int_4 i=0;i<nx_;i++) {
+   if(ndata_(i)<1.) continue;
+   data_(i) /= ndata_(i);
+   err2_(i) = err2_(i)/ndata_(i) - data_(i)*data_(i);
+ }
+ return;
+}
+
+/********* Methode *********/
+/*!
+ Recompute back the original HistoErr after ToVariance action
+  Mixing FromMean and FromVariance leads to unpredictable results
+*/
+void HistoErr::FromVariance(void)
+{
+ if(nx_<1) return;
+ mMean--;
+ for(int_4 i=0;i<nx_;i++) {
+   if(ndata_(i)<1.) continue;
+   err2_(i) = ndata_(i)*(err2_(i) + data_(i)*data_(i));
+   data_(i) *= ndata_(i);
  }
  return;
@@ -148,5 +187,5 @@
    ndata_(ii) += hfrom.ndata_(ii);
  }
- mCorrel = hfrom.mCorrel;
+ mMean = hfrom.mMean;
 
 }
@@ -163,5 +202,5 @@
   err2_  = h.err2_;
   ndata_ = h.ndata_;
-  mCorrel = h.mCorrel;
+  mMean = h.mMean;
   return *this;
 }
@@ -187,5 +226,5 @@
 void HistoErr::Show(ostream & os) const
 {
-  os <<"HistoErr(ncorrel="<<mCorrel<<")"<<endl
+  os <<"HistoErr(nmean="<<mMean<<")"<<endl
      <<"          nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl;
 }
@@ -207,6 +246,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 HistoErr
@@ -236,6 +275,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 HistoErr
