| [658] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | // | 
|---|
|  | 3 | // $Id: histos.h,v 1.1.1.1 1999-11-26 16:37:10 ansari Exp $ | 
|---|
|  | 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 |  | 
|---|
|  | 21 | class Histo : public AnyDataObj { | 
|---|
|  | 22 | friend class ObjFileIO<Histo>; | 
|---|
|  | 23 | public: | 
|---|
|  | 24 |  | 
|---|
|  | 25 | // CREATOR / DESTRUCTOR | 
|---|
|  | 26 | Histo(); | 
|---|
|  | 27 | Histo(float xMin, float xMax, int nBin=100); | 
|---|
|  | 28 | Histo(const Histo& H); | 
|---|
|  | 29 | virtual        ~Histo(); | 
|---|
|  | 30 |  | 
|---|
|  | 31 | // OPTIONS | 
|---|
|  | 32 | void   Errors(); | 
|---|
|  | 33 |  | 
|---|
|  | 34 | // UPDATING or SETTING | 
|---|
|  | 35 | void   Zero(); | 
|---|
|  | 36 | void   Add(float x, float w = 1.); | 
|---|
|  | 37 | void   AddBin(int numBin, float w = 1.); | 
|---|
|  | 38 | void   SetBin(float x, float w = 1.); | 
|---|
|  | 39 | void   SetBin(int numBin, float w = 1.); | 
|---|
|  | 40 | void   SetErr2(float x, double e2); | 
|---|
|  | 41 | void   SetErr2(int numBin, double e2); | 
|---|
|  | 42 | void   SetErr(float x, float e); | 
|---|
|  | 43 | void   SetErr(int numBin, float e); | 
|---|
|  | 44 |  | 
|---|
|  | 45 | // Operators | 
|---|
|  | 46 | Histo& operator = (const Histo& h); | 
|---|
|  | 47 | Histo& operator *= (double b); | 
|---|
|  | 48 | Histo& operator /= (double b); | 
|---|
|  | 49 | Histo& operator += (double b); | 
|---|
|  | 50 | Histo& operator -= (double b); | 
|---|
|  | 51 | friend Histo operator * (const Histo& a, double b); | 
|---|
|  | 52 | friend Histo operator * (double b, const Histo& a); | 
|---|
|  | 53 | friend Histo operator / (const Histo& a, double b); | 
|---|
|  | 54 | friend Histo operator + (const Histo& a, double b); | 
|---|
|  | 55 | friend Histo operator + (double b, const Histo& a); | 
|---|
|  | 56 | friend Histo operator - (const Histo& a, double b); | 
|---|
|  | 57 | friend Histo operator - (double b, const Histo& a); | 
|---|
|  | 58 | Histo& operator += (const Histo& a); | 
|---|
|  | 59 | Histo& operator -= (const Histo& a); | 
|---|
|  | 60 | Histo& operator *= (const Histo& a); | 
|---|
|  | 61 | Histo& operator /= (const Histo& a); | 
|---|
|  | 62 | friend Histo operator + (const Histo& a, const Histo& b); | 
|---|
|  | 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 |  | 
|---|
|  | 67 | // get/put dans/depuis un vector | 
|---|
|  | 68 | void GetAbsc(Vector& v); | 
|---|
|  | 69 | void GetValue(Vector& v); | 
|---|
|  | 70 | void GetError2(Vector& v); | 
|---|
|  | 71 | void GetError(Vector& v); | 
|---|
|  | 72 | void PutValue(Vector& v, int ierr=0); | 
|---|
|  | 73 | void PutValueAdd(Vector &v, int ierr=0); | 
|---|
|  | 74 | void PutError2(Vector& v); | 
|---|
|  | 75 | void PutError2Add(Vector& v); | 
|---|
|  | 76 | void PutError(Vector& v); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | // INLINES | 
|---|
|  | 79 | inline float          XMin() const             {return min;} | 
|---|
|  | 80 | inline float          XMax() const             {return max;} | 
|---|
|  | 81 | inline int_4          NBins() const            {return bins;} | 
|---|
|  | 82 | inline float          BinWidth() const         {return binWidth;} | 
|---|
|  | 83 | inline float*         Bins() const             {return data;} | 
|---|
|  | 84 | inline float          operator()(int i) const  {return data[i];} | 
|---|
|  | 85 | inline float&         operator()(int i)        {return data[i];} | 
|---|
|  | 86 | inline bool           HasErrors() { if(err2) return true; else return false;} | 
|---|
|  | 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.;} | 
|---|
|  | 90 | inline double         Error2(int i) const | 
|---|
|  | 91 | {if(err2) return err2[i]; else return 0.;} | 
|---|
|  | 92 | inline double&        Error2(int i) {return err2[i];} | 
|---|
|  | 93 | inline float          NData() const            {return (float) nHist;} | 
|---|
|  | 94 | inline float          NEntries() const         {return nEntries;} | 
|---|
|  | 95 | inline float          NOver() const            {return over;} | 
|---|
|  | 96 | inline float          NUnder() const           {return under;} | 
|---|
|  | 97 |  | 
|---|
|  | 98 | inline float          BinLowEdge(int i)  const {return min + i*binWidth;} | 
|---|
|  | 99 | inline float          BinCenter(int i)   const {return min + (i+0.5)*binWidth;} | 
|---|
|  | 100 | inline float          BinHighEdge(int i) const {return min + (i+1)*binWidth;} | 
|---|
|  | 101 | inline int_4          FindBin(float x) const | 
|---|
|  | 102 | {return (int_4) floorf((x - min) / binWidth);} | 
|---|
|  | 103 |  | 
|---|
|  | 104 | // Info, statistique et calculs sur les histogrammes | 
|---|
|  | 105 | int            BinNonNul() const; | 
|---|
|  | 106 | int            ErrNonNul() const; | 
|---|
|  | 107 | int            IMax() const; | 
|---|
|  | 108 | int            IMin() const; | 
|---|
|  | 109 | float          VMax() const; | 
|---|
|  | 110 | float          VMin() const; | 
|---|
|  | 111 | float          Mean() const; | 
|---|
|  | 112 | float          Sigma() const; | 
|---|
|  | 113 | float          MeanLH(int il,int ih) const; | 
|---|
|  | 114 | float          SigmaLH(int il,int ih) const; | 
|---|
|  | 115 | float          Mean(float x0, float dx) const; | 
|---|
|  | 116 | float          Sigma(float x0, float dx) const; | 
|---|
|  | 117 | float          CleanedMean() const; | 
|---|
|  | 118 | float          CleanedMean(float& sigma) const; | 
|---|
|  | 119 | int            BinPercent(float per) const; | 
|---|
|  | 120 | int            BinPercent(float x,float per,int& imin,int& imax); | 
|---|
|  | 121 | int            BinPercent(float x,float per,float& xmin,float& xmax); | 
|---|
|  | 122 | void           HInteg(float norm = 0.); | 
|---|
|  | 123 | void           HDeriv(); | 
|---|
|  | 124 | void           HRebin(int nbinew); | 
|---|
|  | 125 |  | 
|---|
|  | 126 | int            MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn); | 
|---|
|  | 127 | float          FitMax(int degree=2, float frac=0.5f, int debug=0) const; | 
|---|
|  | 128 | float          FindWidth(float xmax,float frac=0.5f, int debug=0) const; | 
|---|
|  | 129 | float          FindWidth(float frac=0.5f, int debug=0) const; | 
|---|
|  | 130 | int            EstimeMax(float& xm,int SzPav = 3); | 
|---|
|  | 131 | int            EstimeMax(int& im,float& xm,int SzPav = 3); | 
|---|
|  | 132 | void           EstimeWidthS(float frac,float& widthG,float& widthD); | 
|---|
|  | 133 |  | 
|---|
|  | 134 | // Fit | 
|---|
|  | 135 | int    Fit(GeneralFit& gfit,unsigned short typ_err=0); | 
|---|
|  | 136 | Histo  FitResidus(GeneralFit& gfit); | 
|---|
|  | 137 | Histo  FitFunction(GeneralFit& gfit); | 
|---|
|  | 138 |  | 
|---|
|  | 139 | // Print et Display ASCII | 
|---|
|  | 140 | void           PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1., | 
|---|
|  | 141 | int pflag = 0, int il = 1, int ih = -1); | 
|---|
|  | 142 | void           Print(int dyn = 100, float hmin = 1., float hmax = -1., | 
|---|
|  | 143 | int pflag = 0, int il = 1, int ih = -1); | 
|---|
|  | 144 |  | 
|---|
|  | 145 | protected: | 
|---|
|  | 146 | void Delete(); | 
|---|
|  | 147 |  | 
|---|
|  | 148 | float*         data; | 
|---|
|  | 149 | double*        err2; | 
|---|
|  | 150 | float          under; | 
|---|
|  | 151 | float          over; | 
|---|
|  | 152 | double         nHist; | 
|---|
|  | 153 | int_4          nEntries; | 
|---|
|  | 154 | int_4          bins; | 
|---|
|  | 155 | float          min; | 
|---|
|  | 156 | float          max; | 
|---|
|  | 157 | float          binWidth; | 
|---|
|  | 158 | }; | 
|---|
|  | 159 |  | 
|---|
|  | 160 |  | 
|---|
|  | 161 | inline POutPersist& operator << (POutPersist& os, Histo & obj) | 
|---|
|  | 162 | { ObjFileIO<Histo> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
|  | 163 | inline PInPersist& operator >> (PInPersist& is, Histo & obj) | 
|---|
|  | 164 | { ObjFileIO<Histo> fio(&obj);  fio.Read(is);  return(is); } | 
|---|
|  | 165 |  | 
|---|
|  | 166 | // Classe pour la gestion de persistance | 
|---|
|  | 167 | // ObjFileIO<Histo> | 
|---|
|  | 168 |  | 
|---|
|  | 169 |  | 
|---|
|  | 170 | } // Fin du namespace | 
|---|
|  | 171 |  | 
|---|
|  | 172 | #endif // HISTOS_SEEN | 
|---|