thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
DataPointSetFactory.h
1// -*- C++ -*-
2//
3// DataPointSetFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef LWH_DataPointSetFactory_H
10#define LWH_DataPointSetFactory_H
11//
12// This is the declaration of the DataPointSetFactory class.
13//
14
15#include "AIDataPointSetFactory.h"
16#include "DataPointSet.h"
17#include "Histogram1D.h"
18#include "Tree.h"
19#include <string>
20#include <stdexcept>
21
22namespace LWH {
23
24using namespace AIDA;
25
31class DataPointSetFactory: public IDataPointSetFactory {
32
33public:
34
39 : tree(&t) {}
40
45
60 virtual IDataPointSet *
61 create(const std::string & path, const std::string & title, int dim) {
62 DataPointSet * dset = new DataPointSet(dim);
63 dset->setTitle(title);
64 if ( !tree->insert(path, dset) ) {
65 delete dset;
66 dset = 0;
67 throw std::runtime_error("LWH could not create DataPointSet '"
68 + title + "'." );
69 }
70 return dset;
71 }
72
86 virtual IDataPointSet * create(const std::string & pathAndTitle, int dim) {
87 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
88 return create(pathAndTitle, title, dim);
89 }
90
104 virtual IDataPointSet *
105 createY(const std::string & path, const std::string & title,
106 const std::vector<double> & y, const std::vector<double> & ey) {
107 return createY(path, title, y, ey, ey);
108 }
109
124 virtual IDataPointSet *
125 createY(const std::string & path, const std::string & title,
126 const std::vector<double> & y, const std::vector<double> & eyp,
127 const std::vector<double> & eym) {
128 IDataPointSet * dset = create(path, title, 2);
129 std::vector<double> x, ex;
130 for ( int i = 0, N = y.size(); i < N; ++i ) {
131 dset->addPoint(DataPoint(2));
132 x.push_back(i);
133 ex.push_back(0);
134 }
135 if ( !dset->setCoordinate(0, x, ex, ex) ||
136 !dset->setCoordinate(1, y, eyp, eym) )
137 throw std::runtime_error("LWH could add points to DataPointSet '" +
138 title + "'." );
139 return dset;
140 }
141
157 virtual IDataPointSet *
158 createY(const std::string & pathAndTitle, const std::vector<double> & y,
159 const std::vector<double> & ey) {
160 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
161 return createY(pathAndTitle, title, y, ey);
162 }
163
179 virtual IDataPointSet *
180 createY(const std::string & pathAndTitle,
181 const std::vector<double> & y, const std::vector<double> & eyp,
182 const std::vector<double> & eym) {
183 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
184 return createY(pathAndTitle, title, y, eyp, eym);
185 }
186
200 virtual IDataPointSet *
201 createX(const std::string & path, const std::string & title,
202 const std::vector<double> & x, const std::vector<double> & ex) {
203 return createX(path, title, x, ex, ex);
204 }
205
220 virtual IDataPointSet *
221 createX(const std::string & path, const std::string & title,
222 const std::vector<double> & x, const std::vector<double> & exp,
223 const std::vector<double> & exm) {
224 IDataPointSet * dset = create(path, title, 2);
225 std::vector<double> y, ey;
226 for ( int i = 0, N = x.size(); i < N; ++i ) {
227 dset->addPoint(DataPoint(2));
228 y.push_back(i);
229 ey.push_back(0);
230 }
231 if ( !dset->setCoordinate(0, x, exp, exm) ||
232 !dset->setCoordinate(1, y, ey, ey) )
233 throw std::runtime_error("LWH could add points to DataPointSet '" +
234 title + "'." );
235 return dset;
236 }
237
252 virtual IDataPointSet *
253 createX(const std::string & pathAndTitle, const std::vector<double> & x,
254 const std::vector<double> & ex) {
255 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
256 return createX(pathAndTitle, title, x, ex, ex);
257 }
258
274 virtual IDataPointSet *
275 createX(const std::string & pathAndTitle, const std::vector<double> & x,
276 const std::vector<double> & exp, const std::vector<double> & exm) {
277 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
278 return createX(pathAndTitle, title, x, exp, exm);
279 }
280
297 virtual IDataPointSet *
298 createXY(const std::string & path, const std::string & title,
299 const std::vector<double> & x, const std::vector<double> & y,
300 const std::vector<double> & exp, const std::vector<double> & eyp,
301 const std::vector<double> & exm, const std::vector<double> & eym) {
302 IDataPointSet * dset = create(path, title, 2);
303 for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(2));
304 if ( !dset->setCoordinate(0, x, exp, exm) ||
305 !dset->setCoordinate(1, y, eyp, eym) )
306 throw std::runtime_error("LWH could add points to DataPointSet '" +
307 title + "'." );
308 return dset;
309 }
310
325 virtual IDataPointSet *
326 createXY(const std::string & path, const std::string & title,
327 const std::vector<double> & x, const std::vector<double> & y,
328 const std::vector<double> & ex, const std::vector<double> & ey) {
329 return createXY(path, title, x, y, ex, ey, ex, ey);
330 }
331
349 virtual IDataPointSet *
350 createXY(const std::string & pathAndTitle,
351 const std::vector<double> & x, const std::vector<double> & y,
352 const std::vector<double> & exp, const std::vector<double> & eyp,
353 const std::vector<double> & exm, const std::vector<double> & eym) {
354 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
355 return createXY(pathAndTitle, title, x, y, exp, eyp, exm, eym);
356 }
357
373 virtual IDataPointSet *
374 createXY(const std::string & pathAndTitle,
375 const std::vector<double> & x, const std::vector<double> & y,
376 const std::vector<double> & ex, const std::vector<double> & ey) {
377 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
378 return createXY(pathAndTitle, title, x, y, ex, ey, ex, ey);
379 }
380
400 virtual IDataPointSet *
401 createXYZ(const std::string & path, const std::string & title,
402 const std::vector<double> & x, const std::vector<double> & y,
403 const std::vector<double> & z, const std::vector<double> & exp,
404 const std::vector<double> & eyp, const std::vector<double> & ezp,
405 const std::vector<double> & exm, const std::vector<double> & eym,
406 const std::vector<double> & ezm) {
407 IDataPointSet * dset = create(path, title, 3);
408 for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(3));
409 if ( !dset->setCoordinate(0, x, exp, exm) ||
410 !dset->setCoordinate(1, y, eyp, eym) ||
411 !dset->setCoordinate(2, z, ezp, ezm) )
412 throw std::runtime_error("LWH could add points to DataPointSet '" +
413 title + "'." );
414 return dset;
415 }
416
433 virtual IDataPointSet *
434 createXYZ(const std::string & path, const std::string & title,
435 const std::vector<double> & x, const std::vector<double> & y,
436 const std::vector<double> & z, const std::vector<double> & ex,
437 const std::vector<double> & ey, const std::vector<double> & ez) {
438 return createXYZ(path, title, x, y, z, ex, ey, ez, ex, ey, ez);
439 }
440
461 virtual IDataPointSet *
462 createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
463 const std::vector<double> & y, const std::vector<double> & z,
464 const std::vector<double> & exp, const std::vector<double> & eyp,
465 const std::vector<double> & ezp, const std::vector<double> & exm,
466 const std::vector<double> & eym, const std::vector<double> & ezm) {
467 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
468 return createXYZ(pathAndTitle, title, x, y, z,
469 exp, eyp, ezp, exm, eym, ezm);
470 }
471
489 virtual IDataPointSet *
490 createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
491 const std::vector<double> & y, const std::vector<double> & z,
492 const std::vector<double> & ex, const std::vector<double> & ey,
493 const std::vector<double> & ez) {
494 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
495 return createXYZ(pathAndTitle, title, x, y, z, ex, ey, ez, ex, ey, ez);
496 }
497
508 virtual IDataPointSet *
509 createCopy(const std::string & path, const IDataPointSet & dataPointSet) {
510 IDataPointSet * dset =
511 create(path, dataPointSet.title(), dataPointSet.dimension());
512 for ( int i = 0, N = dataPointSet.size(); i < N; ++i )
513 dset->addPoint(*dataPointSet.point(i));
514 return dset;
515 }
516
522 virtual bool destroy(IDataPointSet * dataPointSet) {
523 IManagedObject * mo = dynamic_cast<IManagedObject *>(dataPointSet);
524 if ( !mo ) return false;
525 return tree->rm(tree->findPath(*mo));
526 }
527
540 virtual IDataPointSet *
541 create(const std::string & path, const IHistogram1D & hist,
542 const std::string & = "") {
543 IDataPointSet * dset = create(path, hist.title(), 2);
544 std::vector<double> x, y, ex, ey;
545 for ( int i = 2, N = hist.axis().bins() + 2; i < N; ++i ) {
546 dset->addPoint(DataPoint(2));
547 x.push_back(hist.binMean(i - 2));
548 ex.push_back(hist.axis().binWidth(i - 2));
549 y.push_back(hist.binHeight(i - 2));
550 ey.push_back(hist.binError(i - 2));
551 }
552 if ( !dset->setCoordinate(0, x, ex, ex) ||
553 !dset->setCoordinate(1, y, ey, ey) )
554 throw std::runtime_error("LWH could add points to DataPointSet '" +
555 hist.title() + "'." );
556 return dset;
557 }
558
572 virtual IDataPointSet *
573 create(const std::string & path, const IHistogram2D & hist,
574 const std::string & = "") {
575 IDataPointSet * dset = create(path, hist.title(), 3);
576
577 std::vector<double> x, y, z, ex, ey, ez;
578 for ( int ix = 2, Nx = hist.xAxis().bins() + 2; ix < Nx; ++ix )
579 for ( int iy = 2, Ny = hist.yAxis().bins() + 2; iy < Ny; ++iy ) {
580 dset->addPoint(DataPoint(3));
581 //x.push_back(hist.binMean(i - 2)); // < "Dynamic" version
582 // Shouldn't IAxis have a binCentre(size_t binId) method?
583 // (According to Java AIDA v3.3.0 API)
584 x.push_back((hist.xAxis().binLowerEdge(ix - 2) +
585 hist.xAxis().binUpperEdge(ix - 2))/2.0);
586 ex.push_back(hist.xAxis().binWidth(ix - 2)/2.0);
587 y.push_back((hist.yAxis().binLowerEdge(iy - 2) +
588 hist.yAxis().binUpperEdge(iy - 2))/2.0);
589 ey.push_back(hist.yAxis().binWidth(iy - 2)/2.0);
590 const double binwidth = hist.xAxis().binWidth(ix - 2)*
591 hist.yAxis().binWidth(iy - 2);
592 z.push_back(hist.binHeight(ix - 2, iy - 2)/binwidth);
593 ez.push_back(hist.binError(ix - 2, iy - 2)/binwidth);
594 }
595 if ( !dset->setCoordinate(0, x, ex, ex) ||
596 !dset->setCoordinate(1, y, ey, ey) ||
597 !dset->setCoordinate(2, z, ez, ez) )
598 throw std::runtime_error("LWH could not add points to DataPointSet '" +
599 hist.title() + "'." );
600 return dset;
601 }
602
603
607 virtual IDataPointSet * create(const std::string &, const IHistogram3D &,
608 const std::string & = "") {
609 return error<IDataPointSet>("IHistogram3D");
610 }
611
615 virtual IDataPointSet * create(const std::string &, const ICloud1D &,
616 const std::string & = "") {
617 return error<IDataPointSet>("ICloud1D");
618 }
619
623 virtual IDataPointSet * create(const std::string &, const ICloud2D &,
624 const std::string & = "") {
625 return error<IDataPointSet>("ICloud2D");
626 }
627
631 virtual IDataPointSet * create(const std::string &, const ICloud3D &,
632 const std::string & = "") {
633 return error<IDataPointSet>("ICloud3D");
634 }
635
639 virtual IDataPointSet * create(const std::string &, const IProfile1D &,
640 const std::string & = "") {
641 return error<IDataPointSet>("IProfile1D");
642 }
643
647 virtual IDataPointSet * create(const std::string &, const IProfile2D &,
648 const std::string & = "") {
649 return error<IDataPointSet>("IProfile2D");
650 }
651
655 virtual IDataPointSet * add(const std::string &,
656 const IDataPointSet &, const IDataPointSet &) {
657 return error<IDataPointSet>("addition of data points");
658 }
659
663 virtual IDataPointSet * subtract(const std::string &, const IDataPointSet &,
664 const IDataPointSet &) {
665 return error<IDataPointSet>("subtraction of data points");
666 }
667
671 virtual IDataPointSet * multiply(const std::string &, const IDataPointSet &,
672 const IDataPointSet &) {
673 return error<IDataPointSet>("multiplication of data points");
674 }
675
679 virtual IDataPointSet * divide(const std::string &, const IDataPointSet &,
680 const IDataPointSet &) {
681 return error<IDataPointSet>("division of data points");
682 }
683
687 virtual IDataPointSet *
688 weightedMean(const std::string &, const IDataPointSet &,
689 const IDataPointSet &) {
690 return error<IDataPointSet>("weighted means of data points");
691 }
692
693private:
694
696 template <typename T>
697 static T * error(std::string feature) {
698 throw std::runtime_error("LWH cannot handle " + feature + ".");
699 }
700
703
704};
705}
706
707#endif
Basic user-level interface for creating a factory of IDataPointSet.
Tree * tree
The tree where the actual data sets are stored.
virtual IDataPointSet * createX(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &ex)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual IDataPointSet * createX(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &exp, const std::vector< double > &exm)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual IDataPointSet * divide(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the division of data points.
virtual IDataPointSet * createXYZ(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &ezp, const std::vector< double > &exm, const std::vector< double > &eym, const std::vector< double > &ezm)
Create a three dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &path, const std::string &title, int dim)
Create an empty IDataPointSet.
virtual IDataPointSet * createXY(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ex, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * weightedMean(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the weighted mean of data points.
DataPointSetFactory(Tree &t)
Standard constructor.
virtual IDataPointSet * add(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the addition of data points.
virtual IDataPointSet * subtract(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the subtraction of data points.
static T * error(std::string feature)
Throw a suitable error.
virtual IDataPointSet * createXYZ(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &ezp, const std::vector< double > &exm, const std::vector< double > &eym, const std::vector< double > &ezm)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &, const ICloud3D &, const std::string &="")
LWH cannot handle a ICloud3D.
virtual IDataPointSet * createXYZ(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &ex, const std::vector< double > &ey, const std::vector< double > &ez)
Create a three dimensional IDataPointSet providing the data.
virtual IDataPointSet * createY(const std::string &pathAndTitle, const std::vector< double > &y, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual ~DataPointSetFactory()
Destructor.
virtual IDataPointSet * createXYZ(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &ex, const std::vector< double > &ey, const std::vector< double > &ez)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * createXY(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &exm, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &, const IProfile1D &, const std::string &="")
LWH cannot handle a IProfile1D.
virtual IDataPointSet * createXY(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ex, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * createY(const std::string &path, const std::string &title, const std::vector< double > &y, const std::vector< double > &eyp, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * create(const std::string &, const ICloud1D &, const std::string &="")
LWH cannot handle a ICloud1.
virtual IDataPointSet * createX(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &ex)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual IDataPointSet * createY(const std::string &path, const std::string &title, const std::vector< double > &y, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * create(const std::string &path, const IHistogram1D &hist, const std::string &="")
Create an IDataPointSet from an IHistogram1D.
virtual IDataPointSet * multiply(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the multiplication of data points.
virtual IDataPointSet * create(const std::string &, const IProfile2D &, const std::string &="")
LWH cannot handle a IProfile2D.
virtual IDataPointSet * create(const std::string &pathAndTitle, int dim)
Create an empty IDataPointSet.
virtual IDataPointSet * create(const std::string &path, const IHistogram2D &hist, const std::string &="")
Create an IDataPointSet from an IHistogram2D.
virtual IDataPointSet * createXY(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &exm, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &, const ICloud2D &, const std::string &="")
LWH cannot handle a ICloud2D.
virtual IDataPointSet * create(const std::string &, const IHistogram3D &, const std::string &="")
LWH cannot handle a IHistogram3D.
virtual IDataPointSet * createCopy(const std::string &path, const IDataPointSet &dataPointSet)
Make a copy of a given IDataPointSet.
virtual IDataPointSet * createY(const std::string &pathAndTitle, const std::vector< double > &y, const std::vector< double > &eyp, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * createX(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &exp, const std::vector< double > &exm)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual bool destroy(IDataPointSet *dataPointSet)
Destroy a given IDataPointSet.
An DataPointSet represents a binned histogram axis.
Definition: DataPointSet.h:33
bool setTitle(const std::string &title)
Set the data set's title.
Definition: DataPointSet.h:83
An DataPoint represents a binned histogram axis.
Definition: DataPoint.h:31
The Tree class is a simple implementation of the AIDA::ITree interface.
Definition: Tree.h:32
std::string findPath(const IManagedObject &o) const
Get the full path of an IManagedObject.
Definition: Tree.h:251
bool rm(const std::string &path)
Remove and delete an IManagedObject by specifying its path.
Definition: Tree.h:237
bool insert(std::string str, IManagedObject *o)
Insert the ManagedObject o in the tree with the path str.
Definition: Tree.h:121
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...