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

#include <MCGIDI_functions.hpp>

Inheritance diagram for MCGIDI::Probabilities::XYs3d:

Public Member Functions

LUPI_HOST_DEVICE XYs3d ()
LUPI_HOST XYs3d (GIDI::Functions::XYs3d const &a_XYs3d)
LUPI_HOST_DEVICE ~XYs3d ()
LUPI_HOST_DEVICE double evaluate (double a_x3, double a_x2, double a_x1) const
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_x3, double a_x2_1, double a_x2_2, double a_rngValue, RNG &&a_rng) const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase3d
LUPI_HOST_DEVICE ProbabilityBase3d ()
LUPI_HOST ProbabilityBase3d (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE ~ProbabilityBase3d ()
LUPI_HOST_DEVICE ProbabilityBase3dType type () const
LUPI_HOST_DEVICE String typeString () const
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double evaluate (double a_x3, double a_x2, double a_x1) const MCGIDI_TRUE_VIRTUAL
template<typename RNG>
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double sample (double a_x3, double a_x2_1, double a_x2_2, 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_x3, double a_x2_1, double a_x2_2, 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::ProbabilityBase3d
ProbabilityBase3dType m_type
Protected Attributes inherited from MCGIDI::Probabilities::ProbabilityBase
Vector< double > m_Xs

Detailed Description

Definition at line 759 of file MCGIDI_functions.hpp.

Constructor & Destructor Documentation

◆ XYs3d() [1/2]

LUPI_HOST_DEVICE MCGIDI::Probabilities::XYs3d::XYs3d ( )

Definition at line 2453 of file MCGIDI_functions.cc.

2453 :
2454 m_probabilities( ) {
2455
2457}

◆ XYs3d() [2/2]

LUPI_HOST MCGIDI::Probabilities::XYs3d::XYs3d ( GIDI::Functions::XYs3d const & a_XYs3d)

Definition at line 2461 of file MCGIDI_functions.cc.

2461 :
2462 ProbabilityBase3d( a_XYs3d, a_XYs3d.Xs( ) ) {
2463
2465
2466 Vector<GIDI::Functions::Function2dForm *> const &functions2d = a_XYs3d.function2ds( );
2467 m_probabilities.resize( functions2d.size( ) );
2468 for( std::size_t i1 = 0; i1 < functions2d.size( ); ++i1 ) m_probabilities[i1] = parseProbability2d_d1( functions2d[i1], nullptr );
2469}
LUPI_HOST ProbabilityBase2d_d1 * parseProbability2d_d1(GIDI::Functions::Function2dForm const *form2d, SetupInfo *a_setupInfo)

◆ ~XYs3d()

LUPI_HOST_DEVICE MCGIDI::Probabilities::XYs3d::~XYs3d ( )

Definition at line 2474 of file MCGIDI_functions.cc.

2474 {
2475
2476 for( std::size_t i1 = 0; i1 < m_probabilities.size( ); ++i1 ) delete m_probabilities[i1];
2477}

Member Function Documentation

◆ evaluate()

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

Definition at line 2481 of file MCGIDI_functions.cc.

2481 {
2482
2483 int intLower = binarySearchVector( a_x3, m_Xs );
2484 double evaluatedValue;
2485
2486 if( intLower == -2 ) { // a_x3 < first value of Xs.
2487 evaluatedValue = m_probabilities[0]->evaluate( a_x2, a_x1 ); }
2488 else if( intLower == -1 ) { // a_x3 > last value of Xs.
2489 evaluatedValue = m_probabilities.back( )->evaluate( a_x2, a_x1 ); }
2490 else {
2491 std::size_t lower = static_cast<std::size_t>( intLower );
2492 double value1 = m_probabilities[lower]->evaluate( a_x2, a_x1 );
2493
2495 evaluatedValue = value1; }
2496 else {
2497 double value2 = m_probabilities[lower+1]->evaluate( a_x2, a_x1 );
2498
2500 double fraction = ( m_Xs[lower+1] - a_x3 ) / ( m_Xs[lower+1] - m_Xs[lower] );
2501 evaluatedValue = fraction * value1 + ( 1 - fraction ) * value2 ; }
2502 else if( interpolation( ) == Interpolation::LOGLIN ) {
2503 double fraction = ( m_Xs[lower+1] - a_x3 ) / ( m_Xs[lower+1] - m_Xs[lower] );
2504 evaluatedValue = value2 * pow( value2 / value1, fraction ); }
2505 else if( interpolation( ) == Interpolation::LINLOG ) {
2506 double fraction = log( m_Xs[lower+1] / a_x3 ) / log( m_Xs[lower+1] / m_Xs[lower] );
2507 evaluatedValue = fraction * value1 + ( 1 - fraction ) * value2; }
2508 else if( interpolation( ) == Interpolation::LOGLOG ) {
2509 double fraction = log( m_Xs[lower+1] / a_x3 ) / log( m_Xs[lower+1] / m_Xs[lower] );
2510 evaluatedValue = value2 * pow( value2 / value1, fraction ); }
2511 else { // This should never happen.
2512 LUPI_THROW( "XYs3d::evaluate: unsupported interpolation." );
2513 }
2514 }
2515 }
2516
2517 return( evaluatedValue );
2518}
#define LUPI_THROW(arg)
LUPI_HOST_DEVICE Interpolation interpolation() const
LUPI_HOST_DEVICE int binarySearchVector(double a_x, Vector< double > const &a_Xs, bool a_boundIndex=false)
Definition MCGIDI.hpp:318

