Skip to content
Snippets Groups Projects
Commit ca5d23d0 authored by Maarten Van Veghel's avatar Maarten Van Veghel
Browse files

speed up NeutralProtoPAlg

parent e572ccb5
No related tags found
1 merge request!5001Fix no cluster for SplitPhoton hypos
Pipeline #11605826 passed
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "CaloDet/DeCalorimeter.h" #include "CaloDet/DeCalorimeter.h"
#include "CaloFutureInterfaces/ICaloFutureHypoEstimator.h" #include "CaloFutureInterfaces/ICaloFutureHypoEstimator.h"
#include "CaloFutureUtils/CaloFutureAlgUtils.h" #include "CaloFutureUtils/CaloFutureAlgUtils.h"
#include "CaloFutureUtils/CaloMomentum.h"
#include "CaloFutureUtils/NeutralClassifierUtils.h" #include "CaloFutureUtils/NeutralClassifierUtils.h"
#include "CaloFutureUtils/TrackUtils.h" #include "CaloFutureUtils/TrackUtils.h"
#include "Core/FloatComparison.h" #include "Core/FloatComparison.h"
...@@ -130,39 +131,14 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s ...@@ -130,39 +131,14 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s
auto tableview = tracktable.buildView(); auto tableview = tracktable.buildView();
auto neutralview = neutralitytable.buildView(); auto neutralview = neutralitytable.buildView();
// wrapper around data map getter, to include track match table the estimator doesn't have access to
auto getData = [&]( auto const* hypo ) {
// hypo data
auto data = m_estimator->get_data( ecal, hcal, *hypo );
// track relation
using namespace LHCb::Calo::Enum;
auto it = data.find( DataType::CellID );
auto cellid = ( it != data.end() ) ? static_cast<unsigned>( it->second ) : 0u;
auto cluster = clusters.find( LHCb::Detector::Calo::CellID( cellid ) );
if ( cluster != clusters.end() ) {
auto cls_idx = cluster->indices().cast();
auto clsview = tableview.scalar()[cls_idx];
auto ntrview = neutralview.scalar()[cls_idx];
if ( clsview.hasRelation() )
data[DataType::ClusterMatch] = clsview.relation().template get<LHCb::Calo::TrackUtils::ClusterMatch>().cast();
if ( ntrview.hasRelation() )
data[DataType::ClusterNeutrality] =
ntrview.relation().template get<LHCb::Calo::NeutralClassifierUtils::TrackMatchClassifier>().cast();
}
return data;
};
// -- reset mass storage // -- reset mass storage
std::map<const int, double> mass_per_cell = { {} }; std::map<const int, double> mass_per_cell = { {} };
// Get masses // Get masses
for ( const auto* hypo : hypos_from_mergedPi0s ) { for ( const auto* hypo : hypos_from_mergedPi0s ) {
if ( !hypo ) continue; auto cluster = LHCb::CaloFutureAlgUtils::ClusterFromHypo( *hypo );
using namespace LHCb::Calo::Enum; if ( !cluster ) continue;
// The call to process is happening twice for mergedPi0s, should be made smarter. LHCb::Calo::Momentum mom( hypo );
auto data = getData( hypo ); mass_per_cell[cluster->seed().all()] = mom.mass();
const int cellCode = data.at( DataType::CellID );
auto it = data.find( DataType::HypoM );
mass_per_cell[cellCode] = ( it != data.end() ? it->second : Default );
} }
//------ loop over all caloHypo containers //------ loop over all caloHypo containers
...@@ -175,7 +151,6 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s ...@@ -175,7 +151,6 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s
// == Loop over CaloHypos // == Loop over CaloHypos
for ( const auto* hypo : hypos ) { for ( const auto* hypo : hypos ) {
if ( !hypo ) { continue; }
count++; count++;
// == create and store the corresponding ProtoParticle // == create and store the corresponding ProtoParticle
...@@ -189,13 +164,24 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s ...@@ -189,13 +164,24 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s
const auto hypothesis = hypo->hypothesis(); const auto hypothesis = hypo->hypothesis();
auto data = getData( hypo ); // hypo data
auto data = m_estimator->get_data( ecal, hcal, *hypo );
// track relation
using namespace LHCb::Calo::Enum;
auto it = data.find( DataType::CellID );
unsigned cellid = ( it != data.end() ) ? static_cast<unsigned>( it->second ) : Default;
auto cluster = clusters.find( LHCb::Detector::Calo::CellID( cellid ) );
if ( cluster != clusters.end() ) {
auto clsview = tableview.scalar()[cluster->indices().cast()];
if ( clsview.hasRelation() )
data[DataType::ClusterMatch] = clsview.relation().template get<LHCb::Calo::TrackUtils::ClusterMatch>().cast();
}
// create NeutralPID object // create NeutralPID object
auto pid = std::make_unique<LHCb::NeutralPID>(); auto pid = std::make_unique<LHCb::NeutralPID>();
pid->setCaloNeutralID( LHCb::Detector::Calo::CellID( cellid ) );
auto cellidcode = data.find( DataType::CellID ) != data.end() ? data.find( DataType::CellID )->second : Default;
pid->setCaloNeutralID( LHCb::Detector::Calo::CellID( (unsigned)cellidcode ) );
auto set = [&]( auto fn, const DataType t ) { auto set = [&]( auto fn, const DataType t ) {
auto i = data.find( t ); auto i = data.find( t );
...@@ -204,7 +190,7 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s ...@@ -204,7 +190,7 @@ LHCb::NeutralProtoPAlg::operator()( const LHCb::CaloHypos& hypos_from_mergedPi0s
// add data to NeutralPID object // add data to NeutralPID object
if ( hypothesis == LHCb::CaloHypo::Hypothesis::Photon || hypothesis == LHCb::CaloHypo::Hypothesis::Pi0Merged ) { if ( hypothesis == LHCb::CaloHypo::Hypothesis::Photon || hypothesis == LHCb::CaloHypo::Hypothesis::Pi0Merged ) {
const auto it = mass_per_cell.find( cellidcode ); const auto it = mass_per_cell.find( cellid );
if ( it != mass_per_cell.end() ) pid->setClusterMass( it->second ); if ( it != mass_per_cell.end() ) pid->setClusterMass( it->second );
} }
set( &LHCb::NeutralPID::setCaloNeutralEcal, DataType::ClusterE ); set( &LHCb::NeutralPID::setCaloNeutralEcal, DataType::ClusterE );
......
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