Changeset 3147 in Sophya for trunk/SophyaLib/HiStats/histerr.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/histerr.cc

    r3136 r3147  
    1818HistoErr::HistoErr(void)
    1919: xmin_(1.), xmax_(-1.), nx_(0), dx_(0.)
    20 , mCorrel(0)
     20, mMean(0)
    2121{
    2222}
     
    2525/*! Constructeur d'un histo */
    2626HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx)
    27 : mCorrel(0)
     27: mMean(0)
    2828{
    2929  CreateOrResize(xmin,xmax,nx);
     
    3333/*! Constructeur par copie */
    3434HistoErr::HistoErr(const HistoErr& H)
    35 : mCorrel(H.mCorrel)
     35: mMean(H.mMean)
    3636{
    3737 if(H.nx_<=0) return;
     
    4646HistoErr::~HistoErr(void)
    4747{
    48  mCorrel = 0;
     48 mMean = 0;
    4949}
    5050
     
    6060    dx_ = (xmax_-xmin_)/nx_;
    6161  }
    62   mCorrel = 0;
     62  mMean = 0;
    6363}
    6464
     
    9595/********* Methode *********/
    9696/*!
    97   Compute the correlation histogram.
    98   Each bin content is divided by the number of entries in that bin.
    99   Each squared error is divided by the number of entries in that bin.
    100   The number of entries by bin is NOT set to 1 (calling ToCorrel
    101     many time will change the histogram !)
    102 */
    103 void HistoErr::ToCorrel(void)
     97  Compute the mean histogram.
     98  Each bin content is divided by the number of entries in the bin.
     99  Each squared error is divided by the number of entries in the bin.
     100  The number of entries by bin is NOT set to 1
     101  (calling ToMean many time will change the histogram !)
     102*/
     103void HistoErr::ToMean(void)
    104104{
    105105 if(nx_<1) return;
    106  mCorrel++;
     106 mMean++;
    107107 for(int_4 i=0;i<nx_;i++) {
    108108   if(ndata_(i)<1.) continue;
     
    115115/********* Methode *********/
    116116/*!
    117  Recompute back the original HistoErr before ToCorrel action
    118 */
    119 void HistoErr::FromCorrel(void)
     117 Recompute back the original HistoErr after ToMean action
     118*/
     119void HistoErr::FromMean(void)
    120120{
    121121 if(nx_<1) return;
    122  mCorrel--;
     122 mMean--;
    123123 for(int_4 i=0;i<nx_;i++) {
    124124   if(ndata_(i)<1.) continue;
    125125   data_(i) *= ndata_(i);
    126126   err2_(i) *= ndata_(i);
     127 }
     128 return;
     129}
     130
     131/********* Methode *********/
     132/*!
     133  Compute the mean histogram and replace the "error table" by the variance.
     134  This should be done if Add(x,w,w) has been used.
     135  The "value table" is divided by the number of entries to get the mean
     136  The "error table" is replace by the variance
     137  The number of entries by bin is NOT set to 1
     138  (calling ToMean many time will change the histogram !)
     139  Mixing ToMean and ToVariance leads to unpredictable results
     140*/
     141void HistoErr::ToVariance(void)
     142{
     143 if(nx_<1) return;
     144 mMean++;
     145 for(int_4 i=0;i<nx_;i++) {
     146   if(ndata_(i)<1.) continue;
     147   data_(i) /= ndata_(i);
     148   err2_(i) = err2_(i)/ndata_(i) - data_(i)*data_(i);
     149 }
     150 return;
     151}
     152
     153/********* Methode *********/
     154/*!
     155 Recompute back the original HistoErr after ToVariance action
     156  Mixing FromMean and FromVariance leads to unpredictable results
     157*/
     158void HistoErr::FromVariance(void)
     159{
     160 if(nx_<1) return;
     161 mMean--;
     162 for(int_4 i=0;i<nx_;i++) {
     163   if(ndata_(i)<1.) continue;
     164   err2_(i) = ndata_(i)*(err2_(i) + data_(i)*data_(i));
     165   data_(i) *= ndata_(i);
    127166 }
    128167 return;
     
    148187   ndata_(ii) += hfrom.ndata_(ii);
    149188 }
    150  mCorrel = hfrom.mCorrel;
     189 mMean = hfrom.mMean;
    151190
    152191}
     
    163202  err2_  = h.err2_;
    164203  ndata_ = h.ndata_;
    165   mCorrel = h.mCorrel;
     204  mMean = h.mMean;
    166205  return *this;
    167206}
     
    187226void HistoErr::Show(ostream & os) const
    188227{
    189   os <<"HistoErr(ncorrel="<<mCorrel<<")"<<endl
     228  os <<"HistoErr(nmean="<<mMean<<")"<<endl
    190229     <<"          nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl;
    191230}
     
    207246is.GetStr(strg);
    208247
    209 // Nombre d'appels a ToCorrel/FromCorrel
    210 is.Get(dobj->mCorrel);
     248// Nombre d'appels a ToMean/FromMean
     249is.Get(dobj->mMean);
    211250
    212251// Lecture des parametres HistoErr
     
    236275os.PutStr(strg);
    237276
    238 // Nombre d'appels a ToCorrel/FromCorrel
    239 os.Put(dobj->mCorrel);
     277// Nombre d'appels a ToMean/FromMean
     278os.Put(dobj->mMean);
    240279
    241280// Ecriture des parametres HistoErr
Note: See TracChangeset for help on using the changeset viewer.