◆ sample()

template<typename RNG>
LUPI_HOST_DEVICE double MCGIDI::Probabilities::XYs3d::sample ( double a_x3,
double a_x2_1,
double a_x2_2,
double a_rngValue,
RNG && a_rng ) const

Definition at line 2128 of file MCGIDI_headerSource.hpp.

2128 {
2129/*
2130C Samples from a pdf(x1|x3,x2). First determine which pdf(s) to sample from given x3
2131C Then use rngValue to sample from pdf2_1(x2) and maybe pdf2_2(x2) and interpolate to
2132C determine x1.
2133*/
2134 double sampledValue = 0;
2135 int intLower = binarySearchVector( a_x3, m_Xs );
2136
2137 if( intLower == -2 ) { // x3 < first value of Xs.
2138 sampledValue = m_probabilities[0]->sample( a_x2_1, a_rngValue, a_rng ); }
2139 else if( intLower == -1 ) { // x3 > last value of Xs.
2140 sampledValue = m_probabilities.back( )->sample( a_x2_1, a_rngValue, a_rng ); }
2141 else {
2142 std::size_t lower = static_cast<std::size_t>( intLower );
2143 double sampled1 = m_probabilities[lower]->sample( a_x2_1, a_rngValue, a_rng );
2144
2146 sampledValue = sampled1; }
2147 else {
2148 double sampled2 = m_probabilities[lower+1]->sample( a_x2_2, a_rngValue, a_rng );
2149
2151 double fraction = ( m_Xs[lower+1] - a_x3 ) / ( m_Xs[lower+1] - m_Xs[lower] );
2152 sampledValue = fraction * sampled1 + ( 1 - fraction ) * sampled2; }
2153 else if( interpolation( ) == Interpolation::LOGLIN ) {
2154 double fraction = ( m_Xs[lower+1] - a_x3 ) / ( m_Xs[lower+1] - m_Xs[lower] );
2155 sampledValue = sampled2 * pow( sampled2 / sampled1, fraction ); }
2156 else if( interpolation( ) == Interpolation::LINLOG ) {
2157 double fraction = log( m_Xs[lower+1] / a_x3 ) / log( m_Xs[lower+1] / m_Xs[lower] );
2158 sampledValue = fraction * sampled1 + ( 1 - fraction ) * sampled2; }
2159 else if( interpolation( ) == Interpolation::LOGLOG ) {
2160 double fraction = log( m_Xs[lower+1] / a_x3 ) / log( m_Xs[lower+1] / m_Xs[lower] );
2161 sampledValue = sampled2 * pow( sampled2 / sampled1, fraction ); }
2162 else { // This should never happen.
2163 LUPI_THROW( "XYs3d::sample: unsupported interpolation." );
2164 }
2165 }
2166 }
2167
2168 return( sampledValue );
2169}

◆ serialize()

LUPI_HOST_DEVICE void MCGIDI::Probabilities::XYs3d::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 2528 of file MCGIDI_functions.cc.

2528 {
2529
2530 ProbabilityBase3d::serialize( a_buffer, a_mode );
2531
2532 std::size_t vectorSize = m_probabilities.size( );
2533 int vectorSizeInt = (int) vectorSize;
2534 DATA_MEMBER_INT( vectorSizeInt, a_buffer, a_mode );
2535 vectorSize = (std::size_t) vectorSizeInt;
2536
2537 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) m_probabilities.resize( vectorSize, &a_buffer.m_placement );
2538 if( a_mode == LUPI::DataBuffer::Mode::Memory ) a_buffer.m_placement += m_probabilities.internalSize();
2539 for( std::size_t vectorIndex = 0; vectorIndex < vectorSize; ++vectorIndex ) {
2540 m_probabilities[vectorIndex] = serializeProbability2d_d1( a_buffer, a_mode, m_probabilities[vectorIndex] );
2541 }
2542}
#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::ProbabilityBase2d_d1 * serializeProbability2d_d1(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode, Probabilities::ProbabilityBase2d_d1 *a_probability2d)

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