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

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

les friend operator ne marche plus ? passage en inline cmv 30/06/00

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