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

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

Fits IO Histo,HProf,HistErr,Histo2D cmv 11/8/2006

File size: 3.0 KB
RevLine 
[2603]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
[3049]11// Forward class declaration for Fits handler
12template <class T> class FitsHandler;
13
[2603]14//! 1 dimension histograms with errors given by user
15class HistoErr : public Histo {
16 friend class ObjFileIO<HistoErr>;
[3049]17 friend class FitsHandler<Histo>;
[2603]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
[2630]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.);}
[2603]41 //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
[2630]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.);}
[2604]53 //! remplissage contenu de l'histo pour le bin numBin poids w et l'erreur e
[2630]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.);}
[2604]58 //! remplissage nombre d'entrees pour le bin numBin
[2626]59 void SetNentB(int_4 numBin, r_8 nb=1.);
[2603]60
61 //! Retourne le nombre d'entree dans le bin
[2626]62 inline r_8 NEntBin(int_4 i) const
63 {if(mNData) return mNData[i]; else return 0.;}
[2603]64
[2608]65 //! get/put from/to a vector
[2626]66 void GetNBin(TVector<r_8>& v) const;
67 void PutNBin(TVector<r_8>& v);
[2603]68
[2608]69 //! Compute the correlation histogram
[2604]70 void ToCorrel(void);
[2819]71 void FromCorrel(void);
[3049]72 int_4 NCorrel(void) {return mCorrel;}
[2604]73
[2628]74 //! Fill an histogram with an histogram
75 void FillFrHErr(HistoErr& hfrom);
76
[2619]77 // Operators
78 HistoErr& operator = (const HistoErr& h);
79
[2603]80protected:
[2608]81 void allocate_mNData(int nbin);
[2619]82 void Delete(void);
83
[2626]84 r_8* mNData; //!< nombre d'entrees dans chaque bin
[3049]85 int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
[2603]86};
87
88/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
89 \brief Persistance management */
90inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
91{ ObjFileIO<HistoErr> fio(&obj); fio.Write(os); return(os); }
92/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
93 \brief Persistance management */
94inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
95{ ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
96
97} // Fin du namespace
98
99#endif // HISTERR_SEEN
Note: See TracBrowser for help on using the repository browser.