Skip to content
Snippets Groups Projects

Monitor algorithm for event variables

Merged Sascha Stahl requested to merge voidmonitor into master
All threads resolved!
@@ -12,23 +12,15 @@
#include "Functors/with_output_tree.h"
#include "Gaudi/Accumulators/Histogram.h"
// #include "GaudiAlg/FilterPredicate.h"
#include "LHCbAlgs/Producer.h"
// #include "LHCbAlgs/Producer.h"
#include "LHCbAlgs/Consumer.h"
namespace {
struct VoidFunctor {
using Signature = std::any();
static constexpr auto PropertyName = "Variable";
};
struct VoidFunctorX {
using Signature = std::any();
static constexpr auto PropertyName = "VariableX";
};
struct VoidFunctorY {
using Signature = std::any();
static constexpr auto PropertyName = "VariableY";
};
using base_type = with_functors<LHCb::Algorithm::Producer<int()>, VoidFunctor>;
using base_type2 = with_functors<LHCb::Algorithm::Producer<int()>, VoidFunctorX, VoidFunctorY>;
using base_type = with_functors<LHCb::Algorithm::Consumer<void()>, VoidFunctor>;
using value_type = float;
} // namespace
@@ -36,9 +28,9 @@ namespace {
*/
struct EventVariableMonitor final : public base_type {
EventVariableMonitor( const std::string& name, ISvcLocator* pSvcLocator )
: base_type{name, pSvcLocator, {"Dummy", ""}} {}
: base_type{name, pSvcLocator, {}} {}
int operator()() const override {
void operator()() const override {
auto const& functor = getFunctor<VoidFunctor>();
Functors::detail::with_output_tree::numeric_value_wrapper w( functor.rtype() );
@@ -48,7 +40,6 @@ struct EventVariableMonitor final : public base_type {
++( *m_histogram )[LHCb::Utils::as_arithmetic( unwrapped )];
},
w.get() );
return 1;
}
StatusCode initialize() override {
@@ -79,57 +70,3 @@ private:
DECLARE_COMPONENT_WITH_ID( EventVariableMonitor, "Monitor__EventVariable" )
struct EventCorrelationsMonitor final : public base_type2 {
EventCorrelationsMonitor( const std::string& name, ISvcLocator* pSvcLocator )
: base_type2{name, pSvcLocator, {"Dummy", ""}} {}
int operator()() const override {
auto const& functorX = getFunctor<VoidFunctorX>();
auto const& functorY = getFunctor<VoidFunctorY>();
Functors::detail::with_output_tree::numeric_value_wrapper wX( functorX.rtype() );
Functors::detail::with_output_tree::numeric_value_wrapper wY( functorY.rtype() );
Functors::detail::with_output_tree::numeric_value valueX;
auto fval = std::invoke( functorX );
std::visit( [&]( auto& x ) { valueX = std::any_cast<std::decay_t<decltype( x )>>( fval ); }, valueX );
// LHCb::Utils::as_arithmetic( valueX.get() );
std::visit(
[&]( auto& x ) {
auto unwrappedX = std::any_cast<std::decay_t<decltype( x )>>( std::invoke( functorX ) );
auto unwrappedY = std::any_cast<std::decay_t<decltype( x )>>( std::invoke( functorY ) );
++( *m_histogram )[{LHCb::Utils::as_arithmetic( unwrappedX ), LHCb::Utils::as_arithmetic( unwrappedY )}];
},
wX.get() );
return 1;
}
StatusCode initialize() override {
auto sc = base_type2::initialize();
if ( sc.isFailure() ) return sc;
if ( m_histogram_title.value().empty() ) m_histogram_title = m_histogram_name.value();
m_histogram.emplace(
this, m_histogram_name.value(), m_histogram_title.value(),
Gaudi::Accumulators::Axis<value_type>{m_binsX.value(), m_rangeX.value().first, m_rangeX.value().second},
Gaudi::Accumulators::Axis<value_type>{m_binsY.value(), m_rangeY.value().first, m_rangeY.value().second} );
return sc;
}
private:
// Counter for recording cut retention statistics
mutable Gaudi::Accumulators::BinomialCounter<> m_cutEff{this, "Cut selection efficiency"};
private:
// properties
Gaudi::Property<std::string> m_histogram_name{this, "HistogramName", "Histogram", "Histogram name"};
Gaudi::Property<std::string> m_histogram_title{this, "HistogramTitle", "",
"Histogram title (it defaults to the histogram name)"};
Gaudi::Property<unsigned int> m_binsX{this, "BinsX", 100};
Gaudi::Property<unsigned int> m_binsY{this, "BinsY", 100};
Gaudi::Property<std::pair<value_type, value_type>> m_rangeX{this, "RangeX", {0., 1.}};
Gaudi::Property<std::pair<value_type, value_type>> m_rangeY{this, "RangeY", {0., 1.}};
mutable std::optional<Gaudi::Accumulators::Histogram<2, Gaudi::Accumulators::atomicity::full, value_type>>
m_histogram;
};
DECLARE_COMPONENT_WITH_ID( EventCorrelationsMonitor, "EventCorrelationsMonitor" )
Loading