| [763] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | // | 
|---|
| [958] | 3 | // $Id: histos.h,v 1.6 2000-04-18 13:38:17 ansari Exp $ | 
|---|
| [763] | 4 | // | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #ifndef HISTOS_SEEN | 
|---|
|  | 7 | #define HISTOS_SEEN | 
|---|
|  | 8 |  | 
|---|
|  | 9 | #include "objfio.h" | 
|---|
|  | 10 | #include <iostream.h> | 
|---|
|  | 11 | #include <stdio.h> | 
|---|
|  | 12 | #include "peida.h" | 
|---|
|  | 13 | #include "tvector.h" | 
|---|
|  | 14 | #include "ppersist.h" | 
|---|
|  | 15 | #include "anydataobj.h" | 
|---|
|  | 16 |  | 
|---|
|  | 17 | namespace SOPHYA { | 
|---|
|  | 18 |  | 
|---|
|  | 19 | class GeneralFit; | 
|---|
|  | 20 |  | 
|---|
| [926] | 21 | //! 1 dimension histograms | 
|---|
| [763] | 22 | class Histo : public AnyDataObj { | 
|---|
|  | 23 | friend class ObjFileIO<Histo>; | 
|---|
|  | 24 | public: | 
|---|
|  | 25 |  | 
|---|
|  | 26 | // CREATOR / DESTRUCTOR | 
|---|
|  | 27 | Histo(); | 
|---|
|  | 28 | Histo(float xMin, float xMax, int nBin=100); | 
|---|
|  | 29 | Histo(const Histo& H); | 
|---|
|  | 30 | virtual        ~Histo(); | 
|---|
|  | 31 |  | 
|---|
|  | 32 | // OPTIONS | 
|---|
|  | 33 | void   Errors(); | 
|---|
|  | 34 |  | 
|---|
|  | 35 | // UPDATING or SETTING | 
|---|
|  | 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 | void   SetErr(int numBin, float e); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | // Operators | 
|---|
|  | 47 | Histo& operator = (const Histo& h); | 
|---|
|  | 48 | Histo& operator *= (double b); | 
|---|
|  | 49 | Histo& operator /= (double b); | 
|---|
|  | 50 | Histo& operator += (double b); | 
|---|
|  | 51 | Histo& operator -= (double b); | 
|---|
|  | 52 | friend Histo operator * (const Histo& a, double b); | 
|---|
|  | 53 | friend Histo operator * (double b, const Histo& a); | 
|---|
|  | 54 | friend Histo operator / (const Histo& a, double b); | 
|---|
|  | 55 | friend Histo operator + (const Histo& a, double b); | 
|---|
|  | 56 | friend Histo operator + (double b, const Histo& a); | 
|---|
|  | 57 | friend Histo operator - (const Histo& a, double b); | 
|---|
|  | 58 | friend Histo operator - (double b, const Histo& a); | 
|---|
|  | 59 | Histo& operator += (const Histo& a); | 
|---|
|  | 60 | Histo& operator -= (const Histo& a); | 
|---|
|  | 61 | Histo& operator *= (const Histo& a); | 
|---|
|  | 62 | Histo& operator /= (const Histo& a); | 
|---|
|  | 63 | friend Histo operator + (const Histo& a, const Histo& b); | 
|---|
|  | 64 | friend Histo operator - (const Histo& a, const Histo& b); | 
|---|
|  | 65 | friend Histo operator * (const Histo& a, const Histo& b); | 
|---|
|  | 66 | friend Histo operator / (const Histo& a, const Histo& b); | 
|---|
|  | 67 |  | 
|---|
|  | 68 | // get/put dans/depuis un vector | 
|---|
| [943] | 69 | void GetAbsc(TVector<r_8>& v); | 
|---|
|  | 70 | void GetValue(TVector<r_8>& v); | 
|---|
|  | 71 | void GetError2(TVector<r_8>& v); | 
|---|
|  | 72 | void GetError(TVector<r_8>& v); | 
|---|
|  | 73 | void PutValue(TVector<r_8>& v, int ierr=0); | 
|---|
|  | 74 | void PutValueAdd(TVector<r_8> &v, int ierr=0); | 
|---|
|  | 75 | void PutError2(TVector<r_8>& v); | 
|---|
|  | 76 | void PutError2Add(TVector<r_8>& v); | 
|---|
|  | 77 | void PutError(TVector<r_8>& v); | 
|---|
| [763] | 78 |  | 
|---|
|  | 79 | // INLINES | 
|---|
| [914] | 80 | //! Retourne l'abscisse minimum | 
|---|
| [763] | 81 | inline float          XMin() const             {return min;} | 
|---|
| [914] | 82 | //! Retourne l'abscisse maximum | 
|---|
| [763] | 83 | inline float          XMax() const             {return max;} | 
|---|
| [914] | 84 | //! Retourne le nombre de bins | 
|---|
| [763] | 85 | inline int_4          NBins() const            {return bins;} | 
|---|
| [914] | 86 | //! Retourne la largeur du bin | 
|---|
| [763] | 87 | inline float          BinWidth() const         {return binWidth;} | 
|---|
| [914] | 88 | //! Retourne le pointeur sur le tableaux des contenus | 
|---|
| [763] | 89 | inline float*         Bins() const             {return data;} | 
|---|
| [914] | 90 | //! Retourne le contenu du bin i | 
|---|
| [763] | 91 | inline float          operator()(int i) const  {return data[i];} | 
|---|
| [914] | 92 | //! Remplit le contenu du bin i | 
|---|
| [763] | 93 | inline float&         operator()(int i)        {return data[i];} | 
|---|
| [914] | 94 | //! retourne "true" si il y a des erreurs stoquees | 
|---|
| [763] | 95 | inline bool           HasErrors() { if(err2) return true; else return false;} | 
|---|
| [914] | 96 | //! Retourne l'erreur du bin i | 
|---|
| [763] | 97 | inline float          Error(int i) const | 
|---|
|  | 98 | {if(err2) {if(err2[i]>0.) return sqrt(err2[i]); else return 0.;} | 
|---|
|  | 99 | else return 0.;} | 
|---|
| [914] | 100 | //! Retourne l'erreur au carre du bin i | 
|---|
| [763] | 101 | inline double         Error2(int i) const | 
|---|
|  | 102 | {if(err2) return err2[i]; else return 0.;} | 
|---|
| [914] | 103 | //! Remplit l'erreur au carre du bin i | 
|---|
| [763] | 104 | inline double&        Error2(int i) {return err2[i];} | 
|---|
| [914] | 105 | //! Retourne la somme ponderee | 
|---|
| [763] | 106 | inline float          NData() const            {return (float) nHist;} | 
|---|
| [914] | 107 | //! Retourne le nombre d'entrees | 
|---|
| [763] | 108 | inline float          NEntries() const         {return nEntries;} | 
|---|
| [914] | 109 | //! Retourne le nombre d'overflow | 
|---|
| [763] | 110 | inline float          NOver() const            {return over;} | 
|---|
| [914] | 111 | //! Retourne le nombre d'underflow | 
|---|
| [763] | 112 | inline float          NUnder() const           {return under;} | 
|---|
|  | 113 |  | 
|---|
| [914] | 114 | //! Retourne l'abscisse du bord inferieur du bin i | 
|---|
| [763] | 115 | inline float          BinLowEdge(int i)  const {return min + i*binWidth;} | 
|---|
| [914] | 116 | //! Retourne l'abscisse du centre du bin i | 
|---|
| [763] | 117 | inline float          BinCenter(int i)   const {return min + (i+0.5)*binWidth;} | 
|---|
| [914] | 118 | //! Retourne l'abscisse du bord superieur du bin i | 
|---|
| [763] | 119 | inline float          BinHighEdge(int i) const {return min + (i+1)*binWidth;} | 
|---|
| [914] | 120 | //! Retourne le numero du bin contenant l'abscisse x | 
|---|
| [763] | 121 | inline int_4          FindBin(float x) const | 
|---|
|  | 122 | {return (int_4) floorf((x - min) / binWidth);} | 
|---|
|  | 123 |  | 
|---|
|  | 124 | // Info, statistique et calculs sur les histogrammes | 
|---|
|  | 125 | int            BinNonNul() const; | 
|---|
|  | 126 | int            ErrNonNul() const; | 
|---|
|  | 127 | int            IMax() const; | 
|---|
|  | 128 | int            IMin() const; | 
|---|
|  | 129 | float          VMax() const; | 
|---|
|  | 130 | float          VMin() const; | 
|---|
|  | 131 | float          Mean() const; | 
|---|
|  | 132 | float          Sigma() const; | 
|---|
|  | 133 | float          MeanLH(int il,int ih) const; | 
|---|
|  | 134 | float          SigmaLH(int il,int ih) const; | 
|---|
|  | 135 | float          Mean(float x0, float dx) const; | 
|---|
|  | 136 | float          Sigma(float x0, float dx) const; | 
|---|
|  | 137 | float          CleanedMean() const; | 
|---|
|  | 138 | float          CleanedMean(float& sigma) const; | 
|---|
|  | 139 | int            BinPercent(float per) const; | 
|---|
|  | 140 | int            BinPercent(float x,float per,int& imin,int& imax); | 
|---|
|  | 141 | int            BinPercent(float x,float per,float& xmin,float& xmax); | 
|---|
|  | 142 | void           HInteg(float norm = 0.); | 
|---|
|  | 143 | void           HDeriv(); | 
|---|
|  | 144 | void           HRebin(int nbinew); | 
|---|
|  | 145 |  | 
|---|
|  | 146 | int            MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn); | 
|---|
|  | 147 | float          FitMax(int degree=2, float frac=0.5f, int debug=0) const; | 
|---|
|  | 148 | float          FindWidth(float xmax,float frac=0.5f, int debug=0) const; | 
|---|
|  | 149 | float          FindWidth(float frac=0.5f, int debug=0) const; | 
|---|
|  | 150 | int            EstimeMax(float& xm,int SzPav = 3); | 
|---|
|  | 151 | int            EstimeMax(int& im,float& xm,int SzPav = 3); | 
|---|
|  | 152 | void           EstimeWidthS(float frac,float& widthG,float& widthD); | 
|---|
|  | 153 |  | 
|---|
|  | 154 | // Fit | 
|---|
|  | 155 | int    Fit(GeneralFit& gfit,unsigned short typ_err=0); | 
|---|
|  | 156 | Histo  FitResidus(GeneralFit& gfit); | 
|---|
|  | 157 | Histo  FitFunction(GeneralFit& gfit); | 
|---|
|  | 158 |  | 
|---|
|  | 159 | // Print et Display ASCII | 
|---|
|  | 160 | void           PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1., | 
|---|
|  | 161 | int pflag = 0, int il = 1, int ih = -1); | 
|---|
|  | 162 | void           Print(int dyn = 100, float hmin = 1., float hmax = -1., | 
|---|
|  | 163 | int pflag = 0, int il = 1, int ih = -1); | 
|---|
|  | 164 |  | 
|---|
|  | 165 | protected: | 
|---|
|  | 166 | void Delete(); | 
|---|
|  | 167 |  | 
|---|
| [914] | 168 | float*         data;     //!< donnees | 
|---|
|  | 169 | double*        err2;     //!< erreurs carrees | 
|---|
|  | 170 | float          under;    //!< underflow | 
|---|
|  | 171 | float          over;     //!< overflow | 
|---|
|  | 172 | double         nHist;    //!< somme ponderee des entrees | 
|---|
|  | 173 | int_4          nEntries; //!< nombre d'entrees | 
|---|
|  | 174 | int_4          bins;     //!< nombre de bins | 
|---|
|  | 175 | float          min;      //!< abscisse minimum | 
|---|
|  | 176 | float          max;      //!< abscisse maximum | 
|---|
|  | 177 | float          binWidth; //!< largeur du bin | 
|---|
| [763] | 178 | }; | 
|---|
|  | 179 |  | 
|---|
|  | 180 |  | 
|---|
| [958] | 181 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo) | 
|---|
|  | 182 | \brief Persistance management */ | 
|---|
| [763] | 183 | inline POutPersist& operator << (POutPersist& os, Histo & obj) | 
|---|
|  | 184 | { ObjFileIO<Histo> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
| [958] | 185 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo) | 
|---|
|  | 186 | \brief Persistance management */ | 
|---|
| [763] | 187 | inline PInPersist& operator >> (PInPersist& is, Histo & obj) | 
|---|
|  | 188 | { ObjFileIO<Histo> fio(&obj);  fio.Read(is);  return(is); } | 
|---|
|  | 189 |  | 
|---|
|  | 190 | // Classe pour la gestion de persistance | 
|---|
|  | 191 | // ObjFileIO<Histo> | 
|---|
|  | 192 |  | 
|---|
|  | 193 |  | 
|---|
|  | 194 | } // Fin du namespace | 
|---|
|  | 195 |  | 
|---|
|  | 196 | #endif // HISTOS_SEEN | 
|---|