Skip to content
Snippets Groups Projects

FIND_DECAY and FIND_MCDECAY functor

Merged Tommaso Fulghesu requested to merge tfulghes-finddecay-functor into master
4 files
+ 1562
10
Compare changes
  • Side-by-side
  • Inline
Files
4
/*****************************************************************************\
/***************************************************************************** \
* (c) Copyright 2019-20 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
@@ -9,20 +9,25 @@
* or submit itself to any jurisdiction. *
\*****************************************************************************/
#pragma once
#include "Functors/Function.h"
#include "Functors/Utilities.h"
#include "GaudiAlg/GaudiTupleAlg.h"
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/System.h"
#include "Kernel/IDecayFinder.h"
#include "MCInterfaces/IMCDecayFinder.h"
/** @file Decay.h
* @brief Definitions of functors related to the decay chain.
*/
namespace Functors::Decay {
template <bool MC = false>
struct FindDecay;
/** @brief Use the DecayFinder algorithm to get the information related to the decay chain. */
struct FindDecay : public Function {
template<>
struct FindDecay<false> : public Function {
FindDecay( std::string decay_desc, std::string tool_name = "DecayFinder" )
: m_decay_desc{std::move( decay_desc )}, m_tool_name{std::move( tool_name )} {}
@@ -43,4 +48,34 @@ namespace Functors::Decay {
std::string m_tool_name;
std::optional<ToolHandle<IDecayFinder>> m_find_decay;
};
/** @brief Use the DecayFinder algorithm to get the information related to the decay chain. */
template<>
struct FindDecay<true> : public Function {
FindDecay( std::string decay_desc, std::string tool_name = "MCDecayFinder" )
: m_decay_desc{std::move( decay_desc )}, m_tool_name{std::move( tool_name )} {}
void bind( TopLevelInfo& top_level ) { m_find_decay.emplace( m_tool_name, top_level.algorithm() ); }
auto prepare( EventContext const&, TopLevelInfo const& ) const {
assert( m_find_decay.has_value() );
if ( !m_find_decay->get() ) m_find_decay->retrieve().ignore();
return [dd = m_decay_desc, tool = m_find_decay->get()]( auto mask, const auto& in ) {
m_find_decay -> setDecay(dd).ignore();
mask = mask && in.size() && m_find_decay -> hasDecay( in );
const LHCb::MCParticle* out = nullptr;
std::vector<const LHCb::MCParticle*> out_v;
while ( m_find_Decay -> findDecay( in, out ) )
out_v.push_back( out );
if ( out_v.size() > 1 )
warning() << "More than one signal decay found." << endmsg;
return mask ? Functors::Optional{out} : std::nullopt;
};
}
private:
std::string m_decay_desc;
std::string m_tool_name;
std::optional<ToolHandle<IMCDecayFinder>> m_find_decay;
};
} // namespace Functors::Decay
Loading