Index: trunk/SophyaLib/HiStats/hist2err.cc
===================================================================
--- trunk/SophyaLib/HiStats/hist2err.cc	(revision 3140)
+++ 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
Index: trunk/SophyaLib/HiStats/hist2err.h
===================================================================
--- trunk/SophyaLib/HiStats/hist2err.h	(revision 3140)
+++ trunk/SophyaLib/HiStats/hist2err.h	(revision 3147)
@@ -83,5 +83,5 @@
     {i=(int_4) floor((x-xmin_)/dx_); j=(int_4) floor((y-ymin_)/dy_);}
 
-  //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
+  //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e2
   inline void Add(r_8 x, r_8 y, r_8 w, r_8 e)
     {
@@ -90,6 +90,5 @@
     data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
     }
-  inline void Add(r_8 x,r_8 y, r_8 w) {Add(x,y,w,1.);}
-  inline void Add(r_8 x,r_8 y) {Add(x,y,1.,1.);}
+  inline void Add(r_8 x,r_8 y, r_8 w) {Add(x,y,w,w);}
 
   //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
@@ -99,6 +98,5 @@
     data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
     }
-  inline void AddBin(int_4 i,int_4 j, r_8 w) {AddBin(i,j,w,1.);}
-  inline void AddBin(int_4 i,int_4 j) {AddBin(i,j,1.,1.);}
+  inline void AddBin(int_4 i,int_4 j, r_8 w) {AddBin(i,j,w,w);}
 
   //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
@@ -110,7 +108,10 @@
     ndata_(i,j) = nb;
     }
-  inline void SetBin(int_4 i,int_4 j, r_8 w, r_8 e) {SetBin(i,j,w,e,1.);}
-  inline void SetBin(int_4 i,int_4 j, r_8 w) {SetBin(i,j,w,1.,1.);}
-  inline void SetBin(int_4 i,int_4 j) {SetBin(i,j,1.,1.,1.);}
+  //! remplissage de la valeur pour le bin i
+  inline void SetBin(int_4 i,int_4 j, r_8 w)
+    {
+    if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
+    data_(i,j) = w;
+    }
   //! remplissage de l'erreur carree pour le bin i
   void SetErr2(int_4 i,int_4 j, r_8 e2)
@@ -126,9 +127,13 @@
     }
 
-  //! Compute the correlation histogram
-  void ToCorrel(void);
-  void FromCorrel(void);
-  int_4 NCorrel(void) {return mCorrel;}
-  void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
+  //! Compute the Mean histogram
+  void ToMean(void);
+  void FromMean(void);
+  int_4 NMean(void) {return mMean;}
+  void SetMean(int_4 nmean) {mMean = nmean;}
+
+  //! Replace the errors by the variance
+  void ToVariance(void);
+  void FromVariance(void);
 
   //! Fill an histogram with an histogram
@@ -156,5 +161,5 @@
   TMatrix<r_8> err2_;
   TMatrix<r_8> ndata_;
-  int_4 mCorrel;  //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
+  int_4 mMean;  //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1)
 };
 
Index: trunk/SophyaLib/HiStats/histerr.cc
===================================================================
--- trunk/SophyaLib/HiStats/histerr.cc	(revision 3140)
+++ 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
Index: trunk/SophyaLib/HiStats/histerr.h
===================================================================
--- trunk/SophyaLib/HiStats/histerr.h	(revision 3140)
+++ trunk/SophyaLib/HiStats/histerr.h	(revision 3147)
@@ -81,6 +81,5 @@
     data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
     }
-  inline void Add(r_8 x, r_8 w) {Add(x,w,1.);}
-  inline void Add(r_8 x) {Add(x,1.,1.);}
+  inline void Add(r_8 x, r_8 w) {Add(x,w,w);}
 
   //! Addition du contenu de l'histo pour le bin i poids w et l'erreur e
@@ -90,6 +89,5 @@
     data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
     }
-  inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,1.);}
-  inline void AddBin(int_4 i) {AddBin(i,1.,1.);}
+  inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,w);}
 
   //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
@@ -101,7 +99,10 @@
     ndata_(i) = nb;
     }
-  inline void SetBin(int_4 i, r_8 w, r_8 e) {SetBin(i,w,e,1.);}
-  inline void SetBin(int_4 i, r_8 w) {SetBin(i,w,1.,1.);}
-  inline void SetBin(int_4 i) {SetBin(i,1.,1.,1.);}
+  //! remplissage de la valeur pour le bin i
+  inline void SetBin(int_4 i, r_8 w)
+    {
+    if(i<0 || i>=nx_) return;
+    data_(i)  = w;
+    }
   //! remplissage de l'erreur carree pour le bin i
   void SetErr2(int_4 i, r_8 e2)
@@ -117,9 +118,13 @@
     }
 
-  //! Compute the correlation histogram
-  void ToCorrel(void);
-  void FromCorrel(void);
-  int_4 NCorrel(void) {return mCorrel;}
-  void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
+  //! Compute the mean histogram
+  void ToMean(void);
+  void FromMean(void);
+  int_4 NMean(void) {return mMean;}
+  void SetMean(int_4 nmean) {mMean = nmean;}
+
+  //! Replace the errors by the variance
+  void ToVariance(void);
+  void FromVariance(void);
 
   //! Fill an histogram with an histogram
@@ -147,5 +152,5 @@
   TVector<r_8> err2_;
   TVector<r_8> ndata_;
-  int_4 mCorrel;  //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
+  int_4 mMean;  //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1)
 };
 
