source: Sophya/trunk/SophyaLib/HiStats/histos.h@ 4036

Last change on this file since 4036 was 3950, checked in by cmv, 15 years ago

ajout d'une methode ReSize publique, cmv 18/02/2011

File size: 9.0 KB
RevLine 
[763]1// This may look like C code, but it is really -*- C++ -*-
2//
[3950]3// $Id: histos.h,v 1.27 2011-02-18 11:15:25 cmv Exp $
[763]4//
5
6#ifndef HISTOS_SEEN
7#define HISTOS_SEEN
8
9#include "objfio.h"
[2322]10#include <iostream>
[763]11#include <stdio.h>
12#include "peida.h"
13#include "tvector.h"
14#include "ppersist.h"
15#include "anydataobj.h"
16
17namespace SOPHYA {
18
[3049]19// Forward class declaration for Fits handler
20template <class T> class FitsHandler;
21
[926]22//! 1 dimension histograms
[763]23class Histo : public AnyDataObj {
24 friend class ObjFileIO<Histo>;
[3049]25 friend class FitsHandler<Histo>;
[763]26public:
27
28 // CREATOR / DESTRUCTOR
29 Histo();
[1092]30 Histo(r_8 xMin, r_8 xMax, int_4 nBin=100);
31 Histo(r_4 xMin, r_4 xMax, int_4 nBin=100);
[763]32 Histo(const Histo& H);
[1056]33 virtual ~Histo();
[763]34
35 // OPTIONS
[3110]36 void Errors();
37 void ReCenterBin();
[763]38
39 // UPDATING or SETTING
[3950]40 void Zero(void);
41 void ReSize(r_8 xMin, r_8 xMax, int_4 nBin);
[2630]42 void Add(r_8 x, r_8 w);
43 inline void Add(r_8 x) {Add(x,1.);}
44 void AddBin(int_4 numBin, r_8 w);
45 inline void AddBin(int_4 numBin) {AddBin(numBin,1.);}
46 void SetBin(r_8 x, r_8 w);
47 inline void SetBin(r_8 x) {SetBin(x,1.);}
48 void SetBin(int_4 numBin, r_8 w);
49 inline void SetBin(int_4 numBin) {SetBin(numBin,1.);}
[1092]50 void SetErr2(r_8 x, r_8 e2);
51 void SetErr2(int_4 numBin, r_8 e2);
52 void SetErr(r_8 x, r_8 e);
53 void SetErr(int_4 numBin, r_8 e);
[1135]54 virtual void UpdateHisto(bool force=false) const;
[763]55
56 // Operators
57 Histo& operator = (const Histo& h);
[1092]58 Histo& operator *= (r_8 b);
59 Histo& operator /= (r_8 b);
60 Histo& operator += (r_8 b);
61 Histo& operator -= (r_8 b);
[763]62 Histo& operator += (const Histo& a);
63 Histo& operator -= (const Histo& a);
64 Histo& operator *= (const Histo& a);
65 Histo& operator /= (const Histo& a);
66
67 // get/put dans/depuis un vector
[1109]68 void GetAbsc(TVector<r_8>& v) const;
69 void GetValue(TVector<r_8>& v) const;
70 void GetError2(TVector<r_8>& v) const;
71 void GetError(TVector<r_8>& v) const;
[1092]72 void PutValue(TVector<r_8>& v, int_4 ierr=0);
73 void PutValueAdd(TVector<r_8> &v, int_4 ierr=0);
[943]74 void PutError2(TVector<r_8>& v);
75 void PutError2Add(TVector<r_8>& v);
76 void PutError(TVector<r_8>& v);
[763]77
78 // INLINES
[914]79 //! Retourne l'abscisse minimum
[1092]80 inline r_8 XMin() const {return mMin;}
[914]81 //! Retourne l'abscisse maximum
[1092]82 inline r_8 XMax() const {return mMax;}
[914]83 //! Retourne le nombre de bins
[1092]84 inline int_4 NBins() const {return mBins;}
[914]85 //! Retourne la largeur du bin
[1092]86 inline r_8 BinWidth() const {return binWidth;}
[914]87 //! Retourne le pointeur sur le tableaux des contenus
[1092]88 inline r_8* Bins() const {return mData;}
[914]89 //! Retourne le contenu du bin i
[1092]90 inline r_8 operator()(int_4 i) const {return mData[i];}
[914]91 //! Remplit le contenu du bin i
[1092]92 inline r_8& operator()(int_4 i) {return mData[i];}
[914]93 //! retourne "true" si il y a des erreurs stoquees
[1109]94 inline bool HasErrors() const
[1092]95 {if(mErr2) return true; else return false;}
[914]96 //! Retourne l'erreur du bin i
[1092]97 inline r_8 Error(int_4 i) const
98 {if(mErr2) {if(mErr2[i]>0.) return sqrt(mErr2[i]); else return 0.;}
[1056]99 else return 0.;}
[914]100 //! Retourne l'erreur au carre du bin i
[1092]101 inline r_8 Error2(int_4 i) const
102 {if(mErr2) return mErr2[i]; else return 0.;}
[914]103 //! Remplit l'erreur au carre du bin i
[1092]104 inline r_8& Error2(int_4 i) {return mErr2[i];}
[914]105 //! Retourne la somme ponderee
[1092]106 inline r_8 NData() const {return nHist;}
[914]107 //! Retourne le nombre d'entrees
[2628]108 inline uint_8 NEntries() const {return nEntries;}
[914]109 //! Retourne le nombre d'overflow
[1092]110 inline r_8 NOver() const {return mOver;}
[914]111 //! Retourne le nombre d'underflow
[1092]112 inline r_8 NUnder() const {return mUnder;}
[763]113
[914]114 //! Retourne l'abscisse du bord inferieur du bin i
[1092]115 inline r_8 BinLowEdge(int_4 i) const {return mMin + i*binWidth;}
[914]116 //! Retourne l'abscisse du centre du bin i
[1092]117 inline r_8 BinCenter(int_4 i) const {return mMin + (i+0.5)*binWidth;}
[914]118 //! Retourne l'abscisse du bord superieur du bin i
[1092]119 inline r_8 BinHighEdge(int_4 i) const {return mMin + (i+1)*binWidth;}
[914]120 //! Retourne le numero du bin contenant l'abscisse x
[1092]121 inline int_4 FindBin(r_8 x) const
122 {return (int_4) floor((x - mMin) / binWidth);}
[763]123
124 // Info, statistique et calculs sur les histogrammes
[1092]125 int_4 BinNonNul() const;
126 int_4 ErrNonNul() const;
127 int_4 IMax() const;
128 int_4 IMin() const;
129 r_8 VMax() const;
130 r_8 VMin() const;
[3110]131 r_8 Sum() const;
132 r_8 Sum2() const;
[1092]133 r_8 Mean() const;
134 r_8 Sigma() const;
135 r_8 MeanLH(int_4 il,int_4 ih) const;
136 r_8 SigmaLH(int_4 il,int_4 ih) const;
137 r_8 Mean(r_8 x0, r_8 dx) const;
138 r_8 Sigma(r_8 x0, r_8 dx) const;
139 r_8 CleanedMean() const;
140 r_8 CleanedMean(r_8& sigma) const;
141 int_4 BinPercent(r_8 per) const;
[1109]142 int_4 BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const;
143 int_4 BinPercent(r_8 x,r_8 per,r_8& xmin,r_8& xmax) const;
[1092]144 void HInteg(r_8 norm = 0.);
[1056]145 void HDeriv();
[1092]146 virtual void HRebin(int_4 nbinew);
[763]147
[1109]148 int_4 MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const;
[1092]149 r_8 FitMax(int_4 degree=2, r_8 frac=0.5f, int_4 debug=0) const;
150 r_8 FindWidth(r_8 xmax,r_8 frac=0.5f, int_4 debug=0) const;
151 r_8 FindWidth(r_8 frac=0.5f, int_4 debug=0) const;
[1109]152 int_4 EstimeMax(r_8& xm,int_4 SzPav = 3) const;
153 int_4 EstimeMax(int_4& im,r_8& xm,int_4 SzPav = 3) const;
154 void EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const;
[763]155
156 // Print et Display ASCII
[1413]157 virtual void Show(ostream& os) const;
158 inline void Show() const { Show(cout); }
[1092]159 void Print(int_4 dyn = 100, r_8 hmin = 1., r_8 hmax = -1.,
[1201]160 int_4 pflag = 0, int_4 il = 1, int_4 ih = -1) const;
[1413]161
[763]162protected:
[3053]163 void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
[3110]164 void Delete(); // Ne pas passer en "virtual"
[763]165
[1092]166 r_8* mData; //!< donnees
167 r_8* mErr2; //!< erreurs carrees
168 r_8 mUnder; //!< underflow
169 r_8 mOver; //!< overflow
170 r_8 nHist; //!< somme ponderee des entrees
[2628]171 uint_8 nEntries; //!< nombre d'entrees
[1092]172 int_4 mBins; //!< nombre de bins
173 r_8 mMin; //!< abscisse minimum
174 r_8 mMax; //!< abscisse maximum
175 r_8 binWidth; //!< largeur du bin
[763]176};
177
[1413]178/*! Prints histogram information on stream \b s (h.Show(s)) */
179inline ostream& operator << (ostream& s, Histo const & h)
180 { h.Show(s); return(s); }
[763]181
[958]182/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
183 \brief Persistance management */
[763]184inline POutPersist& operator << (POutPersist& os, Histo & obj)
185{ ObjFileIO<Histo> fio(&obj); fio.Write(os); return(os); }
[958]186/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
187 \brief Persistance management */
[763]188inline PInPersist& operator >> (PInPersist& is, Histo & obj)
[2479]189{ ObjFileIO<Histo> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
[763]190
191// Classe pour la gestion de persistance
192// ObjFileIO<Histo>
193
[1092]194/*! \ingroup HiStats \fn operator*(const Histo&,r_8)
[1053]195 \brief Operateur H2 = H1 * b */
[1092]196inline Histo operator * (const Histo& a, r_8 b)
[1053]197{
198 Histo result(a);
199 return (result *= b);
200}
[763]201
[1092]202/*! \ingroup HiStats \fn operator*(r_8,const Histo&)
[1053]203 \brief Operateur H2 = b * H1 */
[1092]204inline Histo operator * (r_8 b, const Histo& a)
[1053]205{
206 Histo result(a);
207 return (result *= b);
208}
209
[1092]210/*! \ingroup HiStats \fn operator/(const Histo&,r_8)
[1053]211 \brief Operateur H2 = H1 / b */
[1092]212inline Histo operator / (const Histo& a, r_8 b)
[1053]213{
214 Histo result(a);
215 return (result /= b);
216}
217
[1092]218/*! \ingroup HiStats \fn operator+(const Histo&,r_8)
[1053]219 \brief Operateur H2 = H1 + b */
[1092]220inline Histo operator + (const Histo& a, r_8 b)
[1053]221{
222 Histo result(a);
223 return (result += b);
224}
225
[1092]226/*! \ingroup HiStats \fn operator+(r_8,const Histo&)
[1053]227 \brief Operateur H2 = b + H1 */
[1092]228inline Histo operator + (r_8 b, const Histo& a)
[1053]229{
230 Histo result(a);
231 return (result += b);
232}
233
[1092]234/*! \ingroup HiStats \fn operator-(const Histo&,r_8)
[1053]235 \brief Operateur H2 = H1 - b */
[1092]236inline Histo operator - (const Histo& a, r_8 b)
[1053]237{
238 Histo result(a);
239 return (result -= b);
240}
241
[1092]242/*! \ingroup HiStats \fn operator-(r_8,const Histo&)
[1053]243 \brief Operateur H2 = b - H1 */
[1092]244inline Histo operator - (r_8 b, const Histo& a)
[1053]245{
246 Histo result(a);
247 result *= -1.;
248 return (result += b);
249}
250
251/*! \ingroup HiStats \fn operator+(const Histo&,const Histo&)
252 \brief Operateur H = H1 + H2 */
253inline Histo operator + (const Histo& a, const Histo& b)
254{
[2507]255if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
[1053]256Histo c(a);
257return (c += b);
258}
259
260/*! \ingroup HiStats \fn operator-(const Histo&,const Histo&)
261 \brief Operateur H = H1 - H2 */
262inline Histo operator - (const Histo& a, const Histo& b)
263{
[2507]264if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
[1053]265Histo c(a);
266return (c -= b);
267}
268
269/*! \ingroup HiStats \fn operator*(const Histo&,const Histo&)
270 \brief Operateur H = H1 * H2 */
271inline Histo operator * (const Histo& a, const Histo& b)
272{
[2507]273if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
[1053]274Histo c(a);
275return (c *= b);
276}
277
278/*! \ingroup HiStats \fn operator/(const Histo&,const Histo&)
279 \brief Operateur H = H1 / H2 */
280inline Histo operator / (const Histo& a, const Histo& b)
281{
[2507]282if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
[1053]283Histo c(a);
284return (c /= b);
285}
286
[763]287} // Fin du namespace
288
289#endif // HISTOS_SEEN
Note: See TracBrowser for help on using the repository browser.