Skip to content
Snippets Groups Projects
Commit aea6a239 authored by Christopher Rob Jones's avatar Christopher Rob Jones
Browse files

Add back int based histogram checks to RichFutureKernel test

parent faf0a814
No related branches found
No related tags found
2 merge requests!4987Ignore: merge master into run5 branch,!4855Add back int based histogram checks to RichFutureKernel test
...@@ -26,14 +26,23 @@ namespace Rich::Future::Tests { ...@@ -26,14 +26,23 @@ namespace Rich::Future::Tests {
private: private:
// variable type from hist // variable type from hist
using T = param_t<HIST>; using T = param_t<HIST>;
/// Type for floating point quantities
using FT = std::conditional_t<std::is_floating_point_v<T>, T, double>;
/// Function type enum
enum class Function { Undefined, Normal, Exponential, FlatTop };
private:
// Min/Max range. Set according to function type. // Min/Max range. Set according to function type.
T m_minVar{-1}; T m_minVar{0};
T m_maxVar{1}; T m_maxVar{1};
/// Function type /// Function type property
Gaudi::Property<std::string> m_funcType{this, "Function", "Normal"}; Gaudi::Property<std::string> m_funcType{this, "Function", "Normal"};
/// Function to use
Function m_func{Function::Undefined};
/// test array of (optional) hists. /// test array of (optional) hists.
/// Note last entry is intentionally uninitialised to test handling this scenario. /// Note last entry is intentionally uninitialised to test handling this scenario.
mutable Hist::Array<HIST, 3> m_h; mutable Hist::Array<HIST, 3> m_h;
...@@ -44,79 +53,103 @@ namespace Rich::Future::Tests { ...@@ -44,79 +53,103 @@ namespace Rich::Future::Tests {
Rndm::Numbers m_randWeight{}; Rndm::Numbers m_randWeight{};
private: private:
inline T mean() const { // Function specific parameters
T m{}; inline FT lambda() const noexcept { return 0.075; }
if ( m_funcType.value() == "Normal" ) { inline FT sigma() const noexcept { return 15; }
inline FT a() const noexcept { return m_minVar + T{2}; }
inline FT b() const noexcept { return m_maxVar - T{2}; }
private:
// Function statistical quantities
inline FT mean() const noexcept {
FT m{};
if ( Function::Normal == m_func ) {
m = 0.5 * ( m_maxVar + m_minVar ); m = 0.5 * ( m_maxVar + m_minVar );
} else if ( m_funcType.value() == "Exponential" ) { } else if ( Function::Exponential == m_func ) {
m = 1.0 / lambda(); m = 1.0 / lambda();
} else if ( m_funcType.value() == "FlatTop" ) { } else if ( Function::FlatTop == m_func ) {
m = 0.5 * ( a() + b() ); m = 0.5 * ( a() + b() );
} }
return m; return m;
} }
inline T skewness() const { inline FT skewness() const noexcept { return ( Function::Exponential == m_func ? 2.0 : 0.0 ); }
T s = 0.0; inline FT kurtosis() const noexcept {
if ( m_funcType.value() == "Exponential" ) { s = 2.0; } FT k = 0.0;
return s; if ( Function::Exponential == m_func ) {
}
inline T kurtosis() const {
T k = 0.0;
if ( m_funcType.value() == "Exponential" ) {
k = 6.0; k = 6.0;
} else if ( m_funcType.value() == "FlatTop" ) { } else if ( Function::FlatTop == m_func ) {
k = -6.0 / 5.0; k = -6.0 / 5.0;
} }
return k; return k;
} }
inline T StdDev() const { inline FT StdDev() const noexcept {
T r = 0.0; FT r = 0.0;
if ( m_funcType.value() == "Normal" ) { if ( Function::Normal == m_func ) {
r = sigma(); r = sigma();
} else if ( m_funcType.value() == "Exponential" ) { } else if ( Function::Exponential == m_func ) {
r = 1.0 / lambda(); r = 1.0 / lambda();
} else if ( m_funcType.value() == "FlatTop" ) { } else if ( Function::FlatTop == m_func ) {
r = ( b() - a() ) / std::sqrt( 12.0 ); r = ( b() - a() ) / std::sqrt( 12.0 );
} }
return r; return r;
} }
inline T lambda() const { return 0.75; } private:
inline T sigma() const { return 0.8; } // Generators for function arguments and values
inline T a() const { return m_minVar + 1.0; }
inline T b() const { return m_maxVar - 1.0; }
inline T coordinate() const { inline T coordinate() const {
T res{0}; T res{0};
if constexpr ( is_profile_v<HIST> ) { if constexpr ( is_profile_v<HIST> ) {
// random in min max range // random in min max range
res = m_randCoord.shoot(); if constexpr ( std::is_floating_point_v<T> ) {
res = m_randCoord.shoot();
} else {
res = std::round( m_randCoord.shoot() );
}
} else { } else {
// sample from the given function // sample from the given function
res = m_randFunc.shoot(); if constexpr ( std::is_floating_point_v<T> ) {
res = m_randFunc.shoot();
} else {
res = std::round( m_randFunc.shoot() );
}
} }
debug() << m_funcType.value() << " sample = " << res << endmsg; debug() << m_funcType.value() << " sample = " << res << endmsg;
return res; return res;
} }
inline T func( const T x ) const { inline T func( const T x ) const {
T res{0}; FT res{0};
if ( m_funcType == "Normal" ) { if ( Function::Normal == m_func ) {
res = std::exp( -0.5 * std::pow( ( x - mean() ) / sigma(), 2 ) ); res = std::exp( -0.5 * std::pow( ( x - mean() ) / sigma(), 2 ) );
} else if ( m_funcType.value() == "Exponential" ) { } else if ( Function::Exponential == m_func ) {
res = ( x >= 0 ? ( lambda() * std::exp( -1.0 * lambda() * x ) ) : 0.0 ); res = ( x >= 0 ? ( lambda() * std::exp( -1.0 * lambda() * x ) ) : 0.0 );
} else if ( m_funcType.value() == "FlatTop" ) { } else if ( Function::FlatTop == m_func ) {
res = ( x >= a() && x <= b() ? 1.0 : 0.0 ); res = ( x >= a() && x <= b() ? 1.0 : 0.0 );
} }
debug() << m_funcType.value() << "( " << x << ") = " << res << endmsg; T ret{0};
return res; if constexpr ( std::is_floating_point_v<T> ) {
ret = res;
} else {
ret = T{10000000} * res;
}
debug() << m_funcType.value() << "( " << x << ") = " << ret << endmsg;
return ret;
}
inline T weight() const {
T w{0};
if constexpr ( std::is_floating_point_v<T> ) {
w = m_randWeight.shoot();
} else {
w = T{10} * m_randWeight.shoot();
}
debug() << "Weight = " << w << endmsg;
return w;
} }
inline T weight() const { return m_randWeight.shoot(); }
public: public:
HistoTestBase( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator ) { HistoTestBase( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator ) {
setProperty( "HistoPrint", true ).ignore(); setProperty( "HistoPrint", true ).ignore();
setProperty( "NBins1DHistos", 100 ).ignore(); setProperty( "NBins1DHistos", 200 ).ignore();
setProperty( "NBins2DHistos", 25 ).ignore(); setProperty( "NBins2DHistos", 50 ).ignore();
} }
void operator()() const override { void operator()() const override {
...@@ -206,18 +239,31 @@ namespace Rich::Future::Tests { ...@@ -206,18 +239,31 @@ namespace Rich::Future::Tests {
protected: protected:
StatusCode prebookHistograms() override { StatusCode prebookHistograms() override {
bool ok = true;
if ( m_funcType.value() == "Normal" ) { if ( m_funcType.value() == "Normal" ) {
m_minVar = -5; m_func = Function::Normal;
m_maxVar = 10; m_minVar = -50;
m_maxVar = 100;
m_randFunc = Rndm::Numbers( randSvc(), Rndm::Gauss( mean(), sigma() ) ); m_randFunc = Rndm::Numbers( randSvc(), Rndm::Gauss( mean(), sigma() ) );
} else if ( m_funcType.value() == "Exponential" ) { } else if ( m_funcType.value() == "Exponential" ) {
m_func = Function::Exponential;
m_minVar = 0; m_minVar = 0;
m_maxVar = 20; m_maxVar = 200;
m_randFunc = Rndm::Numbers( randSvc(), Rndm::Exponential( 1.0 / lambda() ) ); m_randFunc = Rndm::Numbers( randSvc(), Rndm::Exponential( 1.0 / lambda() ) );
} else if ( m_funcType.value() == "FlatTop" ) { } else if ( m_funcType.value() == "FlatTop" ) {
m_func = Function::FlatTop;
m_minVar = 0; m_minVar = 0;
m_maxVar = 10; m_maxVar = 100;
m_randFunc = Rndm::Numbers( randSvc(), Rndm::Flat( a(), b() ) ); m_randFunc = Rndm::Numbers( randSvc(), Rndm::Flat( a(), b() ) );
} else {
error() << "Unknown function '" << m_funcType.value() << "'" << endmsg;
return StatusCode::FAILURE;
}
if constexpr ( std::is_integral_v<T> ) {
ok &= ( setProperty( "NBins1DHistos", m_maxVar - m_minVar ).isSuccess() &&
setProperty( "NBins2DHistos", m_maxVar - m_minVar ).isSuccess() );
} }
m_randCoord = Rndm::Numbers( randSvc(), Rndm::Flat( m_minVar, m_maxVar ) ); m_randCoord = Rndm::Numbers( randSvc(), Rndm::Flat( m_minVar, m_maxVar ) );
...@@ -230,19 +276,23 @@ namespace Rich::Future::Tests { ...@@ -230,19 +276,23 @@ namespace Rich::Future::Tests {
info() << "Generating " << m_funcType.value() << " Mean=" << mean() << " StdDev=" << StdDev() info() << "Generating " << m_funcType.value() << " Mean=" << mean() << " StdDev=" << StdDev()
<< " Skewness=" << skewness() << " Kurtosis=" << kurtosis() << endmsg; << " Skewness=" << skewness() << " Kurtosis=" << kurtosis() << endmsg;
bool ok = true; const auto hMin = m_minVar;
const auto hMax = m_maxVar;
const auto nBins = ( is_1d_v<HIST> ? nBins1D() : nBins2D() );
info() << "Hist Min/Max/Bins " << hMin << "/" << hMax << "/" << nBins << endmsg;
if constexpr ( is_1d_v<HIST> ) { if constexpr ( is_1d_v<HIST> ) {
ok &= initHist( m_h[0ul], HID( "testH1D0" ), m_funcType, // ok &= initHist( m_h[0ul], HID( "testH1D0" ), m_funcType, //
m_minVar, m_maxVar, nBins1D(), "X", "Entries" ); hMin, hMax, nBins, "X", "Entries" );
ok &= initHist( m_h[1ul], HID( "testH1D1" ), m_funcType, // ok &= initHist( m_h[1ul], HID( "testH1D1" ), m_funcType, //
m_minVar, m_maxVar, nBins1D(), "X", "Entries" ); hMin, hMax, nBins, "X", "Entries" );
} }
if constexpr ( is_2d_v<HIST> ) { if constexpr ( is_2d_v<HIST> ) {
ok &= initHist( m_h[0ul], HID( "testH2D0" ), m_funcType, // ok &= initHist( m_h[0ul], HID( "testH2D0" ), m_funcType, //
m_minVar, m_maxVar, nBins2D(), m_minVar, m_maxVar, nBins2D(), // hMin, hMax, nBins, hMin, hMax, nBins, //
"X", "Y", "Entries" ); "X", "Y", "Entries" );
ok &= initHist( m_h[1ul], HID( "testH2D1" ), m_funcType, // ok &= initHist( m_h[1ul], HID( "testH2D1" ), m_funcType, //
m_minVar, m_maxVar, nBins2D(), m_minVar, m_maxVar, nBins2D(), // hMin, hMax, nBins, hMin, hMax, nBins, //
"X", "Y", "Entries" ); "X", "Y", "Entries" );
} }
return StatusCode{ok}; return StatusCode{ok};
...@@ -269,10 +319,14 @@ namespace Rich::Future::Tests { ...@@ -269,10 +319,14 @@ namespace Rich::Future::Tests {
DECLARE_COMPONENT_WITH_ID( HistoTestBase<P2D<float>>, "RichTestP2DF" ) DECLARE_COMPONENT_WITH_ID( HistoTestBase<P2D<float>>, "RichTestP2DF" )
DECLARE_COMPONENT_WITH_ID( HistoTestBase<WP2D<float>>, "RichTestWP2DF" ) DECLARE_COMPONENT_WITH_ID( HistoTestBase<WP2D<float>>, "RichTestWP2DF" )
// FixMe : Enable int testing sometime... DECLARE_COMPONENT_WITH_ID( HistoTestBase<H1D<std::int64_t>>, "RichTestH1DI" )
// DECLARE_COMPONENT_WITH_ID( HistoTestBase<H1D<std::int32_t>>, "RichTestH1DI" ) DECLARE_COMPONENT_WITH_ID( HistoTestBase<WH1D<std::int64_t>>, "RichTestWH1DI" )
// DECLARE_COMPONENT_WITH_ID( HistoTestBase<P1D<std::int32_t>>, "RichTestP1DI" ) DECLARE_COMPONENT_WITH_ID( HistoTestBase<P1D<std::int64_t>>, "RichTestP1DI" )
// DECLARE_COMPONENT_WITH_ID( HistoTestBase<H2D<std::int32_t>>, "RichTestH2DI" ) DECLARE_COMPONENT_WITH_ID( HistoTestBase<WP1D<std::int64_t>>, "RichTestWP1DI" )
// DECLARE_COMPONENT_WITH_ID( HistoTestBase<P2D<std::int32_t>>, "RichTestP2DI" )
DECLARE_COMPONENT_WITH_ID( HistoTestBase<H2D<std::int64_t>>, "RichTestH2DI" )
DECLARE_COMPONENT_WITH_ID( HistoTestBase<WH2D<std::int64_t>>, "RichTestWH2DI" )
DECLARE_COMPONENT_WITH_ID( HistoTestBase<P2D<std::int64_t>>, "RichTestP2DI" )
DECLARE_COMPONENT_WITH_ID( HistoTestBase<WP2D<std::int64_t>>, "RichTestWP2DI" )
} // namespace Rich::Future::Tests } // namespace Rich::Future::Tests
...@@ -17,6 +17,8 @@ from Configurables import RichTestH1DD, RichTestWH1DD, RichTestP1DD, RichTestWP1 ...@@ -17,6 +17,8 @@ from Configurables import RichTestH1DD, RichTestWH1DD, RichTestP1DD, RichTestWP1
from Configurables import RichTestH2DD, RichTestWH2DD, RichTestP2DD, RichTestWP2DD from Configurables import RichTestH2DD, RichTestWH2DD, RichTestP2DD, RichTestWP2DD
from Configurables import RichTestH1DF, RichTestWH1DF, RichTestP1DF, RichTestWP1DF from Configurables import RichTestH1DF, RichTestWH1DF, RichTestP1DF, RichTestWP1DF
from Configurables import RichTestH2DF, RichTestWH2DF, RichTestP2DF, RichTestWP2DF from Configurables import RichTestH2DF, RichTestWH2DF, RichTestP2DF, RichTestWP2DF
from Configurables import RichTestH1DI, RichTestWH1DI, RichTestP1DI, RichTestWP1DI
from Configurables import RichTestH2DI, RichTestWH2DI, RichTestP2DI, RichTestWP2DI
# Histo printout should be disabled if either of these is WARNING or above # Histo printout should be disabled if either of these is WARNING or above
outLevel = INFO outLevel = INFO
...@@ -45,6 +47,15 @@ for func in ["Normal", "Exponential", "FlatTop"]: ...@@ -45,6 +47,15 @@ for func in ["Normal", "Exponential", "FlatTop"]:
RichTestWH2DF(func + "_WH2DF", OutputLevel=outLevel, Function=func), RichTestWH2DF(func + "_WH2DF", OutputLevel=outLevel, Function=func),
RichTestP2DF(func + "_P2DF", OutputLevel=outLevel, Function=func), RichTestP2DF(func + "_P2DF", OutputLevel=outLevel, Function=func),
RichTestWP2DF(func + "_WP2DF", OutputLevel=outLevel, Function=func), RichTestWP2DF(func + "_WP2DF", OutputLevel=outLevel, Function=func),
# Ints
RichTestH1DI(func + "_H1DI", OutputLevel=outLevel, Function=func),
RichTestWH1DI(func + "_WH1DI", OutputLevel=outLevel, Function=func),
RichTestP1DI(func + "_P1DI", OutputLevel=outLevel, Function=func),
RichTestWP1DI(func + "_WP1DI", OutputLevel=outLevel, Function=func),
RichTestH2DI(func + "_H2DI", OutputLevel=outLevel, Function=func),
RichTestWH2DI(func + "_WH2DI", OutputLevel=outLevel, Function=func),
RichTestP2DI(func + "_P2DI", OutputLevel=outLevel, Function=func),
RichTestWP2DI(func + "_WP2DI", OutputLevel=outLevel, Function=func),
] ]
AuditorSvc().Auditors += ["FPEAuditor"] AuditorSvc().Auditors += ["FPEAuditor"]
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment