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

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

define module HiStats in Doc cmv 13/4/00

File size: 7.1 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2//
3// $Id: histos.h,v 1.3 2000-04-13 16:41: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
22/*!
23 \class SOPHYA::Histo
24 \ingroup HiStats
25 Classe d'histogrammes 1D
26*/
27class Histo : public AnyDataObj {
28 friend class ObjFileIO<Histo>;
29public:
30
31 // CREATOR / DESTRUCTOR
32 Histo();
33 Histo(float xMin, float xMax, int nBin=100);
34 Histo(const Histo& H);
35 virtual ~Histo();
36
37 // OPTIONS
38 void Errors();
39
40 // UPDATING or SETTING
41 void Zero();
42 void Add(float x, float w = 1.);
43 void AddBin(int numBin, float w = 1.);
44 void SetBin(float x, float w = 1.);
45 void SetBin(int numBin, float w = 1.);
46 void SetErr2(float x, double e2);
47 void SetErr2(int numBin, double e2);
48 void SetErr(float x, float e);
49 void SetErr(int numBin, float e);
50
51 // Operators
52 Histo& operator = (const Histo& h);
53 Histo& operator *= (double b);
54 Histo& operator /= (double b);
55 Histo& operator += (double b);
56 Histo& operator -= (double b);
57 friend Histo operator * (const Histo& a, double b);
58 friend Histo operator * (double b, const Histo& a);
59 friend Histo operator / (const Histo& a, double b);
60 friend Histo operator + (const Histo& a, double b);
61 friend Histo operator + (double b, const Histo& a);
62 friend Histo operator - (const Histo& a, double b);
63 friend Histo operator - (double b, const Histo& a);
64 Histo& operator += (const Histo& a);
65 Histo& operator -= (const Histo& a);
66 Histo& operator *= (const Histo& a);
67 Histo& operator /= (const Histo& a);
68 friend Histo operator + (const Histo& a, const Histo& b);
69 friend Histo operator - (const Histo& a, const Histo& b);
70 friend Histo operator * (const Histo& a, const Histo& b);
71 friend Histo operator / (const Histo& a, const Histo& b);
72
73 // get/put dans/depuis un vector
74 void GetAbsc(Vector& v);
75 void GetValue(Vector& v);
76 void GetError2(Vector& v);
77 void GetError(Vector& v);
78 void PutValue(Vector& v, int ierr=0);
79 void PutValueAdd(Vector &v, int ierr=0);
80 void PutError2(Vector& v);
81 void PutError2Add(Vector& v);
82 void PutError(Vector& v);
83
84 // INLINES
85 //! Retourne l'abscisse minimum
86 inline float XMin() const {return min;}
87 //! Retourne l'abscisse maximum
88 inline float XMax() const {return max;}
89 //! Retourne le nombre de bins
90 inline int_4 NBins() const {return bins;}
91 //! Retourne la largeur du bin
92 inline float BinWidth() const {return binWidth;}
93 //! Retourne le pointeur sur le tableaux des contenus
94 inline float* Bins() const {return data;}
95 //! Retourne le contenu du bin i
96 inline float operator()(int i) const {return data[i];}
97 //! Remplit le contenu du bin i
98 inline float& operator()(int i) {return data[i];}
99 //! retourne "true" si il y a des erreurs stoquees
100 inline bool HasErrors() { if(err2) return true; else return false;}
101 //! Retourne l'erreur du bin i
102 inline float Error(int i) const
103 {if(err2) {if(err2[i]>0.) return sqrt(err2[i]); else return 0.;}
104 else return 0.;}
105 //! Retourne l'erreur au carre du bin i
106 inline double Error2(int i) const
107 {if(err2) return err2[i]; else return 0.;}
108 //! Remplit l'erreur au carre du bin i
109 inline double& Error2(int i) {return err2[i];}
110 //! Retourne la somme ponderee
111 inline float NData() const {return (float) nHist;}
112 //! Retourne le nombre d'entrees
113 inline float NEntries() const {return nEntries;}
114 //! Retourne le nombre d'overflow
115 inline float NOver() const {return over;}
116 //! Retourne le nombre d'underflow
117 inline float NUnder() const {return under;}
118
119 //! Retourne l'abscisse du bord inferieur du bin i
120 inline float BinLowEdge(int i) const {return min + i*binWidth;}
121 //! Retourne l'abscisse du centre du bin i
122 inline float BinCenter(int i) const {return min + (i+0.5)*binWidth;}
123 //! Retourne l'abscisse du bord superieur du bin i
124 inline float BinHighEdge(int i) const {return min + (i+1)*binWidth;}
125 //! Retourne le numero du bin contenant l'abscisse x
126 inline int_4 FindBin(float x) const
127 {return (int_4) floorf((x - min) / binWidth);}
128
129 // Info, statistique et calculs sur les histogrammes
130 int BinNonNul() const;
131 int ErrNonNul() const;
132 int IMax() const;
133 int IMin() const;
134 float VMax() const;
135 float VMin() const;
136 float Mean() const;
137 float Sigma() const;
138 float MeanLH(int il,int ih) const;
139 float SigmaLH(int il,int ih) const;
140 float Mean(float x0, float dx) const;
141 float Sigma(float x0, float dx) const;
142 float CleanedMean() const;
143 float CleanedMean(float& sigma) const;
144 int BinPercent(float per) const;
145 int BinPercent(float x,float per,int& imin,int& imax);
146 int BinPercent(float x,float per,float& xmin,float& xmax);
147 void HInteg(float norm = 0.);
148 void HDeriv();
149 void HRebin(int nbinew);
150
151 int MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn);
152 float FitMax(int degree=2, float frac=0.5f, int debug=0) const;
153 float FindWidth(float xmax,float frac=0.5f, int debug=0) const;
154 float FindWidth(float frac=0.5f, int debug=0) const;
155 int EstimeMax(float& xm,int SzPav = 3);
156 int EstimeMax(int& im,float& xm,int SzPav = 3);
157 void EstimeWidthS(float frac,float& widthG,float& widthD);
158
159 // Fit
160 int Fit(GeneralFit& gfit,unsigned short typ_err=0);
161 Histo FitResidus(GeneralFit& gfit);
162 Histo FitFunction(GeneralFit& gfit);
163
164 // Print et Display ASCII
165 void PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1.,
166 int pflag = 0, int il = 1, int ih = -1);
167 void Print(int dyn = 100, float hmin = 1., float hmax = -1.,
168 int pflag = 0, int il = 1, int ih = -1);
169
170protected:
171 void Delete();
172
173 float* data; //!< donnees
174 double* err2; //!< erreurs carrees
175 float under; //!< underflow
176 float over; //!< overflow
177 double nHist; //!< somme ponderee des entrees
178 int_4 nEntries; //!< nombre d'entrees
179 int_4 bins; //!< nombre de bins
180 float min; //!< abscisse minimum
181 float max; //!< abscisse maximum
182 float binWidth; //!< largeur du bin
183};
184
185
186inline POutPersist& operator << (POutPersist& os, Histo & obj)
187{ ObjFileIO<Histo> fio(&obj); fio.Write(os); return(os); }
188inline PInPersist& operator >> (PInPersist& is, Histo & obj)
189{ ObjFileIO<Histo> fio(&obj); fio.Read(is); return(is); }
190
191// Classe pour la gestion de persistance
192// ObjFileIO<Histo>
193
194
195} // Fin du namespace
196
197#endif // HISTOS_SEEN
Note: See TracBrowser for help on using the repository browser.