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