From 305660aaabb4512d91a8ed0dec634b46f8c3701f Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Tue, 23 Jul 2024 17:41:26 +0200 Subject: [PATCH 01/10] feat: add UTTrackResidualMonitor --- Tr/TrackMonitors/CMakeLists.txt | 1 + .../src/UTTrackResidualMonitor.cpp | 286 ++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp diff --git a/Tr/TrackMonitors/CMakeLists.txt b/Tr/TrackMonitors/CMakeLists.txt index abb9c9a236a..4340a040cd3 100644 --- a/Tr/TrackMonitors/CMakeLists.txt +++ b/Tr/TrackMonitors/CMakeLists.txt @@ -35,6 +35,7 @@ gaudi_add_module(TrackMonitors src/TrackVPOverlapMonitor.cpp src/UTHitEfficiencyMonitor.cpp src/UTTrackMonitor.cpp + src/UTTrackResidualMonitor.cpp src/UTGlobalEffMon.cpp src/VPTrackMonitor.cpp src/VPHitEfficiencyMonitor.cpp diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp new file mode 100644 index 00000000000..d32ad73c76b --- /dev/null +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -0,0 +1,286 @@ +/*****************************************************************************\ +* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, CERN does not waive the privileges and immunities * +* granted to it by virtue of its status as an Intergovernmental Organization * +* or submit itself to any jurisdiction. * +\*****************************************************************************/ +#include "DetDesc/DetectorElement.h" +#include "Event/PrHits.h" +#include "Event/PrKalmanFitResult.h" +#include "Event/Track.h" +#include "Event/TrackFitResult.h" +#include "Gaudi/Accumulators/Histogram.h" +#include "TrackMonitorBase.h" +#include "UTDAQ/UTInfo.h" +#include "UTDet/DeUTDetector.h" + +#include "LHCbAlgs/Consumer.h" + +#include + +using namespace LHCb; +using namespace Gaudi; +using simd = SIMDWrapper::scalar::types; + +/** + * Class for monitoring unbiased UT hits residual of long track + * @author Hangyi Wu + * @date 15-3-2024 + */ + +template +class Mutable { + mutable T m_t; + +public: + template >> + Mutable( Args&&... args ) : m_t{std::forward( args )...} {} + + template + decltype( auto ) operator[]( Arg&& arg ) const { + return m_t[std::forward( arg )]; + } +}; + +template +class UTTrackResidualMonitor + : public LHCb::Algorithm::Consumer< + void( LHCb::Track::Range const&, const Pr::UT::Hits&, DetectorElement const&, const DeUTDetector& ), + LHCb::DetDesc::usesBaseAndConditions> { + +public: + UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); + StatusCode initialize() override; + void operator()( LHCb::Track::Range const&, const Pr::UT::Hits&, DetectorElement const&, + const DeUTDetector& ) const override; + +private: + void fillHistograms( LHCb::Track const& track, const Pr::UT::Hits& utHits, IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const; + std::optional getResidual( LHCb::Track const& track, Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; + mutable Gaudi::Accumulators::Histogram<2> m_xy{this, "xy", "x vs y (mm)", {{500, -1000, 1000}, {500, -1000, 1000}}}; + mutable Gaudi::Accumulators::Histogram<1> m_utHisto{this, "UT", "UT", {200, -5., 5.}}; + using Histo1D = Mutable>; + using Histo2D = Mutable>; + using Axis = Gaudi::Accumulators::Axis; + using H2DArg = Gaudi::Accumulators::HistoInputType; + mutable std::map m_sideHistos; + mutable std::map m_fullLayerHistos; + mutable std::map m_halfLayerHistos; + mutable std::map m_staveHistos; + mutable std::map m_moduleHistos; + + Gaudi::Property m_refZ{this, "ReferenceZ", 2485.0, "midpoint of UT"}; + Gaudi::Property m_trueUnbiased{this, "TrueUnbiased", true, + "Whether tracks contain UT hits (false) or not (true)."}; + void buildHistogramMaps( const DeUTDetector& deUT ); +}; + +template +void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std::string labels, A axis ) { + h.emplace( std::piecewise_construct, std::forward_as_tuple( k ), std::forward_as_tuple( owner, name, labels, axis ) ); +} + +using UTTrResidualMonitor = UTTrackResidualMonitor; +using UTTrResidualMonitor_PrKalman = UTTrackResidualMonitor; +DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor, "UTTrackResidualMonitor" ) +DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor_PrKalman, "UTTrackResidualMonitor_PrKalman" ) + +template +void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { + + const char* title = m_trueUnbiased ? "UnbiasedResidual" : "Residual"; + float xmin = m_trueUnbiased ? -10.f : -1.f; + float xmax = -xmin; + + // create histograms + std::string sideNames[2] = {"Cside", "Aside"}; + std::string layerNames[4] = {"UTaX", "UTaU", "UTbV", "UTbX"}; + for ( unsigned int i = 0; i < 4; i++ ) { + buildHistogram( this, m_fullLayerHistos, i, layerNames[i] + '/' + title, title, Axis{400, xmin, xmax} ); + } + for ( const auto& side : deUT.sides() ) { +#ifdef USE_DD4HEP + auto sideID = side.channelID().side(); +#else + auto sideID = side->channelID().side(); +#endif + buildHistogram( this, m_sideHistos, sideID, sideNames[sideID] + '/' + title, title, Axis{400, xmin, xmax} ); +#ifdef USE_DD4HEP + for ( const auto& layer : side.layers() ) { + auto layerID = layer.channelID().layer(); + auto layerUniqueID = layer.channelID().uniqueLayer(); +#else + for ( const auto& layer : side->layers() ) { + auto layerID = layer->channelID().layer(); + auto layerUniqueID = layer->channelID().uniqueLayer(); +#endif + std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; + buildHistogram( this, m_halfLayerHistos, layerUniqueID, layerPath + '/' + title, title, Axis{400, xmin, xmax} ); +#ifdef USE_DD4HEP + for ( const auto& stave : layer.staves() ) { + auto staveID = stave.channelID().stave(); + auto staveUniqueID = stave.channelID().uniqueStave(); +#else + for ( const auto& stave : layer->staves() ) { + auto staveID = stave->channelID().stave(); + auto staveUniqueID = stave->channelID().uniqueStave(); +#endif + std::string stavePath = + sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); + buildHistogram( this, m_staveHistos, staveUniqueID, stavePath + '/' + title, title, Axis{400, xmin, xmax} ); +#ifdef USE_DD4HEP + for ( const auto& face : stave.faces() ) { + auto faceID = face.channelID().face(); + for ( const auto& module : face.modules() ) { + auto moduleID = module.channelID().module(); + auto moduleUniqueID = module.channelID().uniqueModule(); +#else + for ( const auto& face : stave->faces() ) { + auto faceID = face->channelID().face(); + for ( const auto& module : face->modules() ) { + auto moduleID = module->channelID().module(); + auto moduleUniqueID = module->channelID().uniqueModule(); +#endif + std::string modulePath = sideNames[sideID] + "/" + layerNames[layerID] + "/Stave" + + std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + + std::to_string( moduleID ); + buildHistogram( this, m_moduleHistos, moduleUniqueID, modulePath + '/' + title, title, + Axis{400, xmin, xmax} ); + } + } + } + } + } +} +template +StatusCode UTTrackResidualMonitor::initialize() { + return Consumer::initialize().andThen( [&] { + addConditionDerivation( {inputLocation()}, std::string{}, [&]( DeUTDetector const& det ) { + buildHistogramMaps( det ); + return std::string(); + } ); + return StatusCode::SUCCESS; + } ); +} + +template +UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) + : Consumer( name, pSvcLocator, + {{"TracksInContainer", LHCb::TrackLocation::Default}, + {"UTHitsLocation", UTInfo::HitLocation}, + {"StandardGeometryTop", LHCb::standard_geometry_top}, + {"DeUT", DeUTDetLocation::location()}} ) {} + +template +void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, + const Pr::UT::Hits& utHits, const DetectorElement& lhcb, + const DeUTDetector& deUT ) const { + auto& geometry = *lhcb.geometry(); + + // histograms per track + for ( const LHCb::Track* track : tracks ) { + // find the IT hits on the track + fillHistograms( *track, utHits, geometry, deUT ); + } +} + +template +void UTTrackResidualMonitor::fillHistograms( LHCb::Track const& track, const Pr::UT::Hits& utHits, + IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const { + if ( m_trueUnbiased ) { + // track parameters at some reference z + LHCb::StateVector aState; + extrapolator()->propagate( track, m_refZ, aState, geometry ).ignore(); + if ( fullDetail() ) { ++m_xy[{aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm}]; } + + const auto hits = utHits.scalar(); + for ( auto const hit : hits ) { + const simd::int_v simd_chanid = hit.template get(); + auto const chanID = Detector::UT::ChannelID( simd_chanid.cast() ); + auto residualX = getResidual( track, chanID, geometry, deUT ); + if ( residualX ) { + ++m_utHisto[*residualX]; + ++m_sideHistos.at( chanID.side() )[*residualX]; + ++m_fullLayerHistos.at( chanID.layer() )[*residualX]; + ++m_halfLayerHistos.at( chanID.uniqueLayer() )[*residualX]; + ++m_staveHistos.at( chanID.uniqueStave() )[*residualX]; + ++m_moduleHistos.at( chanID.uniqueModule() )[*residualX]; + } + } + } else { + auto fitResult = dynamic_cast( track.fitResult() ); + for ( const auto& node : nodes( *fitResult ) ) { + if ( !( node.hasMeasurement() && node.isHitOnTrack() && node.isUT() ) ) continue; + if ( node.isOutlier() ) continue; + if ( node.errResidual() == 0.0 ) continue; + + LHCb::LHCbID lhcbID = id( node ); + Detector::UT::ChannelID chanID = lhcbID.utID(); + auto residualX = node.unbiasedResidual(); + ++m_utHisto[residualX]; + ++m_sideHistos.at( chanID.side() )[residualX]; + ++m_fullLayerHistos.at( chanID.layer() )[residualX]; + ++m_halfLayerHistos.at( chanID.uniqueLayer() )[residualX]; + ++m_staveHistos.at( chanID.uniqueStave() )[residualX]; + ++m_moduleHistos.at( chanID.uniqueModule() )[residualX]; + } + } +} +template +std::optional UTTrackResidualMonitor::getResidual( LHCb::Track const& track, + Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const { + auto aSector = deUT.findSector( hitChanID ); +#ifdef USE_DD4HEP + if ( !aSector.isValid() ) { +#else + if ( !aSector ) { +#endif + warning() << "Sector not found with" << hitChanID << endmsg; + return std::nullopt; + } +#ifdef USE_DD4HEP + auto aStrip = aSector.createTraj( hitChanID.strip(), 0 ); +#else + auto aStrip = aSector->trajectory( hitChanID, 0 ); +#endif + ROOT::Math::XYZPoint g1 = aStrip.beginPoint(); + ROOT::Math::XYZPoint g2 = aStrip.endPoint(); + ROOT::Math::XYZPoint hitPos = g1 + ( g2 - g1 ) * 0.5; + auto hitX = hitPos.X(); + auto hitY = hitPos.Y(); + auto hitZ = hitPos.Z(); + + // obtain dxdy + double dxdy, dummy; +#ifdef USE_DD4HEP + aSector.trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); +#else + aSector->trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); +#endif + + LHCb::StateVector aState; + extrapolator()->propagate( track, hitZ, aState, geometry ).ignore(); +#ifdef USE_DD4HEP + if ( aSector.sensor().sensorType() == 'A' || aSector.sensor().sensorType() == 'B' ) +#else + if ( aSector->sensor( 0 ).sensorType() == 'A' || aSector->sensor( 0 ).sensorType() == 'B' ) +#endif + if ( std::abs( hitY - aState.y() ) > 60.0 ) return std::nullopt; +#ifdef USE_DD4HEP + if ( aSector.sensor().sensorType() == 'C' || aSector.sensor().sensorType() == 'D' ) +#else + if ( aSector->sensor( 0 ).sensorType() == 'C' || aSector->sensor( 0 ).sensorType() == 'D' ) +#endif + if ( std::abs( hitY - aState.y() ) > 30.0 ) return std::nullopt; + + return hitX - ( aState.x() + ( hitY - aState.y() ) * dxdy ); +} -- GitLab From c1df02ee93f572af1ec5db57b452fa439e8a5dd9 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Thu, 25 Jul 2024 16:45:20 +0200 Subject: [PATCH 02/10] feat: add biased residual --- .../src/UTTrackResidualMonitor.cpp | 99 ++++++++++++------- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index d32ad73c76b..9792987bd97 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -61,22 +61,30 @@ public: private: void fillHistograms( LHCb::Track const& track, const Pr::UT::Hits& utHits, IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; - std::optional getResidual( LHCb::Track const& track, Detector::UT::ChannelID hitChanID, - IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; - mutable Gaudi::Accumulators::Histogram<2> m_xy{this, "xy", "x vs y (mm)", {{500, -1000, 1000}, {500, -1000, 1000}}}; - mutable Gaudi::Accumulators::Histogram<1> m_utHisto{this, "UT", "UT", {200, -5., 5.}}; + std::optional getResidual( LHCb::Track const& track, Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; using Histo1D = Mutable>; using Histo2D = Mutable>; using Axis = Gaudi::Accumulators::Axis; using H2DArg = Gaudi::Accumulators::HistoInputType; - mutable std::map m_sideHistos; - mutable std::map m_fullLayerHistos; - mutable std::map m_halfLayerHistos; - mutable std::map m_staveHistos; - mutable std::map m_moduleHistos; + mutable Gaudi::Accumulators::Histogram<2> m_xy{this, "xy", "x vs y (mm)", {{500, -1000, 1000}, {500, -1000, 1000}}}; + + mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{this, "UT_Unbiased", "UT", {200, -5., 5.}}; + mutable std::map m_sides_unbiased; + mutable std::map m_layers_unbiased; + mutable std::map m_halflayers_unbiased; + mutable std::map m_staves_unbiased; + mutable std::map m_modules_unbiased; + + mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{this, "UT_Biased", "UT", {200, -5., 5.}}; + mutable std::map m_sides_biased; + mutable std::map m_layers_biased; + mutable std::map m_halflayers_biased; + mutable std::map m_staves_biased; + mutable std::map m_modules_biased; Gaudi::Property m_refZ{this, "ReferenceZ", 2485.0, "midpoint of UT"}; - Gaudi::Property m_trueUnbiased{this, "TrueUnbiased", true, + Gaudi::Property m_trueUnbiased{this, "TrueUnbiased", false, "Whether tracks contain UT hits (false) or not (true)."}; void buildHistogramMaps( const DeUTDetector& deUT ); }; @@ -94,15 +102,18 @@ DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor_PrKalman, "UTTrackResidualMonitor template void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { - const char* title = m_trueUnbiased ? "UnbiasedResidual" : "Residual"; - float xmin = m_trueUnbiased ? -10.f : -1.f; - float xmax = -xmin; + const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; + float xmin = m_trueUnbiased ? -10.f : -1.f; + float xmax = -xmin; + unsigned int nbin = 400; // create histograms std::string sideNames[2] = {"Cside", "Aside"}; std::string layerNames[4] = {"UTaX", "UTaU", "UTbV", "UTbX"}; for ( unsigned int i = 0; i < 4; i++ ) { - buildHistogram( this, m_fullLayerHistos, i, layerNames[i] + '/' + title, title, Axis{400, xmin, xmax} ); + buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, + Axis{nbin, xmin, xmax} ); + buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", Axis{nbin, xmin, xmax} ); } for ( const auto& side : deUT.sides() ) { #ifdef USE_DD4HEP @@ -110,7 +121,10 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe #else auto sideID = side->channelID().side(); #endif - buildHistogram( this, m_sideHistos, sideID, sideNames[sideID] + '/' + title, title, Axis{400, xmin, xmax} ); + buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, + Axis{nbin, xmin, xmax} ); + buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", + Axis{nbin, xmin, xmax} ); #ifdef USE_DD4HEP for ( const auto& layer : side.layers() ) { auto layerID = layer.channelID().layer(); @@ -121,7 +135,10 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe auto layerUniqueID = layer->channelID().uniqueLayer(); #endif std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; - buildHistogram( this, m_halfLayerHistos, layerUniqueID, layerPath + '/' + title, title, Axis{400, xmin, xmax} ); + buildHistogram( this, m_halflayers_unbiased, layerUniqueID, layerPath + '/' + title_unbiased, title_unbiased, + Axis{nbin, xmin, xmax} ); + buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", + Axis{nbin, xmin, xmax} ); #ifdef USE_DD4HEP for ( const auto& stave : layer.staves() ) { auto staveID = stave.channelID().stave(); @@ -133,7 +150,10 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe #endif std::string stavePath = sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); - buildHistogram( this, m_staveHistos, staveUniqueID, stavePath + '/' + title, title, Axis{400, xmin, xmax} ); + buildHistogram( this, m_staves_unbiased, staveUniqueID, stavePath + '/' + title_unbiased, title_unbiased, + Axis{nbin, xmin, xmax} ); + buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", + Axis{nbin, xmin, xmax} ); #ifdef USE_DD4HEP for ( const auto& face : stave.faces() ) { auto faceID = face.channelID().face(); @@ -150,8 +170,10 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe std::string modulePath = sideNames[sideID] + "/" + layerNames[layerID] + "/Stave" + std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + std::to_string( moduleID ); - buildHistogram( this, m_moduleHistos, moduleUniqueID, modulePath + '/' + title, title, - Axis{400, xmin, xmax} ); + buildHistogram( this, m_modules_unbiased, moduleUniqueID, modulePath + '/' + title_unbiased, title_unbiased, + Axis{nbin, xmin, xmax} ); + buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", + Axis{nbin, xmin, xmax} ); } } } @@ -206,12 +228,12 @@ void UTTrackResidualMonitor::fillHistograms( LHCb::Track cons auto const chanID = Detector::UT::ChannelID( simd_chanid.cast() ); auto residualX = getResidual( track, chanID, geometry, deUT ); if ( residualX ) { - ++m_utHisto[*residualX]; - ++m_sideHistos.at( chanID.side() )[*residualX]; - ++m_fullLayerHistos.at( chanID.layer() )[*residualX]; - ++m_halfLayerHistos.at( chanID.uniqueLayer() )[*residualX]; - ++m_staveHistos.at( chanID.uniqueStave() )[*residualX]; - ++m_moduleHistos.at( chanID.uniqueModule() )[*residualX]; + ++m_ut_unbiased[*residualX]; + ++m_sides_unbiased.at( chanID.side() )[*residualX]; + ++m_layers_unbiased.at( chanID.layer() )[*residualX]; + ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[*residualX]; + ++m_staves_unbiased.at( chanID.uniqueStave() )[*residualX]; + ++m_modules_unbiased.at( chanID.uniqueModule() )[*residualX]; } } } else { @@ -221,15 +243,24 @@ void UTTrackResidualMonitor::fillHistograms( LHCb::Track cons if ( node.isOutlier() ) continue; if ( node.errResidual() == 0.0 ) continue; - LHCb::LHCbID lhcbID = id( node ); - Detector::UT::ChannelID chanID = lhcbID.utID(); - auto residualX = node.unbiasedResidual(); - ++m_utHisto[residualX]; - ++m_sideHistos.at( chanID.side() )[residualX]; - ++m_fullLayerHistos.at( chanID.layer() )[residualX]; - ++m_halfLayerHistos.at( chanID.uniqueLayer() )[residualX]; - ++m_staveHistos.at( chanID.uniqueStave() )[residualX]; - ++m_moduleHistos.at( chanID.uniqueModule() )[residualX]; + LHCb::LHCbID lhcbID = id( node ); + Detector::UT::ChannelID chanID = lhcbID.utID(); + auto unbiasedResidual = node.unbiasedResidual(); + auto biasedResidual = node.residual(); + + ++m_ut_unbiased[unbiasedResidual]; + ++m_sides_unbiased.at( chanID.side() )[unbiasedResidual]; + ++m_layers_unbiased.at( chanID.layer() )[unbiasedResidual]; + ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[unbiasedResidual]; + ++m_staves_unbiased.at( chanID.uniqueStave() )[unbiasedResidual]; + ++m_modules_unbiased.at( chanID.uniqueModule() )[unbiasedResidual]; + + ++m_ut_biased[biasedResidual]; + ++m_sides_biased.at( chanID.side() )[biasedResidual]; + ++m_layers_biased.at( chanID.layer() )[biasedResidual]; + ++m_halflayers_biased.at( chanID.uniqueLayer() )[biasedResidual]; + ++m_staves_biased.at( chanID.uniqueStave() )[biasedResidual]; + ++m_modules_biased.at( chanID.uniqueModule() )[biasedResidual]; } } } -- GitLab From ebc7c56991b5ad84a6c11e34500c5ff929d48076 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Tue, 18 Feb 2025 20:34:50 +0100 Subject: [PATCH 03/10] fix: TrackMonitorBase->TupeBase pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/51252400 --- .../src/UTTrackResidualMonitor.cpp | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 9792987bd97..66ca54a16d8 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -14,7 +14,7 @@ #include "Event/Track.h" #include "Event/TrackFitResult.h" #include "Gaudi/Accumulators/Histogram.h" -#include "TrackMonitorBase.h" +#include "TrackMonitorTupleBase.h" #include "UTDAQ/UTInfo.h" #include "UTDet/DeUTDetector.h" @@ -38,7 +38,7 @@ class Mutable { public: template >> - Mutable( Args&&... args ) : m_t{std::forward( args )...} {} + Mutable( Args&&... args ) : m_t{ std::forward( args )... } {} template decltype( auto ) operator[]( Arg&& arg ) const { @@ -50,7 +50,7 @@ template class UTTrackResidualMonitor : public LHCb::Algorithm::Consumer< void( LHCb::Track::Range const&, const Pr::UT::Hits&, DetectorElement const&, const DeUTDetector& ), - LHCb::DetDesc::usesBaseAndConditions> { + LHCb::DetDesc::usesBaseAndConditions> { public: UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); @@ -67,25 +67,26 @@ private: using Histo2D = Mutable>; using Axis = Gaudi::Accumulators::Axis; using H2DArg = Gaudi::Accumulators::HistoInputType; - mutable Gaudi::Accumulators::Histogram<2> m_xy{this, "xy", "x vs y (mm)", {{500, -1000, 1000}, {500, -1000, 1000}}}; + mutable Gaudi::Accumulators::Histogram<2> m_xy{ + this, "xy", "x vs y (mm)", { { 500, -1000, 1000 }, { 500, -1000, 1000 } } }; - mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{this, "UT_Unbiased", "UT", {200, -5., 5.}}; + mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{ this, "UT_Unbiased", "UT", { 200, -5., 5. } }; mutable std::map m_sides_unbiased; mutable std::map m_layers_unbiased; mutable std::map m_halflayers_unbiased; mutable std::map m_staves_unbiased; mutable std::map m_modules_unbiased; - mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{this, "UT_Biased", "UT", {200, -5., 5.}}; + mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{ this, "UT_Biased", "UT", { 200, -5., 5. } }; mutable std::map m_sides_biased; mutable std::map m_layers_biased; mutable std::map m_halflayers_biased; mutable std::map m_staves_biased; mutable std::map m_modules_biased; - Gaudi::Property m_refZ{this, "ReferenceZ", 2485.0, "midpoint of UT"}; - Gaudi::Property m_trueUnbiased{this, "TrueUnbiased", false, - "Whether tracks contain UT hits (false) or not (true)."}; + Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; + Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, + "Whether tracks contain UT hits (false) or not (true)." }; void buildHistogramMaps( const DeUTDetector& deUT ); }; @@ -108,12 +109,12 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe unsigned int nbin = 400; // create histograms - std::string sideNames[2] = {"Cside", "Aside"}; - std::string layerNames[4] = {"UTaX", "UTaU", "UTbV", "UTbX"}; + std::string sideNames[2] = { "Cside", "Aside" }; + std::string layerNames[4] = { "UTaX", "UTaU", "UTbV", "UTbX" }; for ( unsigned int i = 0; i < 4; i++ ) { buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, - Axis{nbin, xmin, xmax} ); - buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", Axis{ nbin, xmin, xmax } ); } for ( const auto& side : deUT.sides() ) { #ifdef USE_DD4HEP @@ -122,9 +123,9 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe auto sideID = side->channelID().side(); #endif buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); #ifdef USE_DD4HEP for ( const auto& layer : side.layers() ) { auto layerID = layer.channelID().layer(); @@ -136,9 +137,9 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe #endif std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; buildHistogram( this, m_halflayers_unbiased, layerUniqueID, layerPath + '/' + title_unbiased, title_unbiased, - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); #ifdef USE_DD4HEP for ( const auto& stave : layer.staves() ) { auto staveID = stave.channelID().stave(); @@ -151,9 +152,9 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe std::string stavePath = sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); buildHistogram( this, m_staves_unbiased, staveUniqueID, stavePath + '/' + title_unbiased, title_unbiased, - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); #ifdef USE_DD4HEP for ( const auto& face : stave.faces() ) { auto faceID = face.channelID().face(); @@ -171,9 +172,9 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + std::to_string( moduleID ); buildHistogram( this, m_modules_unbiased, moduleUniqueID, modulePath + '/' + title_unbiased, title_unbiased, - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", - Axis{nbin, xmin, xmax} ); + Axis{ nbin, xmin, xmax } ); } } } @@ -183,7 +184,7 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe template StatusCode UTTrackResidualMonitor::initialize() { return Consumer::initialize().andThen( [&] { - addConditionDerivation( {inputLocation()}, std::string{}, [&]( DeUTDetector const& det ) { + addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { buildHistogramMaps( det ); return std::string(); } ); @@ -194,10 +195,10 @@ StatusCode UTTrackResidualMonitor::initialize() { template UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, - {{"TracksInContainer", LHCb::TrackLocation::Default}, - {"UTHitsLocation", UTInfo::HitLocation}, - {"StandardGeometryTop", LHCb::standard_geometry_top}, - {"DeUT", DeUTDetLocation::location()}} ) {} + { { "TracksInContainer", LHCb::TrackLocation::Default }, + { "UTHitsLocation", UTInfo::HitLocation }, + { "StandardGeometryTop", LHCb::standard_geometry_top }, + { "DeUT", DeUTDetLocation::location() } } ) {} template void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, @@ -220,7 +221,7 @@ void UTTrackResidualMonitor::fillHistograms( LHCb::Track cons // track parameters at some reference z LHCb::StateVector aState; extrapolator()->propagate( track, m_refZ, aState, geometry ).ignore(); - if ( fullDetail() ) { ++m_xy[{aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm}]; } + if ( fullDetail() ) { ++m_xy[{ aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm }]; } const auto hits = utHits.scalar(); for ( auto const hit : hits ) { -- GitLab From 4c9e58ead1ef4e74aa8ee8188a055dd2c2520850 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Tue, 4 Mar 2025 21:58:46 +0100 Subject: [PATCH 04/10] fix crashes on DetDesc platform pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/52268262 --- Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 66ca54a16d8..0ca253ebc53 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -87,12 +87,14 @@ private: Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, "Whether tracks contain UT hits (false) or not (true)." }; - void buildHistogramMaps( const DeUTDetector& deUT ); + void buildHistogramMaps( const DeUTDetector& deUT ) const; }; template void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std::string labels, A axis ) { - h.emplace( std::piecewise_construct, std::forward_as_tuple( k ), std::forward_as_tuple( owner, name, labels, axis ) ); + if ( !h.contains( k ) ) + h.emplace( std::piecewise_construct, std::forward_as_tuple( k ), + std::forward_as_tuple( owner, name, labels, axis ) ); } using UTTrResidualMonitor = UTTrackResidualMonitor; @@ -101,7 +103,7 @@ DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor, "UTTrackResidualMonitor" ) DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor_PrKalman, "UTTrackResidualMonitor_PrKalman" ) template -void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { +void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) const { const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; float xmin = m_trueUnbiased ? -10.f : -1.f; @@ -183,13 +185,7 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe } template StatusCode UTTrackResidualMonitor::initialize() { - return Consumer::initialize().andThen( [&] { - addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { - buildHistogramMaps( det ); - return std::string(); - } ); - return StatusCode::SUCCESS; - } ); + return Consumer::initialize(); } template @@ -205,6 +201,7 @@ void UTTrackResidualMonitor::operator()( LHCb::Track::Range c const Pr::UT::Hits& utHits, const DetectorElement& lhcb, const DeUTDetector& deUT ) const { auto& geometry = *lhcb.geometry(); + buildHistogramMaps( deUT ); // histograms per track for ( const LHCb::Track* track : tracks ) { -- GitLab From 6061ed16b3f58342398f543ec29e620d9c5bc217 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Tue, 15 Apr 2025 01:31:40 +0200 Subject: [PATCH 05/10] fix: apply a few suggestions drop template in UTTrackResidualMonitor drop using namespace lines drop dependence on TrackMonitorTupleBase replace LHCb::DetDesc with LHCb::Algorithm::Traits remove useless initialize() override pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/54649974 --- .../src/UTTrackResidualMonitor.cpp | 123 ++++++++---------- 1 file changed, 56 insertions(+), 67 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 0ca253ebc53..3b421b9e132 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -9,21 +9,23 @@ * or submit itself to any jurisdiction. * \*****************************************************************************/ #include "DetDesc/DetectorElement.h" +#include "Event/ITrackFitResult.h" #include "Event/PrHits.h" #include "Event/PrKalmanFitResult.h" #include "Event/Track.h" #include "Event/TrackFitResult.h" #include "Gaudi/Accumulators/Histogram.h" -#include "TrackMonitorTupleBase.h" #include "UTDAQ/UTInfo.h" #include "UTDet/DeUTDetector.h" #include "LHCbAlgs/Consumer.h" +#include "TrackInterfaces/ITrackExtrapolator.h" #include -using namespace LHCb; -using namespace Gaudi; +using LHCb::Track; +using std::optional; + using simd = SIMDWrapper::scalar::types; /** @@ -46,23 +48,21 @@ public: } }; -template class UTTrackResidualMonitor - : public LHCb::Algorithm::Consumer< - void( LHCb::Track::Range const&, const Pr::UT::Hits&, DetectorElement const&, const DeUTDetector& ), - LHCb::DetDesc::usesBaseAndConditions> { + : public LHCb::Algorithm::Consumer> { public: UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); - StatusCode initialize() override; - void operator()( LHCb::Track::Range const&, const Pr::UT::Hits&, DetectorElement const&, + void operator()( LHCb::Track::Range const&, const LHCb::Pr::UT::Hits&, DetectorElement const&, const DeUTDetector& ) const override; private: - void fillHistograms( LHCb::Track const& track, const Pr::UT::Hits& utHits, IGeometryInfo const& geometry, + void fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; - std::optional getResidual( LHCb::Track const& track, Detector::UT::ChannelID hitChanID, - IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; + optional getResidual( Track const& track, LHCb::Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; using Histo1D = Mutable>; using Histo2D = Mutable>; using Axis = Gaudi::Accumulators::Axis; @@ -84,10 +84,12 @@ private: mutable std::map m_staves_biased; mutable std::map m_modules_biased; - Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; - Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, + ToolHandle m_extrapolator{ this, "Extrapolator", + "TrackMasterExtrapolator" }; ///< Pointer to extrapolator + Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; + Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, "Whether tracks contain UT hits (false) or not (true)." }; - void buildHistogramMaps( const DeUTDetector& deUT ) const; + void buildHistogramMaps( const DeUTDetector& deUT ) const; }; template @@ -97,13 +99,9 @@ void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std: std::forward_as_tuple( owner, name, labels, axis ) ); } -using UTTrResidualMonitor = UTTrackResidualMonitor; -using UTTrResidualMonitor_PrKalman = UTTrackResidualMonitor; -DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor, "UTTrackResidualMonitor" ) -DECLARE_COMPONENT_WITH_ID( UTTrResidualMonitor_PrKalman, "UTTrackResidualMonitor_PrKalman" ) +DECLARE_COMPONENT_WITH_ID( UTTrackResidualMonitor, "UTTrackResidualMonitor" ) -template -void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) const { +void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) const { const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; float xmin = m_trueUnbiased ? -10.f : -1.f; @@ -183,23 +181,16 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDe } } } -template -StatusCode UTTrackResidualMonitor::initialize() { - return Consumer::initialize(); -} -template -UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) +UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, { { "TracksInContainer", LHCb::TrackLocation::Default }, { "UTHitsLocation", UTInfo::HitLocation }, { "StandardGeometryTop", LHCb::standard_geometry_top }, { "DeUT", DeUTDetLocation::location() } } ) {} -template -void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, - const Pr::UT::Hits& utHits, const DetectorElement& lhcb, - const DeUTDetector& deUT ) const { +void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, const LHCb::Pr::UT::Hits& utHits, + const DetectorElement& lhcb, const DeUTDetector& deUT ) const { auto& geometry = *lhcb.geometry(); buildHistogramMaps( deUT ); @@ -210,20 +201,18 @@ void UTTrackResidualMonitor::operator()( LHCb::Track::Range c } } -template -void UTTrackResidualMonitor::fillHistograms( LHCb::Track const& track, const Pr::UT::Hits& utHits, - IGeometryInfo const& geometry, - const DeUTDetector& deUT ) const { +void UTTrackResidualMonitor::fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const { if ( m_trueUnbiased ) { // track parameters at some reference z LHCb::StateVector aState; - extrapolator()->propagate( track, m_refZ, aState, geometry ).ignore(); - if ( fullDetail() ) { ++m_xy[{ aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm }]; } + m_extrapolator->propagate( track, m_refZ, aState, geometry ).ignore(); + ++m_xy[{ aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm }]; const auto hits = utHits.scalar(); for ( auto const hit : hits ) { - const simd::int_v simd_chanid = hit.template get(); - auto const chanID = Detector::UT::ChannelID( simd_chanid.cast() ); + const simd::int_v simd_chanid = hit.template get(); + auto const chanID = LHCb::Detector::UT::ChannelID( simd_chanid.cast() ); auto residualX = getResidual( track, chanID, geometry, deUT ); if ( residualX ) { ++m_ut_unbiased[*residualX]; @@ -235,38 +224,38 @@ void UTTrackResidualMonitor::fillHistograms( LHCb::Track cons } } } else { - auto fitResult = dynamic_cast( track.fitResult() ); - for ( const auto& node : nodes( *fitResult ) ) { - if ( !( node.hasMeasurement() && node.isHitOnTrack() && node.isUT() ) ) continue; - if ( node.isOutlier() ) continue; - if ( node.errResidual() == 0.0 ) continue; + dispatch( *track.fitResult(), [&]( const auto& fr ) { + for ( const auto& node : nodes( fr ) ) { + if ( !( node.hasMeasurement() && node.isHitOnTrack() && node.isUT() ) ) continue; + if ( node.isOutlier() ) continue; + if ( node.errResidual() == 0.0 ) continue; - LHCb::LHCbID lhcbID = id( node ); - Detector::UT::ChannelID chanID = lhcbID.utID(); - auto unbiasedResidual = node.unbiasedResidual(); - auto biasedResidual = node.residual(); + LHCb::LHCbID lhcbID = id( node ); + LHCb::Detector::UT::ChannelID chanID = lhcbID.utID(); + auto unbiasedResidual = node.unbiasedResidual(); + auto biasedResidual = node.residual(); - ++m_ut_unbiased[unbiasedResidual]; - ++m_sides_unbiased.at( chanID.side() )[unbiasedResidual]; - ++m_layers_unbiased.at( chanID.layer() )[unbiasedResidual]; - ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[unbiasedResidual]; - ++m_staves_unbiased.at( chanID.uniqueStave() )[unbiasedResidual]; - ++m_modules_unbiased.at( chanID.uniqueModule() )[unbiasedResidual]; + ++m_ut_unbiased[unbiasedResidual]; + ++m_sides_unbiased.at( chanID.side() )[unbiasedResidual]; + ++m_layers_unbiased.at( chanID.layer() )[unbiasedResidual]; + ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[unbiasedResidual]; + ++m_staves_unbiased.at( chanID.uniqueStave() )[unbiasedResidual]; + ++m_modules_unbiased.at( chanID.uniqueModule() )[unbiasedResidual]; - ++m_ut_biased[biasedResidual]; - ++m_sides_biased.at( chanID.side() )[biasedResidual]; - ++m_layers_biased.at( chanID.layer() )[biasedResidual]; - ++m_halflayers_biased.at( chanID.uniqueLayer() )[biasedResidual]; - ++m_staves_biased.at( chanID.uniqueStave() )[biasedResidual]; - ++m_modules_biased.at( chanID.uniqueModule() )[biasedResidual]; - } + ++m_ut_biased[biasedResidual]; + ++m_sides_biased.at( chanID.side() )[biasedResidual]; + ++m_layers_biased.at( chanID.layer() )[biasedResidual]; + ++m_halflayers_biased.at( chanID.uniqueLayer() )[biasedResidual]; + ++m_staves_biased.at( chanID.uniqueStave() )[biasedResidual]; + ++m_modules_biased.at( chanID.uniqueModule() )[biasedResidual]; + } + } ); } } -template -std::optional UTTrackResidualMonitor::getResidual( LHCb::Track const& track, - Detector::UT::ChannelID hitChanID, - IGeometryInfo const& geometry, - const DeUTDetector& deUT ) const { +std::optional UTTrackResidualMonitor::getResidual( LHCb::Track const& track, + LHCb::Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const { auto aSector = deUT.findSector( hitChanID ); #ifdef USE_DD4HEP if ( !aSector.isValid() ) { @@ -297,7 +286,7 @@ std::optional UTTrackResidualMonitor::getResidual( LHC #endif LHCb::StateVector aState; - extrapolator()->propagate( track, hitZ, aState, geometry ).ignore(); + m_extrapolator->propagate( track, hitZ, aState, geometry ).ignore(); #ifdef USE_DD4HEP if ( aSector.sensor().sensorType() == 'A' || aSector.sensor().sensorType() == 'B' ) #else -- GitLab From 6e2de66fac68f048cfb35819a700d65820f97617 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Thu, 17 Apr 2025 20:17:21 +0200 Subject: [PATCH 06/10] fix: apply more suggestions - move buildHistograms to initialize() - remove unnecessary mutable pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/54799066 --- .../src/UTTrackResidualMonitor.cpp | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 3b421b9e132..5a4c66db6ca 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -55,7 +55,8 @@ class UTTrackResidualMonitor public: UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); - void operator()( LHCb::Track::Range const&, const LHCb::Pr::UT::Hits&, DetectorElement const&, + StatusCode initialize() override; + void operator()( LHCb::Track::Range const&, const LHCb::Pr::UT::Hits&, DetectorElement const&, const DeUTDetector& ) const override; private: @@ -71,25 +72,25 @@ private: this, "xy", "x vs y (mm)", { { 500, -1000, 1000 }, { 500, -1000, 1000 } } }; mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{ this, "UT_Unbiased", "UT", { 200, -5., 5. } }; - mutable std::map m_sides_unbiased; - mutable std::map m_layers_unbiased; - mutable std::map m_halflayers_unbiased; - mutable std::map m_staves_unbiased; - mutable std::map m_modules_unbiased; + std::map m_sides_unbiased; + std::map m_layers_unbiased; + std::map m_halflayers_unbiased; + std::map m_staves_unbiased; + std::map m_modules_unbiased; mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{ this, "UT_Biased", "UT", { 200, -5., 5. } }; - mutable std::map m_sides_biased; - mutable std::map m_layers_biased; - mutable std::map m_halflayers_biased; - mutable std::map m_staves_biased; - mutable std::map m_modules_biased; + std::map m_sides_biased; + std::map m_layers_biased; + std::map m_halflayers_biased; + std::map m_staves_biased; + std::map m_modules_biased; ToolHandle m_extrapolator{ this, "Extrapolator", "TrackMasterExtrapolator" }; ///< Pointer to extrapolator Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, "Whether tracks contain UT hits (false) or not (true)." }; - void buildHistogramMaps( const DeUTDetector& deUT ) const; + void buildHistogramMaps( const DeUTDetector& deUT ); }; template @@ -101,7 +102,7 @@ void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std: DECLARE_COMPONENT_WITH_ID( UTTrackResidualMonitor, "UTTrackResidualMonitor" ) -void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) const { +void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; float xmin = m_trueUnbiased ? -10.f : -1.f; @@ -182,6 +183,16 @@ void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) cons } } +StatusCode UTTrackResidualMonitor::initialize() { + return Consumer::initialize().andThen( [&] { + addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { + buildHistogramMaps( det ); + return std::string(); + } ); + return StatusCode::SUCCESS; + } ); +} + UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer( name, pSvcLocator, { { "TracksInContainer", LHCb::TrackLocation::Default }, @@ -192,7 +203,6 @@ UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLoc void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, const LHCb::Pr::UT::Hits& utHits, const DetectorElement& lhcb, const DeUTDetector& deUT ) const { auto& geometry = *lhcb.geometry(); - buildHistogramMaps( deUT ); // histograms per track for ( const LHCb::Track* track : tracks ) { -- GitLab From bd5110e32a8d79bf687064a00ae3254f1ab1f686 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Sat, 19 Apr 2025 20:55:35 +0200 Subject: [PATCH 07/10] fix: apply more suggestions - removed using namespace lines - use try_emplace pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/54851769 --- .../src/UTTrackResidualMonitor.cpp | 440 +++++++++--------- 1 file changed, 218 insertions(+), 222 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 5a4c66db6ca..4490a61c857 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -22,293 +22,289 @@ #include "TrackInterfaces/ITrackExtrapolator.h" #include - -using LHCb::Track; -using std::optional; - -using simd = SIMDWrapper::scalar::types; - /** * Class for monitoring unbiased UT hits residual of long track * @author Hangyi Wu * @date 15-3-2024 */ -template -class Mutable { - mutable T m_t; +namespace LHCb::UT { + template + class Mutable { + mutable T m_t; -public: - template >> - Mutable( Args&&... args ) : m_t{ std::forward( args )... } {} + public: + template >> + Mutable( Args&&... args ) : m_t{ std::forward( args )... } {} - template - decltype( auto ) operator[]( Arg&& arg ) const { - return m_t[std::forward( arg )]; - } -}; + template + decltype( auto ) operator[]( Arg&& arg ) const { + return m_t[std::forward( arg )]; + } + }; -class UTTrackResidualMonitor - : public LHCb::Algorithm::Consumer> { + class UTTrackResidualMonitor + : public LHCb::Algorithm::Consumer> { -public: - UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); - StatusCode initialize() override; - void operator()( LHCb::Track::Range const&, const LHCb::Pr::UT::Hits&, DetectorElement const&, - const DeUTDetector& ) const override; + public: + UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ); + StatusCode initialize() override; + void operator()( LHCb::Track::Range const&, const LHCb::Pr::UT::Hits&, DetectorElement const&, + const DeUTDetector& ) const override; -private: - void fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, IGeometryInfo const& geometry, - const DeUTDetector& deUT ) const; - optional getResidual( Track const& track, LHCb::Detector::UT::ChannelID hitChanID, - IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; - using Histo1D = Mutable>; - using Histo2D = Mutable>; - using Axis = Gaudi::Accumulators::Axis; - using H2DArg = Gaudi::Accumulators::HistoInputType; - mutable Gaudi::Accumulators::Histogram<2> m_xy{ - this, "xy", "x vs y (mm)", { { 500, -1000, 1000 }, { 500, -1000, 1000 } } }; + private: + void fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const; + std::optional getResidual( Track const& track, LHCb::Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const; + using Histo1D = Mutable>; + using Histo2D = Mutable>; + using Axis = Gaudi::Accumulators::Axis; + using H2DArg = Gaudi::Accumulators::HistoInputType; + mutable Gaudi::Accumulators::Histogram<2> m_xy{ + this, "xy", "x vs y (mm)", { { 500, -1000, 1000 }, { 500, -1000, 1000 } } }; - mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{ this, "UT_Unbiased", "UT", { 200, -5., 5. } }; - std::map m_sides_unbiased; - std::map m_layers_unbiased; - std::map m_halflayers_unbiased; - std::map m_staves_unbiased; - std::map m_modules_unbiased; + mutable Gaudi::Accumulators::Histogram<1> m_ut_unbiased{ this, "UT_Unbiased", "UT", { 200, -5., 5. } }; + std::map m_sides_unbiased; + std::map m_layers_unbiased; + std::map m_halflayers_unbiased; + std::map m_staves_unbiased; + std::map m_modules_unbiased; - mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{ this, "UT_Biased", "UT", { 200, -5., 5. } }; - std::map m_sides_biased; - std::map m_layers_biased; - std::map m_halflayers_biased; - std::map m_staves_biased; - std::map m_modules_biased; + mutable Gaudi::Accumulators::Histogram<1> m_ut_biased{ this, "UT_Biased", "UT", { 200, -5., 5. } }; + std::map m_sides_biased; + std::map m_layers_biased; + std::map m_halflayers_biased; + std::map m_staves_biased; + std::map m_modules_biased; - ToolHandle m_extrapolator{ this, "Extrapolator", - "TrackMasterExtrapolator" }; ///< Pointer to extrapolator - Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; - Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, - "Whether tracks contain UT hits (false) or not (true)." }; - void buildHistogramMaps( const DeUTDetector& deUT ); -}; + ToolHandle m_extrapolator{ this, "Extrapolator", + "TrackMasterExtrapolator" }; ///< Pointer to extrapolator + Gaudi::Property m_refZ{ this, "ReferenceZ", 2485.0, "midpoint of UT" }; + Gaudi::Property m_trueUnbiased{ this, "TrueUnbiased", false, + "Whether tracks contain UT hits (false) or not (true)." }; + void buildHistogramMaps( const DeUTDetector& deUT ); + }; -template -void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std::string labels, A axis ) { - if ( !h.contains( k ) ) - h.emplace( std::piecewise_construct, std::forward_as_tuple( k ), - std::forward_as_tuple( owner, name, labels, axis ) ); -} + template + void buildHistogram( OWNER owner, std::map& h, K k, std::string name, std::string labels, A axis ) { + h.try_emplace( k, owner, name, labels, axis ); + } -DECLARE_COMPONENT_WITH_ID( UTTrackResidualMonitor, "UTTrackResidualMonitor" ) + DECLARE_COMPONENT_WITH_ID( UTTrackResidualMonitor, "UTTrackResidualMonitor" ) -void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { + void UTTrackResidualMonitor::buildHistogramMaps( const DeUTDetector& deUT ) { - const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; - float xmin = m_trueUnbiased ? -10.f : -1.f; - float xmax = -xmin; - unsigned int nbin = 400; + const char* title_unbiased = m_trueUnbiased ? "UnbiasedResidual_True" : "UnbiasedResidual"; + float xmin = m_trueUnbiased ? -10.f : -1.f; + float xmax = -xmin; + unsigned int nbin = 400; - // create histograms - std::string sideNames[2] = { "Cside", "Aside" }; - std::string layerNames[4] = { "UTaX", "UTaU", "UTbV", "UTbX" }; - for ( unsigned int i = 0; i < 4; i++ ) { - buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", Axis{ nbin, xmin, xmax } ); - } - for ( const auto& side : deUT.sides() ) { -#ifdef USE_DD4HEP - auto sideID = side.channelID().side(); -#else - auto sideID = side->channelID().side(); -#endif - buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + // create histograms + std::string sideNames[2] = { "Cside", "Aside" }; + std::string layerNames[4] = { "UTaX", "UTaU", "UTbV", "UTbX" }; + for ( unsigned int i = 0; i < 4; i++ ) { + buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, + Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", + Axis{ nbin, xmin, xmax } ); + } + for ( const auto& side : deUT.sides() ) { #ifdef USE_DD4HEP - for ( const auto& layer : side.layers() ) { - auto layerID = layer.channelID().layer(); - auto layerUniqueID = layer.channelID().uniqueLayer(); + auto sideID = side.channelID().side(); #else - for ( const auto& layer : side->layers() ) { - auto layerID = layer->channelID().layer(); - auto layerUniqueID = layer->channelID().uniqueLayer(); + auto sideID = side->channelID().side(); #endif - std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; - buildHistogram( this, m_halflayers_unbiased, layerUniqueID, layerPath + '/' + title_unbiased, title_unbiased, + buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", + buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", Axis{ nbin, xmin, xmax } ); #ifdef USE_DD4HEP - for ( const auto& stave : layer.staves() ) { - auto staveID = stave.channelID().stave(); - auto staveUniqueID = stave.channelID().uniqueStave(); + for ( const auto& layer : side.layers() ) { + auto layerID = layer.channelID().layer(); + auto layerUniqueID = layer.channelID().uniqueLayer(); #else - for ( const auto& stave : layer->staves() ) { - auto staveID = stave->channelID().stave(); - auto staveUniqueID = stave->channelID().uniqueStave(); + for ( const auto& layer : side->layers() ) { + auto layerID = layer->channelID().layer(); + auto layerUniqueID = layer->channelID().uniqueLayer(); #endif - std::string stavePath = - sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); - buildHistogram( this, m_staves_unbiased, staveUniqueID, stavePath + '/' + title_unbiased, title_unbiased, + std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; + buildHistogram( this, m_halflayers_unbiased, layerUniqueID, layerPath + '/' + title_unbiased, title_unbiased, Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", + buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", Axis{ nbin, xmin, xmax } ); #ifdef USE_DD4HEP - for ( const auto& face : stave.faces() ) { - auto faceID = face.channelID().face(); - for ( const auto& module : face.modules() ) { - auto moduleID = module.channelID().module(); - auto moduleUniqueID = module.channelID().uniqueModule(); + for ( const auto& stave : layer.staves() ) { + auto staveID = stave.channelID().stave(); + auto staveUniqueID = stave.channelID().uniqueStave(); +#else + for ( const auto& stave : layer->staves() ) { + auto staveID = stave->channelID().stave(); + auto staveUniqueID = stave->channelID().uniqueStave(); +#endif + std::string stavePath = + sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); + buildHistogram( this, m_staves_unbiased, staveUniqueID, stavePath + '/' + title_unbiased, title_unbiased, + Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", + Axis{ nbin, xmin, xmax } ); +#ifdef USE_DD4HEP + for ( const auto& face : stave.faces() ) { + auto faceID = face.channelID().face(); + for ( const auto& module : face.modules() ) { + auto moduleID = module.channelID().module(); + auto moduleUniqueID = module.channelID().uniqueModule(); #else - for ( const auto& face : stave->faces() ) { - auto faceID = face->channelID().face(); - for ( const auto& module : face->modules() ) { - auto moduleID = module->channelID().module(); - auto moduleUniqueID = module->channelID().uniqueModule(); + for ( const auto& face : stave->faces() ) { + auto faceID = face->channelID().face(); + for ( const auto& module : face->modules() ) { + auto moduleID = module->channelID().module(); + auto moduleUniqueID = module->channelID().uniqueModule(); #endif - std::string modulePath = sideNames[sideID] + "/" + layerNames[layerID] + "/Stave" + - std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + - std::to_string( moduleID ); - buildHistogram( this, m_modules_unbiased, moduleUniqueID, modulePath + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + std::string modulePath = sideNames[sideID] + "/" + layerNames[layerID] + "/Stave" + + std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + + std::to_string( moduleID ); + buildHistogram( this, m_modules_unbiased, moduleUniqueID, modulePath + '/' + title_unbiased, + title_unbiased, Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", + Axis{ nbin, xmin, xmax } ); + } } } } } } -} -StatusCode UTTrackResidualMonitor::initialize() { - return Consumer::initialize().andThen( [&] { - addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { - buildHistogramMaps( det ); - return std::string(); + StatusCode UTTrackResidualMonitor::initialize() { + return Consumer::initialize().andThen( [&] { + addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { + buildHistogramMaps( det ); + return std::string(); + } ); + return StatusCode::SUCCESS; } ); - return StatusCode::SUCCESS; - } ); -} + } -UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) - : Consumer( name, pSvcLocator, - { { "TracksInContainer", LHCb::TrackLocation::Default }, - { "UTHitsLocation", UTInfo::HitLocation }, - { "StandardGeometryTop", LHCb::standard_geometry_top }, - { "DeUT", DeUTDetLocation::location() } } ) {} + UTTrackResidualMonitor::UTTrackResidualMonitor( const std::string& name, ISvcLocator* pSvcLocator ) + : Consumer( name, pSvcLocator, + { { "TracksInContainer", LHCb::TrackLocation::Default }, + { "UTHitsLocation", UTInfo::HitLocation }, + { "StandardGeometryTop", LHCb::standard_geometry_top }, + { "DeUT", DeUTDetLocation::location() } } ) {} -void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, const LHCb::Pr::UT::Hits& utHits, - const DetectorElement& lhcb, const DeUTDetector& deUT ) const { - auto& geometry = *lhcb.geometry(); + void UTTrackResidualMonitor::operator()( LHCb::Track::Range const& tracks, const LHCb::Pr::UT::Hits& utHits, + const DetectorElement& lhcb, const DeUTDetector& deUT ) const { + auto& geometry = *lhcb.geometry(); - // histograms per track - for ( const LHCb::Track* track : tracks ) { - // find the IT hits on the track - fillHistograms( *track, utHits, geometry, deUT ); + // histograms per track + for ( const LHCb::Track* track : tracks ) { + // find the IT hits on the track + fillHistograms( *track, utHits, geometry, deUT ); + } } -} -void UTTrackResidualMonitor::fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, - IGeometryInfo const& geometry, const DeUTDetector& deUT ) const { - if ( m_trueUnbiased ) { - // track parameters at some reference z - LHCb::StateVector aState; - m_extrapolator->propagate( track, m_refZ, aState, geometry ).ignore(); - ++m_xy[{ aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm }]; + void UTTrackResidualMonitor::fillHistograms( LHCb::Track const& track, const LHCb::Pr::UT::Hits& utHits, + IGeometryInfo const& geometry, const DeUTDetector& deUT ) const { + if ( m_trueUnbiased ) { + // track parameters at some reference z + LHCb::StateVector aState; + m_extrapolator->propagate( track, m_refZ, aState, geometry ).ignore(); + ++m_xy[{ aState.x() / Gaudi::Units::mm, aState.y() / Gaudi::Units::mm }]; - const auto hits = utHits.scalar(); - for ( auto const hit : hits ) { - const simd::int_v simd_chanid = hit.template get(); - auto const chanID = LHCb::Detector::UT::ChannelID( simd_chanid.cast() ); - auto residualX = getResidual( track, chanID, geometry, deUT ); - if ( residualX ) { - ++m_ut_unbiased[*residualX]; - ++m_sides_unbiased.at( chanID.side() )[*residualX]; - ++m_layers_unbiased.at( chanID.layer() )[*residualX]; - ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[*residualX]; - ++m_staves_unbiased.at( chanID.uniqueStave() )[*residualX]; - ++m_modules_unbiased.at( chanID.uniqueModule() )[*residualX]; + const auto hits = utHits.scalar(); + for ( auto const hit : hits ) { + const auto simd_chanid = hit.template get(); + auto const chanID = LHCb::Detector::UT::ChannelID( simd_chanid.cast() ); + auto residualX = getResidual( track, chanID, geometry, deUT ); + if ( residualX ) { + ++m_ut_unbiased[*residualX]; + ++m_sides_unbiased.at( chanID.side() )[*residualX]; + ++m_layers_unbiased.at( chanID.layer() )[*residualX]; + ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[*residualX]; + ++m_staves_unbiased.at( chanID.uniqueStave() )[*residualX]; + ++m_modules_unbiased.at( chanID.uniqueModule() )[*residualX]; + } } - } - } else { - dispatch( *track.fitResult(), [&]( const auto& fr ) { - for ( const auto& node : nodes( fr ) ) { - if ( !( node.hasMeasurement() && node.isHitOnTrack() && node.isUT() ) ) continue; - if ( node.isOutlier() ) continue; - if ( node.errResidual() == 0.0 ) continue; + } else { + dispatch( *track.fitResult(), [&]( const auto& fr ) { + for ( const auto& node : nodes( fr ) ) { + if ( !( node.hasMeasurement() && node.isHitOnTrack() && node.isUT() ) ) continue; + if ( node.isOutlier() ) continue; + if ( node.errResidual() == 0.0 ) continue; - LHCb::LHCbID lhcbID = id( node ); - LHCb::Detector::UT::ChannelID chanID = lhcbID.utID(); - auto unbiasedResidual = node.unbiasedResidual(); - auto biasedResidual = node.residual(); + LHCb::LHCbID lhcbID = id( node ); + LHCb::Detector::UT::ChannelID chanID = lhcbID.utID(); + auto unbiasedResidual = node.unbiasedResidual(); + auto biasedResidual = node.residual(); - ++m_ut_unbiased[unbiasedResidual]; - ++m_sides_unbiased.at( chanID.side() )[unbiasedResidual]; - ++m_layers_unbiased.at( chanID.layer() )[unbiasedResidual]; - ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[unbiasedResidual]; - ++m_staves_unbiased.at( chanID.uniqueStave() )[unbiasedResidual]; - ++m_modules_unbiased.at( chanID.uniqueModule() )[unbiasedResidual]; + ++m_ut_unbiased[unbiasedResidual]; + ++m_sides_unbiased.at( chanID.side() )[unbiasedResidual]; + ++m_layers_unbiased.at( chanID.layer() )[unbiasedResidual]; + ++m_halflayers_unbiased.at( chanID.uniqueLayer() )[unbiasedResidual]; + ++m_staves_unbiased.at( chanID.uniqueStave() )[unbiasedResidual]; + ++m_modules_unbiased.at( chanID.uniqueModule() )[unbiasedResidual]; - ++m_ut_biased[biasedResidual]; - ++m_sides_biased.at( chanID.side() )[biasedResidual]; - ++m_layers_biased.at( chanID.layer() )[biasedResidual]; - ++m_halflayers_biased.at( chanID.uniqueLayer() )[biasedResidual]; - ++m_staves_biased.at( chanID.uniqueStave() )[biasedResidual]; - ++m_modules_biased.at( chanID.uniqueModule() )[biasedResidual]; - } - } ); + ++m_ut_biased[biasedResidual]; + ++m_sides_biased.at( chanID.side() )[biasedResidual]; + ++m_layers_biased.at( chanID.layer() )[biasedResidual]; + ++m_halflayers_biased.at( chanID.uniqueLayer() )[biasedResidual]; + ++m_staves_biased.at( chanID.uniqueStave() )[biasedResidual]; + ++m_modules_biased.at( chanID.uniqueModule() )[biasedResidual]; + } + } ); + } } -} -std::optional UTTrackResidualMonitor::getResidual( LHCb::Track const& track, - LHCb::Detector::UT::ChannelID hitChanID, - IGeometryInfo const& geometry, - const DeUTDetector& deUT ) const { - auto aSector = deUT.findSector( hitChanID ); + std::optional UTTrackResidualMonitor::getResidual( LHCb::Track const& track, + LHCb::Detector::UT::ChannelID hitChanID, + IGeometryInfo const& geometry, + const DeUTDetector& deUT ) const { + auto aSector = deUT.findSector( hitChanID ); #ifdef USE_DD4HEP - if ( !aSector.isValid() ) { + if ( !aSector.isValid() ) { #else - if ( !aSector ) { + if ( !aSector ) { #endif - warning() << "Sector not found with" << hitChanID << endmsg; - return std::nullopt; - } + warning() << "Sector not found with" << hitChanID << endmsg; + return std::nullopt; + } #ifdef USE_DD4HEP - auto aStrip = aSector.createTraj( hitChanID.strip(), 0 ); + auto aStrip = aSector.createTraj( hitChanID.strip(), 0 ); #else - auto aStrip = aSector->trajectory( hitChanID, 0 ); + auto aStrip = aSector->trajectory( hitChanID, 0 ); #endif - ROOT::Math::XYZPoint g1 = aStrip.beginPoint(); - ROOT::Math::XYZPoint g2 = aStrip.endPoint(); - ROOT::Math::XYZPoint hitPos = g1 + ( g2 - g1 ) * 0.5; - auto hitX = hitPos.X(); - auto hitY = hitPos.Y(); - auto hitZ = hitPos.Z(); + ROOT::Math::XYZPoint g1 = aStrip.beginPoint(); + ROOT::Math::XYZPoint g2 = aStrip.endPoint(); + ROOT::Math::XYZPoint hitPos = g1 + ( g2 - g1 ) * 0.5; + auto hitX = hitPos.X(); + auto hitY = hitPos.Y(); + auto hitZ = hitPos.Z(); - // obtain dxdy - double dxdy, dummy; + // obtain dxdy + double dxdy, dummy; #ifdef USE_DD4HEP - aSector.trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); + aSector.trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); #else - aSector->trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); + aSector->trajectory( hitChanID.strip(), 0, dxdy, dummy, dummy, dummy, dummy, dummy ); #endif - LHCb::StateVector aState; - m_extrapolator->propagate( track, hitZ, aState, geometry ).ignore(); + LHCb::StateVector aState; + m_extrapolator->propagate( track, hitZ, aState, geometry ).ignore(); #ifdef USE_DD4HEP - if ( aSector.sensor().sensorType() == 'A' || aSector.sensor().sensorType() == 'B' ) + if ( aSector.sensor().sensorType() == 'A' || aSector.sensor().sensorType() == 'B' ) #else - if ( aSector->sensor( 0 ).sensorType() == 'A' || aSector->sensor( 0 ).sensorType() == 'B' ) + if ( aSector->sensor( 0 ).sensorType() == 'A' || aSector->sensor( 0 ).sensorType() == 'B' ) #endif - if ( std::abs( hitY - aState.y() ) > 60.0 ) return std::nullopt; + if ( std::abs( hitY - aState.y() ) > 60.0 ) return std::nullopt; #ifdef USE_DD4HEP - if ( aSector.sensor().sensorType() == 'C' || aSector.sensor().sensorType() == 'D' ) + if ( aSector.sensor().sensorType() == 'C' || aSector.sensor().sensorType() == 'D' ) #else - if ( aSector->sensor( 0 ).sensorType() == 'C' || aSector->sensor( 0 ).sensorType() == 'D' ) + if ( aSector->sensor( 0 ).sensorType() == 'C' || aSector->sensor( 0 ).sensorType() == 'D' ) #endif - if ( std::abs( hitY - aState.y() ) > 30.0 ) return std::nullopt; + if ( std::abs( hitY - aState.y() ) > 30.0 ) return std::nullopt; + + return hitX - ( aState.x() + ( hitY - aState.y() ) * dxdy ); + } - return hitX - ( aState.x() + ( hitY - aState.y() ) * dxdy ); -} +} // namespace LHCb::UT -- GitLab From c8edd0fe7a09f332ff216f13b72d5a7b4d6c5f8b Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Mon, 2 Jun 2025 15:16:12 +0200 Subject: [PATCH 08/10] fix: apply more suggestions pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/56910338 --- .../src/UTTrackResidualMonitor.cpp | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index 4490a61c857..da311846ff0 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -101,15 +101,14 @@ namespace LHCb::UT { float xmin = m_trueUnbiased ? -10.f : -1.f; float xmax = -xmin; unsigned int nbin = 400; + const Axis axis{ nbin, xmin, xmax }; // create histograms std::string sideNames[2] = { "Cside", "Aside" }; std::string layerNames[4] = { "UTaX", "UTaU", "UTbV", "UTbX" }; for ( unsigned int i = 0; i < 4; i++ ) { - buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_layers_unbiased, i, layerNames[i] + '/' + title_unbiased, title_unbiased, axis ); + buildHistogram( this, m_layers_biased, i, layerNames[i] + '/' + "Residual", "Residual", axis ); } for ( const auto& side : deUT.sides() ) { #ifdef USE_DD4HEP @@ -117,10 +116,8 @@ namespace LHCb::UT { #else auto sideID = side->channelID().side(); #endif - buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + buildHistogram( this, m_sides_unbiased, sideID, sideNames[sideID] + '/' + title_unbiased, title_unbiased, axis ); + buildHistogram( this, m_sides_biased, sideID, sideNames[sideID] + '/' + "Residual", "Residual", axis ); #ifdef USE_DD4HEP for ( const auto& layer : side.layers() ) { auto layerID = layer.channelID().layer(); @@ -132,9 +129,8 @@ namespace LHCb::UT { #endif std::string layerPath = sideNames[sideID] + "/" + layerNames[layerID]; buildHistogram( this, m_halflayers_unbiased, layerUniqueID, layerPath + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + axis ); + buildHistogram( this, m_halflayers_biased, layerUniqueID, layerPath + '/' + "Residual", "Residual", axis ); #ifdef USE_DD4HEP for ( const auto& stave : layer.staves() ) { auto staveID = stave.channelID().stave(); @@ -147,9 +143,8 @@ namespace LHCb::UT { std::string stavePath = sideNames[sideID] + "/" + layerNames[layerID] + "/" + "Stave" + std::to_string( staveID ); buildHistogram( this, m_staves_unbiased, staveUniqueID, stavePath + '/' + title_unbiased, title_unbiased, - Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + axis ); + buildHistogram( this, m_staves_biased, staveUniqueID, stavePath + '/' + "Residual", "Residual", axis ); #ifdef USE_DD4HEP for ( const auto& face : stave.faces() ) { auto faceID = face.channelID().face(); @@ -167,9 +162,8 @@ namespace LHCb::UT { std::to_string( staveID ) + "/Face" + std::to_string( faceID ) + "/Module" + std::to_string( moduleID ); buildHistogram( this, m_modules_unbiased, moduleUniqueID, modulePath + '/' + title_unbiased, - title_unbiased, Axis{ nbin, xmin, xmax } ); - buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", - Axis{ nbin, xmin, xmax } ); + title_unbiased, axis ); + buildHistogram( this, m_modules_biased, moduleUniqueID, modulePath + '/' + "Residual", "Residual", axis ); } } } -- GitLab From 7475ed5672d2d7594f4d864bb649decf2a210abb Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Thu, 19 Jun 2025 00:00:28 +0200 Subject: [PATCH 09/10] fix!: arm no longer crashes --- Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index da311846ff0..e322b03dfd1 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -173,9 +173,9 @@ namespace LHCb::UT { StatusCode UTTrackResidualMonitor::initialize() { return Consumer::initialize().andThen( [&] { - addConditionDerivation( { inputLocation() }, std::string{}, [&]( DeUTDetector const& det ) { - buildHistogramMaps( det ); - return std::string(); + addConditionDerivation( { DeUTDetLocation::location() }, std::string{}, [this]( DeUTDetector const& det ) { + this->buildHistogramMaps( det ); + return det; } ); return StatusCode::SUCCESS; } ); -- GitLab From 063d3841e471dec5b9200bfffea5292595a430c2 Mon Sep 17 00:00:00 2001 From: Hangyi Wu Date: Tue, 24 Jun 2025 02:54:54 +0200 Subject: [PATCH 10/10] fix!: build errors in detdesc platform pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/57821083 --- Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp index e322b03dfd1..5d151bf6fa7 100644 --- a/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp +++ b/Tr/TrackMonitors/src/UTTrackResidualMonitor.cpp @@ -175,7 +175,7 @@ namespace LHCb::UT { return Consumer::initialize().andThen( [&] { addConditionDerivation( { DeUTDetLocation::location() }, std::string{}, [this]( DeUTDetector const& det ) { this->buildHistogramMaps( det ); - return det; + return ""; } ); return StatusCode::SUCCESS; } ); -- GitLab