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

Last change on this file since 3072 was 3057, checked in by cmv, 19 years ago
  • changement nom variables internes Histo...Histo2D
  • re-arrangement CreateOrResize et operator=
  • protection dans methodes (VMIN etc..) pour Histo 1d+2d vides

cmv 13/8/2006

File size: 3.3 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
74 //! Fill an histogram with an histogram
75 void FillFrHErr(HistoErr& hfrom);
76
77 // Operators
78 HistoErr& operator = (const HistoErr& h);
79
80 // Print
81 virtual void Show(ostream& os) const;
82 inline void Show() const { Show(cout); }
83
84protected:
85 void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
86 void Delete(void);
87
88 r_8* mNData; //!< nombre d'entrees dans chaque bin
89 int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
90};
91
92/*! Prints histogram information on stream \b s (h.Show(s)) */
93inline ostream& operator << (ostream& s, HistoErr const & h)
94 { h.Show(s); return(s); }
95
96/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
97 \brief Persistance management */
98inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
99{ ObjFileIO<HistoErr> fio(&obj); fio.Write(os); return(os); }
100/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
101 \brief Persistance management */
102inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
103{ ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
104
105} // Fin du namespace
106
107#endif // HISTERR_SEEN
Note: See TracBrowser for help on using the repository browser.