Changeset 3147 in Sophya for trunk/SophyaLib
- Timestamp:
- Jan 18, 2007, 7:20:16 PM (19 years ago)
- Location:
- trunk/SophyaLib/HiStats
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/hist2err.cc
r3136 r3147 19 19 : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.) 20 20 , ymin_(1.), ymax_(-1.), ny_(0), dy_(0.) 21 , m Correl(0)21 , mMean(0) 22 22 { 23 23 } … … 33 33 /*! Constructeur par copie */ 34 34 Histo2DErr::Histo2DErr(const Histo2DErr& H) 35 : m Correl(0)35 : mMean(0) 36 36 { 37 37 if(H.nx_<=0 || H.ny_<=0) return; … … 40 40 err2_ = H.err2_; 41 41 ndata_ = H.ndata_; 42 m Correl = H.mCorrel;42 mMean = H.mMean; 43 43 } 44 44 … … 47 47 Histo2DErr::~Histo2DErr(void) 48 48 { 49 m Correl= 0;49 mMean = 0; 50 50 } 51 51 … … 63 63 dy_ = (ymax_-ymin_)/ny_; 64 64 } 65 m Correl= 0;65 mMean = 0; 66 66 } 67 67 … … 113 113 /********* Methode *********/ 114 114 /*! 115 Compute the correlation histogram.116 Each bin content is divided by the number of entries in th atbin.117 Each squared error is divided by the number of entries in th atbin.118 The number of entries by bin is NOT set to 1 (calling ToCorrel119 120 */ 121 void Histo2DErr::To Correl(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 */ 121 void Histo2DErr::ToMean(void) 122 122 { 123 123 if(nx_<1 || ny_<1) return; 124 m Correl++;124 mMean++; 125 125 for(int_4 i=0;i<nx_;i++) { 126 126 for(int_4 j=0;j<ny_;j++) { … … 135 135 /********* Methode *********/ 136 136 /*! 137 Recompute back the original Histo2DErr before ToCorrelaction138 */ 139 void Histo2DErr::From Correl(void)137 Recompute back the original Histo2DErr after ToMean action 138 */ 139 void Histo2DErr::FromMean(void) 140 140 { 141 141 if(nx_<1 || ny_<1) return; 142 m Correl--;142 mMean--; 143 143 for(int_4 i=0;i<nx_;i++) { 144 144 for(int_4 j=0;j<ny_;j++) { … … 146 146 data_(i,j) *= ndata_(i,j); 147 147 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 */ 163 void 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 */ 182 void 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); 148 191 } 149 192 } … … 172 215 } 173 216 } 174 m Correl = hfrom.mCorrel;217 mMean = hfrom.mMean; 175 218 176 219 } … … 187 230 err2_ = h.err2_; 188 231 ndata_ = h.ndata_; 189 m Correl = h.mCorrel;232 mMean = h.mMean; 190 233 return *this; 191 234 } … … 213 256 void Histo2DErr::Show(ostream & os) const 214 257 { 215 os <<"Histo2DErr(n correl="<<mCorrel<<")"<<endl258 os <<"Histo2DErr(nmean="<<mMean<<")"<<endl 216 259 <<" nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl 217 260 <<" ny="<<ny_<<" ["<<ymin_<<","<<ymax_<<"] dy="<<dy_<<endl; … … 234 277 is.GetStr(strg); 235 278 236 // Nombre d'appels a To Correl/FromCorrel237 is.Get(dobj->m Correl);279 // Nombre d'appels a ToMean/FromMean 280 is.Get(dobj->mMean); 238 281 239 282 // Lecture des parametres Histo2DErr … … 267 310 os.PutStr(strg); 268 311 269 // Nombre d'appels a To Correl/FromCorrel270 os.Put(dobj->m Correl);312 // Nombre d'appels a ToMean/FromMean 313 os.Put(dobj->mMean); 271 314 272 315 // Ecriture des parametres Histo2DErr -
trunk/SophyaLib/HiStats/hist2err.h
r3136 r3147 83 83 {i=(int_4) floor((x-xmin_)/dx_); j=(int_4) floor((y-ymin_)/dy_);} 84 84 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 86 86 inline void Add(r_8 x, r_8 y, r_8 w, r_8 e) 87 87 { … … 90 90 data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e; 91 91 } 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);} 94 93 95 94 //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e … … 99 98 data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e; 100 99 } 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);} 103 101 104 102 //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e … … 110 108 ndata_(i,j) = nb; 111 109 } 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 } 115 116 //! remplissage de l'erreur carree pour le bin i 116 117 void SetErr2(int_4 i,int_4 j, r_8 e2) … … 126 127 } 127 128 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); 133 138 134 139 //! Fill an histogram with an histogram … … 156 161 TMatrix<r_8> err2_; 157 162 TMatrix<r_8> ndata_; 158 int_4 m Correl; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)163 int_4 mMean; //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1) 159 164 }; 160 165 -
trunk/SophyaLib/HiStats/histerr.cc
r3136 r3147 18 18 HistoErr::HistoErr(void) 19 19 : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.) 20 , m Correl(0)20 , mMean(0) 21 21 { 22 22 } … … 25 25 /*! Constructeur d'un histo */ 26 26 HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx) 27 : m Correl(0)27 : mMean(0) 28 28 { 29 29 CreateOrResize(xmin,xmax,nx); … … 33 33 /*! Constructeur par copie */ 34 34 HistoErr::HistoErr(const HistoErr& H) 35 : m Correl(H.mCorrel)35 : mMean(H.mMean) 36 36 { 37 37 if(H.nx_<=0) return; … … 46 46 HistoErr::~HistoErr(void) 47 47 { 48 m Correl= 0;48 mMean = 0; 49 49 } 50 50 … … 60 60 dx_ = (xmax_-xmin_)/nx_; 61 61 } 62 m Correl= 0;62 mMean = 0; 63 63 } 64 64 … … 95 95 /********* Methode *********/ 96 96 /*! 97 Compute the correlation histogram.98 Each bin content is divided by the number of entries in th atbin.99 Each squared error is divided by the number of entries in th atbin.100 The number of entries by bin is NOT set to 1 (calling ToCorrel101 102 */ 103 void HistoErr::To Correl(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 */ 103 void HistoErr::ToMean(void) 104 104 { 105 105 if(nx_<1) return; 106 m Correl++;106 mMean++; 107 107 for(int_4 i=0;i<nx_;i++) { 108 108 if(ndata_(i)<1.) continue; … … 115 115 /********* Methode *********/ 116 116 /*! 117 Recompute back the original HistoErr before ToCorrelaction118 */ 119 void HistoErr::From Correl(void)117 Recompute back the original HistoErr after ToMean action 118 */ 119 void HistoErr::FromMean(void) 120 120 { 121 121 if(nx_<1) return; 122 m Correl--;122 mMean--; 123 123 for(int_4 i=0;i<nx_;i++) { 124 124 if(ndata_(i)<1.) continue; 125 125 data_(i) *= ndata_(i); 126 126 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 */ 141 void 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 */ 158 void 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); 127 166 } 128 167 return; … … 148 187 ndata_(ii) += hfrom.ndata_(ii); 149 188 } 150 m Correl = hfrom.mCorrel;189 mMean = hfrom.mMean; 151 190 152 191 } … … 163 202 err2_ = h.err2_; 164 203 ndata_ = h.ndata_; 165 m Correl = h.mCorrel;204 mMean = h.mMean; 166 205 return *this; 167 206 } … … 187 226 void HistoErr::Show(ostream & os) const 188 227 { 189 os <<"HistoErr(n correl="<<mCorrel<<")"<<endl228 os <<"HistoErr(nmean="<<mMean<<")"<<endl 190 229 <<" nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl; 191 230 } … … 207 246 is.GetStr(strg); 208 247 209 // Nombre d'appels a To Correl/FromCorrel210 is.Get(dobj->m Correl);248 // Nombre d'appels a ToMean/FromMean 249 is.Get(dobj->mMean); 211 250 212 251 // Lecture des parametres HistoErr … … 236 275 os.PutStr(strg); 237 276 238 // Nombre d'appels a To Correl/FromCorrel239 os.Put(dobj->m Correl);277 // Nombre d'appels a ToMean/FromMean 278 os.Put(dobj->mMean); 240 279 241 280 // Ecriture des parametres HistoErr -
trunk/SophyaLib/HiStats/histerr.h
r3136 r3147 81 81 data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e; 82 82 } 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);} 85 84 86 85 //! Addition du contenu de l'histo pour le bin i poids w et l'erreur e … … 90 89 data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e; 91 90 } 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);} 94 92 95 93 //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e … … 101 99 ndata_(i) = nb; 102 100 } 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 } 106 107 //! remplissage de l'erreur carree pour le bin i 107 108 void SetErr2(int_4 i, r_8 e2) … … 117 118 } 118 119 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); 124 129 125 130 //! Fill an histogram with an histogram … … 147 152 TVector<r_8> err2_; 148 153 TVector<r_8> ndata_; 149 int_4 m Correl; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)154 int_4 mMean; //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1) 150 155 }; 151 156
Note:
See TracChangeset
for help on using the changeset viewer.