Skip to content
Snippets Groups Projects

Add new algorithm and a functor for storing Hlt1 TIS/TOS information

Merged Abhijit Mathad requested to merge AM_Hlt1TisTos into master
Compare and
2 files
+ 87
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -15,6 +15,7 @@
#include "Functors/Function.h"
#include "Kernel/IParticlePropertySvc.h"
#include "SelKernel/Utilities.h"
#include "Kernel/ITriggerTisTos.h"
/** @file Particle.h
* @brief Definitions of functors for particle-like objects
@@ -147,4 +148,83 @@ namespace Functors::Particle {
return d.template get<LHCb::Event::v3::Tracks>();
}
};
struct Hlt1TisTosTob : public Function {
Hlt1TisTosTob( std::vector<std::string> line_decisions ) : m_line_decisions{std::move( line_decisions )} {}
/* Improve error messages. */
constexpr auto name() const { return "Hlt1TisTosTob"; }
/* Bind to the top-level algorith */
void bind( TopLevelInfo& top_level ) {
//IMPORTANT NOTE: One should be careful setting the property. Can run into trouble if there are two algorithms that are using this functor.
m_hlt1tistostob = ToolHandle<ITriggerTisTos>{top_level.algorithm(), top_level.generate_property_name(), "Hlt1TriggerTisTos", "Hlt1TriggerTisTos"};
//Do I need to call "retrieve" here?
// This snipette of modifying the property of ToolHandle is taken
// from https://gitlab.cern.ch/lhcb/Rec/-/blob/c93052bca860db463f5403c0e30b5339b02ecb37/CaloFuture/CaloFutureTools/src/CaloFutureHypoEstimator.cpp#L78-82
m_hlt1tistostob.retrieve().ignore();
auto& iprop = dynamic_cast<IProperty&>( *m_hlt1tistostob );
auto sc_decreport = iprop.setProperty( "HltDecReportsLocation", "Hlt/DecReports" );
if ( sc_decreport.isFailure() )
throw GaudiException{"Could not set the property \"HltDecReportsLocation\" for the Hlt1TriggerTisTos tool.",
"Functors::Particle::Hlt1TisTosTob::bind()", StatusCode::FAILURE};
auto sc_selreport = iprop.setProperty( "HltSelReportsLocation", "Hlt/SelReports");
if ( sc_selreport.isFailure() )
throw GaudiException{"Could not set the property \"HltSelReportsLocation\" for the Hlt1TriggerTisTos tool.",
"Functors::Particle::Hlt1TisTosTob::bind()", StatusCode::FAILURE};
//TODO: make the overlap fraction b/w LHCbIDs of Hlt1 and Hlt2/Spruce reconstructed objects tunable
// These fractions are defined as properties
// in https://gitlab.cern.ch/lhcb/Rec/-/blob/2cbd84983db8720d53e9e307e7e0b4ee829504af/Phys/TisTosTobbing/src/lib/TisTos.cpp#L44-60
}
template <typename Particle>
auto operator()(const Particle& input_particle) const {
//check that the tool handle has been loaded correctly
if ( !m_hlt1tistostob )
throw GaudiException{"The tool ITriggerTisTos has not been configured properly and is null. Please check!",
"Functors::Particle::Hlt1TisTosTob::operator()", StatusCode::FAILURE};
//check that the line decisions are non-empty
if ( m_line_decisions.empty() )
throw GaudiException{"No Hlt1 line decisions have been specified to store the TIS/TOS/TOB results. Please check!",
"Functors::Particle::Hlt1TisTosTob::operator()", StatusCode::FAILURE};
//create an unordered map into which the result will be added
std::unordered_map<std::string, bool> map_tistostob;
map_tistostob.reserve(m_line_decisions.size());
//set Hlt2/Spruce reconstructed particle
std::scoped_lock guard{m_lock}; //Doing this for now to avoid race conditions. Is this sufficient?
m_hlt1tistostob->setOfflineInput( Sel::Utils::deref_if_ptr( input_particle ) );
for ( const auto& line_decision : m_line_decisions ) { //loop over the user specified decisions
//Note here that "line_decision" for the ITriggerTisTos tool is a regex expression e.g. "Hlt1.*Decision"
//Here I am assuming that the users would pass a list of strings with each string uniquely identifing a Hlt1 line line_decision
//TODO: Ensure that the suffix "Decision" is added to the string if it is not already provided
m_hlt1tistostob->setTriggerInput( line_decision ); //set the Hlt1 reconstructed particle through the line line_decision
const auto result = m_hlt1tistostob->tisTosTobTrigger(); //result after comparing LHCbIDs b/w Hlt1 and Hlt2/Spruce reconstructed object
bool tos = result.tos();
bool tis = result.tis();
bool tob = result.decision() && (!tis) && (!tos);
//fill the map with the results
map_tistostob[line_decision+"_TOS"] = tos;
map_tistostob[line_decision+"_TIS"] = tis;
map_tistostob[line_decision+"_TOB"] = tob;
}
return map_tistostob;
}
private:
std::vector<std::string> m_line_decisions;
/// The tool to compure TIS/TOS needs to be mutable as all the methods of this tool are non-const
/// Here we need to use ITriggerTisTos instead of IParticleTisTos since former returns decisions from decreport
mutable ToolHandle<ITriggerTisTos> m_hlt1tistostob = nullptr;
/// Lock acquired in `operator()` to avoid race conditions during interaction with m_hlt1tistostob
mutable std::mutex m_lock;
};
} // namespace Functors::Particle
Loading