| 1 | // | 
|---|
| 2 | // histogrammes 2D     cmv 2/8/96 | 
|---|
| 3 | // | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef HISTOS2_SEEN | 
|---|
| 6 | #define HISTOS2_SEEN | 
|---|
| 7 |  | 
|---|
| 8 | #include "machdefs.h" | 
|---|
| 9 | #include <string> | 
|---|
| 10 |  | 
|---|
| 11 | #include <list> | 
|---|
| 12 | #if defined(__KCC__) | 
|---|
| 13 | #include <list.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include "peida.h" | 
|---|
| 17 | #include "utils.h" | 
|---|
| 18 | #include "histos.h" | 
|---|
| 19 |  | 
|---|
| 20 | namespace SOPHYA { | 
|---|
| 21 |  | 
|---|
| 22 | class GeneralFit; | 
|---|
| 23 |  | 
|---|
| 24 | class Histo2D : public AnyDataObj { | 
|---|
| 25 | friend class ObjFileIO<Histo2D>; | 
|---|
| 26 | public: | 
|---|
| 27 |  | 
|---|
| 28 | // CREATOR / DESTRUCTOR | 
|---|
| 29 | Histo2D(float xMin, float xMax, int nxBin | 
|---|
| 30 | ,float yMin, float yMax, int nyBin); | 
|---|
| 31 | Histo2D(const Histo2D& h); | 
|---|
| 32 | Histo2D(); | 
|---|
| 33 | virtual  ~Histo2D(); | 
|---|
| 34 |  | 
|---|
| 35 | // OPTIONS | 
|---|
| 36 | void   Errors(); | 
|---|
| 37 |  | 
|---|
| 38 | // UPDATING | 
|---|
| 39 | void   Zero(); | 
|---|
| 40 | void   Add(float x, float y, float w = 1.); | 
|---|
| 41 |  | 
|---|
| 42 | // Operators | 
|---|
| 43 | Histo2D& operator = (const Histo2D& h); | 
|---|
| 44 | Histo2D& operator *= (double b); | 
|---|
| 45 | Histo2D& operator /= (double b); | 
|---|
| 46 | Histo2D& operator += (double b); | 
|---|
| 47 | Histo2D& operator -= (double b); | 
|---|
| 48 | friend Histo2D operator * (const Histo2D& a, double b); | 
|---|
| 49 | friend Histo2D operator * (double b, const Histo2D& a); | 
|---|
| 50 | friend Histo2D operator / (const Histo2D& a, double b); | 
|---|
| 51 | friend Histo2D operator + (const Histo2D& a, double b); | 
|---|
| 52 | friend Histo2D operator + (double b, const Histo2D& a); | 
|---|
| 53 | friend Histo2D operator - (const Histo2D& a, double b); | 
|---|
| 54 | friend Histo2D operator - (double b, const Histo2D& a); | 
|---|
| 55 | Histo2D& operator += (const Histo2D& a); | 
|---|
| 56 | Histo2D& operator -= (const Histo2D& a); | 
|---|
| 57 | Histo2D& operator *= (const Histo2D& a); | 
|---|
| 58 | Histo2D& operator /= (const Histo2D& a); | 
|---|
| 59 | friend Histo2D operator + (const Histo2D& a, const Histo2D& b); | 
|---|
| 60 | friend Histo2D operator - (const Histo2D& a, const Histo2D& b); | 
|---|
| 61 | friend Histo2D operator * (const Histo2D& a, const Histo2D& b); | 
|---|
| 62 | friend Histo2D operator / (const Histo2D& a, const Histo2D& b); | 
|---|
| 63 |  | 
|---|
| 64 | // get/put dans/depuis une matrice / vector | 
|---|
| 65 | void GetXCoor(Vector& v); | 
|---|
| 66 | void GetValue(Matrix &v); | 
|---|
| 67 | void GetYCoor(Vector& v); | 
|---|
| 68 | void GetError2(Matrix& v); | 
|---|
| 69 | void GetError(Matrix& v); | 
|---|
| 70 | void PutValue(Matrix& v, int ierr=0); | 
|---|
| 71 | void PutValueAdd(Matrix& v, int ierr=0); | 
|---|
| 72 | void PutError2(Matrix& v); | 
|---|
| 73 | void PutError2Add(Matrix& v); | 
|---|
| 74 | void PutError(Matrix& v); | 
|---|
| 75 |  | 
|---|
| 76 | // INLINES | 
|---|
| 77 | inline float   XMin() const {return xmin;} | 
|---|
| 78 | inline float   XMax() const {return xmax;} | 
|---|
| 79 | inline float   YMin() const {return ymin;} | 
|---|
| 80 | inline float   YMax() const {return ymax;} | 
|---|
| 81 | inline int_4   NBinX() const {return nx;} | 
|---|
| 82 | inline int_4   NBinY() const {return ny;} | 
|---|
| 83 | inline float   WBinX() const {return wbinx;} | 
|---|
| 84 | inline float   WBinY() const {return wbiny;} | 
|---|
| 85 | inline float*  Bins() const  {return data;} | 
|---|
| 86 | inline float   operator()(int i,int j) const {return data[j*nx+i];} | 
|---|
| 87 | inline float&  operator()(int i,int j)       {return data[j*nx+i];} | 
|---|
| 88 | inline bool    HasErrors() { if(err2) return true; else return false;} | 
|---|
| 89 | inline float   Error(int i,int j)  const | 
|---|
| 90 | {if(err2) | 
|---|
| 91 | {if(err2[j*nx+i]>0.) return sqrt(err2[j*nx+i]); else return 0.;} | 
|---|
| 92 | else return 0.;} | 
|---|
| 93 | inline double  Error2(int i,int j) const | 
|---|
| 94 | {if(err2) return err2[j*nx+i]; else return 0.;} | 
|---|
| 95 | inline double& Error2(int i,int j) {return err2[j*nx+i];} | 
|---|
| 96 | inline float   NData() const    {return (float) nHist;} | 
|---|
| 97 | inline int_4   NEntries() const {return nEntries;} | 
|---|
| 98 | inline void BinLowEdge(int i,int j,float& x,float& y) | 
|---|
| 99 | {x = xmin + i*wbinx; y = ymin + j*wbiny;} | 
|---|
| 100 | inline void BinCenter(int i,int j,float& x,float& y) | 
|---|
| 101 | {x = xmin + (i+0.5)*wbinx; y = ymin + (j+0.5)*wbiny;} | 
|---|
| 102 | inline void BinHighEdge(int i,int j,float& x,float& y) | 
|---|
| 103 | {x = xmin + (i+1)*wbinx; y = ymin + (j+1)*wbiny;} | 
|---|
| 104 | inline void FindBin(float x,float y,int& i,int& j) | 
|---|
| 105 | { i = (int) floorf((x - xmin)/wbinx); j = (int) floorf((y - ymin)/wbiny);} | 
|---|
| 106 |  | 
|---|
| 107 | // Info, statistique et calculs sur les histogrammes | 
|---|
| 108 | float   NOver(int i=-1,int j=-1) const; | 
|---|
| 109 | int     BinNonNul() const; | 
|---|
| 110 | int     ErrNonNul() const; | 
|---|
| 111 | void    IJMax(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1); | 
|---|
| 112 | void    IJMin(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1); | 
|---|
| 113 | float   VMax(int il=1,int ih= -1,int jl=1,int jh= -1) const; | 
|---|
| 114 | float   VMin(int il=1,int ih= -1,int jl=1,int jh= -1) const; | 
|---|
| 115 | int     EstimeMax(float& xm,float& ym,int SzPav = 3 | 
|---|
| 116 | ,int il=1,int ih= -1,int jl=1,int jh= -1); | 
|---|
| 117 | int     EstimeMax(int im,int jm,float& xm,float& ym,int SzPav = 3); | 
|---|
| 118 | int     FindMax(int& im,int& jm,int SzPav = 3,float Dz = 0. | 
|---|
| 119 | ,int il=1,int ih= -1,int jl=1,int jh= -1); | 
|---|
| 120 |  | 
|---|
| 121 | // Fit | 
|---|
| 122 | int      Fit(GeneralFit& gfit,unsigned short typ_err=0); | 
|---|
| 123 | Histo2D  FitResidus(GeneralFit& gfit); | 
|---|
| 124 | Histo2D  FitFunction(GeneralFit& gfit); | 
|---|
| 125 |  | 
|---|
| 126 | // Print et Display ASCII | 
|---|
| 127 | void    PrintStatus(); | 
|---|
| 128 | void    Print(float min=1.,float max=-1. | 
|---|
| 129 | ,int il=1,int ih= -1,int jl=1,int jh= -1); | 
|---|
| 130 |  | 
|---|
| 131 | // PROJECTIONS | 
|---|
| 132 | void           SetProjX(); | 
|---|
| 133 | void           SetProjY(); | 
|---|
| 134 | void           SetProj(); | 
|---|
| 135 | void           DelProjX(); | 
|---|
| 136 | void           DelProjY(); | 
|---|
| 137 | void           DelProj(); | 
|---|
| 138 | void           ZeroProjX(); | 
|---|
| 139 | void           ZeroProjY(); | 
|---|
| 140 | void           ZeroProj(); | 
|---|
| 141 | inline Histo*  HProjX() const {return hprojx;} | 
|---|
| 142 | inline Histo*  HProjY() const {return hprojy;} | 
|---|
| 143 | void           ShowProj(); | 
|---|
| 144 |  | 
|---|
| 145 | // BANDES | 
|---|
| 146 | inline int     NBandX() const {return lbandx.size();} | 
|---|
| 147 | inline int     NBandY() const {return lbandy.size();} | 
|---|
| 148 | int            SetBandX(float ybmin,float ybmax); | 
|---|
| 149 | int            SetBandY(float xbmin,float xbmax); | 
|---|
| 150 | void           DelBandX(); | 
|---|
| 151 | void           DelBandY(); | 
|---|
| 152 | void           ZeroBandX(); | 
|---|
| 153 | void           ZeroBandY(); | 
|---|
| 154 | Histo*         HBandX(int n) const; | 
|---|
| 155 | Histo*         HBandY(int n) const; | 
|---|
| 156 | void           GetBandX(int n,float& ybmin,float& ybmax) const; | 
|---|
| 157 | void           GetBandY(int n,float& xbmin,float& xbmax) const; | 
|---|
| 158 | void           ShowBand(int lp = 0); | 
|---|
| 159 |  | 
|---|
| 160 | // SLICES | 
|---|
| 161 | inline int     NSliX() const {return lslix.size();} | 
|---|
| 162 | inline int     NSliY() const {return lsliy.size();} | 
|---|
| 163 | int            SetSliX(int nsli); | 
|---|
| 164 | int            SetSliY(int nsli); | 
|---|
| 165 | void           DelSliX(); | 
|---|
| 166 | void           DelSliY(); | 
|---|
| 167 | void           ZeroSliX(); | 
|---|
| 168 | void           ZeroSliY(); | 
|---|
| 169 | Histo*         HSliX(int n) const; | 
|---|
| 170 | Histo*         HSliY(int n) const; | 
|---|
| 171 | void           ShowSli(int lp = 0); | 
|---|
| 172 |  | 
|---|
| 173 | #ifndef __DECCXX | 
|---|
| 174 | protected: | 
|---|
| 175 | #endif | 
|---|
| 176 | struct bande_slice { | 
|---|
| 177 | int num; | 
|---|
| 178 | float min, max; | 
|---|
| 179 | Histo* H; | 
|---|
| 180 | STRUCTCOMP(bande_slice) | 
|---|
| 181 | }; | 
|---|
| 182 | #ifdef __DECCXX | 
|---|
| 183 | protected: | 
|---|
| 184 | #endif | 
|---|
| 185 |  | 
|---|
| 186 | void Delete(); | 
|---|
| 187 |  | 
|---|
| 188 | float*         data; | 
|---|
| 189 | double*        err2; | 
|---|
| 190 |  | 
|---|
| 191 | float          over[3][3]; | 
|---|
| 192 | double         nHist; | 
|---|
| 193 | int_4          nEntries; | 
|---|
| 194 |  | 
|---|
| 195 | int_4          nx,ny,nxy; | 
|---|
| 196 | float          xmin; | 
|---|
| 197 | float          xmax; | 
|---|
| 198 | float          ymin; | 
|---|
| 199 | float          ymax; | 
|---|
| 200 | float          wbinx; | 
|---|
| 201 | float          wbiny; | 
|---|
| 202 |  | 
|---|
| 203 | bande_slice    b_s; | 
|---|
| 204 |  | 
|---|
| 205 | Histo*         hprojx; | 
|---|
| 206 | Histo*         hprojy; | 
|---|
| 207 |  | 
|---|
| 208 | list<bande_slice>  lbandx; | 
|---|
| 209 | list<bande_slice>  lbandy; | 
|---|
| 210 |  | 
|---|
| 211 | list<bande_slice>  lslix; | 
|---|
| 212 | list<bande_slice>  lsliy; | 
|---|
| 213 |  | 
|---|
| 214 | }; | 
|---|
| 215 |  | 
|---|
| 216 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 217 | // Classe pour la gestion de persistance | 
|---|
| 218 |  | 
|---|
| 219 | inline POutPersist& operator << (POutPersist& os, Histo2D & obj) | 
|---|
| 220 | { ObjFileIO<Histo2D> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
| 221 | inline PInPersist& operator >> (PInPersist& is, Histo2D & obj) | 
|---|
| 222 | { ObjFileIO<Histo2D> fio(&obj);  fio.Read(is);  return(is); } | 
|---|
| 223 |  | 
|---|
| 224 | // Classe pour la gestion de persistance | 
|---|
| 225 | // ObjFileIO<Histo2D> | 
|---|
| 226 |  | 
|---|
| 227 | } // Fin du namespace | 
|---|
| 228 |  | 
|---|
| 229 | #endif // HISTOS2_SEEN | 
|---|