[763] | 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 |
|
---|
[926] | 24 | //! 2 dimensions histograms
|
---|
[763] | 25 | class Histo2D : public AnyDataObj {
|
---|
| 26 | friend class ObjFileIO<Histo2D>;
|
---|
| 27 | public:
|
---|
| 28 |
|
---|
| 29 | // CREATOR / DESTRUCTOR
|
---|
| 30 | Histo2D(float xMin, float xMax, int nxBin
|
---|
| 31 | ,float yMin, float yMax, int nyBin);
|
---|
| 32 | Histo2D(const Histo2D& h);
|
---|
| 33 | Histo2D();
|
---|
| 34 | virtual ~Histo2D();
|
---|
| 35 |
|
---|
| 36 | // OPTIONS
|
---|
| 37 | void Errors();
|
---|
| 38 |
|
---|
| 39 | // UPDATING
|
---|
| 40 | void Zero();
|
---|
| 41 | void Add(float x, float y, float w = 1.);
|
---|
| 42 |
|
---|
| 43 | // Operators
|
---|
| 44 | Histo2D& operator = (const Histo2D& h);
|
---|
| 45 | Histo2D& operator *= (double b);
|
---|
| 46 | Histo2D& operator /= (double b);
|
---|
| 47 | Histo2D& operator += (double b);
|
---|
| 48 | Histo2D& operator -= (double b);
|
---|
| 49 | Histo2D& operator += (const Histo2D& a);
|
---|
| 50 | Histo2D& operator -= (const Histo2D& a);
|
---|
| 51 | Histo2D& operator *= (const Histo2D& a);
|
---|
| 52 | Histo2D& operator /= (const Histo2D& a);
|
---|
| 53 |
|
---|
| 54 | // get/put dans/depuis une matrice / vector
|
---|
[943] | 55 | void GetXCoor(TVector<r_8>& v);
|
---|
| 56 | void GetValue(TMatrix<r_8> &v);
|
---|
| 57 | void GetYCoor(TVector<r_8>& v);
|
---|
| 58 | void GetError2(TMatrix<r_8>& v);
|
---|
| 59 | void GetError(TMatrix<r_8>& v);
|
---|
| 60 | void PutValue(TMatrix<r_8>& v, int ierr=0);
|
---|
| 61 | void PutValueAdd(TMatrix<r_8>& v, int ierr=0);
|
---|
| 62 | void PutError2(TMatrix<r_8>& v);
|
---|
| 63 | void PutError2Add(TMatrix<r_8>& v);
|
---|
| 64 | void PutError(TMatrix<r_8>& v);
|
---|
[763] | 65 |
|
---|
| 66 | // INLINES
|
---|
[914] | 67 | //! Retourne l'abscisse minimum.
|
---|
[763] | 68 | inline float XMin() const {return xmin;}
|
---|
[914] | 69 | //! Retourne l'abscisse maximum.
|
---|
[763] | 70 | inline float XMax() const {return xmax;}
|
---|
[914] | 71 | //! Retourne l'ordonnee minimum.
|
---|
[763] | 72 | inline float YMin() const {return ymin;}
|
---|
[914] | 73 | //! Retourne l'ordonnee maximum.
|
---|
[763] | 74 | inline float YMax() const {return ymax;}
|
---|
[914] | 75 | //! Retourne le nombre de bins selon X.
|
---|
[763] | 76 | inline int_4 NBinX() const {return nx;}
|
---|
[914] | 77 | //! Retourne le nombre de bins selon Y.
|
---|
[763] | 78 | inline int_4 NBinY() const {return ny;}
|
---|
[914] | 79 | //! Retourne la largeur du bin selon X.
|
---|
[763] | 80 | inline float WBinX() const {return wbinx;}
|
---|
[914] | 81 | //! Retourne la largeur du bin selon Y.
|
---|
[763] | 82 | inline float WBinY() const {return wbiny;}
|
---|
[914] | 83 | //! Retourne le pointeur sur le tableaux des contenus.
|
---|
[763] | 84 | inline float* Bins() const {return data;}
|
---|
[914] | 85 | //! Retourne le contenu du bin i,j.
|
---|
[763] | 86 | inline float operator()(int i,int j) const {return data[j*nx+i];}
|
---|
[914] | 87 | //! Remplit le contenu du bin i,j.
|
---|
[763] | 88 | inline float& operator()(int i,int j) {return data[j*nx+i];}
|
---|
[914] | 89 | //! retourne "true" si il y a des erreurs stoquees
|
---|
[763] | 90 | inline bool HasErrors() { if(err2) return true; else return false;}
|
---|
[914] | 91 | //! Retourne l'erreur du bin i,j.
|
---|
[763] | 92 | inline float Error(int i,int j) const
|
---|
| 93 | {if(err2)
|
---|
| 94 | {if(err2[j*nx+i]>0.) return sqrt(err2[j*nx+i]); else return 0.;}
|
---|
| 95 | else return 0.;}
|
---|
[914] | 96 | //! Remplit l'erreur au carre du bin i,j.
|
---|
[763] | 97 | inline double Error2(int i,int j) const
|
---|
| 98 | {if(err2) return err2[j*nx+i]; else return 0.;}
|
---|
[914] | 99 | //! Remplit l'erreur au carre du bin i,j.
|
---|
[763] | 100 | inline double& Error2(int i,int j) {return err2[j*nx+i];}
|
---|
[914] | 101 | //! Retourne la somme ponderee.
|
---|
[763] | 102 | inline float NData() const {return (float) nHist;}
|
---|
[914] | 103 | //! Retourne le nombre d'entrees.
|
---|
[763] | 104 | inline int_4 NEntries() const {return nEntries;}
|
---|
[914] | 105 | //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
|
---|
[763] | 106 | inline void BinLowEdge(int i,int j,float& x,float& y)
|
---|
| 107 | {x = xmin + i*wbinx; y = ymin + j*wbiny;}
|
---|
[914] | 108 | //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
|
---|
[763] | 109 | inline void BinCenter(int i,int j,float& x,float& y)
|
---|
| 110 | {x = xmin + (i+0.5)*wbinx; y = ymin + (j+0.5)*wbiny;}
|
---|
[914] | 111 | //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
|
---|
[763] | 112 | inline void BinHighEdge(int i,int j,float& x,float& y)
|
---|
| 113 | {x = xmin + (i+1)*wbinx; y = ymin + (j+1)*wbiny;}
|
---|
[914] | 114 | //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
|
---|
[763] | 115 | inline void FindBin(float x,float y,int& i,int& j)
|
---|
| 116 | { i = (int) floorf((x - xmin)/wbinx); j = (int) floorf((y - ymin)/wbiny);}
|
---|
| 117 |
|
---|
| 118 | // Info, statistique et calculs sur les histogrammes
|
---|
| 119 | float NOver(int i=-1,int j=-1) const;
|
---|
| 120 | int BinNonNul() const;
|
---|
| 121 | int ErrNonNul() const;
|
---|
| 122 | void IJMax(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1);
|
---|
| 123 | void IJMin(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1);
|
---|
| 124 | float VMax(int il=1,int ih= -1,int jl=1,int jh= -1) const;
|
---|
| 125 | float VMin(int il=1,int ih= -1,int jl=1,int jh= -1) const;
|
---|
| 126 | int EstimeMax(float& xm,float& ym,int SzPav = 3
|
---|
| 127 | ,int il=1,int ih= -1,int jl=1,int jh= -1);
|
---|
| 128 | int EstimeMax(int im,int jm,float& xm,float& ym,int SzPav = 3);
|
---|
| 129 | int FindMax(int& im,int& jm,int SzPav = 3,float Dz = 0.
|
---|
| 130 | ,int il=1,int ih= -1,int jl=1,int jh= -1);
|
---|
| 131 |
|
---|
| 132 | // Fit
|
---|
| 133 | int Fit(GeneralFit& gfit,unsigned short typ_err=0);
|
---|
| 134 | Histo2D FitResidus(GeneralFit& gfit);
|
---|
| 135 | Histo2D FitFunction(GeneralFit& gfit);
|
---|
| 136 |
|
---|
| 137 | // Print et Display ASCII
|
---|
| 138 | void PrintStatus();
|
---|
| 139 | void Print(float min=1.,float max=-1.
|
---|
| 140 | ,int il=1,int ih= -1,int jl=1,int jh= -1);
|
---|
| 141 |
|
---|
| 142 | // PROJECTIONS
|
---|
| 143 | void SetProjX();
|
---|
| 144 | void SetProjY();
|
---|
| 145 | void SetProj();
|
---|
| 146 | void DelProjX();
|
---|
| 147 | void DelProjY();
|
---|
| 148 | void DelProj();
|
---|
| 149 | void ZeroProjX();
|
---|
| 150 | void ZeroProjY();
|
---|
| 151 | void ZeroProj();
|
---|
[914] | 152 | //! Retourne le pointeur sur l'histo 1D de la projection selon X.
|
---|
[763] | 153 | inline Histo* HProjX() const {return hprojx;}
|
---|
[914] | 154 | //! Retourne le pointeur sur l'histo 1D de la projection selon Y.
|
---|
[763] | 155 | inline Histo* HProjY() const {return hprojy;}
|
---|
| 156 | void ShowProj();
|
---|
| 157 |
|
---|
| 158 | // BANDES
|
---|
[914] | 159 | //! Retourne le nombre de bandes selon X
|
---|
[763] | 160 | inline int NBandX() const {return lbandx.size();}
|
---|
[914] | 161 | //! Retourne le nombre de bandes selon Y
|
---|
[763] | 162 | inline int NBandY() const {return lbandy.size();}
|
---|
| 163 | int SetBandX(float ybmin,float ybmax);
|
---|
| 164 | int SetBandY(float xbmin,float xbmax);
|
---|
| 165 | void DelBandX();
|
---|
| 166 | void DelBandY();
|
---|
| 167 | void ZeroBandX();
|
---|
| 168 | void ZeroBandY();
|
---|
| 169 | Histo* HBandX(int n) const;
|
---|
| 170 | Histo* HBandY(int n) const;
|
---|
| 171 | void GetBandX(int n,float& ybmin,float& ybmax) const;
|
---|
| 172 | void GetBandY(int n,float& xbmin,float& xbmax) const;
|
---|
| 173 | void ShowBand(int lp = 0);
|
---|
| 174 |
|
---|
| 175 | // SLICES
|
---|
[914] | 176 | //! Retourne le nombre de slices selon X
|
---|
[763] | 177 | inline int NSliX() const {return lslix.size();}
|
---|
[914] | 178 | //! Retourne le nombre de slices selon Y
|
---|
[763] | 179 | inline int NSliY() const {return lsliy.size();}
|
---|
| 180 | int SetSliX(int nsli);
|
---|
| 181 | int SetSliY(int nsli);
|
---|
| 182 | void DelSliX();
|
---|
| 183 | void DelSliY();
|
---|
| 184 | void ZeroSliX();
|
---|
| 185 | void ZeroSliY();
|
---|
| 186 | Histo* HSliX(int n) const;
|
---|
| 187 | Histo* HSliY(int n) const;
|
---|
| 188 | void ShowSli(int lp = 0);
|
---|
| 189 |
|
---|
| 190 | #ifndef __DECCXX
|
---|
| 191 | protected:
|
---|
| 192 | #endif
|
---|
[914] | 193 | //! structure de definition des bandes
|
---|
[763] | 194 | struct bande_slice {
|
---|
[914] | 195 | int num; //!< nombre de bandes
|
---|
| 196 | float min; //!< limite minimum pour remplir la bande
|
---|
| 197 | float max; //!< limite maximum pour remplir la bande
|
---|
| 198 | Histo* H; //!< pointer sur l Histo 1D de la bande
|
---|
[763] | 199 | STRUCTCOMP(bande_slice)
|
---|
| 200 | };
|
---|
| 201 | #ifdef __DECCXX
|
---|
| 202 | protected:
|
---|
| 203 | #endif
|
---|
| 204 |
|
---|
| 205 | void Delete();
|
---|
| 206 |
|
---|
[914] | 207 | float* data; //!< donnees
|
---|
| 208 | double* err2; //!< erreurs carrees
|
---|
[763] | 209 |
|
---|
[914] | 210 | float over[3][3]; //!< overflow table
|
---|
| 211 | double nHist; //!< somme ponderee des entrees
|
---|
| 212 | int_4 nEntries; //!< nombre d'entrees
|
---|
[763] | 213 |
|
---|
[914] | 214 | int_4 nx; //!< nombre de bins en X
|
---|
| 215 | int_4 ny; //!< nombre de bins en Y
|
---|
| 216 | int_4 nxy; //!< nombre de bins total
|
---|
| 217 | float xmin; //!< abscisse minimum
|
---|
| 218 | float xmax; //!< abscisse maximum
|
---|
| 219 | float ymin; //!< ordonnee minimum
|
---|
| 220 | float ymax; //!< ordonnee maximum
|
---|
| 221 | float wbinx; //!< largeur du bin en X
|
---|
| 222 | float wbiny; //!< largeur du bin en Y
|
---|
[763] | 223 |
|
---|
| 224 | bande_slice b_s;
|
---|
| 225 |
|
---|
[914] | 226 | Histo* hprojx; //!< pointer sur Histo des proj X
|
---|
| 227 | Histo* hprojy; //!< pointer sur Histo des proj Y
|
---|
[763] | 228 |
|
---|
[914] | 229 | list<bande_slice> lbandx; //!< liste des bandes selon X
|
---|
| 230 | list<bande_slice> lbandy; //!< liste des bandes selon Y
|
---|
[763] | 231 |
|
---|
[914] | 232 | list<bande_slice> lslix; //!< liste des slices selon X
|
---|
| 233 | list<bande_slice> lsliy; //!< liste des slices selon Y
|
---|
[763] | 234 |
|
---|
| 235 | };
|
---|
| 236 |
|
---|
| 237 | /////////////////////////////////////////////////////////////////////////
|
---|
| 238 | // Classe pour la gestion de persistance
|
---|
| 239 |
|
---|
[958] | 240 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
|
---|
| 241 | \brief Persistance management */
|
---|
[763] | 242 | inline POutPersist& operator << (POutPersist& os, Histo2D & obj)
|
---|
| 243 | { ObjFileIO<Histo2D> fio(&obj); fio.Write(os); return(os); }
|
---|
[958] | 244 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
|
---|
| 245 | \brief Persistance management */
|
---|
[763] | 246 | inline PInPersist& operator >> (PInPersist& is, Histo2D & obj)
|
---|
| 247 | { ObjFileIO<Histo2D> fio(&obj); fio.Read(is); return(is); }
|
---|
| 248 |
|
---|
| 249 | // Classe pour la gestion de persistance
|
---|
| 250 | // ObjFileIO<Histo2D>
|
---|
| 251 |
|
---|
[1053] | 252 | /*! \ingroup HiStats \fn operator*(const Histo2D&,double)
|
---|
| 253 | \brief Operateur H2 = H1 * b */
|
---|
| 254 | inline Histo2D operator * (const Histo2D& a, double b)
|
---|
| 255 | {
|
---|
| 256 | Histo2D result(a);
|
---|
| 257 | return (result *= b);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /*! \ingroup HiStats \fn operator*(double,const Histo2D&)
|
---|
| 261 | \brief Operateur H2 = b * H1 */
|
---|
| 262 | inline Histo2D operator * (double b, const Histo2D& a)
|
---|
| 263 | {
|
---|
| 264 | Histo2D result(a);
|
---|
| 265 | return (result *= b);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | /*! \ingroup HiStats \fn operator/(const Histo2D&,double)
|
---|
| 269 | \brief Operateur H2 = H1 / b */
|
---|
| 270 | inline Histo2D operator / (const Histo2D& a, double b)
|
---|
| 271 | {
|
---|
| 272 | Histo2D result(a);
|
---|
| 273 | return (result /= b);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | /*! \ingroup HiStats \fn operator+(const Histo2D&,double)
|
---|
| 277 | \brief Operateur H2 = H1 + b */
|
---|
| 278 | inline Histo2D operator + (const Histo2D& a, double b)
|
---|
| 279 | {
|
---|
| 280 | Histo2D result(a);
|
---|
| 281 | return (result += b);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | /*! \ingroup HiStats \fn operator+(double,const Histo2D&)
|
---|
| 285 | \brief Operateur H2 = b + H1 */
|
---|
| 286 | inline Histo2D operator + (double b, const Histo2D& a)
|
---|
| 287 | {
|
---|
| 288 | Histo2D result(a);
|
---|
| 289 | return (result += b);
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | /*! \ingroup HiStats \fn operator-(const Histo2D&,double)
|
---|
| 293 | \brief Operateur H2 = H1 - b */
|
---|
| 294 | inline Histo2D operator - (const Histo2D& a, double b)
|
---|
| 295 | {
|
---|
| 296 | Histo2D result(a);
|
---|
| 297 | return (result -= b);
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | /*! \ingroup HiStats \fn operator-(double,const Histo2D&)
|
---|
| 301 | \brief Operateur H2 = b - H1 */
|
---|
| 302 | inline Histo2D operator - (double b, const Histo2D& a)
|
---|
| 303 | {
|
---|
| 304 | Histo2D result(a);
|
---|
| 305 | result *= -1.;
|
---|
| 306 | return (result += b);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | /*! \ingroup HiStats \fn operator+(const Histo2D&,const Histo2D&)
|
---|
| 310 | \brief Operateur H = H1 + H2 */
|
---|
| 311 |
|
---|
| 312 | inline Histo2D operator + (const Histo2D& a, const Histo2D& b)
|
---|
| 313 | {
|
---|
| 314 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
| 315 | Histo2D c(a);
|
---|
| 316 | return (c += b);
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | /*! \ingroup HiStats \fn operator-(const Histo2D&,const Histo2D&)
|
---|
| 320 | \brief Operateur H = H1 - H2 */
|
---|
| 321 | inline Histo2D operator - (const Histo2D& a, const Histo2D& b)
|
---|
| 322 | {
|
---|
| 323 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
| 324 | Histo2D c(a);
|
---|
| 325 | return (c -= b);
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | /*! \ingroup HiStats \fn operator*(const Histo2D&,const Histo2D&)
|
---|
| 329 | \brief Operateur H = H1 * H2 */
|
---|
| 330 | inline Histo2D operator * (const Histo2D& a, const Histo2D& b)
|
---|
| 331 | {
|
---|
| 332 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
| 333 | Histo2D c(a);
|
---|
| 334 | return (c *= b);
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | /*! \ingroup HiStats \fn operator/(const Histo2D&,const Histo2D&)
|
---|
| 338 | \brief Operateur H = H1 / H2 */
|
---|
| 339 | inline Histo2D operator / (const Histo2D& a, const Histo2D& b)
|
---|
| 340 | {
|
---|
| 341 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
| 342 | Histo2D c(a);
|
---|
| 343 | return (c /= b);
|
---|
| 344 | }
|
---|
| 345 |
|
---|
[763] | 346 | } // Fin du namespace
|
---|
| 347 |
|
---|
| 348 | #endif // HISTOS2_SEEN
|
---|