CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Data1D_collection.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2014 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 
33 #ifndef __DATA1DC__
34 #define __DATA1DC__
35 
36 #include "Data1D.h"
37 
38 namespace cbl {
39 
40  namespace data {
41 
50  class Data1D_collection : public Data
51  {
52  protected:
53 
58 
61 
63  std::vector<int> m_xsize;
64 
66  std::vector<std::vector<double>> m_x;
67 
69  std::vector<std::vector<int>> m_index;
70 
72 
73  public:
74 
79 
86 
96  Data1D_collection (const std::string input_file, const int skip_header=0);
97 
108  Data1D_collection (const std::vector<std::string> input_files, const int skip_header=0);
109 
120  Data1D_collection (const std::vector<std::vector<double>> xx, const std::vector<std::vector<double>> data);
121 
135  Data1D_collection (const std::vector<std::vector<double>> xx, const std::vector<std::vector<double>> data, const std::vector<std::vector<double>> covariance);
136 
150  Data1D_collection (const std::vector<std::vector<double>> xx, const std::vector<double> data, const std::vector<double> error);
151 
165  Data1D_collection (const std::vector<std::vector<double>> xx, const std::vector<double> data, const std::vector<std::vector<double>> covariance);
166 
170  virtual ~Data1D_collection () = default;
171 
178  std::shared_ptr<Data> as_factory () { return move(std::unique_ptr<Data1D_collection>(this)); }
179 
181 
182 
187 
188  int xsize (const int i) const
189  { return m_xsize[i]; }
190 
200  double xx (const int i, const int j) const { return m_x[i][j]; }
201 
207  void xx (std::vector<std::vector<double> > x) const { x = m_x; }
208 
219  std::vector<std::vector<double>> IndipendentVariable(const int i=-1, const int j=-1) const {(void)i; (void)j; return m_x;}
220 
230  double data (const int i, const int j) const {return m_data[m_index[i][j]];}
231 
237  void data (std::vector<std::vector<double>> &data) const;
238 
248  double error (const int i, const int j) const { return m_error[m_index[i][j]]; }
249 
255  void error (std::vector<std::vector<double>> &error) const;
256 
258 
263 
271  void set_xx (const int i, const std::vector<double> x) { m_x[i] = x; }
272 
274 
279 
284  int ndataset () const { return m_ndataset; }
285 
325  void read (const std::string input_file, const int skip_nlines=0, const std::vector<int> column={1}, const std::vector<int> column_data={}, const std::vector<int> column_errors={}, const std::vector<int> column_edges={}) override;
326 
366  void read (const std::vector<std::string> input_files, const int skip_nlines=0, const std::vector<int> column={1}, const std::vector<int> column_data={}, const std::vector<int> column_errors={}, const std::vector<int> column_edges={}) override;
367 
373  virtual void Print (const int precision=4) const override;
374 
391  void write (const std::string dir, const std::string file, const std::string header, const int prec=4, const int ww=8, const int rank=0) const override;
392 
409  void write (const std::string dir, const std::vector<std::string> files, const std::string header, const int precision=10, const int ww=8, const int rank=0) const override;
410 
420  void write_covariance (const std::string dir, const std::string file, const int precision=10) const override;
421 
423 
429 
437  std::shared_ptr<Data> cut(const int dataset, const double xmin, const double xmax) const override;
438 
445  std::shared_ptr<Data> cut(const std::vector<double> xmin, const std::vector<double> xmax) const override;
446 
448 
449  };
450 
451  }
452 }
453 
454 #endif
The class Data1D.
The class Data1D_collection.
double error(const int i, const int j) const
get value of f(x) error at index i,j
std::vector< int > m_xsize
vector containing the number of data in each dataset
virtual void Print(const int precision=4) const override
print the data on screen
virtual ~Data1D_collection()=default
default destructor
std::vector< std::vector< double > > IndipendentVariable(const int i=-1, const int j=-1) const
get the independet variable, to be used in model computation
std::shared_ptr< Data > cut(const int dataset, const double xmin, const double xmax) const override
cut the data, for Data1D_collection
double xx(const int i, const int j) const
get value of x at index j in the i-th dataset
int m_ndataset
The number of datasets.
void xx(std::vector< std::vector< double > > x) const
get x values
double data(const int i, const int j) const
get data at index i,j
int xsize(const int i) const
get the number of points along x
std::vector< std::vector< double > > m_x
vector containing indipendent variables
void write(const std::string dir, const std::string file, const std::string header, const int prec=4, const int ww=8, const int rank=0) const override
write the data
std::vector< std::vector< int > > m_index
vector containing matrix-to-vector indexes
int ndataset() const
function that returns total number of datasets
void set_xx(const int i, const std::vector< double > x)
set interval variable m_x in the i-th dataset
Data1D_collection()
default constructor
void write_covariance(const std::string dir, const std::string file, const int precision=10) const override
write the interval variable m_covariance on a file,
std::shared_ptr< Data > as_factory()
static factory used to construct objects of class Data1D
void read(const std::string input_file, const int skip_nlines=0, const std::vector< int > column={1}, const std::vector< int > column_data={}, const std::vector< int > column_errors={}, const std::vector< int > column_edges={}) override
read the data
The class Data.
Definition: Data.h:89
void set_dataType(const DataType dataType)
set the data type
Definition: Data.h:121
virtual std::vector< double > xx() const
get the x std::vector
Definition: Data.h:299
virtual std::vector< double > data() const
get data
Definition: Data.h:376
std::vector< double > m_error
standard deviations
Definition: Data.h:103
std::vector< double > m_data
data values
Definition: Data.h:100
virtual std::vector< double > error() const
get standard deviation
Definition: Data.h:389
virtual std::vector< std::vector< double > > covariance() const
get the m_covariance vector
Definition: Data.h:403
@ _1D_collection_
collection of 1D datasets
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38