| [2603] | 1 | #ifndef HISTERR_SEEN
 | 
|---|
 | 2 | #define HISTERR_SEEN
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #include "objfio.h"
 | 
|---|
 | 5 | #include <iostream>
 | 
|---|
 | 6 | #include <stdio.h>
 | 
|---|
| [3123] | 7 | #include "tvector.h"
 | 
|---|
| [2603] | 8 | 
 | 
|---|
 | 9 | namespace SOPHYA {
 | 
|---|
 | 10 | 
 | 
|---|
| [3049] | 11 | //  Forward class declaration for Fits handler
 | 
|---|
 | 12 | template <class T>  class FitsHandler;
 | 
|---|
 | 13 | 
 | 
|---|
| [3123] | 14 | 
 | 
|---|
 | 15 | //! 1 dimensions histograms with errors given by user
 | 
|---|
 | 16 | class HistoErr : public AnyDataObj {
 | 
|---|
| [2603] | 17 |   friend class ObjFileIO<HistoErr>;
 | 
|---|
| [3123] | 18 |   friend class FitsHandler<HistoErr>;
 | 
|---|
| [2603] | 19 | public:
 | 
|---|
 | 20 | 
 | 
|---|
| [3123] | 21 |   //! Create or destroy
 | 
|---|
| [2603] | 22 |   HistoErr(void);
 | 
|---|
| [3123] | 23 |   HistoErr(r_8 xmin,r_8 xmax,int_4 nx);
 | 
|---|
| [2603] | 24 |   HistoErr(const HistoErr& H);
 | 
|---|
 | 25 |   virtual ~HistoErr(void);
 | 
|---|
 | 26 | 
 | 
|---|
| [3123] | 27 |   //! Updating or Setting
 | 
|---|
 | 28 |   void ReCenterBin(void);
 | 
|---|
| [3307] | 29 |   void ReCenterBinW(void);
 | 
|---|
| [2603] | 30 |   void Zero(void);
 | 
|---|
| [3123] | 31 | 
 | 
|---|
 | 32 |   //! Getting Info
 | 
|---|
 | 33 |   int_4 NBins(void) {return nx_;}
 | 
|---|
 | 34 |   r_8 XMin(void) {return xmin_;}
 | 
|---|
 | 35 |   r_8 XMax(void) {return xmax_;}
 | 
|---|
 | 36 |   r_8 BinWidth(void) {return dx_;}
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 |   //! Retourne le contenu du bin
 | 
|---|
 | 39 |   inline r_8 operator()(int_4 i) const
 | 
|---|
 | 40 |     {
 | 
|---|
 | 41 |     if(i<0 || i>=nx_) return 0.;
 | 
|---|
 | 42 |     return data_(i);
 | 
|---|
 | 43 |     }
 | 
|---|
 | 44 |   inline r_8& operator()(int_4 i)
 | 
|---|
 | 45 |     {
 | 
|---|
 | 46 |     return data_(i);
 | 
|---|
 | 47 |     }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |   //! Retourne le nombre l'erreur au carre dans le bin
 | 
|---|
 | 50 |   inline r_8 Error2(int_4 i) const
 | 
|---|
 | 51 |     {
 | 
|---|
 | 52 |     if(i<0 || i>=nx_) return 0.;
 | 
|---|
 | 53 |     return err2_(i);
 | 
|---|
 | 54 |     }
 | 
|---|
| [3124] | 55 |   inline r_8 Error(int_4 i) const
 | 
|---|
 | 56 |     {
 | 
|---|
 | 57 |     if(i<0 || i>=nx_) return 0.;
 | 
|---|
 | 58 |     if(err2_(i)>0.) return sqrt(err2_(i)); else return 0.;
 | 
|---|
 | 59 |     }
 | 
|---|
| [3123] | 60 | 
 | 
|---|
 | 61 |   //! Retourne le nombre d'entree dans le bin
 | 
|---|
 | 62 |   inline r_8 NEntBin(int_4 i) const
 | 
|---|
 | 63 |     {
 | 
|---|
 | 64 |     if(i<0 || i>=nx_) return 0.;
 | 
|---|
 | 65 |     return ndata_(i);
 | 
|---|
 | 66 |     }
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |   //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i.
 | 
|---|
 | 69 |   inline r_8 BinLowEdge(int_4 i) const {return xmin_ + i*dx_;}
 | 
|---|
 | 70 |   //! Retourne l'abscisse et l'ordonnee du centre du bin i.
 | 
|---|
 | 71 |   inline r_8 BinCenter(int_4 i) const  {return xmin_ + (i+0.5)*dx_;}
 | 
|---|
 | 72 |   //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i.
 | 
|---|
 | 73 |   inline r_8 BinHighEdge(int_4 i) const {return xmin_ + (i+1)*dx_;}
 | 
|---|
 | 74 |   //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
 | 
|---|
 | 75 |   inline int_4 FindBin(r_8 x) const {return (int_4)floor((x-xmin_)/dx_);}
 | 
|---|
 | 76 | 
 | 
|---|
| [2603] | 77 |   //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
 | 
|---|
| [2630] | 78 |   inline void Add(r_8 x, r_8 w, r_8 e)
 | 
|---|
| [3123] | 79 |     {
 | 
|---|
 | 80 |     int_4 i = FindBin(x);
 | 
|---|
 | 81 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 82 |     data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
 | 
|---|
 | 83 |     }
 | 
|---|
| [3147] | 84 |   inline void Add(r_8 x, r_8 w) {Add(x,w,w);}
 | 
|---|
| [2603] | 85 | 
 | 
|---|
| [3123] | 86 |   //! Addition du contenu de l'histo pour le bin i poids w et l'erreur e
 | 
|---|
 | 87 |   inline void AddBin(int_4 i, r_8 w, r_8 e)
 | 
|---|
 | 88 |     {
 | 
|---|
 | 89 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 90 |     data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
 | 
|---|
 | 91 |     }
 | 
|---|
| [3147] | 92 |   inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,w);}
 | 
