Jpp test-rotations-old
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 const int index = getIndex(x) + 1;
81
82 if (index <= 0)
83 return this->begin();
84 else if (index >= (int) this->size())
85 return this->end();
86 else
87 return this->begin() + index;
88 }
89
90
91 /**
92 * Get first position of element <tt>i</tt>, where <tt>x >= i->getX()</tt>.
93 *
94 * \param x abscissa value
95 * \return position of corresponding element
96 */
98 {
99 const int index = getIndex(x) + 1;
100
101 if (index <= 0)
102 return this->begin();
103 else if (index >= (int) this->size())
104 return this->end();
105 else
106 return this->begin() + index;
107 }
108 };
109}
110
111#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
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