Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI::Probabilities::XYs2d Class Reference

#include <MCGIDI_functions.hpp>

Inheritance diagram for MCGIDI::Probabilities::XYs2d:

Public Member Functions

LUPI_HOST_DEVICE XYs2d ()
LUPI_HOST XYs2d (GIDI::Functions::XYs2d const &a_XYs2d)
LUPI_HOST_DEVICE ~XYs2d ()
LUPI_HOST_DEVICE double evaluate (double a_x2, double a_x1) const
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_x2, double a_rngValue, RNG &&a_rng) const
template<typename RNG>
LUPI_HOST_DEVICE double sample2dOf3d (double a_x2, double a_rngValue, RNG &&a_rng, double *a_x1_1, double *a_x1_2) const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase2d_d2
LUPI_HOST_DEVICE ProbabilityBase2d_d2 ()
LUPI_HOST ProbabilityBase2d_d2 (GIDI::Functions::FunctionForm const &a_probabilty)
LUPI_HOST ProbabilityBase2d_d2 (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE double evaluate (double a_x2, double a_x1) const
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_x2, double a_rngValue, RNG &&a_rng) const
template<typename RNG>
LUPI_HOST_DEVICE double sample2dOf3d (double a_x2, double a_rngValue, RNG &&a_rng, double *a_x1_1, double *a_x1_2) const
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase2d_d1
LUPI_HOST_DEVICE ProbabilityBase2d_d1 ()
LUPI_HOST ProbabilityBase2d_d1 (GIDI::Functions::FunctionForm const &a_probabilty)
LUPI_HOST ProbabilityBase2d_d1 (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE double evaluate (double a_x2, double a_x1) const
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_x2, double a_rngValue, RNG &&a_rng) const
template<typename RNG>
LUPI_HOST_DEVICE double sample2dOf3d (double a_x2, double a_rngValue, RNG &&a_rng, double *a_x1_1, double *a_x1_2) const
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase2d
LUPI_HOST_DEVICE ProbabilityBase2d ()
LUPI_HOST ProbabilityBase2d (GIDI::Functions::FunctionForm const &a_probabilty)
LUPI_HOST ProbabilityBase2d (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE ~ProbabilityBase2d ()
LUPI_HOST_DEVICE ProbabilityBase2dType type () const
LUPI_HOST_DEVICE String typeString () const
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double evaluate (double a_x2, double a_x1) const MCGIDI_TRUE_VIRTUAL
template<typename RNG>
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double sample (double a_x2, double a_rngValue, RNG &&a_rng) const MCGIDI_TRUE_VIRTUAL
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_x2, double a_rngValue, RNG &&a_rng) const
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase
LUPI_HOST_DEVICE ProbabilityBase ()
LUPI_HOST ProbabilityBase (GIDI::Functions::FunctionForm const &a_probabilty)
LUPI_HOST ProbabilityBase (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE ~ProbabilityBase ()
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Public Member Functions inherited from MCGIDI::Functions::FunctionBase
LUPI_HOST_DEVICE FunctionBase ()
LUPI_HOST FunctionBase (GIDI::Functions::FunctionForm const &a_function)
LUPI_HOST_DEVICE FunctionBase (int a_dimension, double a_domainMin, double a_domainMax, Interpolation a_interpolation, double a_outerDomainValue=0)
virtual LUPI_HOST_DEVICE ~FunctionBase ()=0
LUPI_HOST_DEVICE Interpolation interpolation () const
LUPI_HOST_DEVICE double domainMin () const
LUPI_HOST_DEVICE double domainMax () const
LUPI_HOST_DEVICE double outerDomainValue () const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)

Additional Inherited Members

Protected Attributes inherited from MCGIDI::Probabilities::ProbabilityBase2d
ProbabilityBase2dType m_type
Protected Attributes inherited from MCGIDI::Probabilities::ProbabilityBase
Vector< double > m_Xs

Detailed Description

Definition at line 464 of file MCGIDI_functions.hpp.

Constructor & Destructor Documentation

◆ XYs2d() [1/2]

LUPI_HOST_DEVICE MCGIDI::Probabilities::XYs2d::XYs2d ( )

Definition at line 1608 of file MCGIDI_functions.cc.

1608 :
1609 m_probabilities( ) {
1610
1612}

◆ XYs2d() [2/2]

LUPI_HOST MCGIDI::Probabilities::XYs2d::XYs2d ( GIDI::Functions::XYs2d const & a_XYs2d)

Definition at line 1616 of file MCGIDI_functions.cc.

1616 :
1617 ProbabilityBase2d_d2( a_XYs2d, a_XYs2d.Xs( ) ) {
1618
1620
1621 Vector<GIDI::Functions::Function1dForm *> const &function1ds = a_XYs2d.function1ds( );
1622 m_probabilities.resize( function1ds.size( ) );
1623 for( std::size_t i1 = 0; i1 < function1ds.size( ); ++i1 ) m_probabilities[i1] = parseProbability1d( function1ds[i1] );
1624}
LUPI_HOST ProbabilityBase1d * parseProbability1d(Transporting::MC const &a_settings, GIDI::Suite const &a_suite)

◆ ~XYs2d()

LUPI_HOST_DEVICE MCGIDI::Probabilities::XYs2d::~XYs2d ( )

Definition at line 1629 of file MCGIDI_functions.cc.

1629 {
1630
1631 for( std::size_t i1 = 0; i1 < m_probabilities.size( ); ++i1 ) delete m_probabilities[i1];
1632}

Member Function Documentation

◆ evaluate()

LUPI_HOST_DEVICE double MCGIDI::Probabilities::XYs2d::evaluate ( double a_x2,
double a_x1 ) const

Definition at line 1636 of file MCGIDI_functions.cc.

1636 {
1637
1638 int intLower = binarySearchVector( a_x2, m_Xs );
1639
1640 if( intLower < 0 ) {
1641 if( intLower == -2 ) return( m_probabilities[0]->evaluate( a_x1 ) );
1642 return( m_probabilities.back( )->evaluate( a_x1 ) );
1643 }
1644
1645 std::size_t lower = static_cast<std::size_t>( intLower );
1646 double fraction = ( a_x2 - m_Xs[lower] ) / ( m_Xs[lower+1] - m_Xs[lower] );
1647 double d_value = ( 1.0 - fraction ) * m_probabilities[lower]->evaluate( a_x1 ) + fraction * m_probabilities[lower+1]->evaluate( a_x1 );
1648
1649 return( d_value );
1650}
LUPI_HOST_DEVICE double evaluate(double a_x2, double a_x1) const
LUPI_HOST_DEVICE int binarySearchVector(double a_x, Vector< double > const &a_Xs, bool a_boundIndex=false)
Definition MCGIDI.hpp:318

Referenced by evaluate().

◆ sample()

template<typename RNG>
LUPI_HOST_DEVICE double MCGIDI::Probabilities::XYs2d::sample ( double a_x2,
double a_rngValue,
RNG && a_rng ) const

Definition at line 1870 of file MCGIDI_headerSource.hpp.

1870 {
1871/*
1872C Samples from a pdf(x1|x2). First determine which pdf(s) to sample from given x2.
1873C Then use rngValue to sample from pdf1(x1) and maybe pdf2(x1) and interpolate to
1874C determine x1.
1875*/
1876 double sampledValue = 0;
1877 int intLower = binarySearchVector( a_x2, m_Xs );
1878
1879 if( intLower == -2 ) {
1880 sampledValue = m_probabilities[0]->sample( a_rngValue, a_rng ); }
1881 else if( intLower == -1 ) {
1882 sampledValue = m_probabilities.back( )->sample( a_rngValue, a_rng ); }
1883 else {
1884 auto lower = static_cast<std::size_t>( intLower );
1885 double sampled1 = m_probabilities[lower]->sample( a_rngValue, a_rng );
1886
1888 sampledValue = sampled1; }
1889 else {
1890 double sampled2 = m_probabilities[lower+1]->sample( a_rngValue, a_rng );
1891
1893 double fraction = ( m_Xs[lower+1] - a_x2 ) / ( m_Xs[lower+1] - m_Xs[lower] );
1894 sampledValue = fraction * sampled1 + ( 1 - fraction ) * sampled2; }
1895 else if( interpolation( ) == Interpolation::LOGLIN ) {
1896 double fraction = ( m_Xs[lower+1] - a_x2 ) / ( m_Xs[lower+1] - m_Xs[lower] );
1897 sampledValue = sampled2 * pow( sampled2 / sampled1, fraction ); }
1898 else if( interpolation( ) == Interpolation::LINLOG ) {
1899 double fraction = log( m_Xs[lower+1] / a_x2 ) / log( m_Xs[lower+1] / m_Xs[lower] );
1900 sampledValue = fraction * sampled1 + ( 1 - fraction ) * sampled2; }
1901 else if( interpolation( ) == Interpolation::LOGLOG ) {
1902 double fraction = log( m_Xs[lower+1] / a_x2 ) / log( m_Xs[lower+1] / m_Xs[lower] );
1903 sampledValue = sampled2 * pow( sampled2 / sampled1, fraction ); }
1904 else { // This should never happen.
1905 LUPI_THROW( "XYs2d::sample: unsupported interpolation." );
1906 }
1907 }
1908 }
1909 return( sampledValue );
1910}
#define LUPI_THROW(arg)
LUPI_HOST_DEVICE Interpolation interpolation() const

◆ sample2dOf3d()

template<typename RNG>
LUPI_HOST_DEVICE double MCGIDI::Probabilities::XYs2d::sample2dOf3d ( double a_x2,
double a_rngValue,
RNG && a_rng,
double * a_x1_1,
double * a_x1_2 ) const

This method returns two x1 values for use with ProbabilityBase3d functions.

Parameters
a_x2[in] The value of x2.
a_rngValue[in] The value of the cumulative value used to determine the x1 value.
a_rng[in] The random number generator function that returns a double in the range [0, 1.0).
a_x1_1[in] The lower value of the x1 value.
a_x1_2[in] The upper value of the x1 value.

Definition at line 1923 of file MCGIDI_headerSource.hpp.

1924 {
1925/*
1926C Samples from a pdf(x1|x2). First determine which pdf(s) to sample from given x2. Then use rngValue to sample from pdf1(x1)
1927C and maybe pdf2(x1) and interpolate to determine x1.
1928*/
1929 double sampledValue = 0;
1930 int intLower = binarySearchVector( a_x2, m_Xs );
1931
1932 if( intLower == -2 ) {
1933 sampledValue = m_probabilities[0]->sample( a_rngValue, a_rng );
1934 *a_x1_2 = *a_x1_1 = sampledValue; }
1935 else if( intLower == -1 ) {
1936 sampledValue = m_probabilities.back( )->sample( a_rngValue, a_rng );
1937 *a_x1_2 = *a_x1_1 = sampledValue; }
1938 else {
1939 std::size_t lower = static_cast<std::size_t>( intLower );
1940 *a_x1_1 = m_probabilities[lower]->sample( a_rngValue, a_rng );
1941
1943 sampledValue = *a_x1_2 = *a_x1_1; }
1944 else {
1945 *a_x1_2 = m_probabilities[lower+1]->sample( a_rngValue, a_rng );
1946
1948 double fraction = ( m_Xs[lower+1] - a_x2 ) / ( m_Xs[lower+1] - m_Xs[lower] );
1949 sampledValue = fraction * *a_x1_1 + ( 1 - fraction ) * *a_x1_2; }
1950 else if( interpolation( ) == Interpolation::LOGLIN ) {
1951 double fraction = ( m_Xs[lower+1] - a_x2 ) / ( m_Xs[lower+1] - m_Xs[lower] );
1952 sampledValue = *a_x1_2 * pow( *a_x1_2 / *a_x1_1, fraction ); }
1953 else if( interpolation( ) == Interpolation::LINLOG ) {
1954 double fraction = log( m_Xs[lower+1] / a_x2 ) / log( m_Xs[lower+1] / m_Xs[lower] );
1955 sampledValue = fraction * *a_x1_1 + ( 1 - fraction ) * *a_x1_2; }
1956 else if( interpolation( ) == Interpolation::LOGLOG ) {
1957 double fraction = log( m_Xs[lower+1] / a_x2 ) / log( m_Xs[lower+1] / m_Xs[lower] );
1958 sampledValue = *a_x1_2 * pow( *a_x1_2 / *a_x1_1 , fraction ); }
1959 else { // This should never happen.
1960 LUPI_THROW( "XYs2d::sample: unsupported interpolation." );
1961 }
1962 }
1963 }
1964 return( sampledValue );
1965}

◆ serialize()

LUPI_HOST_DEVICE void MCGIDI::Probabilities::XYs2d::serialize ( LUPI::DataBuffer & a_buffer,
LUPI::DataBuffer::Mode a_mode )

This method serializes this for broadcasting as needed for MPI and GPUs. The method can count the number of required bytes, pack this or unpack this depending on a_mode.

Parameters
a_buffer[in] The buffer to read or write data to depending on a_mode.
a_mode[in] Specifies the action of this method.

Definition at line 1660 of file MCGIDI_functions.cc.

1660 {
1661
1662 ProbabilityBase2d::serialize( a_buffer, a_mode );
1663
1664 std::size_t vectorSize = m_probabilities.size( );
1665 int vectorSizeInt = (int) vectorSize;
1666 DATA_MEMBER_INT( vectorSizeInt, a_buffer, a_mode );
1667 vectorSize = (std::size_t) vectorSizeInt;
1668
1669 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) m_probabilities.resize( vectorSize, &a_buffer.m_placement );
1670 if( a_mode == LUPI::DataBuffer::Mode::Memory ) a_buffer.m_placement += m_probabilities.internalSize();
1671
1672 for( std::size_t vectorIndex = 0; vectorIndex < vectorSize; ++vectorIndex ) {
1673 m_probabilities[vectorIndex] = serializeProbability1d( a_buffer, a_mode, m_probabilities[vectorIndex] );
1674 }
1675}
#define DATA_MEMBER_INT( member, buf, mode)
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE Probabilities::ProbabilityBase1d * serializeProbability1d(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode, Probabilities::ProbabilityBase1d *a_probability1d)

The documentation for this class was generated from the following files: