Changeset 3147 in Sophya for trunk/SophyaLib


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

Location:
trunk/SophyaLib/HiStats
Files:
4 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
  • trunk/SophyaLib/HiStats/hist2err.h

    r3136 r3147  
    8383    {i=(int_4) floor((x-xmin_)/dx_); j=(int_4) floor((y-ymin_)/dy_);}
    8484
    85   //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
     85  //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e2
    8686  inline void Add(r_8 x, r_8 y, r_8 w, r_8 e)
    8787    {
     
    9090    data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
    9191    }
    92   inline void Add(r_8 x,r_8 y, r_8 w) {Add(x,y,w,1.);}
    93   inline void Add(r_8 x,r_8 y) {Add(x,y,1.,1.);}
     92  inline void Add(r_8 x,r_8 y, r_8 w) {Add(x,y,w,w);}
    9493
    9594  //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
     
    9998    data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
    10099    }
    101   inline void AddBin(int_4 i,int_4 j, r_8 w) {AddBin(i,j,w,1.);}
    102   inline void AddBin(int_4 i,int_4 j) {AddBin(i,j,1.,1.);}
     100  inline void AddBin(int_4 i,int_4 j, r_8 w) {AddBin(i,j,w,w);}
    103101
    104102  //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
     
    110108    ndata_(i,j) = nb;
    111109    }
    112   inline void SetBin(int_4 i,int_4 j, r_8 w, r_8 e) {SetBin(i,j,w,e,1.);}
    113   inline void SetBin(int_4 i,int_4 j, r_8 w) {SetBin(i,j,w,1.,1.);}
    114   inline void SetBin(int_4 i,int_4 j) {SetBin(i,j,1.,1.,1.);}
     110  //! remplissage de la valeur pour le bin i
     111  inline void SetBin(int_4 i,int_4 j, r_8 w)
     112    {
     113    if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
     114    data_(i,j) = w;
     115    }
    115116  //! remplissage de l'erreur carree pour le bin i
    116117  void SetErr2(int_4 i,int_4 j, r_8 e2)
     
    126127    }
    127128
    128   //! Compute the correlation histogram
    129   void ToCorrel(void);
    130   void FromCorrel(void);
    131   int_4 NCorrel(void) {return mCorrel;}
    132   void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
     129  //! Compute the Mean histogram
     130  void ToMean(void);
     131  void FromMean(void);
     132  int_4 NMean(void) {return mMean;}
     133  void SetMean(int_4 nmean) {mMean = nmean;}
     134
     135  //! Replace the errors by the variance
     136  void ToVariance(void);
     137  void FromVariance(void);
    133138
    134139  //! Fill an histogram with an histogram
     
    156161  TMatrix<r_8> err2_;
    157162  TMatrix<r_8> ndata_;
    158   int_4 mCorrel;  //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
     163  int_4 mMean;  //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1)
    159164};
    160165
  • 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
  • trunk/SophyaLib/HiStats/histerr.h

    r3136 r3147  
    8181    data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
    8282    }
    83   inline void Add(r_8 x, r_8 w) {Add(x,w,1.);}
    84   inline void Add(r_8 x) {Add(x,1.,1.);}
     83  inline void Add(r_8 x, r_8 w) {Add(x,w,w);}
    8584
    8685  //! Addition du contenu de l'histo pour le bin i poids w et l'erreur e
     
    9089    data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
    9190    }
    92   inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,1.);}
    93   inline void AddBin(int_4 i) {AddBin(i,1.,1.);}
     91  inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,w);}
    9492
    9593  //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
     
    10199    ndata_(i) = nb;
    102100    }
    103   inline void SetBin(int_4 i, r_8 w, r_8 e) {SetBin(i,w,e,1.);}
    104   inline void SetBin(int_4 i, r_8 w) {SetBin(i,w,1.,1.);}
    105   inline void SetBin(int_4 i) {SetBin(i,1.,1.,1.);}
     101  //! remplissage de la valeur pour le bin i
     102  inline void SetBin(int_4 i, r_8 w)
     103    {
     104    if(i<0 || i>=nx_) return;
     105    data_(i)  = w;
     106    }
    106107  //! remplissage de l'erreur carree pour le bin i
    107108  void SetErr2(int_4 i, r_8 e2)
     
    117118    }
    118119
    119   //! Compute the correlation histogram
    120   void ToCorrel(void);
    121   void FromCorrel(void);
    122   int_4 NCorrel(void) {return mCorrel;}
    123   void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
     120  //! Compute the mean histogram
     121  void ToMean(void);
     122  void FromMean(void);
     123  int_4 NMean(void) {return mMean;}
     124  void SetMean(int_4 nmean) {mMean = nmean;}
     125
     126  //! Replace the errors by the variance
     127  void ToVariance(void);
     128  void FromVariance(void);
    124129
    125130  //! Fill an histogram with an histogram
     
    147152  TVector<r_8> err2_;
    148153  TVector<r_8> ndata_;
    149   int_4 mCorrel;  //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
     154  int_4 mMean;  //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1)
    150155};
    151156
Note: See TracChangeset for help on using the changeset viewer.