Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t > Struct Template Reference

1D Binned element with bin centering. More...

#include <JElement.hh>

Inheritance diagram for JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >:
JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t > JMATH::JMath< JFirst_t, JSecond_t >

Public Types

typedef JElement2D< JAbscissa_t, JOrdinate_t > element_type
 
typedef element_type::abscissa_type abscissa_type
 
typedef element_type::ordinate_type ordinate_type
 

Public Member Functions

 JBin1D ()
 Default constructor.
 
 JBin1D (typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y, typename JLANG::JClass< abscissa_type >::argument_type u, typename JLANG::JClass< ordinate_type >::argument_type w2)
 Constructor.
 
 JBin1D (typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type y)
 Constructor.
 
void fill (typename JLANG::JClass< abscissa_type >::argument_type x, typename JLANG::JClass< ordinate_type >::argument_type w)
 Add abscissa value.
 
abscissa_type getBinCenter () const
 Get bin center.
 
ordinate_type getBinContent () const
 Get bin content.
 
ordinate_type getBinError () const
 Get bin error.
 
ordinate_type getEffectiveBinContent () const
 Get effective bin content.
 
JBin1Dnegate ()
 Negate bin.
 
JBin1Dadd (const JBin1D &bin)
 Add bin.
 
JBin1Dsub (const JBin1D &bin)
 Subtract bin.
 
JBin1Dmul (const double value)
 Scale contents.
 
JBin1Ddiv (const double value)
 Divide contents.
 
JBin1Dmul (const JBin1D &bin)
 Multiply bins.
 
abscissa_type getX () const
 Get abscissa value.
 
const ordinate_typegetY () const
 Get ordinate value.
 
ordinate_typegetY ()
 Get ordinate value.
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object.
 

Protected Attributes

abscissa_type __u
 Sum of weighted abscissa values.
 
ordinate_type __w2
 Sum of squared weights.
 
abscissa_type __x
 
ordinate_type __y
 

Detailed Description

template<class JAbscissa_t, class JOrdinate_t>
struct JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >

1D Binned element with bin centering.

Note that the internal data members needed for the calculation of the bin center are not subject to I/O, i.e. the I/O of this class is identical to that of the JElement2D class.

Definition at line 352 of file JElement.hh.

Member Typedef Documentation

◆ element_type

template<class JAbscissa_t , class JOrdinate_t >
JElement2D<JAbscissa_t, JOrdinate_t> JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::element_type

Definition at line 357 of file JElement.hh.

◆ abscissa_type

template<class JAbscissa_t , class JOrdinate_t >
element_type::abscissa_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::abscissa_type

Definition at line 359 of file JElement.hh.

◆ ordinate_type

template<class JAbscissa_t , class JOrdinate_t >
element_type::ordinate_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::ordinate_type

Definition at line 360 of file JElement.hh.

Constructor & Destructor Documentation

◆ JBin1D() [1/3]

template<class JAbscissa_t , class JOrdinate_t >
JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::JBin1D ( )
inline

Default constructor.

Definition at line 366 of file JElement.hh.

366 :
367 element_type(),
368 __u (getZero<ordinate_type>()),
369 __w2(getZero<ordinate_type>())
370 {}
abscissa_type __u
Sum of weighted abscissa values.
Definition JElement.hh:584
ordinate_type __w2
Sum of squared weights.
Definition JElement.hh:585
JElement2D< JAbscissa_t, JOrdinate_t > element_type
Definition JElement.hh:357

◆ JBin1D() [2/3]

template<class JAbscissa_t , class JOrdinate_t >
JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::JBin1D ( typename JLANG::JClass< abscissa_type >::argument_type x,
typename JLANG::JClass< ordinate_type >::argument_type y,
typename JLANG::JClass< abscissa_type >::argument_type u,
typename JLANG::JClass< ordinate_type >::argument_type w2 )
inline

Constructor.

Parameters
xabscissa value
yordinate value (sum of weights)
usum of weighted abscissa values
w2sum of squared weights

Definition at line 381 of file JElement.hh.

384 :
385 element_type(x,y),
386 __u (u),
387 __w2(w2)
388 {
389 using namespace JPP;
390
391 if (w2 < getZero<ordinate_type>()) {
392 THROW(JValueOutOfRange, "JBin1D::JBin1D(): Invalid sum of squared weights " << w2);
393 }
394 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for accessing a value in a collection that is outside of its range.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).

◆ JBin1D() [3/3]

template<class JAbscissa_t , class JOrdinate_t >
JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::JBin1D ( typename JLANG::JClass< abscissa_type >::argument_type x,
typename JLANG::JClass< ordinate_type >::argument_type y )
inline

Constructor.

Parameters
xabscissa value
yordinate value (sum of weights)

Definition at line 403 of file JElement.hh.

404 :
405 JBin1D(x, y, x*y, y)
406 {}
JBin1D()
Default constructor.
Definition JElement.hh:366

Member Function Documentation

◆ fill()

template<class JAbscissa_t , class JOrdinate_t >
void JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::fill ( typename JLANG::JClass< abscissa_type >::argument_type x,
typename JLANG::JClass< ordinate_type >::argument_type w )
inline

Add abscissa value.

Parameters
xabscissa value
wweight

Definition at line 415 of file JElement.hh.

417 {
418 this->__y += w;
419 this->__u += w * x;
420 this->__w2 += w * w;
421 }
ordinate_type __y
Definition JElement.hh:142

◆ getBinCenter()

template<class JAbscissa_t , class JOrdinate_t >
abscissa_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::getBinCenter ( ) const
inline

Get bin center.

Returns
center

