Changeset 3147 in Sophya for trunk/SophyaLib/HiStats/hist2err.cc


Ignore:
Timestamp:
Jan 18, 2007, 7:20:16 PM (19 years ago)
Author:
cmv
Message:

correct bug, intro ToVariance et changement nom ToCorrel->ToMean cmv 18/01/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/HiStats/hist2err.cc

    r3136 r3147  
    1919: xmin_(1.), xmax_(-1.), nx_(0), dx_(0.)
    2020, ymin_(1.), ymax_(-1.), ny_(0), dy_(0.)
    21 , mCorrel(0)
     21, mMean(0)
    2222{
    2323}
     
    3333/*! Constructeur par copie */
    3434Histo2DErr::Histo2DErr(const Histo2DErr& H)
    35 : mCorrel(0)
     35: mMean(0)
    3636{
    3737 if(H.nx_<=0 || H.ny_<=0) return;
     
    4040 err2_  = H.err2_;
    4141 ndata_ = H.ndata_;
    42  mCorrel = H.mCorrel;
     42 mMean = H.mMean;
    4343}
    4444
     
    4747Histo2DErr::~Histo2DErr(void)
    4848{
    49  mCorrel = 0;
     49 mMean = 0;
    5050}
    5151
     
    6363    dy_ = (ymax_-ymin_)/ny_;
    6464  }
    65   mCorrel = 0;
     65  mMean = 0;
    6666}
    6767
     
    113113/********* Methode *********/
    114114/*!
    115   Compute the correlation histogram.
    116   Each bin content is divided by the number of entries in that bin.
    117   Each squared error is divided by the number of entries in that bin.
    118   The number of entries by bin is NOT set to 1 (calling ToCorrel
    119     many time will change the histogram !)
    120 */
    121 void Histo2DErr::ToCorrel(void)
     115  Compute the mean histogram.
     116  Each bin content is divided by the number of entries in the bin.
     117  Each squared error is divided by the number of entries in the bin.
     118  The number of entries by bin is NOT set to 1
     119  (calling ToMean many time will change the histogram !)
     120*/
     121void Histo2DErr::ToMean(void)
    122122{
    123123 if(nx_<1 || ny_<1) return;
    124  mCorrel++;
     124 mMean++;
    125125 for(int_4 i=0;i<nx_;i++) {
    126126   for(int_4 j=0;j<ny_;j++) {
     
    135135/********* Methode *********/
    136136/*!
    137  Recompute back the original Histo2DErr before ToCorrel action
    138 */
    139 void Histo2DErr::FromCorrel(void)
     137 Recompute back the original Histo2DErr after ToMean action
     138*/
     139void Histo2DErr::FromMean(void)
    140140{
    141141 if(nx_<1 || ny_<1) return;
    142  mCorrel--;
     142 mMean--;
    143143 for(int_4 i=0;i<nx_;i++) {
    144144   for(int_4 j=0;j<ny_;j++) {
     
    146146     data_(i,j) *= ndata_(i,j);
    147147     err2_(i,j) *= ndata_(i,j);
     148   }
     149 }
     150 return;
     151}
     152
     153/********* Methode *********/
     154/*!
     155  Compute the mean histogram and replace the "error table" by the variance.
     156  This should be done if Add(x,w,w) has been used.
     157  The "value table" is divided by the number of entries to get the mean
     158  The "error table" is replace by the variance
     159  The number of entries by bin is NOT set to 1
     160  (calling ToMean many time will change the histogram !)
     161  Mixing ToMean and ToVariance leads to unpredictable results
     162*/
     163void Histo2DErr::ToVariance(void)
     164{
     165 if(nx_<1 || ny_<1) return;
     166 mMean++;
     167 for(int_4 i=0;i<nx_;i++) {
     168   for(int_4 j=0;j<ny_;j++) {
     169     if(ndata_(i,j)<1.) continue;
     170     data_(i,j) /= ndata_(i,j);
     171     err2_(i,j) = err2_(i,j)/ndata_(i,j) - data_(i,j)*data_(i,j);
     172   }
     173 }
     174 return;
     175}
     176
     177/********* Methode *********/
     178/*!
     179 Recompute back the original HistoErr after ToVariance action
     180  Mixing FromMean and FromVariance leads to unpredictable results
     181*/
     182void Histo2DErr::FromVariance(void)
     183{
     184 if(nx_<1 || ny_<1) return;
     185 mMean--;
     186 for(int_4 i=0;i<nx_;i++) {
     187   for(int_4 j=0;j<ny_;j++) {
     188     if(ndata_(i,j)<1.) continue;
     189     err2_(i,j) = ndata_(i,j)*(err2_(i,j) + data_(i,j)*data_(i,j));
     190     data_(i,j) *= ndata_(i,j);
    148191   }
    149192 }
     
    172215   }
    173216 }
    174  mCorrel = hfrom.mCorrel;
     217 mMean = hfrom.mMean;
    175218
    176219}
     
    187230  err2_  = h.err2_;
    188231  ndata_ = h.ndata_;
    189   mCorrel = h.mCorrel;
     232  mMean = h.mMean;
    190233  return *this;
    191234}
     
    213256void Histo2DErr::Show(ostream & os) const
    214257{
    215   os <<"Histo2DErr(ncorrel="<<mCorrel<<")"<<endl
     258  os <<"Histo2DErr(nmean="<<mMean<<")"<<endl
    216259     <<"          nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl
    217260     <<"          ny="<<ny_<<" ["<<ymin_<<","<<ymax_<<"] dy="<<dy_<<endl;
     
    234277is.GetStr(strg);
    235278
    236 // Nombre d'appels a ToCorrel/FromCorrel
    237 is.Get(dobj->mCorrel);
     279// Nombre d'appels a ToMean/FromMean
     280is.Get(dobj->mMean);
    238281
    239282// Lecture des parametres Histo2DErr
     
    267310os.PutStr(strg);
    268311
    269 // Nombre d'appels a ToCorrel/FromCorrel
    270 os.Put(dobj->mCorrel);
     312// Nombre d'appels a ToMean/FromMean
     313os.Put(dobj->mMean);
    271314
    272315// Ecriture des parametres Histo2DErr
Note: See TracChangeset for help on using the changeset viewer.