source: Sophya/trunk/SophyaLib/HiStats/histerr.h@ 3122

Last change on this file since 3122 was 3118, checked in by cmv, 19 years ago

intro de SetCorrel cmv 21/12/06

File size: 3.4 KB
Line 
1#ifndef HISTERR_SEEN
2#define HISTERR_SEEN
3
4#include "objfio.h"
5#include <iostream>
6#include <stdio.h>
7#include "histos.h"
8
9namespace SOPHYA {
10
11// Forward class declaration for Fits handler
12template <class T> class FitsHandler;
13
14//! 1 dimension histograms with errors given by user
15class HistoErr : public Histo {
16 friend class ObjFileIO<HistoErr>;
17 friend class FitsHandler<Histo>;
18public:
19
20 // CREATOR / DESTRUCTOR
21 HistoErr(void);
22 HistoErr(r_8 xMin, r_8 xMax, int_4 nBin=100);
23 HistoErr(const HistoErr& H);
24 virtual ~HistoErr(void);
25
26 // UPDATING or SETTING
27 void Zero(void);
28 //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
29 inline void Add(r_8 x, r_8 w, r_8 e)
30 {
31 int_4 numBin = (int_4)floor((x-mMin)/binWidth);
32 if(numBin<0) mUnder += w;
33 else if(numBin>=mBins) mOver += w;
34 else {
35 mData[numBin] += w; mNData[numBin] += 1.; mErr2[numBin] += e*e;
36 nHist += w; nEntries++;
37 }
38 }
39 inline void Add(r_8 x, r_8 w) {Add(x,w,1.);}
40 inline void Add(r_8 x) {Add(x,1.,1.);}
41 //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
42 inline void AddBin(int_4 numBin, r_8 w, r_8 e)
43 {
44 if(numBin<0) mUnder += w;
45 else if(numBin>=mBins) mOver += w;
46 else {
47 mData[numBin] += w; mNData[numBin] += 1.; mErr2[numBin] += e*e;
48 nHist += w; nEntries++;
49 }
50 }
51 inline void AddBin(int_4 numBin, r_8 w) {AddBin(numBin,w,1.);}
52 inline void AddBin(int_4 numBin) {AddBin(numBin,1.,1.);}
53 //! remplissage contenu de l'histo pour le bin numBin poids w et l'erreur e
54 void SetBin(int_4 numBin, r_8 w, r_8 e, r_8 nb);
55 inline void SetBin(int_4 numBin, r_8 w, r_8 e) {SetBin(numBin,w,e,1.);}
56 inline void SetBin(int_4 numBin, r_8 w) {SetBin(numBin,w,1.,1.);}
57 inline void SetBin(int_4 numBin) {SetBin(numBin,1.,1.,1.);}
58 //! remplissage nombre d'entrees pour le bin numBin
59 void SetNentB(int_4 numBin, r_8 nb=1.);
60
61 //! Retourne le nombre d'entree dans le bin
62 inline r_8 NEntBin(int_4 i) const
63 {if(mNData) return mNData[i]; else return 0.;}
64
65 //! get/put from/to a vector
66 void GetNBin(TVector<r_8>& v) const;
67 void PutNBin(TVector<r_8>& v);
68
69 //! Compute the correlation histogram
70 void ToCorrel(void);
71 void FromCorrel(void);
72 int_4 NCorrel(void) {return mCorrel;}
73 void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
74
75 //! Fill an histogram with an histogram
76 void FillFrHErr(HistoErr& hfrom);
77
78 // Operators
79 HistoErr& operator = (const HistoErr& h);
80
81 // Print
82 virtual void Show(ostream& os) const;
83 inline void Show() const { Show(cout); }
84
85protected:
86 void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
87 void Delete(void);
88
89 r_8* mNData; //!< nombre d'entrees dans chaque bin
90 int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
91};
92
93/*! Prints histogram information on stream \b s (h.Show(s)) */
94inline ostream& operator << (ostream& s, HistoErr const & h)
95 { h.Show(s); return(s); }
96
97/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
98 \brief Persistance management */
99inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
100{ ObjFileIO<HistoErr> fio(&obj); fio.Write(os); return(os); }
101/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
102 \brief Persistance management */
103inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
104{ ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
105
106} // Fin du namespace
107
108#endif // HISTERR_SEEN
Note: See TracBrowser for help on using the repository browser.