g4tools  5.4.0
dps
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_histo_dps
5 #define tools_histo_dps
6 
7 // data point set.
8 
9 #include <vector>
10 #include <string>
11 #include "../mnmx"
12 
13 #ifdef TOOLS_MEM
14 #include "../mem"
15 #endif
16 
17 namespace tools {
18 namespace histo {
19 
20 class measurement {
21  static const std::string& s_class() {
22  static const std::string s_v("tools::histo::measurement");
23  return s_v;
24  }
25 public:
27 #ifdef TOOLS_MEM
28  mem::increment(s_class().c_str());
29 #endif
30  }
31  measurement(double a_value,double a_error_plus,double a_error_minus)
32  :m_value(a_value)
33  ,m_error_plus(a_error_plus)
34  ,m_error_minus(a_error_minus)
35  {
36 #ifdef TOOLS_MEM
37  mem::increment(s_class().c_str());
38 #endif
39  }
40  virtual ~measurement(){
41 #ifdef TOOLS_MEM
42  mem::decrement(s_class().c_str());
43 #endif
44  }
45 public:
46  measurement(const measurement& a_from)
47  :m_value(a_from.m_value)
48  ,m_error_plus(a_from.m_error_plus)
50  {
51 #ifdef TOOLS_MEM
52  mem::increment(s_class().c_str());
53 #endif
54  }
55  measurement& operator=(const measurement& a_from) {
56  if(&a_from==this) return *this;
57  m_value = a_from.m_value;
58  m_error_plus = a_from.m_error_plus;
60  return *this;
61  }
62 public:
63  double value() const {return m_value;}
64  double error_plus() const {return m_error_plus;}
65  double error_minus() const {return m_error_minus;}
66  void set_value(double a_v) {m_value = a_v;}
67  void set_error_plus(double a_v) {m_error_plus = a_v;}
68  void set_error_minus(double a_v) {m_error_minus = a_v;}
69 protected:
70  double m_value;
71  double m_error_plus;
72  double m_error_minus;
73 };
74 
75 class data_point {
76  static const std::string& s_class() {
77  static const std::string s_v("tools::histo::data_point");
78  return s_v;
79  }
80 public:
81  data_point(unsigned int a_dim):m_measurements(a_dim){
82 #ifdef TOOLS_MEM
83  mem::increment(s_class().c_str());
84 #endif
85  }
86  virtual ~data_point() {
87 #ifdef TOOLS_MEM
88  mem::decrement(s_class().c_str());
89 #endif
90  }
91 public:
92  data_point(const data_point& a_from)
94  {
95 #ifdef TOOLS_MEM
96  mem::increment(s_class().c_str());
97 #endif
98  }
99  data_point& operator=(const data_point& a_from) {
100  if(&a_from==this) return *this;
102  return *this;
103  }
104 public: //AIDA/Idata_point
105  size_t dimension() const {return m_measurements.size();}
106  measurement& coordinate(unsigned int a_coord) {
107  //WARNING : no check done on a_coord vs m_dim.
108  return m_measurements[a_coord];
109  }
110  const measurement& coordinate(unsigned int a_coord) const {
111  //WARNING : no check done on a_coord vs m_dim.
112  return m_measurements[a_coord];
113  }
114 protected:
115  std::vector<measurement> m_measurements;
116 };
117 
118 
119 class dps {
120 public:
121  static const std::string& s_class() {
122  static const std::string s_v("tools::histo::dps");
123  return s_v;
124  }
125 public:
126  dps():m_dim(0){}
127 
128  dps(const std::string& a_title,unsigned int a_dim)
129  :m_title(a_title),m_dim(a_dim)
130  {}
131  virtual ~dps(){}
132 public:
133  dps(const dps& a_from)
134  :m_title(a_from.m_title)
135  ,m_dim(a_from.m_dim)
136  ,m_points(a_from.m_points)
137  {}
138  dps& operator=(const dps& a_from) {
139  if(&a_from==this) return *this;
140  m_title = a_from.m_title;
141  m_dim = a_from.m_dim;
142  m_points = a_from.m_points;
143  return *this;
144  }
145 
146 public:
147  const std::string& title() const {return m_title;}
148 
149  void set_title(const std::string& a_s) {m_title = a_s;}
150 
151  unsigned int dimension() const {return m_dim;}
152  void clear() {m_points.clear();}
153  size_t size() const {return m_points.size();}
154 
155  const data_point& point(size_t a_index) const {
156  //WARNING : no check done on a_index.
157  return m_points[a_index];
158  }
159  data_point& point(size_t a_index) {
160  //WARNING : no check done on a_index.
161  return m_points[a_index];
162  }
163 
165  m_points.push_back(data_point(m_dim));
166  return m_points.back();
167  }
168 
169  bool remove_point(size_t a_index) {
170  bool done = false;
171  if(a_index<m_points.size()){
172  std::vector<data_point>::iterator it = m_points.begin();
173  it += a_index;
174  m_points.erase(it);
175  done = true;
176  }
177  return done;
178  }
179 
180  bool lower_extent(unsigned int a_coord,double& a_value) const {
181  if(m_points.empty()||(a_coord>=m_dim)){
182  a_value = 0;
183  return false;
184  }
185  std::vector<data_point>::const_iterator it = m_points.begin();
186  a_value = (*it).coordinate(a_coord).value();
187  ++it;
188  for(;it!=m_points.end();++it) {
189  a_value = mn<double>(a_value,(*it).coordinate(a_coord).value());
190  }
191  return true;
192  }
193 
194  bool upper_extent(unsigned int a_coord,double& a_value) const {
195  if(m_points.empty()||(a_coord>=m_dim)){
196  a_value = 0;
197  return false;
198  }
199  std::vector<data_point>::const_iterator it = m_points.begin();
200  a_value = (*it).coordinate(a_coord).value();
201  ++it;
202  for(;it!=m_points.end();++it) {
203  a_value = mx<double>(a_value,(*it).coordinate(a_coord).value());
204  }
205  return true;
206  }
207 
208  void scale(double a_scale) {
209  std::vector<data_point>::iterator it;
210  for(it=m_points.begin();it!=m_points.end();++it) {
211  for(unsigned int coord=0;coord<m_dim;coord++) {
212  measurement& m = (*it).coordinate(coord);
213  m.set_value(m.value() * a_scale);
214  m.set_error_plus(m.error_plus() * a_scale);
215  m.set_error_minus(m.error_minus() * a_scale);
216  }
217  }
218  }
219 
220  void scale_value(double a_scale) {
221  std::vector<data_point>::iterator it;
222  for(it=m_points.begin();it!=m_points.end();++it) {
223  for(unsigned int coord=0;coord<m_dim;coord++) {
224  measurement& m = (*it).coordinate(coord);
225  m.set_value(m.value() * a_scale);
226  }
227  }
228  }
229 
230  void scale_errors(double a_scale) {
231  std::vector<data_point>::iterator it;
232  for(it=m_points.begin();it!=m_points.end();++it) {
233  for(unsigned int coord=0;coord<m_dim;coord++) {
234  measurement& m = (*it).coordinate(coord);
235  m.set_error_plus(m.error_plus() * a_scale);
236  m.set_error_minus(m.error_minus() * a_scale);
237  }
238  }
239  }
240 
241 protected:
242  std::string m_title;
243  unsigned int m_dim;
244  std::vector<data_point> m_points;
245 };
246 
247 }}
248 
249 #endif
tools::histo::dps::remove_point
bool remove_point(size_t a_index)
Definition: dps:169
tools::histo::dps::title
const std::string & title() const
Definition: dps:147
tools::histo::dps::dimension
unsigned int dimension() const
Definition: dps:151
tools::histo::measurement::measurement
measurement(double a_value, double a_error_plus, double a_error_minus)
Definition: dps:31
tools::histo::measurement::m_value
double m_value
Definition: dps:70
tools::histo::dps::m_title
std::string m_title
Definition: dps:242
tools::histo::data_point::m_measurements
std::vector< measurement > m_measurements
Definition: dps:115
tools::histo::dps::~dps
virtual ~dps()
Definition: dps:131
tools::histo::dps::dps
dps(const std::string &a_title, unsigned int a_dim)
Definition: dps:128
tools::histo::dps::dps
dps(const dps &a_from)
Definition: dps:133
tools::histo::measurement::set_value
void set_value(double a_v)
Definition: dps:66
tools::histo::dps::upper_extent
bool upper_extent(unsigned int a_coord, double &a_value) const
Definition: dps:194
tools::histo::data_point
Definition: dps:75
tools::histo::dps::point
const data_point & point(size_t a_index) const
Definition: dps:155
tools::histo::data_point::operator=
data_point & operator=(const data_point &a_from)
Definition: dps:99
tools::histo::dps::m_points
std::vector< data_point > m_points
Definition: dps:244
tools::histo::dps::scale
void scale(double a_scale)
Definition: dps:208
tools::histo::measurement::error_plus
double error_plus() const
Definition: dps:64
tools::histo::dps::set_title
void set_title(const std::string &a_s)
Definition: dps:149
tools::histo::measurement::m_error_minus
double m_error_minus
Definition: dps:72
tools::histo::dps::point
data_point & point(size_t a_index)
Definition: dps:159
tools::histo::measurement::operator=
measurement & operator=(const measurement &a_from)
Definition: dps:55
tools::histo::data_point::data_point
data_point(const data_point &a_from)
Definition: dps:92
tools::histo::data_point::~data_point
virtual ~data_point()
Definition: dps:86
tools::histo::dps::size
size_t size() const
Definition: dps:153
tools::histo::data_point::data_point
data_point(unsigned int a_dim)
Definition: dps:81
tools::histo::dps::s_class
static const std::string & s_class()
Definition: dps:121
tools::histo::dps::dps
dps()
Definition: dps:126
tools::histo::measurement::value
double value() const
Definition: dps:63
tools::histo::measurement::set_error_minus
void set_error_minus(double a_v)
Definition: dps:68
tools::histo::measurement::measurement
measurement()
Definition: dps:26
tools::histo::dps::m_dim
unsigned int m_dim
Definition: dps:243
tools::histo::dps::add_point
data_point & add_point()
Definition: dps:164
tools::histo::measurement::m_error_plus
double m_error_plus
Definition: dps:71
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::histo::dps::operator=
dps & operator=(const dps &a_from)
Definition: dps:138
tools::histo::measurement::~measurement
virtual ~measurement()
Definition: dps:40
tools::histo::measurement
Definition: dps:20
tools::histo::data_point::dimension
size_t dimension() const
Definition: dps:105
tools::histo::measurement::error_minus
double error_minus() const
Definition: dps:65
tools::histo::dps::clear
void clear()
Definition: dps:152
tools::histo::measurement::set_error_plus
void set_error_plus(double a_v)
Definition: dps:67
tools::histo::dps::scale_errors
void scale_errors(double a_scale)
Definition: dps:230
tools::histo::measurement::measurement
measurement(const measurement &a_from)
Definition: dps:46
tools::histo::data_point::coordinate
const measurement & coordinate(unsigned int a_coord) const
Definition: dps:110
tools::histo::dps
Definition: dps:119
tools::histo::data_point::coordinate
measurement & coordinate(unsigned int a_coord)
Definition: dps:106
tools::histo::dps::lower_extent
bool lower_extent(unsigned int a_coord, double &a_value) const
Definition: dps:180
tools::histo::dps::scale_value
void scale_value(double a_scale)
Definition: dps:220