1 #ifndef __JTOOLS__JPOLINT__
2 #define __JTOOLS__JPOLINT__
24 namespace JPP {
using namespace JTOOLS; }
37 template<
unsigned int N,
39 template<
class,
class>
class JCollection_t,
52 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
58 public JCollection_t<JElement_t, JDistance_t>,
59 public JFunction<typename JElement_t::abscissa_type,
60 typename JResultType<typename JElement_t::ordinate_type>::result_type>
73 typedef typename collection_type::iterator
iterator;
99 if (this->size() <= 1
u) {
100 return this->getExceptionHandler().action(
JFunctionalException(
"JPolintFunction<>::evaluate() not enough data."));
107 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
108 (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
109 return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
115 const int n = std::min((
int) (
N + 1), (
int) this->size());
117 for (
int i = n/2; i != 0 && p != this->end(); --i, ++p) {}
118 for (
int i = n ; i != 0 && p != this->begin(); --i, --p) {}
123 for (
int i = 0; i !=
n; ++p, ++i) {
129 if (fabs(
u[i]) < fabs(
u[j])) {
139 for (
int m = 1; m !=
n; ++m) {
141 for (
int i = 0; i != n-m; ++i) {
143 const double ho =
u[ i ];
144 const double hp =
u[i+m];
145 const double dx = ho - hp;
173 mutable double u[
N+1];
183 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
189 public JCollection_t<JElement_t, JDistance_t>,
190 public JFunction<typename JElement_t::abscissa_type,
191 typename JResultType<typename JElement_t::ordinate_type>::result_type>
204 typedef typename collection_type::iterator
iterator;
230 if (this->size() <= 1
u) {
231 return this->getExceptionHandler().action(
JFunctionalException(
"JPolintFunction<>::evaluate() not enough data."));
238 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
239 (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
241 return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
268 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
274 public JCollection_t<JElement_t, JDistance_t>,
275 public JFunction<typename JElement_t::abscissa_type,
276 typename JResultType<typename JElement_t::ordinate_type>::result_type>
289 typedef typename collection_type::iterator
iterator;
315 if (this->size() <= 1
u) {
316 return this->getExceptionHandler().action(
JFunctionalException(
"JPolintFunction<>::evaluate() not enough data."));
323 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
324 (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
326 return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
334 const double dx = this->
getDistance(p->getX(), q->getX());
336 const double b = 1.0 -
a;
373 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
379 public JCollection_t<JElement_t, JDistance_t>,
380 public JFunction<typename JElement_t::abscissa_type,
381 JResultPDF<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
394 typedef typename collection_type::iterator
iterator;
422 if (this->size() <= 1
u) {
423 return this->getExceptionHandler().action(
JFunctionalException(
"JPolintFunction<>::evaluate() not enough data."));
430 if (p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) {
439 result.V = this->rbegin()->getIntegral();
447 }
else if (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision) {
455 result.v = this->rbegin()->getIntegral();
456 result.V = this->rbegin()->getIntegral();
468 const int n = std::min((
int) (
N + 1), (
int) this->size());
470 for (
int i = n/2; i != 0 && p != this->end(); --i, ++p) {}
471 for (
int i = n ; i != 0 && p != this->begin(); --i, --p) {}
476 for (
int i = 0; i !=
n; ++p, ++i) {
482 w[i][2] =
v[i][2] = p->getIntegral();
484 if (fabs(
u[i]) < fabs(
u[j])) {
493 result.V = this->rbegin()->getIntegral();
497 for (
int m = 1; m !=
n; ++m) {
499 for (
int i = 0; i != n-m; ++i) {
501 const double ho =
u[ i ];
502 const double hp =
u[i+m];
503 const double dx = ho - hp;
505 for (
int k = 0;
k != 3; ++
k) {
506 r[
k] = (
v[i+1][
k] -
w[i][
k]) / dx;
511 v[i][1] = ho * r[1] - r[0];
512 w[i][1] = hp * r[1] - r[0];
517 if (2*(j+1) < n - m) {
549 this->begin()->setIntegral(V);
551 for (
iterator j = this->begin(), i =
j++;
j != this->end(); ++i, ++
j) {
558 const abscissa_type x = 0.5 * (xmax + xmin + m->getX() * (xmax - xmin));
570 mutable double u[
N+1];
582 template<
unsigned int N,
584 template<
class,
class>
class JCollection_t,
595 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t,
unsigned int M>
601 public JCollection_t<JElement_t, JDistance_t>,
607 typedef JCollection_t<JElement_t, JDistance_t> collection_type;
609 typedef typename collection_type::abscissa_type abscissa_type;
610 typedef typename collection_type::ordinate_type ordinate_type;
611 typedef typename collection_type::value_type value_type;
612 typedef typename collection_type::distance_type distance_type;
614 typedef typename collection_type::const_iterator const_iterator;
615 typedef typename collection_type::const_reverse_iterator const_reverse_iterator;
616 typedef typename collection_type::iterator iterator;
617 typedef typename collection_type::reverse_iterator reverse_iterator;
619 typedef typename JResultType<ordinate_type>::result_type data_type;
620 typedef JFunction<abscissa_type, JResultPolynome<M, data_type> > function_type;
622 typedef typename function_type::argument_type argument_type;
623 typedef typename function_type::result_type result_type;
625 using JFunctional<>::compile;
641 result_type evaluate(const argument_type* pX) const
643 if (this->size() <= N) {
644 THROW(JFunctionalException, "JPolintFunction<>::evaluate() not enough data.");
647 const argument_type x = *pX;
649 const_iterator p = this->lower_bound(x);
651 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
652 (p == this->end() &&
this->
getDistance((--p)->getX(),
x) > distance_type::precision)) {
660 const int n = std::min((
int) (
N + 1), (
int) this->size());
662 for (
int i =
n/2; i != 0 && p != this->end(); --i, ++p) {}
663 for (
int i =
n ; i != 0 && p != this->begin(); --i, --p) {}
668 for (
int i = 0; i !=
n; ++p, ++i) {
674 for (
unsigned int k = 1;
k !=
M+1; ++
k) {
678 if (fabs(
u[i]) < fabs(
u[
j])) {
684 for (
unsigned int k = 0;
k !=
M+1; ++
k) {
690 for (
int m = 1; m !=
n; ++m) {
692 for (
int i = 0; i !=
n-m; ++i) {
694 const double ho =
u[ i ];
695 const double hp =
u[i+m];
696 const double dx = ho - hp;
698 for (
int k = 0;
k !=
M+1; ++
k) {
699 r[
k] = (
v[i+1][
k] -
w[i][
k]) / dx;
705 for (
int k = 1;
k !=
M+1; ++
k) {
706 v[i][
k] = ho * r[
k] -
k * r[
k-1];
707 w[i][
k] = hp * r[
k] -
k * r[
k-1];
711 if (2*(
j+1) <
n - m) {
713 for (
int k = 0;
k !=
M+1; ++
k) {
719 for (
int k = 0;
k !=
M+1; ++
k) {
739 mutable double u[
N+1];
740 mutable data_type
v[
N+1][
M+1];
741 mutable data_type
w[
N+1][
M+1];
742 mutable data_type
r[
M+1];
744 mutable result_type
result;
751 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t,
unsigned int M>
760 JResultPolynome<M, typename JResultType<typename JElement_t::ordinate_type>::result_type>,
762 public JFunction<typename JElement_t::abscissa_type,
763 JResultPolynome<N, typename JResultType<typename JElement_t::ordinate_type>::result_type> >
780 typedef typename collection_type::iterator
iterator;
807 return collection_type::evaluate(pX);
810 return this->getExceptionHandler().action(error);
819 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
828 JResultPolynome<1, typename JResultType<typename JElement_t::ordinate_type>::result_type>,
830 public JFunction<typename JElement_t::abscissa_type,
831 JResultDerivative<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
848 typedef typename collection_type::iterator
iterator;
877 return collection_type::evaluate(pX);
880 return this->getExceptionHandler().action(error);
889 template<
unsigned int N,
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
898 JResultPolynome<2, typename JResultType<typename JElement_t::ordinate_type>::result_type>,
900 public JFunction<typename JElement_t::abscissa_type,
901 JResultHesse<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
918 typedef typename collection_type::iterator
iterator;
947 return collection_type::evaluate(pX);
950 return this->getExceptionHandler().action(error);
961 template<
unsigned int N,
963 template<
class,
class>
class JCollection_t,
964 class JResult_t =
typename JElement_t::ordinate_type,
967 public JPolintFunction<N, JElement_t, JCollection_t, JResult_t, JDistance_t>,
968 public JFunction1D<typename JElement_t::abscissa_type, JResult_t>
1004 template<
class JAbscissa_t,
class JOrdinate_t>
1007 template<
template<
class,
class,
class>
class JMap_t>
1014 template<
unsigned int N,
1017 template<
class,
class,
class>
class JMap_t,
1022 JElement2D<JKey_t, JValue_t>,
1023 JMapCollection<JMap_t>::template collection_type,
1068 template<
unsigned int N,
1070 template<
class,
class>
class JCollection_t,
1073 inline typename JElement_t::ordinate_type
1092 template<
unsigned int N,
1094 template<
class,
class>
class JCollection_t,
1097 inline typename JElement_t::ordinate_type
1102 typedef typename JElement_t::abscissa_type abscissa_type;
1103 typedef typename JElement_t::ordinate_type ordinate_type;
1108 if (input.getSize() > 1) {
1110 output.
put(input.begin()->getX(),
V);
1114 for (const_iterator
j = input.begin(), i =
j++;
j != input.end(); ++i, ++
j) {
1116 const abscissa_type xmin = i->getX();
1117 const abscissa_type xmax =
j->getX();
1121 const abscissa_type
x = 0.5 * (xmax + xmin + m->getX() * (xmax - xmin));
1122 const ordinate_type
v = 0.5 * (xmax - xmin) * m->getY() *
get_value(input(x));
1127 output.
put(xmax, V);
1145 template<
class JElement_t,
1146 template<
class,
class>
class JCollection_t,
1149 inline typename JElement_t::ordinate_type
1154 typedef typename JElement_t::ordinate_type ordinate_type;
1159 if (input.getSize() > 1) {
1161 output.
put(input.begin()->getX(),
V);
1163 for (const_iterator
j = input.begin(), i =
j++;
j != input.end(); ++i, ++
j) {
1165 V += input.getDistance(i->getX(),
j->getX()) *
j->getY();
1167 output.
put(
j->getX(),
V);
1185 template<
class JElement_t,
1186 template<
class,
class>
class JCollection_t,
1189 inline typename JElement_t::ordinate_type
1194 typedef typename JElement_t::ordinate_type ordinate_type;
1199 if (input.getSize() > 1) {
1201 output.
put(input.begin()->getX(),
V);
1203 for (const_iterator
j = input.begin(), i =
j++;
j != input.end(); ++i, ++
j) {
1205 V += 0.5 * input.getDistance(i->getX(),
j->getX()) * (i->getY() +
j->getY());
1207 output.
put(
j->getX(),
V);
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Exception for a functional operation.
The elements in a collection are sorted according to their abscissa values and a given distance opera...
This include file containes various data structures that can be used as specific return types for the...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
static const JZero zero
Function object to assign zero value.
Generation of compiler error.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
size_t getSize(T(&array)[N])
Get size of c-array.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
Auxiliary template class for type bool.
Exception for numerical precision error.
Auxiliary classes for numerical integration.
Exception for accessing a value in a collection that is outside of its range.
do if[[!-f $ACOUSTICS_WORKDIR/${KEY}.txt]]