yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
Scatter.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2023 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_Scatter_h
7#define YODA_Scatter_h
8
10#include "YODA/Point.h"
11#include "YODA/Transformation.h"
12#include "YODA/Utils/Traits.h"
14#include "YODA/Utils/ndarray.h"
15#include <vector>
16#include <set>
17#include <string>
18#include <utility>
19#include <memory>
20
21namespace YODA {
22
24 namespace {
25
26 // Checks that the first half of tuple arguments
27 // can be cast to double and the second half
28 // to pair<double,double>
29 template<class T, class U, typename = void>
30 struct HalfValsHalfPairs : std::false_type { };
31 //
32 template<class T, size_t... Is>
33 struct HalfValsHalfPairs<T, std::index_sequence<Is...>,
34 std::enable_if_t<( std::is_same<double,
35 std::common_type_t<std::tuple_element_t<Is,T>...,
36 double>>::value && // first half double
37 std::is_same<std::pair<double,double>,
38 std::common_type_t<std::tuple_element_t<sizeof...(Is)+Is,T>...,
39 std::pair<double,double>>>::value // second half pair<double,double>
40 )>> : std::true_type { };
41 }
42
44 class Scatter {
45 public:
46
48
50 virtual ~Scatter() {}
51
53
54
56 virtual size_t dim() const noexcept = 0;
57
58
60
61
63 virtual void reset() = 0;
64
66 //virtual void scale(size_t i, double scale) = 0;
67
69
70
72
73
75 virtual size_t numPoints() const = 0;
76
77
80
82 virtual void rmPoint(size_t index) = 0;
83
85 virtual void rmPoints(std::vector<size_t> indices) {
86 // remove points in decreasing order, so the numbering isn't invalidated mid-loop:
87 std::sort(indices.begin(), indices.end(), std::greater<size_t>()); //< reverse-sort
88 for (size_t i : indices) rmPoint(i);
89 }
90
92
93
100
101 // /// Insert a new point, defined as the x value and no errors
102 // void addPoint(double x) {
103 // Point1D thisPoint=Point1D(x);
104 // thisPoint.setParentAO(this);
105 // _points.insert(thisPoint);
106 // }
107
108 // /// Insert a new point, defined as the x value and symmetric errors
109 // void addPoint(double x, double ex) {
110 // Point1D thisPoint=Point1D(x, ex);
111 // thisPoint.setParentAO(this);
112 // _points.insert(thisPoint);
113 // }
114
115 // /// Insert a new point, defined as the x value and an asymmetric error pair
116 // void addPoint(double x, const std::pair<double,double>& ex) {
117 // Point1D thisPoint=Point1D(x, ex);
118 // thisPoint.setParentAO(this);
119 // _points.insert(thisPoint);
120 // }
121
122 // /// Insert a new point, defined as the x value and explicit asymmetric errors
123 // void addPoint(double x, double exminus, double explus) {
124 // Point1D thisPoint=Point1D(x, exminus, explus);
125 // thisPoint.setParentAO(this);
126 // _points.insert(thisPoint);
127 // }
128
129 // /// Insert a collection of new points
130 // void addPoints(const Points& pts) {
131 // for (const Point1D& pt : pts) addPoint(pt);
132 // }
133
135
136
137 // /// Equality operator
138 // bool operator == (const Scatter1D& other) {
139 // return _points == other._points;
140 // }
141
142 // /// Non-equality operator
143 // bool operator != (const Scatter1D& other) {
144 // return ! operator == (other);
145 // }
146
147 };
148
149
150
151
153 template <size_t N>
154 class ScatterND : public AnalysisObject, public Scatter {
155 protected:
156
157 // Convenient aliases
158 using Pair = std::pair<double,double>;
159 using ValVec = std::vector<double>;
160 using PairVec = std::vector<Pair>;
161 using ValList = std::initializer_list<double>;
162 using PairList = std::initializer_list<Pair>;
163
164 // extract the content type of an array Arr
165 template<typename Arr>
166 using containedType = std::decay_t<decltype(*std::declval<Arr>().begin())>;
167
168 // check if content type of an array Arr is Pair
169 template<typename Arr>
170 using containsPair = typename std::is_same<containedType<Arr>, Pair>;
171
172 // succeeds if the first argument is vector<vector<double> (or similar iterable)
173 // and the second argument is vector<vector<Pair>> (or similar iterable)
174 template<typename T, typename U>
175 using enableIfNestedArrayWithPair = std::enable_if_t<(isIterable<T,U,containedType<T>,containedType<U>> &&
177
178 // check if every element in parameter pack can be cast to double
179 template<typename... Args>
180 using isAllVals = std::is_same<double, std::common_type_t<Args..., double>>;
181
182 // check if every element in first half of parameter pack can be
183 // cast to double and every element in the second half to Pair
184 // (based on helper struct defined at the top of the file)
185 template<typename... Args>
186 using isHalfValsHalfPairs = HalfValsHalfPairs<std::tuple<Args...>, std::make_index_sequence<N>>;
187
188 public:
189
190 // Typedefs
191 using NdVal = Utils::ndarray<double, N>;
192 using NdValPair = Utils::ndarray<std::pair<double,double>, N>;
194 using Points = Utils::sortedvector<Point>;
195 using Ptr = std::shared_ptr<ScatterND>;
196 using AnalysisObject::operator =;
197
198
201
203 ScatterND(const std::string& path = "", const std::string& title="")
204 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title) { }
205
208 const std::string& path="", const std::string& title="")
209 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title),
210 _points(points) { }
211
214 const std::string& path="", const std::string& title="")
215 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title),
216 _points(std::move(points)) { }
217
219 template <typename ValRange = std::initializer_list<ValList>,
220 typename = std::enable_if_t<isIterable<ValRange, containedType<ValRange>>>> // enable if is nested array
221 ScatterND(ValRange&& positions, const std::string& path="", const std::string& title="")
222 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title) {
223 for (size_t i = 0; i < positions.size(); ++i) {
224 addPoint(PointND<N>(std::forward<containedType<ValRange>>(positions[i])));
225 }
226 }
227
229 template <typename ValRange = std::initializer_list<ValList>,
230 typename = std::enable_if_t<isIterable<ValRange, containedType<ValRange>>>> // enable if is nested array
231 ScatterND(ValRange&& positions, ValRange&& errors, const std::string& path="", const std::string& title="")
232 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title) {
233 if (positions.size() != errors.size()) throw RangeError("Number of errors doesn't match number of positions");
234 for (size_t i = 0; i < positions.size(); ++i) {
235 addPoint(PointND<N>(std::forward<containedType<ValRange>>(positions[i]),
236 std::forward<containedType<ValRange>>(errors[i])));
237 }
238 }
239
241 template <typename ValRange = std::initializer_list<ValList>,
242 typename PairRange = std::initializer_list<PairList>,
243 typename = enableIfNestedArrayWithPair<ValRange,PairRange>>
244 ScatterND(ValRange&& positions, PairRange&& errors, const std::string& path="", const std::string& title="")
245 : AnalysisObject("Scatter"+std::to_string(N)+"D", path, title) {
246 if (positions.size() != errors.size()) throw RangeError("Number of error pairs doesn't match number of positions");
247 for (size_t i = 0; i < positions.size(); ++i) {
248 addPoint(PointND<N>(std::forward<containedType<ValRange>>(positions[i]),
249 std::forward<containedType<PairRange>>(errors[i])));
250 }
251 }
252
254 ScatterND(const ScatterND<N>& s, const std::string& path = "")
255 : AnalysisObject("Scatter"+std::to_string(N)+"D", (path != "")? path : s.path(), s, s.title()),
256 _points(s._points) { }
257
259 ScatterND(ScatterND<N>&& s, const std::string& path = "")
260 : AnalysisObject("Scatter"+std::to_string(N)+"D", (path != "")? path : s.path(), s, s.title()),
261 _points(std::move(s._points)) {
262 }
263
264
267 if (this != &s) {
269 _points = s._points;
270 }
271 return *this;
272 }
273
276 if (this != &s) {
278 _points = std::move(s._points);
279 }
280 return *this;
281 }
282
285 return ScatterND<N>(*this);
286 }
287
290 return new ScatterND<N>(*this);
291 }
292
294
296 size_t dim() const noexcept { return N; }
297
300
302 void reset() {
303 _points.clear();
304 }
305
307 void scale(const NdVal& scales) {
308 for (PointND<N>& p : _points) p.scale(scales);
309 }
310
311 void scale(const std::vector<double>& scales) {
312 if (scales.size() != N) throw RangeError("Expected " + std::to_string(N) + " scale factors");
313 for (PointND<N>& p : _points) p.scale(scales);
314 }
315
316 void scale(const size_t i, double factor) {
317 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
318 std::array<double,N> scales;
319 scales.fill(1.0);
320 scales[i] = factor;
321 for (PointND<N>& p : _points) p.scale(scales);
322 }
323
325
326
328
329
332
334 size_t numPoints() const {
335 return _points.size();
336 }
337
338
341 return _points;
342 }
343
344
346 const Points& points() const {
347 return _points;
348 }
349
350
352 PointND<N>& point(size_t index) {
353 return _points.at(index);
354 }
355
356
358 const PointND<N>& point(size_t index) const {
359 return _points.at(index);
360 }
361
363
364
367
370 _points.insert(pt);
371 return *this;
372 }
373
376 _points.insert(std::move(pt));
377 return *this;
378 }
379
381 template <typename ValRange = ValList,
382 typename = std::enable_if_t<isIterable<ValRange>>>
383 ScatterND<N>& addPoint(ValRange&& pos) {
384 _points.insert(PointND<N>(std::forward<ValRange>(pos)));
385 return *this;
386 }
387
389 template <typename ValRange = ValList,
390 typename = std::enable_if_t<isIterable<ValRange>>>
391 ScatterND<N>& addPoint(ValRange&& pos, ValRange&& err) {
392 _points.insert(PointND<N>(std::forward<ValRange>(pos), std::forward<ValRange>(err)));
393 return *this;
394 }
395
397 template <typename ValRange = ValList,
398 typename = std::enable_if_t<isIterable<ValRange>>>
399 ScatterND<N>& addPoint(ValRange&& pos, ValRange&& errdn, ValRange&& errup) {
400 _points.insert(PointND<N>(std::forward<ValRange>(pos),
401 std::forward<ValRange>(errdn),
402 std::forward<ValRange>(errup)));
403 return *this;
404 }
405
407 template <typename ValRange = ValList, typename PairRange = PairList>
408 auto addPoint(ValRange&& pos, PairRange&& err)
409 -> std::enable_if_t<(isIterable<ValRange,PairRange> && containsPair<PairRange>::value), ScatterND<N>>& {
410 _points.insert(PointND<N>(pos, err));
411 return *this;
412 }
413
435 template<typename... Args>
436 auto addPoint(Args&&... args)
437 -> std::enable_if_t<(sizeof...(Args) == 2*N || sizeof...(Args) == 3*N), ScatterND<N>>& {
438 return addPoint_aux(std::make_tuple(std::forward<Args>(args)...), std::make_index_sequence<N>{});
439 }
440
441 protected:
442
458 template<typename... Args, size_t... Is>
459 auto addPoint_aux(std::tuple<Args...>&& t, std::index_sequence<Is...>)
460 -> std::enable_if_t<(isAllVals<Args...>::value), ScatterND<N>>& {
461 if constexpr(sizeof...(Args) == 2*N) { // Case 1: symmetric errors
462 _points.insert(
463 PointND<N>( ValVec{ static_cast<double>(std::get<Is>(t))...},
464 PairVec{{static_cast<double>(std::get<N+Is>(t)),
465 static_cast<double>(std::get<N+Is>(t))}...} ));
466 }
467 else { // Case 2: asymmetric errors
468 _points.insert(PointND<N>( ValVec{ static_cast<double>(std::get<Is>(t))...},
469 PairVec{{static_cast<double>(std::get<N+2*Is>(t)),
470 static_cast<double>(std::get<N+2*Is+1>(t))}...} ));
471 }
472 return *this;
473 }
474
475
489 template<typename... Args, size_t... Is>
490 auto addPoint_aux(std::tuple<Args...>&& t, std::index_sequence<Is...>) // Case 3: error pairs
491 -> std::enable_if_t<(sizeof...(Args) == 2*N && isHalfValsHalfPairs<Args...>::value), ScatterND<N>>& {
492 _points.insert(PointND<N>( ValVec{ static_cast<double>(std::get<Is>(t))...},
493 PairVec{ static_cast<Pair>(std::get<N+Is>(t))...} ));
494 return *this;
495 }
496
497
498 public:
499
502 for (const PointND<N>& pt : pts) addPoint(pt);
503 return *this;
504 }
505
506 void rmPoint(size_t index) {
507 _points.erase(_points.begin()+index);
508 }
509
511
513
514
515 size_t lengthContent(bool fixed_length = false) const noexcept {
516 if (fixed_length) return 0;
517 return numPoints() * Point::DataSize::value;
518 }
519
520 std::vector<double> serializeContent(bool fixed_length = false) const noexcept {
521
522 if (fixed_length) return { }; // cannot guarantee fixed length
523
524 std::vector<double> rtn;
525 rtn.reserve(numPoints() * Point::DataSize::value);
526 for (size_t i = 0; i < numPoints(); ++i) {
527 std::vector<double> pdata = point(i)._serializeContent();
528 rtn.insert(std::end(rtn),
529 std::make_move_iterator(std::begin(pdata)),
530 std::make_move_iterator(std::end(pdata)));
531 }
532 return rtn;
533 }
534
535 void deserializeContent(const std::vector<double>& data) {
536
537 if (data.size() % Point::DataSize::value)
538 throw UserError("Length of serialized data should be a multiple of "+std::to_string(Point::DataSize::value)+"!");
539
540 const size_t nPoints = data.size()/Point::DataSize::value;
541 const auto itr = data.cbegin();
542 reset();
543 for (size_t i = 0; i < nPoints; ++i) {
544 addPoint(Point());
545 auto first = itr + i*Point::DataSize::value;
546 auto last = first + Point::DataSize::value;
547 point(i)._deserializeContent(std::vector<double>{first, last});
548 }
549
550 }
551
552 // @}
553
556
559 addPoints(other.points());
560 return *this;
561 }
562
565 addPoints(std::move(other._points));
566 return *this;
567 }
568
570 ScatterND<N>& combineWith(const std::vector< ScatterND<N> >& others) {
571 for (const ScatterND<N>& s : others) combineWith(s);
572 return *this;
573 }
574
576 ScatterND<N>& combineWith(std::vector< ScatterND<N> >&& others) {
577 for (ScatterND<N>&& s : others) combineWith(std::move(s));
578 return *this;
579 }
580
582
585
587 ValVec vals(const size_t i) const {
588 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
589 ValVec rtn; rtn.reserve(_points.size());
590 for (const auto& pt : _points) {
591 rtn.push_back( pt.val(i) );
592 }
593 return rtn;
594 }
595
597 ValVec mins(const size_t i) const {
598 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
599 ValVec rtn; rtn.reserve(_points.size());
600 for (const auto& pt : _points) {
601 rtn.push_back( pt.min(i) );
602 }
603 return rtn;
604 }
605
607 ValVec maxs(const size_t i) const {
608 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
609 ValVec rtn; rtn.reserve(_points.size());
610 for (const auto& pt : _points) {
611 rtn.push_back( pt.max(i) );
612 }
613 return rtn;
614 }
615
617 double min(const size_t i) const {
618 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
619 const ValVec cvals = vals(i);
620 return *std::min_element(cvals.begin(), cvals.end());
621 }
622
624 double max(const size_t i) const {
625 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
626 const ValVec cvals = vals(i);
627 return *std::max_element(cvals.begin(), cvals.end());
628 }
629
631 PairVec errs(const size_t i) const {
632 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
633 PairVec rtn; rtn.reserve(_points.size());
634 for (const auto& pt : _points) {
635 rtn.push_back( pt.errs(i) );
636 }
637 return rtn;
638 }
639
641 ValVec errsAvg(const size_t i) const {
642 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
643 ValVec rtn; rtn.reserve(_points.size());
644 for (const auto& pt : _points) {
645 rtn.push_back( pt.errAvg(i) );
646 }
647 return rtn;
648 }
649
651 ValVec xVals() const { return vals(0); }
652
654 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
655 ValVec yVals() const { return vals(1); }
656
658 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
659 ValVec zVals() const { return vals(2); }
660
662 ValVec xMins() const { return mins(0); }
663
665 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
666 ValVec yMins() const { return mins(1); }
667
669 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
670 ValVec zMins() const { return mins(2); }
671
673 ValVec xMaxs() const { return maxs(0); }
674
676 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
677 ValVec yMaxs() const { return maxs(1); }
678
680 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
681 ValVec zMaxs() const { return maxs(2); }
682
684 double xMin() const { return min(0); }
685
687 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
688 double yMin() const { return min(1); }
689
691 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
692 double zMin() const { return min(2); }
693
695 double xMax() const { return max(0); }
696
698 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
699 double yMax() const { return max(1); }
700
702 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
703 double zMax() const { return max(2); }
704
706 PairVec xErrs() const { return errs(0); }
707
709 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 2)>>
710 PairVec yErrs() const { return errs(1); }
711
713 template<size_t axisN = N, typename = std::enable_if_t<(axisN >= 3)>>
714 PairVec zErrs() const { return errs(2); }
715
717
720
721 // @brief Render information about this AO
722 void _renderYODA(std::ostream& os, const int width = 13) const noexcept {
723
724 os << "# ";
725 for (size_t i = 0; i < N; ++i) {
726 os << std::setw(width - int(i? 0 : 2)) << std::left << ("val" + std::to_string(i+1)) << "\t"
727 << std::setw(width) << std::left << ("err" + std::to_string(i+1) + "-") << "\t"
728 << std::setw(width) << std::left << ("err" + std::to_string(i+1) + "+") << "\t";
729 }
730 os << "\n";
731
732 for (const auto& pt : _points) {
733 pt._renderYODA(os, width);
734 }
735 }
736
737 // @brief Render information about this AO
738 void _renderFLAT(std::ostream& os, const int width = 13) const noexcept { _renderYODA(os, width); }
739
741
744
745 std::vector<Pair> edges(const size_t i) const {
746 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
747 std::vector<Pair> rtn;
748 rtn.resize(numPoints());
749 size_t j = 0;
750 for (const Point& p : points()) {
751 rtn[j++] = std::make_pair(p.min(i), p.max(i));
752 }
753 std::sort(rtn.begin(), rtn.end());
754 rtn.erase(std::unique(rtn.begin(), rtn.end()), rtn.end());
755 return rtn;
756 }
757
759
760 private:
761
762 Points _points;
763
764 };
765
766
769
770 template <int N>
772 a.combineWith(b);
773 return a;
774 }
775
776 template <int N>
778 a.combineWith(std::move(b));
779 return a;
780 }
781
782 template <int N>
783 inline ScatterND<N> combine(const std::vector< ScatterND<N> >& scatters) {
784 ScatterND<N> rtn;
785 rtn.combineWith(scatters);
786 return rtn;
787 }
788
789 template <int N>
790 inline ScatterND<N> combine(std::vector< ScatterND<N> >&& scatters) {
791 ScatterND<N> rtn;
792 rtn.combineWith(std::move(scatters));
793 return rtn;
794 }
795
797
798
800
801
802 // /// @name Combining scatters: global operators, assuming aligned points
803 // /// @{
804
805 // /// Add two scatters
806 // template <size_t N>
807 // Scatter add(const Scatter& first, const Scatter& second);
808
809
810 // /// Add two scatters
811 // template <size_t N>
812 // inline Scatter operator + (const Scatter& first, const Scatter& second) {
813 // return add(first, second);
814 // }
815
816
817 // /// Subtract two scatters
818 // template <size_t N>
819 // Scatter subtract(const Scatter& first, const Scatter& second);
820
821
822 // /// Subtract two scatters
823 // template <size_t N>
824 // inline Scatter operator - (const Scatter& first, const Scatter& second) {
825 // return subtract(first, second);
826 // }
827
828
829 // /// Divide two scatters
830 // template <size_t N>
831 // Scatter divide(const Scatter& numer, const Scatter& denom);
832
833
834 // /// Divide two scatters
835 // template <size_t N>
836 // inline Scatter operator / (const Scatter& numer, const Scatter& denom) {
837 // return divide(numer, denom);
838 // }
839
840 // /// @}
841
842
844
845
848
849 template<size_t N>
850 inline void transform(ScatterND<N>& s, const Trf<N>& fn, const size_t i) {
851 for (auto& p : s.points()) {
852 p.transform(i, fn);
853 }
854 }
855
856 template<size_t N, typename FN>
857 inline void transform(ScatterND<N>& s, const FN& fn, const size_t i) {
858 transform(s, Trf<N>(fn), i);
859 }
860
861 template<size_t N, typename FN>
862 inline void transformX(ScatterND<N>& s, const FN& fn) {
863 transform(s, fn, 0);
864 }
865
866 template<size_t N, typename FN>
867 inline void transformY(ScatterND<N>& s, const FN& fn) {
868 transform(s, fn, 1);
869 }
870
871 template<size_t N, typename FN>
872 inline void transformZ(ScatterND<N>& s, const FN& fn) {
873 transform(s, fn, 2);
874 }
875
877
880
885 using S1D = Scatter1D;
886 using S2D = Scatter2D;
887 using S3D = Scatter3D;
888 using S4D = Scatter4D;
889
891
892
893}
894
895#endif
AnalysisObject is the base class for histograms and scatters.
virtual AnalysisObject & operator=(const AnalysisObject &ao) noexcept
Default copy assignment operator.
const std::string title() const
Get the AO title.
const std::string path() const
Get the AO path.
Error for e.g. use of invalid bin ranges.
Definition Exceptions.h:34
A generic data type which is just a collection of n-dim data points with errors.
Definition Scatter.h:154
auto addPoint_aux(std::tuple< Args... > &&t, std::index_sequence< Is... >) -> std::enable_if_t<(sizeof...(Args)==2 *N &&isHalfValsHalfPairs< Args... >::value), ScatterND< N > > &
Definition Scatter.h:490
typename std::is_same< containedType< Arr >, Pair > containsPair
Definition Scatter.h:170
std::decay_t< decltype(*std::declval< Arr >().begin())> containedType
Definition Scatter.h:166
std::vector< Pair > edges(const size_t i) const
Definition Scatter.h:745
double zMin() const
Axis-specific alias.
Definition Scatter.h:692
size_t numPoints() const
Number of points in the scatter.
Definition Scatter.h:334
double yMin() const
Axis-specific alias.
Definition Scatter.h:688
ScatterND(const ScatterND< N > &s, const std::string &path="")
Copy constructor with optional new path.
Definition Scatter.h:254
void scale(const size_t i, double factor)
Definition Scatter.h:316
ScatterND< N > * newclone() const
Make a copy on the heap, via 'new'.
Definition Scatter.h:289
PointND< N > & point(size_t index)
Get a reference to the point with index index.
Definition Scatter.h:352
std::enable_if_t<(isIterable< T, U, containedType< T >, containedType< U > > &&containsPair< containedType< U > >::value)> enableIfNestedArrayWithPair
Definition Scatter.h:176
double zMax() const
Axis-specific alias.
Definition Scatter.h:703
size_t lengthContent(bool fixed_length=false) const noexcept
Length of serialized content vector for MPI reduce operations.
Definition Scatter.h:515
ScatterND< N > & addPoint(ValRange &&pos, ValRange &&errdn, ValRange &&errup)
Insert a new point from position and asymmetric error arrays (of N elements)
Definition Scatter.h:399
ValVec maxs(const size_t i) const
Get the positive error vector along axis i.
Definition Scatter.h:607
ScatterND< N > clone() const
Make a copy on the stack.
Definition Scatter.h:284
double max(const size_t i) const
Get the largest central value along axis i.
Definition Scatter.h:624
ValVec yVals() const
Axis-specific alias.
Definition Scatter.h:655
size_t dim() const noexcept
Dimension of this data object.
Definition Scatter.h:296
HalfValsHalfPairs< std::tuple< Args... >, std::make_index_sequence< N > > isHalfValsHalfPairs
Definition Scatter.h:186
Utils::sortedvector< Point > Points
Definition Scatter.h:194
const PointND< N > & point(size_t index) const
Get the point with index index (const version)
Definition Scatter.h:358
auto addPoint(Args &&... args) -> std::enable_if_t<(sizeof...(Args)==2 *N||sizeof...(Args)==3 *N), ScatterND< N > > &
Definition Scatter.h:436
ScatterND(ScatterND< N > &&s, const std::string &path="")
Move constructor with optional new path.
Definition Scatter.h:259
std::initializer_list< Pair > PairList
Definition Scatter.h:162
PairVec zErrs() const
Axis-specific alias.
Definition Scatter.h:714
ValVec errsAvg(const size_t i) const
Get the average error along axis i.
Definition Scatter.h:641
ValVec vals(const size_t i) const
Get the coordinate vector along axis i.
Definition Scatter.h:587
void rmPoint(size_t index)
Remove the point with index index.
Definition Scatter.h:506
ScatterND(ValRange &&positions, PairRange &&errors, const std::string &path="", const std::string &title="")
Constructor from vectors of values for positions and a single set of symmetric errors.
Definition Scatter.h:244
ScatterND< N > & addPoint(const PointND< N > &pt)
Insert a new point.
Definition Scatter.h:369
const Points & points() const
Get the collection of points (const version)
Definition Scatter.h:346
ScatterND< N > & combineWith(const ScatterND< N > &other)
Definition Scatter.h:558
Utils::ndarray< std::pair< double, double >, N > NdValPair
Definition Scatter.h:192
PairVec yErrs() const
Axis-specific alias.
Definition Scatter.h:710
ValVec xMaxs() const
Axis-specific alias.
Definition Scatter.h:673
ValVec mins(const size_t i) const
Get the lowest value vector along axis i.
Definition Scatter.h:597
ScatterND< N > & combineWith(std::vector< ScatterND< N > > &&others)
Definition Scatter.h:576
ScatterND< N > & operator=(const ScatterND< N > &s)
Assignment operator.
Definition Scatter.h:266
Utils::ndarray< double, N > NdVal
Definition Scatter.h:191
ScatterND< N > & combineWith(const std::vector< ScatterND< N > > &others)
Definition Scatter.h:570
std::vector< Pair > PairVec
Definition Scatter.h:160
PointND< N > Point
Definition Scatter.h:193
ScatterND(const std::string &path="", const std::string &title="")
Empty constructor.
Definition Scatter.h:203
void deserializeContent(const std::vector< double > &data)
Content deserialisation for MPI reduce operations.
Definition Scatter.h:535
ScatterND(Points &&points, const std::string &path="", const std::string &title="")
Constructor from a set of rvalue points.
Definition Scatter.h:213
double min(const size_t i) const
Get the smallest central value along axis i.
Definition Scatter.h:617
ValVec xMins() const
Axis-specific alias.
Definition Scatter.h:662
PairVec errs(const size_t i) const
Get the error pairs along axis i.
Definition Scatter.h:631
auto addPoint_aux(std::tuple< Args... > &&t, std::index_sequence< Is... >) -> std::enable_if_t<(isAllVals< Args... >::value), ScatterND< N > > &
Definition Scatter.h:459
Points & points()
Get the collection of points.
Definition Scatter.h:340
ScatterND(ValRange &&positions, const std::string &path="", const std::string &title="")
Constructor from a vector of position values with no errors.
Definition Scatter.h:221
ScatterND< N > & addPoint(ValRange &&pos)
Insert a new point from a position array (of N elements)
Definition Scatter.h:383
double yMax() const
Axis-specific alias.
Definition Scatter.h:699
ValVec xVals() const
Axis-specific alias.
Definition Scatter.h:651
std::is_same< double, std::common_type_t< Args..., double > > isAllVals
Definition Scatter.h:180
ValVec zVals() const
Axis-specific alias.
Definition Scatter.h:659
ScatterND< N > & addPoints(Points pts)
Insert a collection of new points.
Definition Scatter.h:501
PairVec xErrs() const
Axis-specific alias.
Definition Scatter.h:706
ValVec zMins() const
Axis-specific alias.
Definition Scatter.h:670
void reset()
Clear all points.
Definition Scatter.h:302
ScatterND< N > & combineWith(ScatterND< N > &&other)
Definition Scatter.h:564
void scale(const NdVal &scales)
Scaling.
Definition Scatter.h:307
std::shared_ptr< ScatterND > Ptr
Definition Scatter.h:195
ScatterND< N > & addPoint(ValRange &&pos, ValRange &&err)
Insert a new point from position and symmetric error arrays (of N elements)
Definition Scatter.h:391
ValVec yMins() const
Axis-specific alias.
Definition Scatter.h:666
ScatterND(const Points &points, const std::string &path="", const std::string &title="")
Constructor from a set of points.
Definition Scatter.h:207
auto addPoint(ValRange &&pos, PairRange &&err) -> std::enable_if_t<(isIterable< ValRange, PairRange > &&containsPair< PairRange >::value), ScatterND< N > > &
Insert a new point from a position and error-pair array.
Definition Scatter.h:408
void scale(const std::vector< double > &scales)
Definition Scatter.h:311
std::pair< double, double > Pair
Definition Scatter.h:158
ValVec yMaxs() const
Axis-specific alias.
Definition Scatter.h:677
std::initializer_list< double > ValList
Definition Scatter.h:161
ScatterND(ValRange &&positions, ValRange &&errors, const std::string &path="", const std::string &title="")
Constructor from vectors of values for positions and a single set of symmetric errors.
Definition Scatter.h:231
double xMin() const
Axis-specific alias.
Definition Scatter.h:684
std::vector< double > ValVec
Definition Scatter.h:159
double xMax() const
Axis-specific alias.
Definition Scatter.h:695
std::vector< double > serializeContent(bool fixed_length=false) const noexcept
Content serialisation for MPI reduce operations.
Definition Scatter.h:520
ScatterND< N > & addPoint(PointND< N > &&pt)
Insert a new rvalue point.
Definition Scatter.h:375
ValVec zMaxs() const
Axis-specific alias.
Definition Scatter.h:681
A base class for common operations on scatter types (Scatter1D, etc.)
Definition Scatter.h:44
virtual ~Scatter()
Virtual destructor for inheritance.
Definition Scatter.h:50
virtual size_t numPoints() const =0
Scaling along direction i.
virtual void reset()=0
Clear all points.
virtual size_t dim() const noexcept=0
Dimension of this data object.
virtual void rmPoint(size_t index)=0
Remove the point with index index.
virtual void rmPoints(std::vector< size_t > indices)
Safely remove the points with indices indices.
Definition Scatter.h:85
Error for problems introduced outside YODA, to put it nicely.
Definition Exceptions.h:100
Anonymous namespace to limit visibility.
void transform(BinnedEstimate< AxisT... > &est, const Trf< 1 > &fn)
ScatterND< 3 > Scatter3D
Definition Scatter.h:883
void transformX(ScatterND< N > &s, const FN &fn)
Definition Scatter.h:862
void transformY(ScatterND< N > &s, const FN &fn)
Definition Scatter.h:867
ScatterND< 4 > Scatter4D
Definition Scatter.h:884
void transformZ(ScatterND< N > &s, const FN &fn)
Definition Scatter.h:872
ScatterND< N > combine(ScatterND< N > a, const ScatterND< N > &b)
Definition Scatter.h:771
ScatterND< 1 > Scatter1D
Definition Scatter.h:881
ScatterND< 2 > Scatter2D
Definition Scatter.h:882