Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JGridCollection.hh
Go to the documentation of this file.
1#ifndef __JTOOLS__JGRIDCOLLECTION__
2#define __JTOOLS__JGRIDCOLLECTION__
3
4#include "JLang/JClass.hh"
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JTOOLS {}
13namespace JPP { using namespace JTOOLS; }
14
15namespace JTOOLS {
16
17 using JLANG::JClass;
18
19
20 /**
21 * General purpose class for collection of equidistant elements.
22 *
23 * For a collection with equidistant elements, the index of the nearest element can directly be computed
24 * based on the minimal abscissa value, the maximal abscissa value and the number of elements in the collection.
25 * The lower_bound methods are re-implemented in this class which otherwise simply derives from JCollection.
26 *
27 * For convenience, the implementation of the standard map operator <tt>[]</tt> of the JCollection class is maintained.
28 */
29 template<class JElement_t, class JDistance_t = JDistance<typename JElement_t::abscissa_type> >
31 public JCollection<JElement_t, JDistance_t>
32 {
33 public:
34
36
40
45
47
48
49 /**
50 * Default constructor.
51 */
54
55
56 /**
57 * Get index of given abscissa value.
58 *
59 * For values within the range of this collection, the index starts at zero and ends at number of elements minus one.
60 * Note that the index could be less than zero or larger than (or equal to) the number of elements,
61 * if the given abscissa value is outside the range of this collection.
62 *
63 * \param x abscissa value
64 * \return index
65 */
67 {
68 return (int) ((this->size() - 1) * (x - this->begin()->getX()) / (this->rbegin()->getX() - this->begin()->getX()));
69 }
70
71
72 /**
73 * Get first position of element <tt>i</tt>, where <tt>x < i->getX()</tt>.
74 *
75 * \param x abscissa value
76 * \return position of corresponding element
77 */
79 {
80 if (x < this-> begin()->getX())
81 return this->begin();
82 else if (x > this->rbegin()->getX())
83 return this->end();
84 else
85 return this->begin() + getIndex(x) + 1;
86 }
87
88
89 /**
90 * Get first position of element <tt>i</tt>, where <tt>x < i->getX()</tt>.
91 *
92 * \param x abscissa value
93 * \return position of corresponding element
94 */
96 {
97 if (x < this-> begin()->getX())
98 return this->begin();
99 else if (x > this->rbegin()->getX())
100 return this->end();
101 else
102 return this->begin() + getIndex(x) + 1;
103 }
104 };
105}
106
107#endif
General purpose class for a collection of sorted elements.
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements....
Definition JSet.hh:22
JElement_t value_type
JElement_t::ordinate_type ordinate_type
virtual abscissa_type getX(int index) const override
Get abscissa value.
container_type::reverse_iterator reverse_iterator
JElement_t::abscissa_type abscissa_type
container_type::iterator iterator
container_type::const_iterator const_iterator
container_type::const_reverse_iterator const_reverse_iterator
General purpose class for collection of equidistant elements.
int getIndex(typename JClass< abscissa_type >::argument_type x) const
Get index of given abscissa value.
collection_type::reverse_iterator reverse_iterator
collection_type::abscissa_type abscissa_type
collection_type::const_reverse_iterator const_reverse_iterator
const_iterator lower_bound(typename JClass< abscissa_type >::argument_type x) const
Get first position of element i, where x < i->getX().
collection_type::ordinate_type ordinate_type
collection_type::const_iterator const_iterator
collection_type::value_type value_type
iterator lower_bound(typename JClass< abscissa_type >::argument_type x)
Get first position of element i, where x < i->getX().
collection_type::iterator iterator
JGridCollection()
Default constructor.
collection_type::pair_type pair_type
JCollection< JElement_t, JDistance_t > collection_type
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Template for generic class types.
Definition JClass.hh:80
JArgument< T >::argument_type argument_type
Definition JClass.hh:82