Changeset 1056 in Sophya
- Timestamp:
- Jul 7, 2000, 10:41:11 AM (25 years ago)
- Location:
- trunk/SophyaLib/HiStats
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/hisprof.cc
r1053 r1056 47 47 HProf::HProf(const HProf& H) 48 48 : Histo(H) 49 , SumY(new double[H.bins]), SumY2(new double[H.bins]), SumW(new double[H.bins]) 49 , SumY((H.bins>0) ? new double[H.bins] : NULL) 50 , SumY2((H.bins>0) ? new double[H.bins] : NULL) 51 , SumW((H.bins>0) ? new double[H.bins] : NULL) 50 52 , Ok(H.Ok), YMin(H.YMin), YMax(H.YMax), Opt(H.Opt) 51 53 { 52 memcpy(SumY, H.SumY, bins*sizeof(double)); 53 memcpy(SumY2, H.SumY2, bins*sizeof(double)); 54 memcpy(SumW, H.SumW, bins*sizeof(double)); 54 if(bins>0) { 55 memcpy(SumY, H.SumY, bins*sizeof(double)); 56 memcpy(SumY2, H.SumY2, bins*sizeof(double)); 57 memcpy(SumW, H.SumW, bins*sizeof(double)); 58 } 55 59 END_CONSTRUCTOR 56 60 } … … 125 129 void HProf::UpdateHisto() const 126 130 { 127 128 131 float m,e2; 132 if(bins<=0) return; 129 133 for(int i=0;i<bins;i++) { 130 134 if(SumW[i]<=0.) { … … 185 189 /********* Methode *********/ 186 190 /*! 187 Operateur H = H1191 Operateur HProf H = H1 188 192 */ 189 193 HProf& HProf::operator = (const HProf& h) … … 209 213 /********* Methode *********/ 210 214 /*! 211 Operateur H += H1215 Operateur HProf H += H1 212 216 213 217 Attention dans cette addition il n'y a pas de gestion … … 273 277 char strg[256]; 274 278 275 dobj->UpdateHisto();279 if(!(dobj->IsOk())) dobj->UpdateHisto(); 276 280 277 281 // Ecriture entete pour identifier facilement -
trunk/SophyaLib/HiStats/hisprof.h
r1053 r1056 22 22 23 23 // UPDATING or SETTING 24 void Zero();25 void UpdateHisto() const;26 void SetErrOpt(bool spread = true);27 void 28 void 24 void UpdateHisto() const; 25 void SetErrOpt(bool spread = true); 26 void Zero(); 27 void Add(float x, float y, float w = 1.); 28 void AddBin(int numBin, float y, float w = 1.); 29 29 30 30 // Acces a l information 31 //! Retourne true si l'histogramme est a jours, false sinon. 32 inline bool IsOk() const {return Ok;} 31 33 //! Retourne l'histogramme de profil. 32 34 inline Histo GetHisto() 33 35 {if(!Ok) UpdateHisto(); return (Histo) *this;} 34 36 //! Retourne le contenu de la moyenne dans le vecteur v 35 inline void Get Mean(TVector<r_8>& v)37 inline void GetValue(TVector<r_8>& v) 36 38 {if(!Ok) UpdateHisto(); Histo::GetValue(v);} 37 39 //! Retourne le contenu au carre de la dispersion/erreur dans le vecteur v 38 40 inline void GetError2(TVector<r_8>& v) 39 41 {if(!Ok) UpdateHisto(); Histo::GetError2(v);} 42 //! Retourne le contenu au carre de la dispersion/erreur dans le vecteur v 43 inline void GetError(TVector<r_8>& v) 44 {if(!Ok) UpdateHisto(); Histo::GetError(v);} 40 45 //! Retourne le contenu du bin i 41 46 inline float operator()(int i) const 42 47 {if(!Ok) UpdateHisto(); return data[i];} 43 48 //! Retourne le carre de la dispersion/erreur du bin i 44 inline floatError2(int i) const45 49 inline double Error2(int i) const 50 {if(!Ok) UpdateHisto(); return (float) err2[i];} 46 51 //! Retourne la dispersion/erreur du bin i 47 52 inline float Error(int i) const 48 53 {if(!Ok) UpdateHisto(); 49 return err2[i]>0.? (float) sqrt(err2[i]) : 0.f;}54 return (err2[i]>0.) ? (float) sqrt(err2[i]) : 0.f;} 50 55 51 56 // Operators … … 55 60 // Fit 56 61 //! Fit du profile par ``gfit''. 57 inline int 62 inline int Fit(GeneralFit& gfit) 58 63 {if(!Ok) UpdateHisto(); return Histo::Fit(gfit,0);} 59 64 //! Retourne l'Histogramme des residus par ``gfit''. 60 inline Histo 65 inline Histo FitResidus(GeneralFit& gfit) 61 66 {if(!Ok) UpdateHisto(); return Histo::FitResidus(gfit);} 62 67 //! Retourne l'Histogramme de la fonction fittee par ``gfit''. 63 inline Histo 68 inline Histo FitFunction(GeneralFit& gfit) 64 69 {if(!Ok) UpdateHisto(); return Histo::FitFunction(gfit);} 65 70 66 71 // Print 67 72 //! Print, voir detail dans Histo::Print 68 inline void Print(int dyn=100,float hmin=1.,float hmax=-1.,int pflag=0,int il=1,int ih=-1) 69 {if(!Ok) UpdateHisto(); Histo::Print(dyn,hmin,hmax,pflag,il,ih);} 73 inline void Print(int dyn=100,float hmin=1.,float hmax=-1. 74 ,int pflag=0,int il=1,int ih=-1) 75 {if(!Ok) UpdateHisto(); Histo::Print(dyn,hmin,hmax,pflag,il,ih);} 76 //! PrintF, voir detail dans Histo::PrintF 77 inline void PrintF(FILE * fp,int dyn=100,float hmin=1.,float hmax=-1. 78 ,int pflag=0,int il=1,int ih=-1) 79 {if(!Ok) UpdateHisto(); Histo::PrintF(fp,dyn,hmin,hmax,pflag,il,ih);} 70 80 71 81 protected: … … 75 85 double* SumY2; //!< somme des carres 76 86 double* SumW; //!< somme des poids 77 bool Ok; //!< true i siupdate fait87 bool Ok; //!< true if update fait 78 88 float YMin; //!< limite minimum Y pour somme 79 89 float YMax; //!< limite maximum Y pour somme -
trunk/SophyaLib/HiStats/histos.cc
r1053 r1056 1 1 // 2 // $Id: histos.cc,v 1. 6 2000-06-30 13:21:52ansari Exp $2 // $Id: histos.cc,v 1.7 2000-07-07 08:41:11 ansari Exp $ 3 3 // 4 4 … … 45 45 /*! Constructeur par copie */ 46 46 Histo::Histo(const Histo& H) 47 : data(new float[H.bins]), err2(NULL), 47 : data((H.bins>0)? new float[H.bins] : NULL), 48 err2(NULL), 48 49 under(H.under), over(H.over), nHist(H.nHist), nEntries(H.nEntries), 49 50 bins(H.bins), min(H.min), max(H.max), 50 51 binWidth(H.binWidth) 51 52 { 52 memcpy(data, H.data, bins*sizeof(float)); 53 if( H.err2 != NULL ) { 54 err2 = new double[bins]; 55 memcpy(err2, H.err2, bins*sizeof(double)); 53 if(bins>0) { 54 memcpy(data, H.data, bins*sizeof(float)); 55 if( H.err2 != NULL ) { 56 err2 = new double[bins]; 57 memcpy(err2, H.err2, bins*sizeof(double)); 58 } 56 59 } 57 60 END_CONSTRUCTOR … … 82 85 void Histo::Zero() 83 86 { 87 if(bins<=0) return; 84 88 memset(data, 0, bins*sizeof(float)); 85 89 under = over = 0; … … 95 99 void Histo::Errors() 96 100 { 97 if( bins > 0 ) { 98 if(err2==NULL) err2 = new double[bins]; 99 memset(err2, 0, bins*sizeof(double)); 100 } 101 } 102 103 /********* Methode *********/ 104 /*! 105 Operateur egal 101 if(bins<=0) return; 102 if(err2==NULL) err2 = new double[bins]; 103 memset(err2, 0, bins*sizeof(double)); 104 } 105 106 /********* Methode *********/ 107 /*! 108 Operateur egal Histo = Histo 106 109 */ 107 110 Histo& Histo::operator = (const Histo& h) 108 111 { 109 112 if(this == &h) return *this; 113 if( h.bins <= 0 ) {Delete(); return *this;} 110 114 if( h.bins > bins ) Delete(); 115 if(!h.err2 && err2 ) { delete [] err2; err2=NULL;} 111 116 if(!data) data = new float[h.bins]; 112 if( !h.err2 && err2 ) { delete [] err2; err2=NULL;} 113 if( h.err2 && !err2 ) err2 = new double[h.bins]; 117 if(h.err2 && !err2 ) err2 = new double[h.bins]; 114 118 115 119 under = h.under; … … 817 821 if( nbinew <= 0 ) return; 818 822 819 // memor aisation de l'histogramme original823 // memorisation de l'histogramme original 820 824 Histo H(*this); 821 825 … … 1324 1328 int il, int ih) 1325 1329 { 1326 1327 1330 1328 1331 if( il > ih ) { il = 0; ih = bins-1; } … … 1342 1345 << " min=" << min << " max=" << max 1343 1346 << " binWidth=" << binWidth << endl; 1344 cout << " mean=" << Mean() << " r.m.s=" << Sigma() << endl; 1347 cout << " mean=" << Mean() << " r.m.s=" << Sigma() 1348 << " Errors="<<HasErrors()<< endl; 1345 1349 1346 1350 if(hdyn<0 || pflag<0 ) return; -
trunk/SophyaLib/HiStats/histos.h
r1053 r1056 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: histos.h,v 1. 7 2000-06-30 13:21:53ansari Exp $3 // $Id: histos.h,v 1.8 2000-07-07 08:41:11 ansari Exp $ 4 4 // 5 5 … … 28 28 Histo(float xMin, float xMax, int nBin=100); 29 29 Histo(const Histo& H); 30 virtual 30 virtual ~Histo(); 31 31 32 32 // OPTIONS 33 void 33 void Errors(); 34 34 35 35 // UPDATING or SETTING 36 void 37 void 38 void 39 void 40 void 41 void 42 void 43 void 36 void Zero(); 37 void Add(float x, float w = 1.); 38 void AddBin(int numBin, float w = 1.); 39 void SetBin(float x, float w = 1.); 40 void SetBin(int numBin, float w = 1.); 41 void SetErr2(float x, double e2); 42 void SetErr2(int numBin, double e2); 43 void SetErr(float x, float e); 44 44 void SetErr(int numBin, float e); 45 45 … … 68 68 // INLINES 69 69 //! Retourne l'abscisse minimum 70 inline float XMin() const{return min;}70 inline float XMin() const {return min;} 71 71 //! Retourne l'abscisse maximum 72 inline float XMax() const{return max;}72 inline float XMax() const {return max;} 73 73 //! Retourne le nombre de bins 74 inline int_4 NBins() const{return bins;}74 inline int_4 NBins() const {return bins;} 75 75 //! Retourne la largeur du bin 76 inline float BinWidth() const{return binWidth;}76 inline float BinWidth() const {return binWidth;} 77 77 //! Retourne le pointeur sur le tableaux des contenus 78 inline float* Bins() const{return data;}78 inline float* Bins() const {return data;} 79 79 //! Retourne le contenu du bin i 80 inline float 80 inline float operator()(int i) const {return data[i];} 81 81 //! Remplit le contenu du bin i 82 inline float& operator()(int i){return data[i];}82 inline float& operator()(int i) {return data[i];} 83 83 //! retourne "true" si il y a des erreurs stoquees 84 inline bool HasErrors() { if(err2) return true; else return false;} 84 inline bool HasErrors() 85 {if(err2) return true; else return false;} 85 86 //! Retourne l'erreur du bin i 86 inline float 87 88 87 inline float Error(int i) const 88 {if(err2) {if(err2[i]>0.) return sqrt(err2[i]); else return 0.;} 89 else return 0.;} 89 90 //! Retourne l'erreur au carre du bin i 90 inline double 91 91 inline double Error2(int i) const 92 {if(err2) return err2[i]; else return 0.;} 92 93 //! Remplit l'erreur au carre du bin i 93 inline double& 94 inline double& Error2(int i) {return err2[i];} 94 95 //! Retourne la somme ponderee 95 inline float 96 inline float NData() const {return (float) nHist;} 96 97 //! Retourne le nombre d'entrees 97 inline float 98 inline float NEntries() const {return nEntries;} 98 99 //! Retourne le nombre d'overflow 99 inline float 100 inline float NOver() const {return over;} 100 101 //! Retourne le nombre d'underflow 101 inline float 102 inline float NUnder() const {return under;} 102 103 103 104 //! Retourne l'abscisse du bord inferieur du bin i 104 inline float 105 inline float BinLowEdge(int i) const {return min + i*binWidth;} 105 106 //! Retourne l'abscisse du centre du bin i 106 inline float 107 inline float BinCenter(int i) const {return min + (i+0.5)*binWidth;} 107 108 //! Retourne l'abscisse du bord superieur du bin i 108 inline float 109 inline float BinHighEdge(int i) const {return min + (i+1)*binWidth;} 109 110 //! Retourne le numero du bin contenant l'abscisse x 110 inline int_4 111 111 inline int_4 FindBin(float x) const 112 {return (int_4) floorf((x - min) / binWidth);} 112 113 113 114 // Info, statistique et calculs sur les histogrammes 114 int 115 int 116 int 117 int 118 float 119 float 120 float 121 float 122 float 123 float 124 float 125 float 126 float 127 float 128 int 129 int 130 int 131 void 132 void 133 void 134 135 int 136 float 137 float 138 float 139 int 140 int 141 void 115 int BinNonNul() const; 116 int ErrNonNul() const; 117 int IMax() const; 118 int IMin() const; 119 float VMax() const; 120 float VMin() const; 121 float Mean() const; 122 float Sigma() const; 123 float MeanLH(int il,int ih) const; 124 float SigmaLH(int il,int ih) const; 125 float Mean(float x0, float dx) const; 126 float Sigma(float x0, float dx) const; 127 float CleanedMean() const; 128 float CleanedMean(float& sigma) const; 129 int BinPercent(float per) const; 130 int BinPercent(float x,float per,int& imin,int& imax); 131 int BinPercent(float x,float per,float& xmin,float& xmax); 132 void HInteg(float norm = 0.); 133 void HDeriv(); 134 void HRebin(int nbinew); 135 136 int MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn); 137 float FitMax(int degree=2, float frac=0.5f, int debug=0) const; 138 float FindWidth(float xmax,float frac=0.5f, int debug=0) const; 139 float FindWidth(float frac=0.5f, int debug=0) const; 140 int EstimeMax(float& xm,int SzPav = 3); 141 int EstimeMax(int& im,float& xm,int SzPav = 3); 142 void EstimeWidthS(float frac,float& widthG,float& widthD); 142 143 143 144 // Fit … … 147 148 148 149 // Print et Display ASCII 149 void 150 151 void 152 150 void PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1., 151 int pflag = 0, int il = 1, int ih = -1); 152 void Print(int dyn = 100, float hmin = 1., float hmax = -1., 153 int pflag = 0, int il = 1, int ih = -1); 153 154 154 155 protected: 155 156 void Delete(); 156 157 157 float* 158 double* 159 float 160 float 161 double 162 int_4 163 int_4 164 float 165 float 166 float 158 float* data; //!< donnees 159 double* err2; //!< erreurs carrees 160 float under; //!< underflow 161 float over; //!< overflow 162 double nHist; //!< somme ponderee des entrees 163 int_4 nEntries; //!< nombre d'entrees 164 int_4 bins; //!< nombre de bins 165 float min; //!< abscisse minimum 166 float max; //!< abscisse maximum 167 float binWidth; //!< largeur du bin 167 168 }; 168 169 -
trunk/SophyaLib/HiStats/histos2.cc
r1053 r1056 1002 1002 void Histo2D::PrintStatus() 1003 1003 { 1004 printf("~Histo::Print nHist=%g nEntries=%d\n",nHist,nEntries); 1004 printf("~Histo::Print nHist=%g nEntries=%d",nHist,nEntries); 1005 if(HasErrors()) printf(" Errors=1\n"); else printf(" Errors=0\n"); 1005 1006 printf("over: [ %g %g %g // %g %g %g // %g %g %g ]\n" 1006 1007 ,over[2][0],over[2][1],over[2][2]
Note:
See TracChangeset
for help on using the changeset viewer.