1 #ifndef __JTOOLS__JSPLINE__
2 #define __JTOOLS__JSPLINE__
22 namespace JPP {
using namespace JTOOLS; }
35 template<
class JOrdinate_t>
121 throw JNoValue(
"JSplineBounds: missing 1st derivative.");
135 throw JNoValue(
"JSplineBounds: missing 1st derivative.");
151 template<
class JOrdinate_t>
153 const JOrdinate_t fpAtXmax)
175 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
177 public JCollection_t<JElement_t, JDistance_t>,
190 typedef typename collection_type::iterator
iterator;
203 const int numberOfElements = this->size();
207 if (numberOfElements > 2) {
216 const double dx = this->
getDistance(i->getX(), j->getX());
232 for (
iterator k = this->begin(),
i =
k++,
j =
k++;
k != this->end(); ++
i, ++
j, ++
k, ++index) {
243 const double h = sig * buffer[index-1] + 2.0;
245 buffer[index] = (sig - 1.0) / h;
250 j->setU((6.0 * j->getU() / this->
getDistance(x1, x3) - sig *
i->getU()) / h);
259 index = numberOfElements - 2;
261 const double dx = this->
getDistance(i->getX(), j->getX());
266 i->setU((i->getU() - 0.5*j->getU()) / (0.5*buffer[index] + 1.0));
277 index = numberOfElements - 2;
279 for ( ; j != this->rend(); ++
i, ++
j, --index) {
280 j->setU(j->getU() + i->getU() * buffer[index]);
285 for (
iterator i = this->begin();
i != this->end(); ++
i) {
313 template<
class JElement_t,
314 template<
class,
class>
class JCollection_t,
323 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
329 public virtual JFunction<typename JElement_t::abscissa_type,
330 typename JResultType<typename JElement_t::ordinate_type>::result_type>
343 typedef typename collection_type::iterator
iterator;
371 if (this->size() > 1
u) {
375 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
376 (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
383 std::ostringstream os;
385 os << __FILE__ <<
':' << __LINE__ <<
" abscissa out of range "
386 <<
STREAM(
"?") << x <<
" <> "
387 <<
STREAM(
"?") << this->begin() ->getX() <<
' '
388 <<
STREAM(
"?") << this->rbegin()->getX();
396 const double dx = this->
getDistance(p->getX(), q->getX());
398 const double b = 1.0 -
a;
400 return (a * p->getY() + b * q->getY()
401 - a*b * ((a + 1.0)*p->getU() + (b + 1.0)*q->getU()) * dx*dx/6);
403 }
else if (this->size() == 1
u && this->
getDistance(x, this->begin()->getX()) <= distance_type::precision) {
405 return this->begin()->getY();
414 std::ostringstream os;
416 os << __FILE__ <<
':' << __LINE__ <<
" not enough data " <<
STREAM(
"?") <<
x;
428 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
434 public virtual JFunction<typename JElement_t::abscissa_type,
435 JResultDerivative<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
448 typedef typename collection_type::iterator
iterator;
478 if (this->size() <= 1
u) {
485 std::ostringstream os;
487 os << __FILE__ <<
':' << __LINE__ <<
" not enough data " <<
STREAM(
"?") <<
x;
496 if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
497 (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
504 std::ostringstream os;
506 os << __FILE__ <<
':' << __LINE__ <<
" abscissa out of range "
507 <<
STREAM(
"?") << x <<
" <> "
508 <<
STREAM(
"?") << this->begin() ->getX() <<
' '
509 <<
STREAM(
"?") << this->rbegin()->getX();
517 const double dx = this->
getDistance(p->getX(), q->getX());
519 const double b = 1.0 -
a;
521 result.f = a * p->getY() + b * q->getY()
522 - a*b * ((a + 1.0)*p->getU() + (b + 1.0)*q->getU()) * dx*dx/6;
524 result.fp = (q->getY() - p->getY() + (p->getU()*(1.0 - 3*a*
a) -
525 q->getU()*(1.0 - 3*b*b)) * dx*dx/6) / dx;
546 template<
class JElement_t,
template<
class,
class>
class JCollection_t,
class JDistance_t>
552 public virtual JFunction<typename JElement_t::abscissa_type,
553 JResultPDF<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
566 typedef typename collection_type::iterator
iterator;
593 if (this->size() >= 2
u) {
595 collection_type::compile(bounds);
599 for (
iterator j = this->begin(),
i =
j++;
j != this->end(); ++
i, ++
j) {
608 j->setIntegral(
i->getIntegral() + v -
w);
624 if (this->size() <= 1
u) {
631 std::ostringstream os;
633 os << __FILE__ <<
':' << __LINE__ <<
" not enough data " <<
STREAM(
"?") <<
x;
641 if (p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) {
650 result.V = this->rbegin()->getIntegral();
654 std::ostringstream os;
656 os << __FILE__ <<
':' << __LINE__ <<
" abscissa out of range " <<
STREAM(
"?") << x <<
" < " <<
STREAM(
"?") << this->begin() ->getX();
663 }
else if (p == this->end() && this->
getDistance((--p)->getX(), x) > distance_type::precision) {
671 result.v = this->rbegin()->getIntegral();
672 result.V = this->rbegin()->getIntegral();
676 std::ostringstream os;
678 os << __FILE__ <<
':' << __LINE__ <<
" abscissa out of range " <<
STREAM(
"?") << x <<
" > " <<
STREAM(
"?") << this->rbegin()->getX();
688 const double dx = this->
getDistance(p->getX(), q->getX());
690 const double b = 1.0 -
a;
692 result.f = a * p->getY() + b * q->getY()
693 - a*b * ((a + 1.0)*p->getU() + (b + 1.0)*q->getU()) * dx*dx/6;
695 result.fp = (q->getY() - p->getY() + (p->getU()*(1.0 - 3*a*
a) -
696 q->getU()*(1.0 - 3*b*b)) * dx*dx/6) / dx;
698 result.v = p->getIntegral()
699 + 0.5*dx * (p->getY() - 0.5*p->getU()*dx*dx/6)
700 - 0.5*dx * ((a*a*p->getY() - b*b*q->getY()) +
701 (p->getU() * a*a*(0.5*a*a - 1.0) -
702 q->getU() * b*b*(0.5*b*b - 1.0)) * dx*dx/6);
704 result.V = this->rbegin()->getIntegral();
730 template<
class JElement_t,
731 template<
class,
class>
class JCollection_t,
732 class JResult_t =
typename JElement_t::ordinate_type,
735 public JSplineFunction<JElement_t, JCollection_t, JResult_t, JDistance_t>,
736 public JFunction1D<typename JElement_t::abscissa_type, JResult_t>
772 template<
class JAbscissa_t,
class JOrdinate_t>
775 template<
template<
class,
class,
class>
class JMap_t>
782 template<
class JKey_t,
784 template<
class,
class,
class>
class JMap_t,
788 public JMap_t<JKey_t, JValue_t, JDistance_t>,
855 for (
iterator i = this->begin();
i != this->end(); ++
i) {
874 template<
class JElement_t,
875 template<
class,
class>
class JCollection_t,
878 inline typename JElement_t::ordinate_type
887 if (input.getSize() > 1) {
889 output.
put(input.begin()->getX(),
V);
891 for (const_iterator
j = input.begin(),
i =
j++;
j != input.end(); ++
i, ++
j) {
893 const double dx = input.getDistance(
i->getX(),
j->getX());
894 const ordinate_type
y =
i->getY() +
j->getY();
895 const ordinate_type z =
i->getU() +
j->getU();
896 const ordinate_type
v = dx * 0.50 *
y;
897 const ordinate_type
w = dx * 0.25 * z*dx*dx/6;
901 output.
put(
j->getX(),
V);
918 template<
class JElement_t,
919 template<
class,
class>
class JCollection_t,
921 inline typename JElement_t::ordinate_type
929 if (input.getSize() > 1) {
931 for (const_iterator
i = input.begin();
i != input.end(); ++
i) {
932 output.
put(
i->getX(),
i->getIntegral());
935 return input.rbegin()->getIntegral();
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
std::vector< event_type > data_type
Exception for a functional operation.
This include file containes various data structures that can be used as specific return types for the...
static const JZero zero
Function object to assign zero value.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
Definition of zero value for any class.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
Exception for missing value.
JArgument< T >::argument_type argument_type
Auxiliary data structure for handling std::ostream.
Exception for division by zero.
Exception for accessing a value in a collection that is outside of its range.