Definition at line 429 of file JElement.hh.

430 {
431 if (this->__y != getZero<ordinate_type>())
432 return this->__u / this->__y;
433 else
434 return this->__x;
435 }
abscissa_type __x
Definition JElement.hh:141

◆ getBinContent()

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::getBinContent ( ) const
inline

Get bin content.

Returns
content

Definition at line 443 of file JElement.hh.

444 {
445 return this->__y;
446 }

◆ getBinError()

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::getBinError ( ) const
inline

Get bin error.

Returns
error

Definition at line 454 of file JElement.hh.

455 {
456 return sqrt(this->__w2);
457 }

◆ getEffectiveBinContent()

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::getEffectiveBinContent ( ) const
inline

Get effective bin content.


For a bin filled with identical weights the return value of this function
corresponds to a Poisson count with equivalent relative error.

Returns
effective bin content

Definition at line 467 of file JElement.hh.

468 {
469 using namespace JPP;
470
471 const ordinate_type y = getBinContent();
472 const ordinate_type ey = getBinError();
473
474 if (ey > getZero<ordinate_type>()) {
475 return y*y/ey/ey;
476 } else {
477 THROW(JDivisionByZero, "JBin1D::getEffectiveBinContent(): Invalid effective bin content (bin content error is zero)");
478 }
479 }
Exception for division by zero.
ordinate_type getBinContent() const
Get bin content.
Definition JElement.hh:443
element_type::ordinate_type ordinate_type
Definition JElement.hh:360
ordinate_type getBinError() const
Get bin error.
Definition JElement.hh:454

◆ negate()

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::negate ( )
inline

Negate bin.


Note: This method should only be used for binned elements which can hold negative weights.

Returns
this bin

Definition at line 488 of file JElement.hh.

489 {
490 this->__y = -this->__y;
491
492 return *this;
493 }

◆ add()

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::add ( const JBin1D< JAbscissa_t, JOrdinate_t > & bin)
inline

Add bin.

Parameters
binbin
Returns
this bin

Definition at line 502 of file JElement.hh.

503 {
504 this->__y += bin.__y;
505 this->__u += bin.__u;
506 this->__w2 += bin.__w2;
507
508 return *this;
509 }

◆ sub()

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::sub ( const JBin1D< JAbscissa_t, JOrdinate_t > & bin)
inline

Subtract bin.

Parameters
binbin
Returns
this bin

Definition at line 518 of file JElement.hh.

519 {
520 this->__y -= bin.__y;
521 this->__u -= bin.__u;
522 this->__w2 += bin.__w2;
523
524 return *this;
525 }

◆ mul() [1/3]

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::mul ( const double value)
inline

Scale contents.

Parameters
valuemultiplication factor
Returns
this bin

Definition at line 534 of file JElement.hh.

535 {
536 this->__y *= value;
537 this->__u *= value;
538 this->__w2 *= value*value;
539
540 return *this;
541 }

◆ div()

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::div ( const double value)
inline

Divide contents.

Parameters
valuedivision factor
Returns
this bin

Definition at line 550 of file JElement.hh.

551 {
552 this->__y /= value;
553 this->__u /= value;
554 this->__w2 /= value*value;
555
556 return *this;
557 }

◆ mul() [2/3]

template<class JAbscissa_t , class JOrdinate_t >
JBin1D & JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::mul ( const JBin1D< JAbscissa_t, JOrdinate_t > & bin)
inline

Multiply bins.

Parameters
binbin
Returns
this bin

Definition at line 566 of file JElement.hh.

567 {
568 const double y1 = this->getBinContent();
569 const double ey1 = this->getBinError();
570
571 const double y2 = bin.getBinContent();
572 const double ey2 = bin.getBinError();
573
574 this->__y *= y2;
575 this->__u *= y2;
576 this->__w2 = ((ey1 * ey1 * y2 * y2) +
577 (ey2 * ey2 * y1 * y1));
578
579 return *this;
580 }

◆ getX()

template<class JAbscissa_t , class JOrdinate_t >
abscissa_type JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >::getX ( ) const
inlineinherited

Get abscissa value.

Returns
abscissa value

Definition at line 80 of file JElement.hh.

81 {
82 return __x;
83 }

◆ getY() [1/2]

template<class JAbscissa_t , class JOrdinate_t >
const ordinate_type & JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >::getY ( ) const
inlineinherited

Get ordinate value.

Returns
ordinate value

Definition at line 91 of file JElement.hh.

92 {
93 return __y;
94 }

◆ getY() [2/2]

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type & JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >::getY ( )
inlineinherited

Get ordinate value.

Returns
ordinate value

Definition at line 102 of file JElement.hh.

103 {
104 return __y;
105 }

◆ mul() [3/3]

template<class JFirst_t , class JSecond_t >
JFirst_t & JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

Member Data Documentation

◆ __u

template<class JAbscissa_t , class JOrdinate_t >
abscissa_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::__u
protected

Sum of weighted abscissa values.

Definition at line 584 of file JElement.hh.

◆ __w2

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type JTOOLS::JBin1D< JAbscissa_t, JOrdinate_t >::__w2
protected

Sum of squared weights.

Definition at line 585 of file JElement.hh.

◆ __x

template<class JAbscissa_t , class JOrdinate_t >
abscissa_type JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >::__x
protectedinherited

Definition at line 141 of file JElement.hh.

◆ __y

template<class JAbscissa_t , class JOrdinate_t >
ordinate_type JTOOLS::JElement2D< JAbscissa_t, JOrdinate_t >::__y
protectedinherited

Definition at line 142 of file JElement.hh.


The documentation for this struct was generated from the following file: