[763] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | //
|
---|
[1053] | 3 | // $Id: histos.h,v 1.7 2000-06-30 13:21:53 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 | Histo& operator += (const Histo& a);
|
---|
| 53 | Histo& operator -= (const Histo& a);
|
---|
| 54 | Histo& operator *= (const Histo& a);
|
---|
| 55 | Histo& operator /= (const Histo& a);
|
---|
| 56 |
|
---|
| 57 | // get/put dans/depuis un vector
|
---|
[943] | 58 | void GetAbsc(TVector<r_8>& v);
|
---|
| 59 | void GetValue(TVector<r_8>& v);
|
---|
| 60 | void GetError2(TVector<r_8>& v);
|
---|
| 61 | void GetError(TVector<r_8>& v);
|
---|
| 62 | void PutValue(TVector<r_8>& v, int ierr=0);
|
---|
| 63 | void PutValueAdd(TVector<r_8> &v, int ierr=0);
|
---|
| 64 | void PutError2(TVector<r_8>& v);
|
---|
| 65 | void PutError2Add(TVector<r_8>& v);
|
---|
| 66 | void PutError(TVector<r_8>& v);
|
---|
[763] | 67 |
|
---|
| 68 | // INLINES
|
---|
[914] | 69 | //! Retourne l'abscisse minimum
|
---|
[763] | 70 | inline float XMin() const {return min;}
|
---|
[914] | 71 | //! Retourne l'abscisse maximum
|
---|
[763] | 72 | inline float XMax() const {return max;}
|
---|
[914] | 73 | //! Retourne le nombre de bins
|
---|
[763] | 74 | inline int_4 NBins() const {return bins;}
|
---|
[914] | 75 | //! Retourne la largeur du bin
|
---|
[763] | 76 | inline float BinWidth() const {return binWidth;}
|
---|
[914] | 77 | //! Retourne le pointeur sur le tableaux des contenus
|
---|
[763] | 78 | inline float* Bins() const {return data;}
|
---|
[914] | 79 | //! Retourne le contenu du bin i
|
---|
[763] | 80 | inline float operator()(int i) const {return data[i];}
|
---|
[914] | 81 | //! Remplit le contenu du bin i
|
---|
[763] | 82 | inline float& operator()(int i) {return data[i];}
|
---|
[914] | 83 | //! retourne "true" si il y a des erreurs stoquees
|
---|
[763] | 84 | inline bool HasErrors() { if(err2) return true; else return false;}
|
---|
[914] | 85 | //! Retourne l'erreur du bin i
|
---|
[763] | 86 | inline float Error(int i) const
|
---|
| 87 | {if(err2) {if(err2[i]>0.) return sqrt(err2[i]); else return 0.;}
|
---|
| 88 | else return 0.;}
|
---|
[914] | 89 | //! Retourne l'erreur au carre du bin i
|
---|
[763] | 90 | inline double Error2(int i) const
|
---|
| 91 | {if(err2) return err2[i]; else return 0.;}
|
---|
[914] | 92 | //! Remplit l'erreur au carre du bin i
|
---|
[763] | 93 | inline double& Error2(int i) {return err2[i];}
|
---|
[914] | 94 | //! Retourne la somme ponderee
|
---|
[763] | 95 | inline float NData() const {return (float) nHist;}
|
---|
[914] | 96 | //! Retourne le nombre d'entrees
|
---|
[763] | 97 | inline float NEntries() const {return nEntries;}
|
---|
[914] | 98 | //! Retourne le nombre d'overflow
|
---|
[763] | 99 | inline float NOver() const {return over;}
|
---|
[914] | 100 | //! Retourne le nombre d'underflow
|
---|
[763] | 101 | inline float NUnder() const {return under;}
|
---|
| 102 |
|
---|
[914] | 103 | //! Retourne l'abscisse du bord inferieur du bin i
|
---|
[763] | 104 | inline float BinLowEdge(int i) const {return min + i*binWidth;}
|
---|
[914] | 105 | //! Retourne l'abscisse du centre du bin i
|
---|
[763] | 106 | inline float BinCenter(int i) const {return min + (i+0.5)*binWidth;}
|
---|
[914] | 107 | //! Retourne l'abscisse du bord superieur du bin i
|
---|
[763] | 108 | inline float BinHighEdge(int i) const {return min + (i+1)*binWidth;}
|
---|
[914] | 109 | //! Retourne le numero du bin contenant l'abscisse x
|
---|
[763] | 110 | inline int_4 FindBin(float x) const
|
---|
| 111 | {return (int_4) floorf((x - min) / binWidth);}
|
---|
| 112 |
|
---|
| 113 | // Info, statistique et calculs sur les histogrammes
|
---|
| 114 | int BinNonNul() const;
|
---|
| 115 | int ErrNonNul() const;
|
---|
| 116 | int IMax() const;
|
---|
| 117 | int IMin() const;
|
---|
| 118 | float VMax() const;
|
---|
| 119 | float VMin() const;
|
---|
| 120 | float Mean() const;
|
---|
| 121 | float Sigma() const;
|
---|
| 122 | float MeanLH(int il,int ih) const;
|
---|
| 123 | float SigmaLH(int il,int ih) const;
|
---|
| 124 | float Mean(float x0, float dx) const;
|
---|
| 125 | float Sigma(float x0, float dx) const;
|
---|
| 126 | float CleanedMean() const;
|
---|
| 127 | float CleanedMean(float& sigma) const;
|
---|
| 128 | int BinPercent(float per) const;
|
---|
| 129 | int BinPercent(float x,float per,int& imin,int& imax);
|
---|
| 130 | int BinPercent(float x,float per,float& xmin,float& xmax);
|
---|
| 131 | void HInteg(float norm = 0.);
|
---|
| 132 | void HDeriv();
|
---|
| 133 | void HRebin(int nbinew);
|
---|
| 134 |
|
---|
| 135 | int MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn);
|
---|
| 136 | float FitMax(int degree=2, float frac=0.5f, int debug=0) const;
|
---|
| 137 | float FindWidth(float xmax,float frac=0.5f, int debug=0) const;
|
---|
| 138 | float FindWidth(float frac=0.5f, int debug=0) const;
|
---|
| 139 | int EstimeMax(float& xm,int SzPav = 3);
|
---|
| 140 | int EstimeMax(int& im,float& xm,int SzPav = 3);
|
---|
| 141 | void EstimeWidthS(float frac,float& widthG,float& widthD);
|
---|
| 142 |
|
---|
| 143 | // Fit
|
---|
| 144 | int Fit(GeneralFit& gfit,unsigned short typ_err=0);
|
---|
| 145 | Histo FitResidus(GeneralFit& gfit);
|
---|
| 146 | Histo FitFunction(GeneralFit& gfit);
|
---|
| 147 |
|
---|
| 148 | // Print et Display ASCII
|
---|
| 149 | void PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1.,
|
---|
| 150 | int pflag = 0, int il = 1, int ih = -1);
|
---|
| 151 | void Print(int dyn = 100, float hmin = 1., float hmax = -1.,
|
---|
| 152 | int pflag = 0, int il = 1, int ih = -1);
|
---|
| 153 |
|
---|
| 154 | protected:
|
---|
| 155 | void Delete();
|
---|
| 156 |
|
---|
[914] | 157 | float* data; //!< donnees
|
---|
| 158 | double* err2; //!< erreurs carrees
|
---|
| 159 | float under; //!< underflow
|
---|
| 160 | float over; //!< overflow
|
---|
| 161 | double nHist; //!< somme ponderee des entrees
|
---|
| 162 | int_4 nEntries; //!< nombre d'entrees
|
---|
| 163 | int_4 bins; //!< nombre de bins
|
---|
| 164 | float min; //!< abscisse minimum
|
---|
| 165 | float max; //!< abscisse maximum
|
---|
| 166 | float binWidth; //!< largeur du bin
|
---|
[763] | 167 | };
|
---|
| 168 |
|
---|
| 169 |
|
---|
[958] | 170 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
| 171 | \brief Persistance management */
|
---|
[763] | 172 | inline POutPersist& operator << (POutPersist& os, Histo & obj)
|
---|
| 173 | { ObjFileIO<Histo> fio(&obj); fio.Write(os); return(os); }
|
---|
[958] | 174 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
| 175 | \brief Persistance management */
|
---|
[763] | 176 | inline PInPersist& operator >> (PInPersist& is, Histo & obj)
|
---|
| 177 | { ObjFileIO<Histo> fio(&obj); fio.Read(is); return(is); }
|
---|
| 178 |
|
---|
| 179 | // Classe pour la gestion de persistance
|
---|
| 180 | // ObjFileIO<Histo>
|
---|
| 181 |
|
---|
[1053] | 182 | /*! \ingroup HiStats \fn operator*(const Histo&,double)
|
---|
| 183 | \brief Operateur H2 = H1 * b */
|
---|
| 184 | inline Histo operator * (const Histo& a, double b)
|
---|
| 185 | {
|
---|
| 186 | Histo result(a);
|
---|
| 187 | return (result *= b);
|
---|
| 188 | }
|
---|
[763] | 189 |
|
---|
[1053] | 190 | /*! \ingroup HiStats \fn operator*(double,const Histo&)
|
---|
| 191 | \brief Operateur H2 = b * H1 */
|
---|
| 192 | inline Histo operator * (double b, const Histo& a)
|
---|
| 193 | {
|
---|
| 194 | Histo result(a);
|
---|
| 195 | return (result *= b);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | /*! \ingroup HiStats \fn operator/(const Histo&,double)
|
---|
| 199 | \brief Operateur H2 = H1 / b */
|
---|
| 200 | inline Histo operator / (const Histo& a, double b)
|
---|
| 201 | {
|
---|
| 202 | Histo result(a);
|
---|
| 203 | return (result /= b);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | /*! \ingroup HiStats \fn operator+(const Histo&,double)
|
---|
| 207 | \brief Operateur H2 = H1 + b */
|
---|
| 208 | inline Histo operator + (const Histo& a, double b)
|
---|
| 209 | {
|
---|
| 210 | Histo result(a);
|
---|
| 211 | return (result += b);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /*! \ingroup HiStats \fn operator+(double,const Histo&)
|
---|
| 215 | \brief Operateur H2 = b + H1 */
|
---|
| 216 | inline Histo operator + (double b, const Histo& a)
|
---|
| 217 | {
|
---|
| 218 | Histo result(a);
|
---|
| 219 | return (result += b);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | /*! \ingroup HiStats \fn operator-(const Histo&,double)
|
---|
| 223 | \brief Operateur H2 = H1 - b */
|
---|
| 224 | inline Histo operator - (const Histo& a, double b)
|
---|
| 225 | {
|
---|
| 226 | Histo result(a);
|
---|
| 227 | return (result -= b);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | /*! \ingroup HiStats \fn operator-(double,const Histo&)
|
---|
| 231 | \brief Operateur H2 = b - H1 */
|
---|
| 232 | inline Histo operator - (double b, const Histo& a)
|
---|
| 233 | {
|
---|
| 234 | Histo result(a);
|
---|
| 235 | result *= -1.;
|
---|
| 236 | return (result += b);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | /*! \ingroup HiStats \fn operator+(const Histo&,const Histo&)
|
---|
| 240 | \brief Operateur H = H1 + H2 */
|
---|
| 241 | inline Histo operator + (const Histo& a, const Histo& b)
|
---|
| 242 | {
|
---|
| 243 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
| 244 | Histo c(a);
|
---|
| 245 | return (c += b);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | /*! \ingroup HiStats \fn operator-(const Histo&,const Histo&)
|
---|
| 249 | \brief Operateur H = H1 - H2 */
|
---|
| 250 | inline Histo operator - (const Histo& a, const Histo& b)
|
---|
| 251 | {
|
---|
| 252 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
| 253 | Histo c(a);
|
---|
| 254 | return (c -= b);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /*! \ingroup HiStats \fn operator*(const Histo&,const Histo&)
|
---|
| 258 | \brief Operateur H = H1 * H2 */
|
---|
| 259 | inline Histo operator * (const Histo& a, const Histo& b)
|
---|
| 260 | {
|
---|
| 261 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
| 262 | Histo c(a);
|
---|
| 263 | return (c *= b);
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | /*! \ingroup HiStats \fn operator/(const Histo&,const Histo&)
|
---|
| 267 | \brief Operateur H = H1 / H2 */
|
---|
| 268 | inline Histo operator / (const Histo& a, const Histo& b)
|
---|
| 269 | {
|
---|
| 270 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
| 271 | Histo c(a);
|
---|
| 272 | return (c /= b);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[763] | 275 | } // Fin du namespace
|
---|
| 276 |
|
---|
| 277 | #endif // HISTOS_SEEN
|
---|