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