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

Last change on this file since 262 was 220, checked in by ansari, 26 years ago

Creation module DPC/NTools Reza 09/04/99

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