File indexing completed on 2026-08-06 09:38:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LWH_DataPointSet_H
0010 #define LWH_DataPointSet_H
0011
0012
0013
0014
0015
0016 #include <vector>
0017 #include <limits>
0018 #include <cmath>
0019 #include <algorithm>
0020 #include "AIDataPointSet.h"
0021 #include "ManagedObject.h"
0022 #include "DataPoint.h"
0023
0024 namespace LWH {
0025
0026 using namespace AIDA;
0027
0028
0029
0030
0031
0032
0033 class DataPointSet: public IDataPointSet, public ManagedObject {
0034
0035 public:
0036
0037
0038
0039
0040
0041 DataPointSet(int D): dim(D) {}
0042
0043
0044
0045
0046 virtual ~DataPointSet() {}
0047
0048
0049
0050
0051 IAnnotation & annotation() {
0052 throw std::runtime_error("LWH cannot handle annotations");
0053 }
0054
0055
0056
0057
0058 const IAnnotation & annotation() const {
0059 throw std::runtime_error("LWH cannot handle annotations");
0060 }
0061
0062
0063
0064
0065
0066 std::string title() const {
0067 return theTitle;
0068 }
0069
0070
0071
0072
0073
0074 std::string name() const {
0075 return theTitle;
0076 }
0077
0078
0079
0080
0081
0082
0083 bool setTitle(const std::string & title) {
0084 theTitle = title;
0085 return true;
0086 }
0087
0088
0089
0090
0091
0092
0093 int dimension() const {
0094 return dim;
0095 }
0096
0097
0098
0099
0100
0101 void clear() {
0102 dset.clear();
0103 }
0104
0105
0106
0107
0108
0109
0110 int size() const {
0111 return dset.size();
0112 }
0113
0114
0115
0116
0117
0118
0119 IDataPoint * point(int index) {
0120 return &(dset[index]);
0121 }
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 bool setCoordinate(int coord,
0137 const std::vector<double> & val,
0138 const std::vector<double> & err) {
0139 return setCoordinate(coord, val, err, err);
0140 }
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 bool setCoordinate(int coord,
0158 const std::vector<double> & val,
0159 const std::vector<double> & errp,
0160 const std::vector<double> & errm) {
0161 if ( coord < 0 || coord >= dimension() ) return false;
0162 if ( val.size() != dset.size() || errp.size() != dset.size() ||
0163 errm.size() != dset.size() ) return false;
0164 for ( int i = 0, N = val.size(); i < N; ++i ) {
0165 dset[i].coordinate(coord)->setValue(val[i]);
0166 dset[i].coordinate(coord)->setErrorPlus(errp[i]);
0167 dset[i].coordinate(coord)->setErrorMinus(errm[i]);
0168 }
0169 return true;
0170 }
0171
0172
0173
0174
0175
0176 const IDataPoint * point(int index) const {
0177 if ( index < 0 || unsigned(index) >= dset.size() ) return 0;
0178 return &(dset[index]);
0179 }
0180
0181
0182
0183
0184
0185 IDataPoint * addPoint() {
0186 dset.push_back(DataPoint(dimension()));
0187 return &(dset.back());
0188 }
0189
0190
0191
0192
0193
0194
0195
0196 bool addPoint(const IDataPoint & point) {
0197 if ( dimension() && dimension() != point.dimension() ) return false;
0198 dset.push_back(DataPoint(point));
0199 return true;
0200 }
0201
0202
0203
0204
0205
0206
0207 bool removePoint(int index) {
0208 if ( index < 0 || unsigned(index) >= dset.size() ) return false;
0209 dset.erase(dset.begin() + index);
0210 return true;
0211 }
0212
0213
0214
0215
0216
0217
0218
0219
0220 double lowerExtent(int coord) const {
0221 if ( dset.empty() ) return std::numeric_limits<double>::quiet_NaN();
0222 if ( coord < 0 || coord >= dimension() )
0223 return std::numeric_limits<double>::quiet_NaN();
0224 double low = dset[0].coordinate(coord)->value();
0225 for ( int i = 1, N = dset.size(); i < N; ++i )
0226 low = std::min(low, dset[i].coordinate(coord)->value());
0227 return low;
0228 }
0229
0230
0231
0232
0233
0234
0235
0236
0237 double upperExtent(int coord) const {
0238 if ( dset.empty() ) return std::numeric_limits<double>::quiet_NaN();
0239 if ( coord < 0 || coord >= dimension() )
0240 return std::numeric_limits<double>::quiet_NaN();
0241 double upp = dset[0].coordinate(coord)->value();
0242 for ( int i = 1, N = dset.size(); i < N; ++i )
0243 upp = std::max(upp, dset[i].coordinate(coord)->value());
0244 return upp;
0245 }
0246
0247
0248
0249
0250
0251
0252
0253 bool scale(double scale) {
0254 for ( int i = 0, N = dset.size(); i < N; ++i )
0255 for ( int j = 0, M = dset[i].dimension(); j < M; ++j ) {
0256 IMeasurement * m = dset[i].coordinate(j);
0257 m->setValue(m->value()*scale);
0258 m->setErrorPlus(m->errorPlus()*scale);
0259 m->setErrorMinus(m->errorPlus()*scale);
0260 }
0261 return true;
0262 }
0263
0264
0265
0266
0267
0268
0269
0270 bool scaleValues(double scale) {
0271 for ( int i = 0, N = dset.size(); i < N; ++i )
0272 for ( int j = 0, M = dset[i].dimension(); j < M; ++j ) {
0273 IMeasurement * m = dset[i].coordinate(j);
0274 m->setValue(m->value()*scale);
0275 }
0276 return true;
0277 }
0278
0279
0280
0281
0282
0283
0284
0285 bool scaleErrors(double scale) {
0286 for ( int i = 0, N = dset.size(); i < N; ++i )
0287 for ( int j = 0, M = dset[i].dimension(); j < M; ++j ) {
0288 IMeasurement * m = dset[i].coordinate(j);
0289 m->setErrorPlus(m->errorPlus()*scale);
0290 m->setErrorMinus(m->errorPlus()*scale);
0291 }
0292 return true;
0293 }
0294
0295
0296
0297
0298
0299 void * cast(const std::string &) const {
0300 return 0;
0301 }
0302
0303
0304
0305
0306 bool writeXML(std::ostream & os, std::string path, std::string name) {
0307 os << " <dataPointSet name=\"" << name
0308 << "\"\n title=\"" << title()
0309 << "\" path=\"" << path
0310 << "\" dimension=\"" << dimension() << "\">\n";
0311 for ( int d = 0; d < dimension(); ++d )
0312 os << " <dimension dim=\"" << d << "\" title=\"unknown\" />\n";
0313 for ( int i = 0, N = size(); i < N; ++i ) {
0314 os << " <dataPoint>\n";
0315 for ( int j = 0, M = dimension(); j < M; ++j )
0316 os << " <measurement value=\""
0317 << point(i)->coordinate(j)->value()
0318 << "\" errorPlus=\""
0319 << point(i)->coordinate(j)->errorPlus()
0320 << "\" errorMinus=\""
0321 << point(i)->coordinate(j)->errorMinus()
0322 << "\"/>\n";
0323 os << " </dataPoint>\n";
0324 }
0325 os << " </dataPointSet>" << std::endl;
0326 return true;
0327 }
0328
0329
0330
0331
0332
0333
0334 bool writeFLAT(std::ostream & os, std::string path, std::string name) {
0335 os << "# " << path << "/" << name << " " << size()
0336 << " \"" << title() << " \" dimension " << dimension() << std::endl;
0337 for ( int i = 0, N = size(); i < N; ++i ) {
0338 for ( int j = 0, M = dimension(); j < M; ++j )
0339 os << point(i)->coordinate(j)->value() << " ";
0340 for ( int j = 0, M = dimension(); j < M; ++j )
0341 os << point(i)->coordinate(j)->errorPlus() << " ";
0342 for ( int j = 0, M = dimension(); j < M; ++j )
0343 os << point(i)->coordinate(j)->errorMinus() << " ";
0344 os << std::endl;
0345 }
0346 os << std::endl;
0347 return true;
0348 }
0349
0350 private:
0351
0352
0353 std::string theTitle;
0354
0355
0356
0357
0358 std::vector<DataPoint> dset;
0359
0360
0361
0362
0363 unsigned int dim;
0364
0365
0366 };
0367
0368 }
0369
0370 #endif