CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Histogram.h
Go to the documentation of this file.
1 /*******************************************************************
2  * Copyright (C) 2010 by Federico Marulli and Alfonso Veropalumbo *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful,*
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  *******************************************************************/
20 
31 #ifndef __HIST__
32 #define __HIST__
33 
34 
35 #include "Kernel.h"
36 
37 
38 // =====================================================================================
39 
40 
41 namespace cbl {
42 
43  namespace glob {
44 
49  enum class HistogramType {
50 
52  _N_V_,
53 
55  _n_V_,
56 
58  _dn_dV_,
59 
61  _dn_dlogV_,
62 
64  _dn_dlnV_
65 
66  };
67 
74  inline std::vector<std::string> HistogramTypeNames ()
75  { return {"dn_dV", "dn_dlogV", "dn_dlnV", "N_V", "n_V"}; }
76 
83  inline HistogramType HistogramTypeCast (const int histogramTypeIndex)
84  { return castFromValue<HistogramType>(histogramTypeIndex); }
85 
92  inline HistogramType HistogramTypeCast (const std::string histogramTypeName)
93  { return castFromName<HistogramType>(histogramTypeName, HistogramTypeNames()); }
94 
101  inline std::vector<HistogramType> HistogramTypeCast (const std::vector<int> histogramTypeIndeces)
102  { return castFromValues<HistogramType>(histogramTypeIndeces); }
103 
110  inline std::vector<HistogramType> HistogramTypeCast (const std::vector<std::string> histogramTypeNames)
111  { return castFromNames<HistogramType>(histogramTypeNames, HistogramTypeNames()); }
112 
113 
118  class Histogram
119  {
120  public:
121 
125  Histogram () = default;
126 
131  ~Histogram () = default;
132 
137 
148  virtual void set (const size_t nbins, const double minVar=par::defaultDouble, const double maxVar=par::defaultDouble, const double shift=0.5, const BinType bin_type=BinType::_linear_, const std::vector<double> vec_edges={})
149  { (void)nbins; (void)minVar; (void)maxVar; (void)shift; (void)bin_type; (void)vec_edges; ErrorCBL("", "set", "Histogram.h"); }
150 
158  virtual int digitize (const double var)
159  { (void)var; return ErrorCBL("", "digitize", "Histogram.h"); }
160 
168  virtual std::vector<int> digitize (const std::vector<double> var)
169  { (void)var; ErrorCBL("", "digitize", "Histogram.h"); std::vector<int> vv; return vv; }
170 
178  virtual void put (const double var, const double weight)
179  { (void)var; (void)weight; ErrorCBL("", "put", "Histogram.h"); }
180 
188  virtual void put (const std::vector<double> var, const std::vector<double> weight)
189  { (void)var; (void)weight; ErrorCBL("", "put", "Histogram.h"); }
190 
200  virtual void put (const int bin, const double weight, const double var)
201  { (void)bin; (void)weight; (void)var; ErrorCBL("", "put", "Histogram.h"); }
202 
212  virtual void put (const std::vector<int> bins, const std::vector<double> weight, const std::vector<double> var)
213  { (void)bins; (void)weight; (void)var; ErrorCBL("", "put", "Histogram.h"); }
214 
233  virtual void set (const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_, const std::vector<double> vec_edges1={}, const std::vector<double> vec_edges2={})
234  { (void)nbins1; (void)minVar1; (void)maxVar1; (void)nbins2; (void)minVar2; (void)maxVar2; (void)shift1; (void)shift2; (void)bin_type1; (void)bin_type2; (void)vec_edges1; (void)vec_edges2; ErrorCBL("", "set", "Histogram.h"); }
235 
244  virtual std::vector<int> digitize (const double var1, const double var2)
245  { (void)var1; (void)var2; ErrorCBL("", "digitize", "Histogram.h"); std::vector<int> vv; return vv; }
246 
255  virtual std::vector<std::vector<int>> digitize (const std::vector<double> var1, const std::vector<double> var2)
256  { (void)var1; (void)var2; ErrorCBL("", "digitize", "Histogram.h"); std::vector<std::vector<int>> vv; return vv; }
257 
267  virtual void put (const double var1, const double var2, const double weight)
268  { (void)var1; (void)var2; (void)weight; ErrorCBL("", "put", "Histogram.h"); }
269 
279  virtual void put (const std::vector<double> var1, const std::vector<double> var2, const std::vector<double> weight)
280  { (void)var1; (void)var2; (void)weight; ErrorCBL("", "put", "Histogram.h"); }
281 
295  virtual void put (const int bin1, const int bin2, const double weight, const double var1, const double var2)
296  { (void)bin1; (void)bin2; (void)weight; (void)var1; (void)var2; ErrorCBL("", "put", "Histogram.h"); }
297 
309  virtual void put (const std::vector<std::vector<int>> bins, const std::vector<double> weight, const std::vector<double> var1, const std::vector<double> var2)
310  { (void)bins; (void)weight; (void)var1; (void)var2; ErrorCBL("", "put", "Histogram.h"); }
311 
313 
318 
325  virtual size_t nbins () const
326  { ErrorCBL("", "nbins", "Histogram.h"); return 1; }
327 
333  virtual double binSize () const
334  { ErrorCBL("", "binSize", "Histogram.h"); return 0.; }
335 
342  virtual double minVar() const
343  { ErrorCBL("", "minVar", "Histogram.h"); return 0.; }
344 
351  virtual double maxVar() const
352  { ErrorCBL("", "maxVar", "Histogram.h"); return 0.; }
353 
359  virtual double shift() const
360  { ErrorCBL("", "shift", "Histogram.h"); return 0.; }
361 
367  virtual BinType bin_type() const
368  { ErrorCBL("", "bin_type", "Histogram.h"); return BinType::_linear_; }
369 
377  virtual double bin (const size_t i) const
378  {(void)i; ErrorCBL("", "bin", "Histogram.h"); return 0.; }
379 
385  virtual std::vector<double> bins () const
386  { ErrorCBL("", "bins", "Histogram.h"); std::vector<double> vv; return vv; }
387 
393  virtual std::vector<double> averaged_bins () const
394  { ErrorCBL("", "averaged_bins", "Histogram.h"); std::vector<double> vv; return vv; }
395 
401  virtual std::vector<double> error_bins () const
402  { ErrorCBL("", "error_bins", "Histogram.h"); std::vector<double> vv; return vv; }
403 
411  virtual double edge (const size_t i) const
412  { (void)i; ErrorCBL("", "edge", "Histogram.h"); return 0.; }
413 
419  virtual std::vector<double> edges () const
420  { ErrorCBL("", "edges", "Histogram.h"); std::vector<double> vv; return vv; }
421 
428  virtual size_t nbins1 () const
429  { ErrorCBL("", "nbins1", "Histogram.h"); return 1; }
430 
436  virtual double binSize1 () const
437  { ErrorCBL("", "binSize1", "Histogram.h"); return 1.; }
438 
446  virtual double minVar1() const
447  { ErrorCBL("", "minVar1", "Histogram.h"); return 1.; }
448 
456  virtual double maxVar1() const
457  { ErrorCBL("", "maxVar1", "Histogram.h"); return 1.; }
458 
465  virtual double shift1() const
466  { ErrorCBL("", "shift1", "Histogram.h"); return 1.; }
467 
474  virtual BinType bin_type1() const
475  { ErrorCBL("", "bin_type1", "Histogram.h"); return BinType::_linear_; }
476 
483  virtual size_t nbins2 () const
484  { ErrorCBL("", "bins2", "Histogram.h"); return 1; }
485 
491  virtual double binSize2 () const
492  { ErrorCBL("", "binSize2", "Histogram.h"); return 1.; }
493 
501  virtual double minVar2() const
502  { ErrorCBL("", "minVar2", "Histogram.h"); return 1.; }
503 
511  virtual double maxVar2() const
512  { ErrorCBL("", "maxVar2", "Histogram.h"); return 1.; }
513 
520  virtual double shift2() const
521  { ErrorCBL("", "shift2", "Histogram.h"); return 1.; }
522 
529  virtual BinType bin_type2() const
530  { ErrorCBL("", "bin_type2", "Histogram.h"); return BinType::_linear_; }
531 
539  virtual double bin1 (const size_t i) const
540  { (void)i; ErrorCBL("", "bin1", "Histogram.h"); return 0.; }
541 
547  virtual std::vector<double> bins1 () const
548  { ErrorCBL("", "bins1", "Histogram.h"); std::vector<double> vv; return vv; }
549 
555  virtual std::vector<std::vector<double>> averaged_bins1 () const
556  { ErrorCBL("", "averaged_bins1", "Histogram.h"); std::vector<std::vector<double>> vv; return vv; }
557 
563  virtual std::vector<std::vector<double>> error_bins1 () const
564  { ErrorCBL("", "error_bins1", "Histogram.h"); std::vector<std::vector<double>> vv; return vv; }
565 
573  virtual double edge1 (const size_t i) const
574  { (void)i; ErrorCBL("", "edge1", "Histogram.h"); return 0.; }
575 
581  virtual std::vector<double> edges1 () const
582  { ErrorCBL("", "edges1", "Histogram.h"); std::vector<double> vv; return vv; }
583 
591  virtual double bin2 (const size_t i) const
592  { (void)i; ErrorCBL("", "bin2", "Histogram.h"); return 0.; }
593 
599  virtual std::vector<double> bins2 () const
600  { ErrorCBL("", "bins2", "Histogram.h"); std::vector<double> vv; return vv; }
601 
607  virtual std::vector<std::vector<double>> averaged_bins2 () const
608  { ErrorCBL("", "averaged_bins2", "Histogram.h"); std::vector<std::vector<double>> vv; return vv; }
609 
615  virtual std::vector<std::vector<double>> error_bins2 () const
616  { ErrorCBL("", "error_bins2", "Histogram.h"); std::vector<std::vector<double>> vv; return vv; }
617 
625  virtual double edge2 (const size_t i) const
626  { (void)i; ErrorCBL("", "edge2", "Histogram.h"); return 0.; }
627 
633  virtual std::vector<double> edges2 () const
634  { ErrorCBL("", "edges2", "Histogram.h"); std::vector<double> vv; return vv; }
635 
648  virtual double operator() ( const int i, const HistogramType hist_type, const double fact=1.) const
649  { (void)i; (void)hist_type; (void)fact; ErrorCBL("", "operator ()", "Histogram.h"); return 0.; }
650 
665  virtual double operator() ( const int i, const int j, const HistogramType hist_type, const double fact=1.) const
666  { (void)i; (void)j; (void)hist_type; (void)fact; ErrorCBL("", "operator()", "Histogram.h"); return 0.; }
667 
668 
679  virtual std::vector<double> operator() (const HistogramType hist_type, const double fact=1.) const
680  { (void)hist_type; (void)fact; ErrorCBL("", "operator ()", "Histogram.h"); std::vector<double> vv; return vv; }
681 
694  virtual double normalization (const int i, const HistogramType hist_type, const double fact=1.) const
695  { (void)i; (void)hist_type; (void)fact; ErrorCBL("", "normalization", "Histogram.h"); return 0.; }
696 
711  virtual double normalization (const int i, const int j, const HistogramType hist_type, const double fact=1.) const
712  { (void)i; (void)j; (void)hist_type; (void)fact; ErrorCBL("", "normalization", "Histogram.h"); return 0.; }
713 
721  virtual int unweighted_counts (const int i) const
722  { (void)i; ErrorCBL("", "counts", "Histogram.h"); return 0; }
723 
729  virtual std::vector<int> unweighted_counts () const
730  { ErrorCBL("", "weights", "Histogram.h"); std::vector<int> vv; return vv; }
731 
741  virtual int unweighted_counts (const int i, const int j) const
742  { (void)i; (void)j; ErrorCBL("", "weight", "Histogram.h"); return 0.; }
743 
757  virtual double error ( const int i, const HistogramType hist_type, const double fact=1.) const
758  { (void)i; (void)hist_type; (void)fact; ErrorCBL("", "error", "Histogram.h"); return 0.; }
759 
775  virtual double error ( const int i, const int j, const HistogramType hist_type, const double fact=1.) const
776  { (void)i; (void)j; (void)hist_type; (void)fact; ErrorCBL("", "error", "Histogram.h"); return 0.; }
777 
778 
790  virtual std::vector<double> error (const HistogramType hist_type, const double fact=1.) const
791  { (void)hist_type; (void)fact; ErrorCBL("", "error", "Histogram.h"); std::vector<double> vv; return vv; }
792 
794 
799 
812  virtual void write (const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const
813  { (void)dir; (void)file; (void)hist_type; (void)fact; ErrorCBL("", "write", "Histogram.h"); }
814 
816 
817  };
818 
826  class Histogram1D : public Histogram
827  {
828 
829  private:
830 
832  std::shared_ptr<gsl_histogram> m_histo;
833 
835  std::shared_ptr<gsl_histogram> m_histo_error;
836 
838  std::vector<int> m_counts;
839 
841  std::vector<double> m_var;
842 
844  std::vector<double> m_var_err;
845 
847  std::vector<double> m_bins;
848 
850  std::vector<double> m_edges;
851 
853  size_t m_nbins;
854 
856  double m_binSize;
857 
859  double m_shift;
860 
862  double m_minVar;
863 
865  double m_maxVar;
866 
868  BinType m_binType;
869 
870  public:
871 
876 
880  Histogram1D () = default;
881 
899  Histogram1D (const std::vector<double> var, const std::vector<double> weight, const size_t nbins, const double minVar=par::defaultDouble, const double maxVar=par::defaultDouble, const double shift = 0.5, const BinType bin_type=BinType::_linear_);
900 
905  ~Histogram1D () = default;
906 
908 
913 
926  void set (const size_t nbins, const double minVar=par::defaultDouble, const double maxVar=par::defaultDouble, const double shift=0.5, const BinType bin_type=BinType::_linear_, const std::vector<double> vec_edges={}) override;
927 
935  int digitize (const double var) override;
936 
944  std::vector<int> digitize (const std::vector<double> var) override;
945 
955  void put (const double var, const double weight) override;
956 
966  void put (const std::vector<double> var, const std::vector<double> weight) override;
967 
979  void put (const int bin, const double weight, const double var) override;
980 
992  void put (const std::vector<int> bin, const std::vector<double> weight, const std::vector<double> var) override;
993 
995 
1000 
1007  size_t nbins () const override { return m_nbins; }
1008 
1014  double binSize () const override { return m_binSize; }
1015 
1022  double minVar() const override { return m_minVar; }
1023 
1030  double maxVar() const override { return m_maxVar; }
1031 
1037  double shift() const override { return m_shift; }
1038 
1044  BinType bin_type() const override { return m_binType; }
1045 
1053  double bin (const size_t i) const override { return m_bins[i]; }
1054 
1060  std::vector<double> bins () const override { return m_bins; }
1061 
1067  std::vector<double> averaged_bins () const { return m_var;}
1068 
1074  std::vector<double> error_bins () const;
1075 
1083  double edge (const size_t i) const override { return m_edges[i]; }
1084 
1090  std::vector<double> edges () const override { return m_edges; }
1091 
1104  double normalization (const int i, const HistogramType hist_type, const double fact=1.) const override;
1105 
1113  int unweighted_counts (const int i) const override { return m_counts[i]; }
1114 
1120  std::vector<int> unweighted_counts () const override { return m_counts; }
1121 
1134  double operator() ( const int i, const HistogramType hist_type, const double fact=1.) const override;
1135 
1146  std::vector<double> operator() ( const HistogramType hist_type, const double fact=1.) const override;
1147 
1160  double error ( const int i, const HistogramType hist_type, const double fact=1.) const override;
1161 
1173  std::vector<double> error ( const HistogramType hist_type, const double fact=1.) const override;
1174 
1176 
1181 
1196  void write (const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const override;
1197 
1199 
1200  };
1201 
1209  class Histogram2D : public Histogram
1210  {
1211  private:
1212 
1214  std::shared_ptr<gsl_histogram2d> m_histo;
1215 
1217  std::shared_ptr<gsl_histogram2d> m_histo_error;
1218 
1220  std::vector<std::vector<int>> m_counts;
1221 
1223  std::vector<std::vector<double>> m_var1;
1224 
1226  std::vector<std::vector<double>> m_var1_err;
1227 
1229  std::vector<std::vector<double>> m_var2;
1230 
1232  std::vector<std::vector<double>> m_var2_err;
1233 
1235  std::vector<double> m_bins1;
1236 
1238  std::vector<double> m_edges1;
1239 
1241  size_t m_nbins1;
1242 
1244  double m_binSize1;
1245 
1247  double m_shift1;
1248 
1250  double m_minVar1;
1251 
1253  double m_maxVar1;
1254 
1257 
1259  std::vector<double> m_bins2;
1260 
1262  std::vector<double> m_edges2;
1263 
1265  size_t m_nbins2;
1266 
1268  double m_binSize2;
1269 
1271  double m_shift2;
1272 
1274  double m_minVar2;
1275 
1277  double m_maxVar2;
1278 
1281 
1282  public:
1283 
1288 
1292  Histogram2D () = default;
1293 
1323  Histogram2D (const std::vector<double> var1, const std::vector<double> var2, const std::vector<double> weight, const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_);
1324 
1329  ~Histogram2D () = default;
1330 
1332 
1337 
1366  void set (const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_, const std::vector<double> vec_edges1={}, const std::vector<double> vec_edges2={}) override;
1367 
1376  std::vector<int> digitize (const double var1, const double var2) override;
1377 
1386  std::vector<std::vector<int>> digitize (const std::vector<double> var1, const std::vector<double> var2) override;
1387 
1399  void put (const double var1, const double var2, const double weight) override;
1400 
1412  void put (const std::vector<double> var1, const std::vector<double> var2, const std::vector<double> weight) override;
1413 
1429  void put (const int bin1, const int bin2, const double weight, const double var1, const double var2) override;
1430 
1445  void put (const std::vector<std::vector<int>> bins, const std::vector<double> weight, const std::vector<double> var1, const std::vector<double> var2) override;
1446 
1448 
1453 
1460  size_t nbins1 () const override { return m_nbins1; }
1461 
1468  double binSize1 () const override { return m_binSize1; }
1469 
1477  double minVar1 () const override { return m_minVar1; }
1478 
1486  double maxVar1 () const override { return m_maxVar1; }
1487 
1494  double shift1 () const override { return m_shift1; }
1495 
1502  BinType bin_type1 () const override { return m_binType1; }
1503 
1510  size_t nbins2 () const override { return m_nbins2; }
1511 
1518  double binSize2 () const override { return m_binSize2; }
1519 
1527  double minVar2 () const override { return m_minVar2; }
1528 
1536  double maxVar2 () const override { return m_maxVar2; }
1537 
1544  double shift2 () const override { return m_shift2; }
1545 
1552  BinType bin_type2 () const override { return m_binType2; }
1553 
1561  double bin1 (const size_t i) const override { return m_bins1[i]; }
1562 
1568  std::vector<double> bins1 () const override { return m_bins1; }
1569 
1575  std::vector<std::vector<double>> averaged_bins1 () const { return m_var1; }
1576 
1582  std::vector<std::vector<double>> averaged_bins2 () const { return m_var2; }
1583 
1589  std::vector<std::vector<double>> error_bins1 () const;
1590 
1596  std::vector<std::vector<double>> error_bins2 () const;
1597 
1605  double edge1 (const size_t i) const override { return m_edges1[i]; }
1606 
1612  std::vector<double> edges1 () const override { return m_edges1; }
1613 
1621  double bin2 (const size_t i) const override { return m_bins2[i]; }
1622 
1628  std::vector<double> bins2 () const override { return m_bins2; }
1629 
1637  double edge2 (const size_t i) const override { return m_edges2[i]; }
1638 
1644  std::vector<double> edges2 () const override { return m_edges2; }
1645 
1660  double normalization (const int i, const int j, const HistogramType hist_type, const double fact=1.) const override;
1661 
1671  int unweighted_counts (const int i, const int j) const override { return m_counts[i][j]; }
1672 
1687  double operator() ( const int i, const int j, const HistogramType hist_type, const double fact=1.) const override;
1688 
1704  double error (const int i, const int j, const HistogramType hist_type, const double fact=1.) const override;
1705 
1707 
1712 
1727  void write (const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const override;
1728 
1730 
1731  };
1732 
1733  }
1734 }
1735 
1736 #endif
Useful generic functions.
The class Histogram2D.
Definition: Histogram.h:1210
double bin1(const size_t i) const override
return the i-th bin of the first variable
Definition: Histogram.h:1561
double m_minVar1
minimum first variable value
Definition: Histogram.h:1250
double normalization(const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
return the bin normalization
Definition: Histogram.cpp:544
std::vector< std::vector< double > > m_var1
bin-weighted first variable
Definition: Histogram.h:1223
BinType m_binType1
first variable bin type
Definition: Histogram.h:1256
double shift2() const override
return the bin shift for the second variable
Definition: Histogram.h:1544
std::vector< std::vector< double > > averaged_bins2() const
return the averaged bins
Definition: Histogram.h:1582
std::vector< double > m_edges1
first variable edges
Definition: Histogram.h:1238
std::vector< std::vector< int > > m_counts
histogram weights
Definition: Histogram.h:1220
Histogram2D()=default
default constructor
double m_binSize1
the binSize for the first variable
Definition: Histogram.h:1244
BinType m_binType2
second variable bin type
Definition: Histogram.h:1280
std::shared_ptr< gsl_histogram2d > m_histo_error
GSL histogram error.
Definition: Histogram.h:1217
std::vector< std::vector< double > > m_var1_err
bin-weighted first variable error
Definition: Histogram.h:1226
double shift1() const override
return the bin shift for the first variable
Definition: Histogram.h:1494
double m_shift2
the bin shift for the second variable
Definition: Histogram.h:1271
double maxVar2() const override
return the upper limit of the histogram for the second variable
Definition: Histogram.h:1536
std::vector< std::vector< double > > m_var2
bin-weighted second variable
Definition: Histogram.h:1229
double minVar2() const override
return the lower limit of the histogram for the second variable
Definition: Histogram.h:1527
~Histogram2D()=default
default destructor
std::shared_ptr< gsl_histogram2d > m_histo
GSL histogram.
Definition: Histogram.h:1214
std::vector< std::vector< double > > m_var2_err
bin-weighted second variable error
Definition: Histogram.h:1232
double m_binSize2
the binSize for the second variable
Definition: Histogram.h:1268
std::vector< double > edges2() const override
return the histogram edges of the second variable
Definition: Histogram.h:1644
size_t m_nbins2
the number of bins
Definition: Histogram.h:1265
size_t nbins2() const override
return the number of bins for the second variable
Definition: Histogram.h:1510
std::vector< std::vector< double > > error_bins1() const
return the averaged bins
Definition: Histogram.cpp:590
std::vector< int > digitize(const double var1, const double var2) override
get the histogram index
Definition: Histogram.cpp:460
std::vector< double > m_edges2
variable edges
Definition: Histogram.h:1262
std::vector< double > edges1() const override
return the histogram edges of the first variable
Definition: Histogram.h:1612
double m_maxVar2
maximum second variable value
Definition: Histogram.h:1277
std::vector< double > bins1() const override
return the first variable bins
Definition: Histogram.h:1568
std::vector< std::vector< double > > error_bins2() const
return the averaged bins
Definition: Histogram.cpp:603
void write(const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const override
write the histogram
Definition: Histogram.cpp:625
std::vector< double > m_bins1
first variable bins
Definition: Histogram.h:1235
double m_minVar2
minimum second variable value
Definition: Histogram.h:1274
double binSize2() const override
return the bin size for the second variable
Definition: Histogram.h:1518
int unweighted_counts(const int i, const int j) const override
return the bin unweighted counts
Definition: Histogram.h:1671
double edge2(const size_t i) const override
return the i-th edge of the second variable
Definition: Histogram.h:1637
void set(const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_, const std::vector< double > vec_edges1={}, const std::vector< double > vec_edges2={}) override
set the histogram variables
Definition: Histogram.cpp:337
double m_maxVar1
maximum first variable value
Definition: Histogram.h:1253
std::vector< std::vector< double > > averaged_bins1() const
return the averaged bins
Definition: Histogram.h:1575
void put(const double var1, const double var2, const double weight) override
bin the data
Definition: Histogram.cpp:488
double bin2(const size_t i) const override
return the i-th bin of the second variable
Definition: Histogram.h:1621
double minVar1() const override
return the lower limit of the histogram for the first variable
Definition: Histogram.h:1477
BinType bin_type1() const override
return the bin type for the first variable
Definition: Histogram.h:1502
double maxVar1() const override
return the upper limit of the histogram for the first variable
Definition: Histogram.h:1486
size_t m_nbins1
the number of bins for the first variable
Definition: Histogram.h:1241
BinType bin_type2() const override
return the bin type for the second variable
Definition: Histogram.h:1552
std::vector< double > bins2() const override
return the second variable bins
Definition: Histogram.h:1628
double m_shift1
the bin shift for the first variable
Definition: Histogram.h:1247
double error(const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
return the poisson error of the histogram at (i,j)
Definition: Histogram.cpp:616
std::vector< double > m_bins2
variable bins
Definition: Histogram.h:1259
size_t nbins1() const override
return the number of bins for the first variable
Definition: Histogram.h:1460
double edge1(const size_t i) const override
return the i-th edge of the first variable
Definition: Histogram.h:1605
double operator()(const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
return the histogram at (i,j)
Definition: Histogram.cpp:581
double binSize1() const override
return the bin size for the first variable
Definition: Histogram.h:1468
The class Histogram.
Definition: Histogram.h:119
virtual double normalization(const int i, const int j, const HistogramType hist_type, const double fact=1.) const
return the bin normalization
Definition: Histogram.h:711
virtual void put(const std::vector< double > var, const std::vector< double > weight)
bin the data
Definition: Histogram.h:188
virtual std::vector< std::vector< double > > averaged_bins2() const
return the second variable averaged bins
Definition: Histogram.h:607
virtual void put(const std::vector< double > var1, const std::vector< double > var2, const std::vector< double > weight)
bin the data
Definition: Histogram.h:279
virtual BinType bin_type2() const
return the bin type for the second variable
Definition: Histogram.h:529
virtual double edge(const size_t i) const
return the i-th edge
Definition: Histogram.h:411
virtual int unweighted_counts(const int i, const int j) const
return the unweighted bin counts
Definition: Histogram.h:741
virtual double shift2() const
return the bin shift for the second variable
Definition: Histogram.h:520
virtual size_t nbins2() const
return the number of bins for the second variable
Definition: Histogram.h:483
virtual void put(const std::vector< std::vector< int >> bins, const std::vector< double > weight, const std::vector< double > var1, const std::vector< double > var2)
bin the data
Definition: Histogram.h:309
virtual double minVar() const
return the lower limit of the histogram
Definition: Histogram.h:342
virtual double maxVar() const
return the upper limit of the histogram
Definition: Histogram.h:351
virtual int digitize(const double var)
get the histogram index
Definition: Histogram.h:158
virtual size_t nbins1() const
return the number of bins for the first variable
Definition: Histogram.h:428
virtual std::vector< double > averaged_bins() const
return the averaged bins
Definition: Histogram.h:393
virtual double maxVar2() const
return the upper limit of the histogram for the second variable
Definition: Histogram.h:511
virtual void write(const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const
write the histogram
Definition: Histogram.h:812
~Histogram()=default
default destructor
virtual double bin1(const size_t i) const
return the i-th bin of the first variable
Definition: Histogram.h:539
virtual double operator()(const int i, const HistogramType hist_type, const double fact=1.) const
return the histogram
Definition: Histogram.h:648
virtual double binSize2() const
return the second variable bin size
Definition: Histogram.h:491
virtual double error(const int i, const int j, const HistogramType hist_type, const double fact=1.) const
return the error of the histogram at (i,j)
Definition: Histogram.h:775
virtual std::vector< double > bins2() const
return the second variable bins
Definition: Histogram.h:599
virtual std::vector< int > unweighted_counts() const
return the weights
Definition: Histogram.h:729
virtual double shift() const
return the bin shift
Definition: Histogram.h:359
virtual double normalization(const int i, const HistogramType hist_type, const double fact=1.) const
return the bin normalization
Definition: Histogram.h:694
virtual std::vector< double > error(const HistogramType hist_type, const double fact=1.) const
return the error of the histogram
Definition: Histogram.h:790
virtual double minVar1() const
return the lower limit of the histogram for the first variable
Definition: Histogram.h:446
virtual std::vector< std::vector< int > > digitize(const std::vector< double > var1, const std::vector< double > var2)
get the histogram indeces
Definition: Histogram.h:255
virtual void put(const int bin, const double weight, const double var)
bin the data
Definition: Histogram.h:200
virtual double binSize1() const
return the first variable bin size
Definition: Histogram.h:436
virtual void put(const double var1, const double var2, const double weight)
bin the data
Definition: Histogram.h:267
virtual std::vector< double > bins1() const
return the first variable bins
Definition: Histogram.h:547
virtual std::vector< double > error_bins() const
return the bin errors
Definition: Histogram.h:401
virtual int unweighted_counts(const int i) const
return the unweighted bin counts
Definition: Histogram.h:721
virtual std::vector< double > edges() const
return the histogram edges
Definition: Histogram.h:419
virtual std::vector< std::vector< double > > averaged_bins1() const
return the first variable averaged bins
Definition: Histogram.h:555
virtual void put(const double var, const double weight)
bin the data
Definition: Histogram.h:178
virtual std::vector< int > digitize(const double var1, const double var2)
get the histogram index
Definition: Histogram.h:244
virtual double edge1(const size_t i) const
return the i-th edge of the first variable
Definition: Histogram.h:573
Histogram()=default
default constructor
virtual double bin(const size_t i) const
return the i-th bin
Definition: Histogram.h:377
virtual std::vector< double > bins() const
return the bins
Definition: Histogram.h:385
virtual double binSize() const
return the bin size
Definition: Histogram.h:333
virtual void put(const int bin1, const int bin2, const double weight, const double var1, const double var2)
bin the data
Definition: Histogram.h:295
virtual double error(const int i, const HistogramType hist_type, const double fact=1.) const
return the poisson error of the histogram
Definition: Histogram.h:757
virtual std::vector< std::vector< double > > error_bins1() const
return the first variable averaged bin errors
Definition: Histogram.h:563
virtual double minVar2() const
return the lower limit of the histogram for the second variable
Definition: Histogram.h:501
virtual std::vector< int > digitize(const std::vector< double > var)
get the histogram indeces
Definition: Histogram.h:168
virtual std::vector< double > edges2() const
return the histogram edges of the second variable
Definition: Histogram.h:633
virtual BinType bin_type() const
return the bin type
Definition: Histogram.h:367
virtual double bin2(const size_t i) const
return the i-th bin of the second variable
Definition: Histogram.h:591
virtual void put(const std::vector< int > bins, const std::vector< double > weight, const std::vector< double > var)
bin the data
Definition: Histogram.h:212
virtual double shift1() const
return the bin shift for the first variable
Definition: Histogram.h:465
virtual void set(const size_t nbins, const double minVar=par::defaultDouble, const double maxVar=par::defaultDouble, const double shift=0.5, const BinType bin_type=BinType::_linear_, const std::vector< double > vec_edges={})
set the histogram variables
Definition: Histogram.h:148
virtual std::vector< std::vector< double > > error_bins2() const
return the second variable averaged bin errors
Definition: Histogram.h:615
virtual double maxVar1() const
return the upper limit of the histogram for the first variable
Definition: Histogram.h:456
virtual void set(const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_, const std::vector< double > vec_edges1={}, const std::vector< double > vec_edges2={})
set the histogram variables
Definition: Histogram.h:233
virtual std::vector< double > edges1() const
return the histogram edges of the first variable
Definition: Histogram.h:581
virtual double edge2(const size_t i) const
return the i-th edge of the second variable
Definition: Histogram.h:625
virtual size_t nbins() const
return the number of bins
Definition: Histogram.h:325
virtual BinType bin_type1() const
return the bin type for the first variable
Definition: Histogram.h:474
static const double defaultDouble
default double value
Definition: Constants.h:348
HistogramType HistogramTypeCast(const int histogramTypeIndex)
cast an enum of type HistogramType from its index
Definition: Histogram.h:83
HistogramType
the histogram type
Definition: Histogram.h:49
@ _n_V_
the normalised binned counts, i.e. , where the factor is a number provided in input
@ _N_V_
the binned counts,
@ _dn_dV_
, where are the bin limits
@ _dn_dlogV_
, where are the bin limits
@ _dn_dlnV_
, where are the bin limits
std::vector< std::string > HistogramTypeNames()
return a vector containing the HistogramType names
Definition: Histogram.h:74
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780
BinType
the binning type
Definition: Kernel.h:505
@ _linear_
linear binning