|---|
| [2603] | 93 | 
 | 
|---|
| [3123] | 94 |   //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
 | 
|---|
 | 95 |   inline void SetBin(int_4 i, r_8 w, r_8 e, r_8 nb)
 | 
|---|
 | 96 |     {
 | 
|---|
 | 97 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 98 |     data_(i)  = w;
 | 
|---|
 | 99 |     err2_(i)  = e*e;
 | 
|---|
 | 100 |     ndata_(i) = nb;
 | 
|---|
 | 101 |     }
 | 
|---|
| [3147] | 102 |   //! remplissage de la valeur pour le bin i
 | 
|---|
 | 103 |   inline void SetBin(int_4 i, r_8 w)
 | 
|---|
 | 104 |     {
 | 
|---|
 | 105 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 106 |     data_(i)  = w;
 | 
|---|
 | 107 |     }
 | 
|---|
| [3123] | 108 |   //! remplissage de l'erreur carree pour le bin i
 | 
|---|
 | 109 |   void SetErr2(int_4 i, r_8 e2)
 | 
|---|
 | 110 |     {
 | 
|---|
 | 111 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 112 |     err2_(i) = e2;
 | 
|---|
 | 113 |     }
 | 
|---|
 | 114 |   //! remplissage nombre d'entrees pour le bin i
 | 
|---|
 | 115 |   void SetNentB(int_4 i, r_8 nb)
 | 
|---|
 | 116 |     {
 | 
|---|
 | 117 |     if(i<0 || i>=nx_) return;
 | 
|---|
 | 118 |     ndata_(i) = nb;
 | 
|---|
 | 119 |     }
 | 
|---|
| [2603] | 120 | 
 | 
|---|
| [3147] | 121 |   //! Compute the mean histogram
 | 
|---|
 | 122 |   void ToMean(void);
 | 
|---|
 | 123 |   void FromMean(void);
 | 
