source: Sophya/trunk/SophyaLib/NTools/histos.h@ 394

Last change on this file since 394 was 307, checked in by ansari, 26 years ago

FIO_... + grosses modifs cmv 19/5/99

File size: 6.2 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2//
3// $Id: histos.h,v 1.2 1999-05-19 15:58:00 ansari Exp $
4//
5
6#ifndef HISTOS_SEEN
7#define HISTOS_SEEN
8
9#include <stdio.h>
10#include "peida.h"
11#include "cvector.h"
12#include "ppersist.h"
13#include "anydataobj.h"
14
15namespace PlanckDPC {
16
17class GeneralFit;
18
19class Histo : public AnyDataObj {
20 friend class FIO_Histo;
21public:
22
23 // CREATOR / DESTRUCTOR
24 Histo();
25 Histo(float xMin, float xMax, int nBin=100);
26 Histo(const Histo& H);
27 virtual ~Histo();
28
29 // OPTIONS
30 void Errors();
31
32 // UPDATING or SETTING
33 void Zero();
34 void Add(float x, float w = 1.);
35 void AddBin(int numBin, float w = 1.);
36 void SetBin(float x, float w = 1.);
37 void SetBin(int numBin, float w = 1.);
38 void SetErr2(float x, double e2);
39 void SetErr2(int numBin, double e2);
40 void SetErr(float x, float e);
41 void SetErr(int numBin, float e);
42
43 // Operators
44 Histo& operator = (const Histo& h);
45 Histo& operator *= (double b);
46 Histo& operator /= (double b);
47 Histo& operator += (double b);
48 Histo& operator -= (double b);
49 friend Histo operator * (const Histo& a, double b);
50 friend Histo operator * (double b, const Histo& a);
51 friend Histo operator / (const Histo& a, double b);
52 friend Histo operator + (const Histo& a, double b);
53 friend Histo operator + (double b, const Histo& a);
54 friend Histo operator - (const Histo& a, double b);
55 friend Histo operator - (double b, const Histo& a);
56 Histo& operator += (const Histo& a);
57 Histo& operator -= (const Histo& a);
58 Histo& operator *= (const Histo& a);
59 Histo& operator /= (const Histo& a);
60 friend Histo operator + (const Histo& a, const Histo& b);
61 friend Histo operator - (const Histo& a, const Histo& b);
62 friend Histo operator * (const Histo& a, const Histo& b);
63 friend Histo operator / (const Histo& a, const Histo& b);
64
65 // get/put dans/depuis un vector
66 void GetAbsc(Vector& v);
67 void GetValue(Vector& v);
68 void GetError2(Vector& v);
69 void GetError(Vector& v);
70 void PutValue(Vector& v, int ierr=0);
71 void PutValueAdd(Vector &v, int ierr=0);
72 void PutError2(Vector& v);
73 void PutError2Add(Vector& v);
74 void PutError(Vector& v);
75
76 // INLINES
77 inline float XMin() const {return min;}
78 inline float XMax() const {return max;}
79 inline int_4 NBins() const {return bins;}
80 inline float BinWidth() const {return binWidth;}
81 inline float* Bins() const {return data;}
82 inline float operator()(int i) const {return data[i];}
83 inline float& operator()(int i) {return data[i];}
84 inline bool HasErrors() { if(err2) return true; else return false;}
85 inline float Error(int i) const
86 {if(err2) {if(err2[i]>0.) return sqrt(err2[i]); else return 0.;}
87 else return 0.;}
88 inline double Error2(int i) const
89 {if(err2) return err2[i]; else return 0.;}
90 inline double& Error2(int i) {return err2[i];}
91 inline float NData() const {return (float) nHist;}
92 inline float NEntries() const {return nEntries;}
93 inline float NOver() const {return over;}
94 inline float NUnder() const {return under;}
95
96 inline float BinLowEdge(int i) const {return min + i*binWidth;}
97 inline float BinCenter(int i) const {return min + (i+0.5)*binWidth;}
98 inline float BinHighEdge(int i) const {return min + (i+1)*binWidth;}
99 inline int_4 FindBin(float x) const
100 {return (int_4) floorf((x - min) / binWidth);}
101
102 // Info, statistique et calculs sur les histogrammes
103 int BinNonNul() const;
104 int ErrNonNul() const;
105 int IMax() const;
106 int IMin() const;
107 float VMax() const;
108 float VMin() const;
109 float Mean() const;
110 float Sigma() const;
111 float MeanLH(int il,int ih) const;
112 float SigmaLH(int il,int ih) const;
113 float Mean(float x0, float dx) const;
114 float Sigma(float x0, float dx) const;
115 float CleanedMean() const;
116 float CleanedMean(float& sigma) const;
117 int BinPercent(float per) const;
118 int BinPercent(float x,float per,int& imin,int& imax);
119 int BinPercent(float x,float per,float& xmin,float& xmax);
120 void HInteg(float norm = 0.);
121 void HDeriv();
122 void HRebin(int nbinew);
123
124 int MaxiLocal(float& maxi,int& imax,float& maxn,int& imaxn);
125 float FitMax(int degree=2, float frac=0.5f, int debug=0) const;
126 float FindWidth(float xmax,float frac=0.5f, int debug=0) const;
127 float FindWidth(float frac=0.5f, int debug=0) const;
128 int EstimeMax(float& xm,int SzPav = 3);
129 int EstimeMax(int& im,float& xm,int SzPav = 3);
130 void EstimeWidthS(float frac,float& widthG,float& widthD);
131
132 // Fit
133 int Fit(GeneralFit& gfit,unsigned short typ_err=0);
134 Histo FitResidus(GeneralFit& gfit);
135 Histo FitFunction(GeneralFit& gfit);
136
137 // Print et Display ASCII
138 void PrintF(FILE * fp, int dyn = 100, float hmin = 1., float hmax = -1.,
139 int pflag = 0, int il = 1, int ih = -1);
140 void Print(int dyn = 100, float hmin = 1., float hmax = -1.,
141 int pflag = 0, int il = 1, int ih = -1);
142
143protected:
144 void Delete();
145
146 float* data;
147 double* err2;
148 float under;
149 float over;
150 double nHist;
151 int_4 nEntries;
152 int_4 bins;
153 float min;
154 float max;
155 float binWidth;
156};
157
158/////////////////////////////////////////////////////////////////////////
159// Classe pour la gestion de persistance
160class FIO_Histo : public PPersist {
161public:
162 FIO_Histo();
163 FIO_Histo(string const & filename);
164 FIO_Histo(const Histo & obj);
165 FIO_Histo(Histo * obj);
166 virtual ~FIO_Histo();
167 virtual AnyDataObj* DataObj();
168 inline operator Histo() { return(*dobj); }
169protected :
170 virtual void ReadSelf(PInPersist&);
171 virtual void WriteSelf(POutPersist&) const;
172 Histo * dobj;
173 bool ownobj;
174};
175
176} // Fin du namespace
177
178#endif // HISTOS_SEEN
Note: See TracBrowser for help on using the repository browser.