9 #ifndef LWH_DataPointSet_H 10 #define LWH_DataPointSet_H 20 #include "AIDataPointSet.h" 21 #include "ManagedObject.h" 22 #include "DataPoint.h" 52 throw std::runtime_error(
"LWH cannot handle annotations");
59 throw std::runtime_error(
"LWH cannot handle annotations");
120 return &(dset[index]);
137 const std::vector<double> & val,
138 const std::vector<double> & err) {
139 return setCoordinate(coord, val, err, err);
158 const std::vector<double> & val,
159 const std::vector<double> & errp,
160 const std::vector<double> & errm) {
161 if ( coord < 0 || coord >= dimension() )
return false;
162 if ( val.size() != dset.size() || errp.size() != dset.size() ||
163 errm.size() != dset.size() )
return false;
164 for (
int i = 0, N = val.size(); i < N; ++i ) {
165 dset[i].coordinate(coord)->setValue(val[i]);
166 dset[i].coordinate(coord)->setErrorPlus(errp[i]);
167 dset[i].coordinate(coord)->setErrorMinus(errm[i]);
176 const IDataPoint *
point(
int index)
const {
177 if ( index < 0 ||
unsigned(index) >= dset.size() )
return 0;
178 return &(dset[index]);
187 return &(dset.back());
197 if ( dimension() && dimension() != point.dimension() )
return false;
208 if ( index < 0 ||
unsigned(index) >= dset.size() )
return false;
209 dset.erase(dset.begin() + index);
221 if ( dset.empty() )
return std::numeric_limits<double>::quiet_NaN();
222 if ( coord < 0 || coord >= dimension() )
223 return std::numeric_limits<double>::quiet_NaN();
224 double low = dset[0].coordinate(coord)->value();
225 for (
int i = 1, N = dset.size(); i < N; ++i )
226 low = std::min(low, dset[i].coordinate(coord)->value());
238 if ( dset.empty() )
return std::numeric_limits<double>::quiet_NaN();
239 if ( coord < 0 || coord >= dimension() )
240 return std::numeric_limits<double>::quiet_NaN();
241 double upp = dset[0].coordinate(coord)->value();
242 for (
int i = 1, N = dset.size(); i < N; ++i )
243 upp = std::max(upp, dset[i].coordinate(coord)->value());
254 for (
int i = 0, N = dset.size(); i < N; ++i )
255 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
256 IMeasurement * m = dset[i].coordinate(j);
257 m->setValue(m->value()*scale);
258 m->setErrorPlus(m->errorPlus()*scale);
259 m->setErrorMinus(m->errorPlus()*scale);
271 for (
int i = 0, N = dset.size(); i < N; ++i )
272 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
273 IMeasurement * m = dset[i].coordinate(j);
274 m->setValue(m->value()*scale);
286 for (
int i = 0, N = dset.size(); i < N; ++i )
287 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
288 IMeasurement * m = dset[i].coordinate(j);
289 m->setErrorPlus(m->errorPlus()*scale);
290 m->setErrorMinus(m->errorPlus()*scale);
299 void *
cast(
const std::string &)
const {
306 bool writeXML(std::ostream & os, std::string path, std::string name) {
307 os <<
" <dataPointSet name=\"" << name
308 <<
"\"\n title=\"" << title()
309 <<
"\" path=\"" << path
310 <<
"\" dimension=\"" << dimension() <<
"\">\n";
311 for (
int d = 0; d < dimension(); ++d )
312 os <<
" <dimension dim=\"" << d <<
"\" title=\"unknown\" />\n";
313 for (
int i = 0, N = size(); i < N; ++i ) {
314 os <<
" <dataPoint>\n";
315 for (
int j = 0, M = dimension(); j < M; ++j )
316 os <<
" <measurement value=\"" 317 << point(i)->coordinate(j)->value()
319 << point(i)->coordinate(j)->errorPlus()
320 <<
"\" errorMinus=\"" 321 << point(i)->coordinate(j)->errorMinus()
323 os <<
" </dataPoint>\n";
325 os <<
" </dataPointSet>" << std::endl;
334 bool writeFLAT(std::ostream & os, std::string path, std::string name) {
335 os <<
"# " << path <<
"/" << name <<
" " << size()
336 <<
" \"" << title() <<
" \" dimension " << dimension() << std::endl;
337 for (
int i = 0, N = size(); i < N; ++i ) {
338 for (
int j = 0, M = dimension(); j < M; ++j )
339 os << point(i)->coordinate(j)->value() <<
" ";
340 for (
int j = 0, M = dimension(); j < M; ++j )
341 os << point(i)->coordinate(j)->errorPlus() <<
" ";
342 for (
int j = 0, M = dimension(); j < M; ++j )
343 os << point(i)->coordinate(j)->errorMinus() <<
" ";
const IAnnotation & annotation() const
Not implemented in LWH.
bool writeXML(std::ostream &os, std::string path, std::string name)
Write out the data set in the AIDA xml format.
std::string name() const
Get the data set's title.
std::vector< DataPoint > dset
The included data points.
double lowerExtent(int coord) const
Get the lower value for a give axis.
const IDataPoint * point(int index) const
Return the data point at the given index.
DataPointSet(int D)
Standard constructor takes the dimension, D, of the data points as argument.
IDataPoint * point(int index)
Get the IDataPoint at a give index in the set.
bool scaleValues(double scale)
Scales the values of all the measurements of each point by a given factor.
IAnnotation & annotation()
Not implemented in LWH.
virtual ~DataPointSet()
Destructor.
An DataPointSet represents a binned histogram axis.
void clear()
Remove all the IDataPoints in the set.
bool scale(double scale)
Scales the values and the errors of all the measurements of each point by a given factor...
bool addPoint(const IDataPoint &point)
Add a copy of an IDataPoint at the end of the set.
bool scaleErrors(double scale)
Scales the errors of all the measurements of each point by a given factor.
void * cast(const std::string &) const
Not implemented in LWH.
IDataPoint * addPoint()
Add a new empty IDataPoint at the end of the set.
int size() const
Get the current size of the IDataPointSet, i.e.
bool removePoint(int index)
Remove the IDataPoint at a given index.
int dimension() const
Get the dimension of the IDataPoints that can be stored in the set.
IAnnotation * anno
dummy pointer to non-existen annotation.
unsigned int dim
The dimension of the points in this set.
bool setCoordinate(int coord, const std::vector< double > &val, const std::vector< double > &errp, const std::vector< double > &errm)
Set the values and errors of a given coordinate all at once.
bool setTitle(const std::string &title)
Set the data set's title.
double upperExtent(int coord) const
Get the upper value for a give axis.
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...
An DataPoint represents a binned histogram axis.
std::string title() const
Get the data set's title.
bool writeFLAT(std::ostream &os, std::string path, std::string name)
Write out the data set in a flat text file suitable for eg.
bool setCoordinate(int coord, const std::vector< double > &val, const std::vector< double > &err)
Set the values and errors of a given coordinate all at once.
std::string theTitle
The title.