|---|
 | 124 |   int_4 NMean(void) {return mMean;}
 | 
|---|
 | 125 |   void SetMean(int_4 nmean) {mMean = nmean;}
 | 
|---|
| [2604] | 126 | 
 | 
|---|
| [3147] | 127 |   //! Replace the errors by the variance
 | 
|---|
 | 128 |   void ToVariance(void);
 | 
|---|
 | 129 |   void FromVariance(void);
 | 
|---|
 | 130 | 
 | 
|---|
| [2628] | 131 |   //! Fill an histogram with an histogram
 | 
|---|
 | 132 |   void FillFrHErr(HistoErr& hfrom);
 | 
|---|
 | 133 | 
 | 
|---|
| [3123] | 134 |   //! Recuperation des matrices elementaires
 | 
|---|
| [3136] | 135 |   void GetData(TVector<r_8>& data) {data = data_;}
 | 
|---|
 | 136 |   void GetError2(TVector<r_8>& err2) {err2 = err2_;}
 | 
|---|
 | 137 |   void GetNData(TVector<r_8>& ndata) {ndata = ndata_;}
 | 
|---|
| [3123] | 138 | 
 | 
|---|
| [3198] | 139 |   //! Recuperation d'information
 | 
|---|
 | 140 |   double Sum(void);
 | 
|---|
 | 141 |   double Sum2(void);
 | 
|---|
 | 142 |   double SumN(void);
 | 
|---|
 | 143 | 
 | 
|---|
| [2619] | 144 |   // Operators
 | 
|---|
 | 145 |   HistoErr& operator = (const HistoErr& h);
 | 
|---|
| [3136] | 146 |   HistoErr& operator *= (r_8 b);
 | 
|---|
| [2619] | 147 | 
 | 
|---|
| [3053] | 148 |   // Print
 | 
|---|
| [3136] | 149 |   void Show(ostream& os) const;
 | 
|---|
 | 150 |   void Show() const { Show(cout); }
 | 
|---|
| [3053] | 151 | 
 | 
|---|
| [3156] | 152 |   // Write ASCII
 | 
|---|
 | 153 |   int WriteASCII(string fname);
 | 
|---|
 | 154 |   int ReadASCII(string fname);
 | 
|---|
 | 155 | 
 | 
|---|
| [2603] | 156 | protected:
 | 
|---|
| [3123] | 157 |   void CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx);
 | 
|---|
| [2619] | 158 | 
 | 
|---|
| [3123] | 159 |   r_4 xmin_,xmax_,dx_;
 | 
|---|
 | 160 |   int_4 nx_;
 | 
|---|
 | 161 |   TVector<r_8> data_;
 | 
|---|
 | 162 |   TVector<r_8> err2_;
 | 
|---|
 | 163 |   TVector<r_8> ndata_;
 | 
|---|
| [3147] | 164 |   int_4 mMean;  //!< Nombre d'appels a ToMean/Variance(+1) ou FromMean/Variance(-1)
 | 
|---|
| [2603] | 165 | };
 | 
|---|
 | 166 | 
 | 
|---|
| [3053] | 167 | /*! Prints histogram information on stream \b s (h.Show(s)) */
 | 
|---|
 | 168 | inline ostream& operator << (ostream& s, HistoErr const & h)
 | 
|---|
 | 169 |   {  h.Show(s);  return(s);  }
 | 
|---|
 | 170 | 
 | 
|---|
| [2603] | 171 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
 | 
|---|
 | 172 |   \brief Persistance management */
 | 
|---|
 | 173 | inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
 | 
|---|
 | 174 | { ObjFileIO<HistoErr> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
 | 175 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
 | 
|---|
 | 176 |   \brief Persistance management */
 | 
|---|
 | 177 | inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
 | 
|---|
 | 178 | { ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | } // Fin du namespace
 | 
|---|
 | 181 | 
 | 
|---|
 | 182 | #endif // HISTERR_SEEN
 | 
|---|