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

Last change on this file since 1089 was 1089, checked in by ansari, 25 years ago

updatehisto formalisation cmv 25/7/00

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