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

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

documentation cmv 13/4/00

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