From faf8478eed732f9264da1c4bdd4b509063598f24 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 09:22:24 +0100 Subject: [PATCH 01/23] Add algorithm for converting tracks --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 9100d887e91..ba0bb34173b 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -16,6 +16,7 @@ // LHCb #include "Event/Track.h" #include "Event/Track_v3.h" +#include "Event/PrVeloTracks.h" #include "Event/TrackEnums.h" #include "Event/UniqueIDGenerator.h" #include "Event/StateParameters.h" @@ -810,6 +811,80 @@ namespace GaudiAllen::Converters::v3 { } }; + /** + * + * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. + */ + using PrVeloTracks = LHCb::Pr::Velo::Tracks; + using AllenConsolidatedTrack = Allen::Views::Velo::Consolidated::Track; + using AllenConsolidatedTracks = Allen::Views::Velo::Consolidated::Tracks; + using AllenConsolidatedTracksMEC = Allen::Views::Velo::Consolidated::MultiEventTracks; + using AllenStates = Allen::Views::Physics::KalmanStates; + using AllenConsolidatedHit = Allen::Views::Velo::Consolidated::Hit; + using AllenConsolidatedHits = Allen::Views::Velo::Consolidated::Hits; + using AllenConsolidatedStates = Allen::Views::Velo::Consolidated::States; + using VeloConsolidatedStates = Velo::Consolidated::States; + + using AllenOutType = std::tuple; + + class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< + AllenOutType( + PrVeloTracks const&, PrVeloTracks const&)> { + public: + /// Standard constructor + PrVeloToGaudiAllenVeloTracks(const std::string& name, ISvcLocator* pSvcLocator) : + MultiTransformer(name, pSvcLocator, + {KeyValue {"PrVeloTracksForward", ""}, KeyValue{"PrVeloTracksBackward", ""}}, + {KeyValue{"AllenVeloTracksMEC", ""}, KeyValue{"AllenVeloTracksView", ""}, KeyValue{"AllenBeamlineStatesView", ""}, KeyValue{"NumberOfReconstructedVeloTracks", ""}}) + {} + + /// Algorithm execution + AllenOutType operator()( + PrVeloTracks const& pr_tracks_forward, + PrVeloTracks const& pr_tracks_backward) const override + { + const unsigned n_events = 1; // only one event is processed at a time + const unsigned n_tracks = pr_tracks_forward.size()+pr_tracks_backward.size(); // total number of tracks + + + const unsigned* offset_tracks = new unsigned[n_events+1] {0, n_tracks}; // offset for the tracks in the output container + const unsigned* offset_hits = new unsigned[n_events] {0}; // offset for the hits in the output container + + AllenConsolidatedTrack* ptr_tracks = new AllenConsolidatedTrack[n_tracks]; // Create the memory for the tracks + VeloConsolidatedStates kalman_beamline_states(nullptr, n_tracks); // Create the memory for the beamline states + + unsigned i_track = 0; // track index + // Loop over the tracks + for ( const auto& tracks : {&pr_tracks_forward, &pr_tracks_backward} ) { + // Get scalar view of the tracks + for ( auto const& track : tracks->scalar() ) { + // Get the state parameters + auto loc = LHCb::Event::Enum::State::Location::ClosestToBeam; + auto pos = track.StatePos( loc ); + auto dir = track.StateDir( loc ); + auto covX = track.StateCovX( loc ); + auto covY = track.StateCovY( loc ); + + KalmanVeloState kalman_beamline_state(pos.x().cast(), pos.y().cast(), pos.z().cast(), dir.x().cast(), dir.y().cast(), covX.x().cast(), covX.y().cast(), covX.z().cast(), covY.x().cast(), covY.y().cast(), covY.z().cast()); + kalman_beamline_states.set(i_track, kalman_beamline_state); + + AllenConsolidatedHits* hits = new AllenConsolidatedHits{nullptr, offset_tracks, offset_hits, n_events-1, n_events}; // Create a new Allen hit container + ptr_tracks[i_track] = AllenConsolidatedTrack(hits, offset_tracks, offset_hits, i_track, n_events-1); // Create a new Allen track + } + i_track++; + } + + // Create the output container + AllenStates allen_states_view{reinterpret_cast(kalman_beamline_states), offset_tracks, n_events-1}; + AllenConsolidatedTracks allen_tracks_view{ptr_tracks, offset_tracks, n_events-1}; + AllenConsolidatedTracks* ptr_allen_tracks_view = new AllenConsolidatedTracks[n_events]; + ptr_allen_tracks_view[n_events-1] = allen_tracks_view; + AllenConsolidatedTracksMEC allen_tracks_mec{ptr_allen_tracks_view, n_events}; + + assert(allen_tracks_view.size() == n_tracks/SIMDWrapper::type_map_t::size); // check that all tracks have been added + return std::tuple{allen_tracks_mec, allen_tracks_view, allen_states_view, allen_tracks_view.size()}; + } + }; using GaudiAllenMEBasicParticlesToV3Tracks = GaudiAllenTrackViewsToV3Tracks; DECLARE_COMPONENT_WITH_ID(GaudiAllenMEBasicParticlesToV3Tracks, "GaudiAllenMEBasicParticlesToV3Tracks") @@ -823,4 +898,6 @@ namespace GaudiAllen::Converters::v3 { beamline_states, endvelo_states>; DECLARE_COMPONENT_WITH_ID(GaudiAllenUTToV3Tracks, "GaudiAllenUTToV3Tracks") + DECLARE_COMPONENT_WITH_ID(PrVeloToGaudiAllenVeloTracks, "PrVeloToGaudiAllenVeloTracks") + } // namespace GaudiAllen::Converters::v3 -- GitLab From 02946f0294cc60722b4a59c06f9fd10265d0643b Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 10:04:24 +0100 Subject: [PATCH 02/23] Fix converter to Kalman State --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index ba0bb34173b..1cc7325a96d 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -815,17 +815,7 @@ namespace GaudiAllen::Converters::v3 { * * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. */ - using PrVeloTracks = LHCb::Pr::Velo::Tracks; - using AllenConsolidatedTrack = Allen::Views::Velo::Consolidated::Track; - using AllenConsolidatedTracks = Allen::Views::Velo::Consolidated::Tracks; - using AllenConsolidatedTracksMEC = Allen::Views::Velo::Consolidated::MultiEventTracks; - using AllenStates = Allen::Views::Physics::KalmanStates; - using AllenConsolidatedHit = Allen::Views::Velo::Consolidated::Hit; - using AllenConsolidatedHits = Allen::Views::Velo::Consolidated::Hits; - using AllenConsolidatedStates = Allen::Views::Velo::Consolidated::States; - using VeloConsolidatedStates = Velo::Consolidated::States; - - using AllenOutType = std::tuple; + using AllenOutType = std::tuple; class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< AllenOutType( @@ -840,8 +830,8 @@ namespace GaudiAllen::Converters::v3 { /// Algorithm execution AllenOutType operator()( - PrVeloTracks const& pr_tracks_forward, - PrVeloTracks const& pr_tracks_backward) const override + LHCb::Pr::Velo::Tracks const& pr_tracks_forward, + LHCb::Pr::Velo::Tracks const& pr_tracks_backward) const override { const unsigned n_events = 1; // only one event is processed at a time const unsigned n_tracks = pr_tracks_forward.size()+pr_tracks_backward.size(); // total number of tracks @@ -850,13 +840,14 @@ namespace GaudiAllen::Converters::v3 { const unsigned* offset_tracks = new unsigned[n_events+1] {0, n_tracks}; // offset for the tracks in the output container const unsigned* offset_hits = new unsigned[n_events] {0}; // offset for the hits in the output container - AllenConsolidatedTrack* ptr_tracks = new AllenConsolidatedTrack[n_tracks]; // Create the memory for the tracks - VeloConsolidatedStates kalman_beamline_states(nullptr, n_tracks); // Create the memory for the beamline states + Allen::Views::Velo::Consolidated::Track* ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks + char* ptr_states = nullptr; + Velo::Consolidated::States kalman_beamline_states(ptr_states, n_tracks); // Create the memory for the beamline states unsigned i_track = 0; // track index // Loop over the tracks for ( const auto& tracks : {&pr_tracks_forward, &pr_tracks_backward} ) { - // Get scalar view of the tracks + // Get scalar view of the tracks, to cast to the correct type for ( auto const& track : tracks->scalar() ) { // Get the state parameters auto loc = LHCb::Event::Enum::State::Location::ClosestToBeam; @@ -867,21 +858,25 @@ namespace GaudiAllen::Converters::v3 { KalmanVeloState kalman_beamline_state(pos.x().cast(), pos.y().cast(), pos.z().cast(), dir.x().cast(), dir.y().cast(), covX.x().cast(), covX.y().cast(), covX.z().cast(), covY.x().cast(), covY.y().cast(), covY.z().cast()); kalman_beamline_states.set(i_track, kalman_beamline_state); - - AllenConsolidatedHits* hits = new AllenConsolidatedHits{nullptr, offset_tracks, offset_hits, n_events-1, n_events}; // Create a new Allen hit container - ptr_tracks[i_track] = AllenConsolidatedTrack(hits, offset_tracks, offset_hits, i_track, n_events-1); // Create a new Allen track + + char* velo_trac_hits = nullptr; + //TBC: offset hits + //Velo::Consolidated::Hits hits(velo_trac_hits, offset_hits, offset_hits, n_events-1, n_events); // Create a new Velo hit container + //Loop over the hits from Pr::Velo::Track + Allen::Views::Velo::Consolidated::Hits* hits = new Allen::Views::Velo::Consolidated::Hits{velo_trac_hits, offset_tracks, offset_hits, n_events-1, n_events}; // Create a new Allen hit container + ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track(hits, offset_tracks, offset_hits, i_track, n_events-1); // Create a new Allen track + + i_track++; } - i_track++; } // Create the output container - AllenStates allen_states_view{reinterpret_cast(kalman_beamline_states), offset_tracks, n_events-1}; - AllenConsolidatedTracks allen_tracks_view{ptr_tracks, offset_tracks, n_events-1}; - AllenConsolidatedTracks* ptr_allen_tracks_view = new AllenConsolidatedTracks[n_events]; + Allen::Views::Physics::KalmanStates allen_states_view{ptr_states, offset_tracks, n_events-1, n_events}; + Allen::Views::Velo::Consolidated::Tracks allen_tracks_view{ptr_tracks, offset_tracks, n_events-1}; + Allen::Views::Velo::Consolidated::Tracks* ptr_allen_tracks_view = new Allen::Views::Velo::Consolidated::Tracks[n_events]; ptr_allen_tracks_view[n_events-1] = allen_tracks_view; - AllenConsolidatedTracksMEC allen_tracks_mec{ptr_allen_tracks_view, n_events}; + Allen::Views::Velo::Consolidated::MultiEventTracks allen_tracks_mec{ptr_allen_tracks_view, n_events}; - assert(allen_tracks_view.size() == n_tracks/SIMDWrapper::type_map_t::size); // check that all tracks have been added return std::tuple{allen_tracks_mec, allen_tracks_view, allen_states_view, allen_tracks_view.size()}; } }; -- GitLab From 9a41fa728b4d526c58236554f4ea62764d5024c0 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 10:15:37 +0100 Subject: [PATCH 03/23] Remove unused part from make_pvs --- .../python/AllenConf/primary_vertex_reconstruction.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/configuration/python/AllenConf/primary_vertex_reconstruction.py b/configuration/python/AllenConf/primary_vertex_reconstruction.py index e6f21861d2b..e703b98ee17 100644 --- a/configuration/python/AllenConf/primary_vertex_reconstruction.py +++ b/configuration/python/AllenConf/primary_vertex_reconstruction.py @@ -42,14 +42,9 @@ def make_pvs(velo_tracks, number_of_events = initialize_number_of_events() host_number_of_events = number_of_events["host_number_of_events"] - dev_number_of_events = number_of_events["dev_number_of_events"] host_number_of_reconstructed_velo_tracks = velo_tracks[ "host_number_of_reconstructed_velo_tracks"] - dev_offsets_all_velo_tracks = velo_tracks["dev_offsets_all_velo_tracks"] - dev_offsets_velo_track_hit_number = velo_tracks[ - "dev_offsets_velo_track_hit_number"] - dev_velo_track_hits = velo_tracks["dev_velo_track_hits"] velo_states = run_velo_kalman_filter(velo_tracks, pv_name) -- GitLab From 68d78995e7876b7d7c86893fe920ada8f909680a Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 17 Jan 2025 09:47:36 +0000 Subject: [PATCH 04/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/49460860 --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 98 ++++++++++++------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 1cc7325a96d..c8ea39e0afd 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -812,20 +812,28 @@ namespace GaudiAllen::Converters::v3 { }; /** - * + * * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. */ - using AllenOutType = std::tuple; - - class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< - AllenOutType( - PrVeloTracks const&, PrVeloTracks const&)> { + using AllenOutType = std::tuple< + Allen::Views::Velo::Consolidated::MultiEventTracks, + Allen::Views::Velo::Consolidated::Tracks, + Allen::Views::Physics::KalmanStates, + unsigned int>; + + class PrVeloToGaudiAllenVeloTracks final + : public Gaudi::Functional::MultiTransformer { public: /// Standard constructor PrVeloToGaudiAllenVeloTracks(const std::string& name, ISvcLocator* pSvcLocator) : - MultiTransformer(name, pSvcLocator, - {KeyValue {"PrVeloTracksForward", ""}, KeyValue{"PrVeloTracksBackward", ""}}, - {KeyValue{"AllenVeloTracksMEC", ""}, KeyValue{"AllenVeloTracksView", ""}, KeyValue{"AllenBeamlineStatesView", ""}, KeyValue{"NumberOfReconstructedVeloTracks", ""}}) + MultiTransformer( + name, + pSvcLocator, + {KeyValue {"PrVeloTracksForward", ""}, KeyValue {"PrVeloTracksBackward", ""}}, + {KeyValue {"AllenVeloTracksMEC", ""}, + KeyValue {"AllenVeloTracksView", ""}, + KeyValue {"AllenBeamlineStatesView", ""}, + KeyValue {"NumberOfReconstructedVeloTracks", ""}}) {} /// Algorithm execution @@ -834,50 +842,66 @@ namespace GaudiAllen::Converters::v3 { LHCb::Pr::Velo::Tracks const& pr_tracks_backward) const override { const unsigned n_events = 1; // only one event is processed at a time - const unsigned n_tracks = pr_tracks_forward.size()+pr_tracks_backward.size(); // total number of tracks + const unsigned n_tracks = pr_tracks_forward.size() + pr_tracks_backward.size(); // total number of tracks - - const unsigned* offset_tracks = new unsigned[n_events+1] {0, n_tracks}; // offset for the tracks in the output container + const unsigned* offset_tracks = + new unsigned[n_events + 1] {0, n_tracks}; // offset for the tracks in the output container const unsigned* offset_hits = new unsigned[n_events] {0}; // offset for the hits in the output container - Allen::Views::Velo::Consolidated::Track* ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks + Allen::Views::Velo::Consolidated::Track* ptr_tracks = + new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks char* ptr_states = nullptr; - Velo::Consolidated::States kalman_beamline_states(ptr_states, n_tracks); // Create the memory for the beamline states + Velo::Consolidated::States kalman_beamline_states( + ptr_states, n_tracks); // Create the memory for the beamline states unsigned i_track = 0; // track index // Loop over the tracks - for ( const auto& tracks : {&pr_tracks_forward, &pr_tracks_backward} ) { + for (const auto& tracks : {&pr_tracks_forward, &pr_tracks_backward}) { // Get scalar view of the tracks, to cast to the correct type - for ( auto const& track : tracks->scalar() ) { + for (auto const& track : tracks->scalar()) { // Get the state parameters auto loc = LHCb::Event::Enum::State::Location::ClosestToBeam; - auto pos = track.StatePos( loc ); - auto dir = track.StateDir( loc ); - auto covX = track.StateCovX( loc ); - auto covY = track.StateCovY( loc ); - - KalmanVeloState kalman_beamline_state(pos.x().cast(), pos.y().cast(), pos.z().cast(), dir.x().cast(), dir.y().cast(), covX.x().cast(), covX.y().cast(), covX.z().cast(), covY.x().cast(), covY.y().cast(), covY.z().cast()); - kalman_beamline_states.set(i_track, kalman_beamline_state); - + auto pos = track.StatePos(loc); + auto dir = track.StateDir(loc); + auto covX = track.StateCovX(loc); + auto covY = track.StateCovY(loc); + + KalmanVeloState kalman_beamline_state( + pos.x().cast(), + pos.y().cast(), + pos.z().cast(), + dir.x().cast(), + dir.y().cast(), + covX.x().cast(), + covX.y().cast(), + covX.z().cast(), + covY.x().cast(), + covY.y().cast(), + covY.z().cast()); + kalman_beamline_states.set(i_track, kalman_beamline_state); + char* velo_trac_hits = nullptr; - //TBC: offset hits - //Velo::Consolidated::Hits hits(velo_trac_hits, offset_hits, offset_hits, n_events-1, n_events); // Create a new Velo hit container - //Loop over the hits from Pr::Velo::Track - Allen::Views::Velo::Consolidated::Hits* hits = new Allen::Views::Velo::Consolidated::Hits{velo_trac_hits, offset_tracks, offset_hits, n_events-1, n_events}; // Create a new Allen hit container - ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track(hits, offset_tracks, offset_hits, i_track, n_events-1); // Create a new Allen track - + // TBC: offset hits + // Velo::Consolidated::Hits hits(velo_trac_hits, offset_hits, offset_hits, n_events-1, n_events); // Create a + // new Velo hit container Loop over the hits from Pr::Velo::Track + Allen::Views::Velo::Consolidated::Hits* hits = new Allen::Views::Velo::Consolidated::Hits { + velo_trac_hits, offset_tracks, offset_hits, n_events - 1, n_events}; // Create a new Allen hit container + ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track( + hits, offset_tracks, offset_hits, i_track, n_events - 1); // Create a new Allen track + i_track++; } } // Create the output container - Allen::Views::Physics::KalmanStates allen_states_view{ptr_states, offset_tracks, n_events-1, n_events}; - Allen::Views::Velo::Consolidated::Tracks allen_tracks_view{ptr_tracks, offset_tracks, n_events-1}; - Allen::Views::Velo::Consolidated::Tracks* ptr_allen_tracks_view = new Allen::Views::Velo::Consolidated::Tracks[n_events]; - ptr_allen_tracks_view[n_events-1] = allen_tracks_view; - Allen::Views::Velo::Consolidated::MultiEventTracks allen_tracks_mec{ptr_allen_tracks_view, n_events}; - - return std::tuple{allen_tracks_mec, allen_tracks_view, allen_states_view, allen_tracks_view.size()}; + Allen::Views::Physics::KalmanStates allen_states_view {ptr_states, offset_tracks, n_events - 1, n_events}; + Allen::Views::Velo::Consolidated::Tracks allen_tracks_view {ptr_tracks, offset_tracks, n_events - 1}; + Allen::Views::Velo::Consolidated::Tracks* ptr_allen_tracks_view = + new Allen::Views::Velo::Consolidated::Tracks[n_events]; + ptr_allen_tracks_view[n_events - 1] = allen_tracks_view; + Allen::Views::Velo::Consolidated::MultiEventTracks allen_tracks_mec {ptr_allen_tracks_view, n_events}; + + return std::tuple {allen_tracks_mec, allen_tracks_view, allen_states_view, allen_tracks_view.size()}; } }; using GaudiAllenMEBasicParticlesToV3Tracks = -- GitLab From e60004d1f9f28dc7f382b73ce8c27f3662ed62dd Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 13:43:13 +0100 Subject: [PATCH 05/23] Fix expliciting types for input particles --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index c8ea39e0afd..7b956550c42 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -822,7 +822,7 @@ namespace GaudiAllen::Converters::v3 { unsigned int>; class PrVeloToGaudiAllenVeloTracks final - : public Gaudi::Functional::MultiTransformer { + : public Gaudi::Functional::MultiTransformer { public: /// Standard constructor PrVeloToGaudiAllenVeloTracks(const std::string& name, ISvcLocator* pSvcLocator) : -- GitLab From 597e1139f48fea283bc48e08f8b7f96cf6fe74ce Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 17 Jan 2025 12:43:50 +0000 Subject: [PATCH 06/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/49471575 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 7b956550c42..1feefc091e1 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -822,7 +822,8 @@ namespace GaudiAllen::Converters::v3 { unsigned int>; class PrVeloToGaudiAllenVeloTracks final - : public Gaudi::Functional::MultiTransformer { + : public Gaudi::Functional::MultiTransformer< + AllenOutType(LHCb::Pr::Velo::Tracks const&, LHCb::Pr::Velo::Tracks const&)> { public: /// Standard constructor PrVeloToGaudiAllenVeloTracks(const std::string& name, ISvcLocator* pSvcLocator) : -- GitLab From 37097dc82467c64514f38b78a6879ab64b845b22 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 17:26:15 +0100 Subject: [PATCH 07/23] Add KalmanStates to the primary_vertex reconstruction for converted tracks --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 6 ++++-- .../python/AllenConf/primary_vertex_reconstruction.py | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 1feefc091e1..afac2d9ced7 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -881,12 +881,14 @@ namespace GaudiAllen::Converters::v3 { covY.z().cast()); kalman_beamline_states.set(i_track, kalman_beamline_state); - char* velo_trac_hits = nullptr; + char* velo_track_hits = nullptr; // TBC: offset hits // Velo::Consolidated::Hits hits(velo_trac_hits, offset_hits, offset_hits, n_events-1, n_events); // Create a // new Velo hit container Loop over the hits from Pr::Velo::Track + // Velo::Consolidated::Tracks velo_tracks(offset_tracks, offset_hits, n_events - 1, n_events); // Create a new + // Velo track Allen::Views::Velo::Consolidated::Hits* hits = new Allen::Views::Velo::Consolidated::Hits { - velo_trac_hits, offset_tracks, offset_hits, n_events - 1, n_events}; // Create a new Allen hit container + velo_track_hits, offset_tracks, offset_hits, n_events - 1, n_events}; // Create a new Allen hit container ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track( hits, offset_tracks, offset_hits, i_track, n_events - 1); // Create a new Allen track diff --git a/configuration/python/AllenConf/primary_vertex_reconstruction.py b/configuration/python/AllenConf/primary_vertex_reconstruction.py index e703b98ee17..40a16365658 100644 --- a/configuration/python/AllenConf/primary_vertex_reconstruction.py +++ b/configuration/python/AllenConf/primary_vertex_reconstruction.py @@ -25,7 +25,8 @@ def make_pvs(velo_tracks, zmin=-541., zmax=307., SMOG2_pp_separation=-334., - Nbins=3392): + Nbins=3392, + use_converted_tracks=False): dz = 0.25 pp_maxTrackZ0Err = 1.5 @@ -46,7 +47,10 @@ def make_pvs(velo_tracks, host_number_of_reconstructed_velo_tracks = velo_tracks[ "host_number_of_reconstructed_velo_tracks"] - velo_states = run_velo_kalman_filter(velo_tracks, pv_name) + if use_converted_tracks: + velo_states = velo_tracks["dev_velo_kalman_beamline_states_view"] + else: + velo_states = run_velo_kalman_filter(velo_tracks, pv_name) pv_beamline_extrapolate = make_algorithm( pv_beamline_extrapolate_t, -- GitLab From 80ab20d6b1d41a4dde103661a30a50fda08f39ea Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 18:10:56 +0100 Subject: [PATCH 08/23] Reserve memory for the pointer to state and add requirement on state in make_pvs --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 3 ++- .../python/AllenConf/primary_vertex_reconstruction.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index afac2d9ced7..4bbf86d4b37 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -851,7 +851,8 @@ namespace GaudiAllen::Converters::v3 { Allen::Views::Velo::Consolidated::Track* ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks - char* ptr_states = nullptr; + n_pars_state = 11; // Number of paramters for each state + char* ptr_states = static_cast(std::malloc(n_tracks * n_pars_state * sizeof(float))); Velo::Consolidated::States kalman_beamline_states( ptr_states, n_tracks); // Create the memory for the beamline states diff --git a/configuration/python/AllenConf/primary_vertex_reconstruction.py b/configuration/python/AllenConf/primary_vertex_reconstruction.py index 40a16365658..fcdb4eacc07 100644 --- a/configuration/python/AllenConf/primary_vertex_reconstruction.py +++ b/configuration/python/AllenConf/primary_vertex_reconstruction.py @@ -48,9 +48,10 @@ def make_pvs(velo_tracks, "host_number_of_reconstructed_velo_tracks"] if use_converted_tracks: - velo_states = velo_tracks["dev_velo_kalman_beamline_states_view"] + velo_states_view = velo_tracks["dev_velo_kalman_beamline_states_view"] else: velo_states = run_velo_kalman_filter(velo_tracks, pv_name) + velo_states_view = velo_states["dev_velo_kalman_beamline_states_view"] pv_beamline_extrapolate = make_algorithm( pv_beamline_extrapolate_t, @@ -58,8 +59,7 @@ def make_pvs(velo_tracks, host_number_of_reconstructed_velo_tracks_t= host_number_of_reconstructed_velo_tracks, dev_velo_tracks_view_t=velo_tracks["dev_velo_tracks_view"], - dev_velo_states_view_t=velo_states[ - "dev_velo_kalman_beamline_states_view"]) + dev_velo_states_view_t=velo_states_view) pv_beamline_histo = make_algorithm( pv_beamline_histo_t, -- GitLab From 49c461e5f87300db4a09dcb4fffa6d9f20714d44 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 17 Jan 2025 18:24:22 +0100 Subject: [PATCH 09/23] Fix type --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 4bbf86d4b37..6f41b1b7c34 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -851,7 +851,7 @@ namespace GaudiAllen::Converters::v3 { Allen::Views::Velo::Consolidated::Track* ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks - n_pars_state = 11; // Number of paramters for each state + unsigned n_pars_state = 11; // Number of paramters for each state char* ptr_states = static_cast(std::malloc(n_tracks * n_pars_state * sizeof(float))); Velo::Consolidated::States kalman_beamline_states( ptr_states, n_tracks); // Create the memory for the beamline states -- GitLab From 717ff3b4701c84a3f84944db3ffdb7c749980765 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 17 Jan 2025 17:24:58 +0000 Subject: [PATCH 10/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/49492977 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 6f41b1b7c34..13ee28d956a 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -851,7 +851,7 @@ namespace GaudiAllen::Converters::v3 { Allen::Views::Velo::Consolidated::Track* ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks - unsigned n_pars_state = 11; // Number of paramters for each state + unsigned n_pars_state = 11; // Number of paramters for each state char* ptr_states = static_cast(std::malloc(n_tracks * n_pars_state * sizeof(float))); Velo::Consolidated::States kalman_beamline_states( ptr_states, n_tracks); // Create the memory for the beamline states -- GitLab From 8ebebbebd747b151f39e20e65ca073baf74f7dbd Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 7 Feb 2025 12:02:18 +0100 Subject: [PATCH 11/23] Fix memory menagement for pointers and add lhcbID for track hits --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 194 +++++++++++++----- 1 file changed, 142 insertions(+), 52 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 13ee28d956a..2157505a0eb 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -273,6 +273,7 @@ namespace GaudiAllen::Converters::v3 { auto last_hit(const Allen::Views::Physics::Track& track) { using Track = Allen::Views::Physics::Track; + using segment = Track::segment; auto tref = static_cast(track); return last_hit(tref.track_segment()); @@ -683,9 +684,13 @@ namespace GaudiAllen::Converters::v3 { std::vector> const&... allen_states_containers, const LHCb::UniqueIDGenerator& unique_id_gen) const override { + MsgStream log(this->msgSvc(), this->name()); + log << MSG::INFO << "Converting Allen tracks to LHCb v3 tracks" << endmsg; const unsigned i_event = 0; const auto allen_tracks_view = allen_tracks_mec[0].container(i_event); - const auto number_of_tracks = allen_tracks_view.size(); + unsigned number_of_tracks = allen_tracks_view.size(); + + log << MSG::INFO << "Converting " << number_of_tracks << " tracks" << endmsg; // Construct the output container auto output = make_output_container>(unique_id_gen); @@ -698,6 +703,8 @@ namespace GaudiAllen::Converters::v3 { convert_track(newTrack, track, states, unique_id_gen); } + log << MSG::INFO << "Converted " << number_of_tracks << " tracks" << endmsg; + assert(get_output_size(output) == number_of_tracks); return output; } @@ -811,16 +818,19 @@ namespace GaudiAllen::Converters::v3 { } }; + using AllenOutType = std::tuple< + std::vector, + std::vector, + std::vector, + std::vector>; + /** * * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. + * The converter is a MultiTransformer that takes two PrVeloTracks as input and returns + * Allen::Views::Velo::Consolidated::Tracks and beamline states. + * */ - using AllenOutType = std::tuple< - Allen::Views::Velo::Consolidated::MultiEventTracks, - Allen::Views::Velo::Consolidated::Tracks, - Allen::Views::Physics::KalmanStates, - unsigned int>; - class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< AllenOutType(LHCb::Pr::Velo::Tracks const&, LHCb::Pr::Velo::Tracks const&)> { @@ -842,21 +852,36 @@ namespace GaudiAllen::Converters::v3 { LHCb::Pr::Velo::Tracks const& pr_tracks_forward, LHCb::Pr::Velo::Tracks const& pr_tracks_backward) const override { - const unsigned n_events = 1; // only one event is processed at a time - const unsigned n_tracks = pr_tracks_forward.size() + pr_tracks_backward.size(); // total number of tracks - const unsigned* offset_tracks = - new unsigned[n_events + 1] {0, n_tracks}; // offset for the tracks in the output container - const unsigned* offset_hits = new unsigned[n_events] {0}; // offset for the hits in the output container + MsgStream log(msgSvc(), name()); + + log << MSG::INFO << "Converting PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks" << endmsg; + + const unsigned n_events = 1; // only one event is processed at a time + const auto simd = SIMDWrapper::InstructionSet::Scalar; // scalar instruction set + const unsigned n_tracks = (pr_tracks_forward.size() + pr_tracks_backward.size()) / + SIMDWrapper::type_map_t::size; // total number of tracks + + log << MSG::INFO << "Size of simd scalar: " << SIMDWrapper::type_map_t::size << endmsg; + auto offset_tracks = std::make_unique(n_events + 1); // memory for the tracks + offset_tracks[n_events - 1] = 0; + offset_tracks[n_events] = n_tracks; + log << MSG::INFO << "Offset tracks created with " << n_tracks << " tracks" << endmsg; + + auto ptr_tracks = std::make_unique(n_tracks); // memory for the tracks + unsigned nb_elements_state = 6; // number of parameters in the state + unsigned nb_elements_cov = 6; // number of elements in the covariance matrix + auto ptr_states = + std::make_unique(n_tracks * (nb_elements_state + nb_elements_cov)); // memory for the states - Allen::Views::Velo::Consolidated::Track* ptr_tracks = - new Allen::Views::Velo::Consolidated::Track[n_tracks]; // Create the memory for the tracks - unsigned n_pars_state = 11; // Number of paramters for each state - char* ptr_states = static_cast(std::malloc(n_tracks * n_pars_state * sizeof(float))); - Velo::Consolidated::States kalman_beamline_states( - ptr_states, n_tracks); // Create the memory for the beamline states + std::vector hits; + auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hits - unsigned i_track = 0; // track index + log << MSG::INFO << "Allocating " << n_tracks * (nb_elements_cov + nb_elements_state) * sizeof(float) + << " bytes for the states" << endmsg; + + unsigned i_track = 0; // track index + unsigned tot_hits = 0; // total number of hits // Loop over the tracks for (const auto& tracks : {&pr_tracks_forward, &pr_tracks_backward}) { // Get scalar view of the tracks, to cast to the correct type @@ -868,44 +893,109 @@ namespace GaudiAllen::Converters::v3 { auto covX = track.StateCovX(loc); auto covY = track.StateCovY(loc); - KalmanVeloState kalman_beamline_state( - pos.x().cast(), - pos.y().cast(), - pos.z().cast(), - dir.x().cast(), - dir.y().cast(), - covX.x().cast(), - covX.y().cast(), - covX.z().cast(), - covY.x().cast(), - covY.y().cast(), - covY.z().cast()); - kalman_beamline_states.set(i_track, kalman_beamline_state); - - char* velo_track_hits = nullptr; - // TBC: offset hits - // Velo::Consolidated::Hits hits(velo_trac_hits, offset_hits, offset_hits, n_events-1, n_events); // Create a - // new Velo hit container Loop over the hits from Pr::Velo::Track - // Velo::Consolidated::Tracks velo_tracks(offset_tracks, offset_hits, n_events - 1, n_events); // Create a new - // Velo track - Allen::Views::Velo::Consolidated::Hits* hits = new Allen::Views::Velo::Consolidated::Hits { - velo_track_hits, offset_tracks, offset_hits, n_events - 1, n_events}; // Create a new Allen hit container - ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track( - hits, offset_tracks, offset_hits, i_track, n_events - 1); // Create a new Allen track - + ptr_states[i_track * nb_elements_state] = pos.x().cast(); + ptr_states[i_track * nb_elements_state + 1] = pos.y().cast(); + ptr_states[i_track * nb_elements_state + 2] = pos.z().cast(); + ptr_states[i_track * nb_elements_state + 3] = dir.x().cast(); + ptr_states[i_track * nb_elements_state + 4] = dir.y().cast(); + // no qop in the PrVeloTracks + ptr_states[i_track * nb_elements_state + 5] = 0.0f; + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = covX.x().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = covX.y().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] = covX.z().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] = covY.x().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] = covY.y().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 5] = covY.z().cast(); + + // Get the number of hits + unsigned n_hits = track.nHits().cast(); + std::vector velo_track_hits; + if (i_track == 0) { + log << MSG::INFO << "State for track 0: " << ptr_states[i_track * nb_elements_state] << " " + << ptr_states[i_track * nb_elements_state + 1] << " " << ptr_states[i_track * nb_elements_state + 2] + << " " << ptr_states[i_track * nb_elements_state + 3] << " " + << ptr_states[i_track * nb_elements_state + 4] << endmsg; + log << MSG::INFO << "Covariant matrix for state: " + << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] << " " + << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] << " " + << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] << " " + << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] << " " + << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] << endmsg; + log << MSG::INFO << "Number of hits in the first track: " << n_hits << endmsg; + } + + offset_hits[i_track] = tot_hits; + offset_hits[i_track + 1] = tot_hits + n_hits; + + // Loop over the hits to get the LHCbID + for (uint i_hit = 0; i_hit < n_hits; i_hit++) { + if (i_track == 0) { + log << MSG::INFO << "Hit " << i_hit << " with LHCbID: " << track.vp_lhcbID(i_hit).LHCbID().lhcbID() + << endmsg; + } + velo_track_hits.emplace_back(track.vp_lhcbID(i_hit).LHCbID().lhcbID()); + } + + hits.emplace_back(Allen::Views::Velo::Consolidated::Hits( + reinterpret_cast(velo_track_hits.data()), + offset_tracks.get(), + offset_hits.get(), + n_events - 1, + n_events)); // Create a new Allen hit container + tot_hits += n_hits; i_track++; } } + for (UInt_t i_track = 0; i_track < n_tracks; i_track++) { + ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track( + hits.data(), offset_tracks.get(), offset_hits.get(), i_track, n_events - 1); // Create a new Allen track + } + // Create the output container - Allen::Views::Physics::KalmanStates allen_states_view {ptr_states, offset_tracks, n_events - 1, n_events}; - Allen::Views::Velo::Consolidated::Tracks allen_tracks_view {ptr_tracks, offset_tracks, n_events - 1}; - Allen::Views::Velo::Consolidated::Tracks* ptr_allen_tracks_view = - new Allen::Views::Velo::Consolidated::Tracks[n_events]; - ptr_allen_tracks_view[n_events - 1] = allen_tracks_view; - Allen::Views::Velo::Consolidated::MultiEventTracks allen_tracks_mec {ptr_allen_tracks_view, n_events}; - - return std::tuple {allen_tracks_mec, allen_tracks_view, allen_states_view, allen_tracks_view.size()}; + std::vector allen_states_view; + allen_states_view.emplace_back(Allen::Views::Physics::KalmanStates { + reinterpret_cast(ptr_states.get()), offset_tracks.get(), n_events - 1, n_events}); + std::vector allen_tracks_view; + allen_tracks_view.emplace_back( + Allen::Views::Velo::Consolidated::Tracks {ptr_tracks.get(), offset_tracks.get(), n_events - 1}); + std::vector allen_tracks_mec; + allen_tracks_mec.emplace_back( + Allen::Views::Velo::Consolidated::MultiEventTracks {allen_tracks_view.data(), n_events}); + + log << MSG::INFO << "DONE - Total number of reconstructed states: " << allen_states_view[0].size() << endmsg; + log << MSG::INFO << "DONE - Total number of reconstructed tracks: " << allen_tracks_view[0].size() << endmsg; + log << MSG::INFO << "MEC size: " << allen_tracks_mec[0].container(n_events - 1).size() << endmsg; + log << MSG::INFO << "DONE - Offset of the track: " << allen_tracks_view[0].offset() << endmsg; + + /**DEBUG + * + */ + // Print values in the loop + for (unsigned int i_track = 0; i_track < n_tracks; ++i_track) { + Allen::Views::Velo::Consolidated::Track debug_track = allen_tracks_view[0].track(i_track); + Allen::Views::Physics::KalmanState debug_state = allen_states_view[0].state(i_track); + if (i_track == 0) { + log << MSG::INFO << "State for track " << i_track << ": " << debug_state.x() << " " << debug_state.y() << " " + << debug_state.z() << " " << debug_state.tx() << " " << debug_state.ty() << " " << debug_state.qop() + << endmsg; + log << MSG::INFO << "Covariant matrix for state: " << debug_state.c00() << " " << debug_state.c11() << " " + << debug_state.c22() << " " << debug_state.c33() << " " << endmsg; + } + log << MSG::INFO << "Track " << i_track << " with " << debug_track.number_of_hits() << " hits" << endmsg; + + for (unsigned int i_hit = 0; i_hit < debug_track.number_of_hits(); i_hit++) { + log << MSG::INFO << debug_track.hit(i_hit).id() << " "; + } + log << MSG::INFO << endmsg; + } + + std::vector number_of_tracks; + number_of_tracks.emplace_back(static_cast(allen_tracks_view[0].size())); + + assert(number_of_tracks[0] == n_tracks); + + return std::tuple {allen_tracks_mec, allen_tracks_view, allen_states_view, number_of_tracks}; } }; using GaudiAllenMEBasicParticlesToV3Tracks = -- GitLab From 0a49eec2b34a66a5b40c2aa62256dcdc3914fc16 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Mon, 10 Feb 2025 12:56:12 +0100 Subject: [PATCH 12/23] Successfully convert IDs and states, add qop --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 131 ++++++------------ 1 file changed, 42 insertions(+), 89 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 2157505a0eb..e6d12d773a9 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -684,14 +684,10 @@ namespace GaudiAllen::Converters::v3 { std::vector> const&... allen_states_containers, const LHCb::UniqueIDGenerator& unique_id_gen) const override { - MsgStream log(this->msgSvc(), this->name()); - log << MSG::INFO << "Converting Allen tracks to LHCb v3 tracks" << endmsg; const unsigned i_event = 0; const auto allen_tracks_view = allen_tracks_mec[0].container(i_event); unsigned number_of_tracks = allen_tracks_view.size(); - log << MSG::INFO << "Converting " << number_of_tracks << " tracks" << endmsg; - // Construct the output container auto output = make_output_container>(unique_id_gen); for (unsigned int t = 0; t < number_of_tracks; t++) { @@ -703,8 +699,6 @@ namespace GaudiAllen::Converters::v3 { convert_track(newTrack, track, states, unique_id_gen); } - log << MSG::INFO << "Converted " << number_of_tracks << " tracks" << endmsg; - assert(get_output_size(output) == number_of_tracks); return output; } @@ -782,7 +776,8 @@ namespace GaudiAllen::Converters::v3 { // set charge based on hit 0 of the velo track // (part of original implementation of GaudiAllenVeloToV2Tracks) - const int firstRow = LHCb::LHCbID(velo_track.id(0)).channelID(); + auto first_hit = velo_track.id(0); + const int firstRow = LHCb::LHCbID(first_hit).channelID(); const float charge = (firstRow % 2 == 0 ? -1.f : 1.f); const float tx1 = beamline_state.tx(); @@ -801,7 +796,6 @@ namespace GaudiAllen::Converters::v3 { const auto qop_w_var = qop_and_var(track, input_states...); const float qop = qop_w_var.first; const float qopVar = qop_w_var.second; - // if a state is part of the AllenTrack, then add it. if constexpr (std::is_same_v) { auto velo_beamline_state = static_cast(track.state()); @@ -852,33 +846,22 @@ namespace GaudiAllen::Converters::v3 { LHCb::Pr::Velo::Tracks const& pr_tracks_forward, LHCb::Pr::Velo::Tracks const& pr_tracks_backward) const override { - - MsgStream log(msgSvc(), name()); - - log << MSG::INFO << "Converting PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks" << endmsg; - const unsigned n_events = 1; // only one event is processed at a time const auto simd = SIMDWrapper::InstructionSet::Scalar; // scalar instruction set const unsigned n_tracks = (pr_tracks_forward.size() + pr_tracks_backward.size()) / SIMDWrapper::type_map_t::size; // total number of tracks - log << MSG::INFO << "Size of simd scalar: " << SIMDWrapper::type_map_t::size << endmsg; auto offset_tracks = std::make_unique(n_events + 1); // memory for the tracks offset_tracks[n_events - 1] = 0; offset_tracks[n_events] = n_tracks; - log << MSG::INFO << "Offset tracks created with " << n_tracks << " tracks" << endmsg; - - auto ptr_tracks = std::make_unique(n_tracks); // memory for the tracks - unsigned nb_elements_state = 6; // number of parameters in the state - unsigned nb_elements_cov = 6; // number of elements in the covariance matrix - auto ptr_states = - std::make_unique(n_tracks * (nb_elements_state + nb_elements_cov)); // memory for the states - - std::vector hits; - auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hits - log << MSG::INFO << "Allocating " << n_tracks * (nb_elements_cov + nb_elements_state) * sizeof(float) - << " bytes for the states" << endmsg; + auto ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // memory for the tracks + unsigned nb_elements_state = 6; // number of parameters in the state + unsigned nb_elements_cov = 6; // number of elements in the covariance matrix + auto ptr_states = new float[n_tracks * (nb_elements_state + nb_elements_cov)]; // memory for the states + std::vector ptr_hits; // memory for the hits + auto hits = new Allen::Views::Velo::Consolidated::Hits[n_tracks]; // memory for the hits + auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hits unsigned i_track = 0; // track index unsigned tot_hits = 0; // total number of hits @@ -898,8 +881,8 @@ namespace GaudiAllen::Converters::v3 { ptr_states[i_track * nb_elements_state + 2] = pos.z().cast(); ptr_states[i_track * nb_elements_state + 3] = dir.x().cast(); ptr_states[i_track * nb_elements_state + 4] = dir.y().cast(); - // no qop in the PrVeloTracks - ptr_states[i_track * nb_elements_state + 5] = 0.0f; + // no qop in the PrVeloTracks, needs to be extracted from the PrVeloTrack + ptr_states[i_track * nb_elements_state + 5] = get_qop(track); ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = covX.x().cast(); ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = covX.y().cast(); ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] = covX.z().cast(); @@ -909,94 +892,65 @@ namespace GaudiAllen::Converters::v3 { // Get the number of hits unsigned n_hits = track.nHits().cast(); - std::vector velo_track_hits; - if (i_track == 0) { - log << MSG::INFO << "State for track 0: " << ptr_states[i_track * nb_elements_state] << " " - << ptr_states[i_track * nb_elements_state + 1] << " " << ptr_states[i_track * nb_elements_state + 2] - << " " << ptr_states[i_track * nb_elements_state + 3] << " " - << ptr_states[i_track * nb_elements_state + 4] << endmsg; - log << MSG::INFO << "Covariant matrix for state: " - << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] << " " - << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] << " " - << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] << " " - << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] << " " - << ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] << endmsg; - log << MSG::INFO << "Number of hits in the first track: " << n_hits << endmsg; - } offset_hits[i_track] = tot_hits; offset_hits[i_track + 1] = tot_hits + n_hits; // Loop over the hits to get the LHCbID for (uint i_hit = 0; i_hit < n_hits; i_hit++) { - if (i_track == 0) { - log << MSG::INFO << "Hit " << i_hit << " with LHCbID: " << track.vp_lhcbID(i_hit).LHCbID().lhcbID() - << endmsg; - } - velo_track_hits.emplace_back(track.vp_lhcbID(i_hit).LHCbID().lhcbID()); + ptr_hits.push_back(track.vp_lhcbID(i_hit).LHCbID().lhcbID()); } - hits.emplace_back(Allen::Views::Velo::Consolidated::Hits( - reinterpret_cast(velo_track_hits.data()), - offset_tracks.get(), - offset_hits.get(), - n_events - 1, - n_events)); // Create a new Allen hit container tot_hits += n_hits; i_track++; } } for (UInt_t i_track = 0; i_track < n_tracks; i_track++) { + hits[i_track] = Allen::Views::Velo::Consolidated::Hits( + reinterpret_cast(ptr_hits.data()), + offset_tracks.get(), + offset_hits.get(), + n_events - 1, + n_events); // Create a new Allen hit container + ptr_tracks[i_track] = Allen::Views::Velo::Consolidated::Track( - hits.data(), offset_tracks.get(), offset_hits.get(), i_track, n_events - 1); // Create a new Allen track + hits, offset_tracks.get(), offset_hits.get(), i_track, n_events - 1); // Create a new Allen track } // Create the output container std::vector allen_states_view; - allen_states_view.emplace_back(Allen::Views::Physics::KalmanStates { - reinterpret_cast(ptr_states.get()), offset_tracks.get(), n_events - 1, n_events}); + allen_states_view.emplace_back(reinterpret_cast(ptr_states), offset_tracks.get(), n_events - 1, n_events); std::vector allen_tracks_view; - allen_tracks_view.emplace_back( - Allen::Views::Velo::Consolidated::Tracks {ptr_tracks.get(), offset_tracks.get(), n_events - 1}); + allen_tracks_view.emplace_back(ptr_tracks, offset_tracks.get(), n_events - 1); + Allen::Views::Velo::Consolidated::Tracks* ptr_tracks_view = + new Allen::Views::Velo::Consolidated::Tracks(ptr_tracks, offset_tracks.get(), n_events - 1); std::vector allen_tracks_mec; - allen_tracks_mec.emplace_back( - Allen::Views::Velo::Consolidated::MultiEventTracks {allen_tracks_view.data(), n_events}); - - log << MSG::INFO << "DONE - Total number of reconstructed states: " << allen_states_view[0].size() << endmsg; - log << MSG::INFO << "DONE - Total number of reconstructed tracks: " << allen_tracks_view[0].size() << endmsg; - log << MSG::INFO << "MEC size: " << allen_tracks_mec[0].container(n_events - 1).size() << endmsg; - log << MSG::INFO << "DONE - Offset of the track: " << allen_tracks_view[0].offset() << endmsg; - - /**DEBUG - * - */ - // Print values in the loop - for (unsigned int i_track = 0; i_track < n_tracks; ++i_track) { - Allen::Views::Velo::Consolidated::Track debug_track = allen_tracks_view[0].track(i_track); - Allen::Views::Physics::KalmanState debug_state = allen_states_view[0].state(i_track); - if (i_track == 0) { - log << MSG::INFO << "State for track " << i_track << ": " << debug_state.x() << " " << debug_state.y() << " " - << debug_state.z() << " " << debug_state.tx() << " " << debug_state.ty() << " " << debug_state.qop() - << endmsg; - log << MSG::INFO << "Covariant matrix for state: " << debug_state.c00() << " " << debug_state.c11() << " " - << debug_state.c22() << " " << debug_state.c33() << " " << endmsg; - } - log << MSG::INFO << "Track " << i_track << " with " << debug_track.number_of_hits() << " hits" << endmsg; - - for (unsigned int i_hit = 0; i_hit < debug_track.number_of_hits(); i_hit++) { - log << MSG::INFO << debug_track.hit(i_hit).id() << " "; - } - log << MSG::INFO << endmsg; - } + allen_tracks_mec.emplace_back(ptr_tracks_view, n_events); std::vector number_of_tracks; - number_of_tracks.emplace_back(static_cast(allen_tracks_view[0].size())); + number_of_tracks.push_back(static_cast(allen_tracks_view[0].size())); assert(number_of_tracks[0] == n_tracks); return std::tuple {allen_tracks_mec, allen_tracks_view, allen_states_view, number_of_tracks}; } + + private: + template + float get_qop(const PrVeloTrack& track) const + { + auto dir = track.closestToBeamStateDir(); + // no qop in the PrVeloTracks, needs to be extracted from the PrVeloTrack + const float tx = dir.x().cast(); + const float ty = dir.y().cast(); + const float slope2 = std::max(tx * tx + ty * ty, 1.e-20f); + const int firstRow = track.vp_lhcbID(0).LHCbID().channelID(); + const float charge = (firstRow % 2 == 0 ? -1.f : 1.f); + const float pT = 400 * Gaudi::Units::MeV; // default pT for Velo tracks + const float qop = charge / (pT * std::sqrt(1.f + 1.f / slope2)); + return qop; + } }; using GaudiAllenMEBasicParticlesToV3Tracks = GaudiAllenTrackViewsToV3Tracks; @@ -1012,5 +966,4 @@ namespace GaudiAllen::Converters::v3 { endvelo_states>; DECLARE_COMPONENT_WITH_ID(GaudiAllenUTToV3Tracks, "GaudiAllenUTToV3Tracks") DECLARE_COMPONENT_WITH_ID(PrVeloToGaudiAllenVeloTracks, "PrVeloToGaudiAllenVeloTracks") - } // namespace GaudiAllen::Converters::v3 -- GitLab From 569ee1b7b76c24cbdfb1739bddf5b2bbcbb2270c Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Mon, 10 Feb 2025 19:54:01 +0100 Subject: [PATCH 13/23] Add extrapolation to beamline --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 89 +++++++++++++++---- 1 file changed, 73 insertions(+), 16 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index e6d12d773a9..cb15f8b8797 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -20,6 +20,9 @@ #include "Event/TrackEnums.h" #include "Event/UniqueIDGenerator.h" #include "Event/StateParameters.h" +#include "LHCbDet/InteractionRegion.h" +#include "DetDesc/GenericConditionAccessorHolder.h" +#include "LHCbAlgs/Transformer.h" // Allen #include "Logger.h" @@ -827,24 +830,47 @@ namespace GaudiAllen::Converters::v3 { */ class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< - AllenOutType(LHCb::Pr::Velo::Tracks const&, LHCb::Pr::Velo::Tracks const&)> { + AllenOutType( + LHCb::Pr::Velo::Tracks const&, + LHCb::Pr::Velo::Tracks const&, + const LHCb::Conditions::InteractionRegion&), + LHCb::Algorithm::Traits::usesConditions> { public: - /// Standard constructor + //============================================================================= + // Standard constructor, initializes variables + //============================================================================= PrVeloToGaudiAllenVeloTracks(const std::string& name, ISvcLocator* pSvcLocator) : MultiTransformer( name, pSvcLocator, - {KeyValue {"PrVeloTracksForward", ""}, KeyValue {"PrVeloTracksBackward", ""}}, + {KeyValue {"PrVeloTracksForward", ""}, + KeyValue {"PrVeloTracksBackward", ""}, + {KeyValue {"InteractionRegionCache", "AlgorithmSpecific-" + name + "-InteractionRegion"}}}, {KeyValue {"AllenVeloTracksMEC", ""}, KeyValue {"AllenVeloTracksView", ""}, KeyValue {"AllenBeamlineStatesView", ""}, KeyValue {"NumberOfReconstructedVeloTracks", ""}}) {} - /// Algorithm execution + //============================================================================= + // initialize() + //============================================================================= + StatusCode initialize() override + { + auto sc = MultiTransformer::initialize().andThen([&]() { + LHCb::Conditions::InteractionRegion::addConditionDerivation( + this, inputLocation()); + }); + return sc; + } + + //============================================================================= + // execute() + //============================================================================= AllenOutType operator()( LHCb::Pr::Velo::Tracks const& pr_tracks_forward, - LHCb::Pr::Velo::Tracks const& pr_tracks_backward) const override + LHCb::Pr::Velo::Tracks const& pr_tracks_backward, + LHCb::Conditions::InteractionRegion const& region) const override { const unsigned n_events = 1; // only one event is processed at a time const auto simd = SIMDWrapper::InstructionSet::Scalar; // scalar instruction set @@ -857,7 +883,7 @@ namespace GaudiAllen::Converters::v3 { auto ptr_tracks = new Allen::Views::Velo::Consolidated::Track[n_tracks]; // memory for the tracks unsigned nb_elements_state = 6; // number of parameters in the state - unsigned nb_elements_cov = 6; // number of elements in the covariance matrix + unsigned nb_elements_cov = 8; // number of elements in the covariance matrix auto ptr_states = new float[n_tracks * (nb_elements_state + nb_elements_cov)]; // memory for the states std::vector ptr_hits; // memory for the hits auto hits = new Allen::Views::Velo::Consolidated::Hits[n_tracks]; // memory for the hits @@ -876,19 +902,49 @@ namespace GaudiAllen::Converters::v3 { auto covX = track.StateCovX(loc); auto covY = track.StateCovY(loc); - ptr_states[i_track * nb_elements_state] = pos.x().cast(); - ptr_states[i_track * nb_elements_state + 1] = pos.y().cast(); - ptr_states[i_track * nb_elements_state + 2] = pos.z().cast(); - ptr_states[i_track * nb_elements_state + 3] = dir.x().cast(); - ptr_states[i_track * nb_elements_state + 4] = dir.y().cast(); - // no qop in the PrVeloTracks, needs to be extracted from the PrVeloTrack + // Get the beamline position and direction + const auto beamspot = region.avgPosition; + const auto beamlineX = beamspot.x(); + const auto beamlineY = beamspot.y(); + const auto beamlineTx = region.tX(); + const auto beamlineTy = region.tY(); + + /// Extrapolate the state at the beamline + auto const dx = beamlineX - pos.x().cast(); + auto const dy = beamlineY - pos.y().cast(); + auto const tx = dir.x().cast() - beamlineTx; + auto const ty = dir.y().cast() - beamlineTy; + auto const dz = tx * ty != 0 ? (tx * dx + ty * dy) / (tx * tx + ty * ty) : 0.f; + auto const dz2 = dz * dz; + auto const xbeam = beamlineX + tx * dz; + auto const ybeam = beamlineY + ty * dz; + auto const zbeam = pos.z().cast() + dz; + auto const Vx = (covX.x().cast() + 2.f * dz * covX.y() + dz2 * covX.z().cast()).cast(); + auto const Vy = (covY.x().cast() + 2.f * dz * covY.y() + dz2 * covY.z().cast()).cast(); + auto const Vxy = covX.y().cast() + dz * covX.z().cast(); + auto const Vyx = covY.y().cast() + dz * covY.z().cast(); + auto const Wx = Vx != 0 ? 1. / Vx : 1.f; + auto const Wy = Vy != 0 ? 1. / Vy : 1.f; + // auto const zweight = tx * Wx * tx + ty * Wy * ty; + // auto const zerr = zweight!=0 ? 1. / std::sqrt(zweight) : 1.f; + auto const blchi2 = dx * Wx * dx + dy * Wy * dy; + + // Fill the state parameters + ptr_states[i_track * nb_elements_state] = xbeam; + ptr_states[i_track * nb_elements_state + 1] = ybeam; + ptr_states[i_track * nb_elements_state + 2] = zbeam; + ptr_states[i_track * nb_elements_state + 3] = tx; + ptr_states[i_track * nb_elements_state + 4] = ty; + // no qop in the PrVeloTracks, needs to be extracted from the first hit ptr_states[i_track * nb_elements_state + 5] = get_qop(track); - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = covX.x().cast(); - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = covX.y().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = Vx; + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = Vxy; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] = covX.z().cast(); - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] = covY.x().cast(); - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] = covY.y().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] = Vy; + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] = Vyx; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 5] = covY.z().cast(); + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 6] = blchi2; // DEBUG + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 7] = 5; // default // Get the number of hits unsigned n_hits = track.nHits().cast(); @@ -952,6 +1008,7 @@ namespace GaudiAllen::Converters::v3 { return qop; } }; + using GaudiAllenMEBasicParticlesToV3Tracks = GaudiAllenTrackViewsToV3Tracks; DECLARE_COMPONENT_WITH_ID(GaudiAllenMEBasicParticlesToV3Tracks, "GaudiAllenMEBasicParticlesToV3Tracks") -- GitLab From 6760b3d3daaebfb09ef87f1c12844b9e153bcc95 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 14 Feb 2025 11:36:57 +0100 Subject: [PATCH 14/23] Clean-up changes --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index cb15f8b8797..c8f452d2bb9 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -276,7 +276,6 @@ namespace GaudiAllen::Converters::v3 { auto last_hit(const Allen::Views::Physics::Track& track) { using Track = Allen::Views::Physics::Track; - using segment = Track::segment; auto tref = static_cast(track); return last_hit(tref.track_segment()); @@ -689,7 +688,7 @@ namespace GaudiAllen::Converters::v3 { { const unsigned i_event = 0; const auto allen_tracks_view = allen_tracks_mec[0].container(i_event); - unsigned number_of_tracks = allen_tracks_view.size(); + const auto number_of_tracks = allen_tracks_view.size(); // Construct the output container auto output = make_output_container>(unique_id_gen); @@ -779,8 +778,7 @@ namespace GaudiAllen::Converters::v3 { // set charge based on hit 0 of the velo track // (part of original implementation of GaudiAllenVeloToV2Tracks) - auto first_hit = velo_track.id(0); - const int firstRow = LHCb::LHCbID(first_hit).channelID(); + const int firstRow = LHCb::LHCbID(velo_track.id(0)).channelID(); const float charge = (firstRow % 2 == 0 ? -1.f : 1.f); const float tx1 = beamline_state.tx(); @@ -799,6 +797,7 @@ namespace GaudiAllen::Converters::v3 { const auto qop_w_var = qop_and_var(track, input_states...); const float qop = qop_w_var.first; const float qopVar = qop_w_var.second; + // if a state is part of the AllenTrack, then add it. if constexpr (std::is_same_v) { auto velo_beamline_state = static_cast(track.state()); @@ -916,9 +915,9 @@ namespace GaudiAllen::Converters::v3 { auto const ty = dir.y().cast() - beamlineTy; auto const dz = tx * ty != 0 ? (tx * dx + ty * dy) / (tx * tx + ty * ty) : 0.f; auto const dz2 = dz * dz; - auto const xbeam = beamlineX + tx * dz; - auto const ybeam = beamlineY + ty * dz; - auto const zbeam = pos.z().cast() + dz; + auto const xbeam = pos.x().cast() + tx * dz; + auto const ybeam = pos.y().cast() + ty * dz; + auto const zbeam = pos.z().cast() + dz;pos.y().cast(); auto const Vx = (covX.x().cast() + 2.f * dz * covX.y() + dz2 * covX.z().cast()).cast(); auto const Vy = (covY.x().cast() + 2.f * dz * covY.y() + dz2 * covY.z().cast()).cast(); auto const Vxy = covX.y().cast() + dz * covX.z().cast(); -- GitLab From 761624e22cd8d5f2a36d3488b643d081c9178394 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 14 Feb 2025 10:37:31 +0000 Subject: [PATCH 15/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/51006024 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index c8f452d2bb9..d54ba8fe3c2 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -917,7 +917,8 @@ namespace GaudiAllen::Converters::v3 { auto const dz2 = dz * dz; auto const xbeam = pos.x().cast() + tx * dz; auto const ybeam = pos.y().cast() + ty * dz; - auto const zbeam = pos.z().cast() + dz;pos.y().cast(); + auto const zbeam = pos.z().cast() + dz; + pos.y().cast(); auto const Vx = (covX.x().cast() + 2.f * dz * covX.y() + dz2 * covX.z().cast()).cast(); auto const Vy = (covY.x().cast() + 2.f * dz * covY.y() + dz2 * covY.z().cast()).cast(); auto const Vxy = covX.y().cast() + dz * covX.z().cast(); -- GitLab From 92ae27837f0d205433af9aa832d142a8633f8ef7 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Tue, 18 Mar 2025 12:18:10 +0100 Subject: [PATCH 16/23] Cleanup removing unused output --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index d54ba8fe3c2..bb977d9a8b5 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -815,10 +815,9 @@ namespace GaudiAllen::Converters::v3 { }; using AllenOutType = std::tuple< - std::vector, std::vector, std::vector, - std::vector>; + std::vector> /** * @@ -845,8 +844,7 @@ namespace GaudiAllen::Converters::v3 { {KeyValue {"PrVeloTracksForward", ""}, KeyValue {"PrVeloTracksBackward", ""}, {KeyValue {"InteractionRegionCache", "AlgorithmSpecific-" + name + "-InteractionRegion"}}}, - {KeyValue {"AllenVeloTracksMEC", ""}, - KeyValue {"AllenVeloTracksView", ""}, + {KeyValue {"AllenVeloTracksView", ""}, KeyValue {"AllenBeamlineStatesView", ""}, KeyValue {"NumberOfReconstructedVeloTracks", ""}}) {} @@ -981,15 +979,13 @@ namespace GaudiAllen::Converters::v3 { allen_tracks_view.emplace_back(ptr_tracks, offset_tracks.get(), n_events - 1); Allen::Views::Velo::Consolidated::Tracks* ptr_tracks_view = new Allen::Views::Velo::Consolidated::Tracks(ptr_tracks, offset_tracks.get(), n_events - 1); - std::vector allen_tracks_mec; - allen_tracks_mec.emplace_back(ptr_tracks_view, n_events); std::vector number_of_tracks; number_of_tracks.push_back(static_cast(allen_tracks_view[0].size())); assert(number_of_tracks[0] == n_tracks); - return std::tuple {allen_tracks_mec, allen_tracks_view, allen_states_view, number_of_tracks}; + return std::tuple {allen_tracks_view, allen_states_view, number_of_tracks}; } private: -- GitLab From c1e398530841a5fa43fce34f78a476639b08ee69 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Tue, 18 Mar 2025 11:18:53 +0000 Subject: [PATCH 17/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/52901468 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index bb977d9a8b5..aa9dc1db01d 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -819,14 +819,14 @@ namespace GaudiAllen::Converters::v3 { std::vector, std::vector> - /** - * - * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. - * The converter is a MultiTransformer that takes two PrVeloTracks as input and returns - * Allen::Views::Velo::Consolidated::Tracks and beamline states. - * - */ - class PrVeloToGaudiAllenVeloTracks final + /** + * + * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. + * The converter is a MultiTransformer that takes two PrVeloTracks as input and returns + * Allen::Views::Velo::Consolidated::Tracks and beamline states. + * + */ + class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< AllenOutType( LHCb::Pr::Velo::Tracks const&, -- GitLab From 10f68e4cec26265acdcd33f89f4420c0ba988502 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Tue, 18 Mar 2025 21:29:48 +0100 Subject: [PATCH 18/23] Fix typo --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index aa9dc1db01d..943506c2474 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -817,7 +817,7 @@ namespace GaudiAllen::Converters::v3 { using AllenOutType = std::tuple< std::vector, std::vector, - std::vector> + std::vector>; /** * -- GitLab From 248936f26c570ba51fe7e94ad5bbacbd36fc1080 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Tue, 18 Mar 2025 20:30:16 +0000 Subject: [PATCH 19/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/52934503 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 943506c2474..8957ed4e873 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -819,14 +819,14 @@ namespace GaudiAllen::Converters::v3 { std::vector, std::vector>; - /** - * - * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. - * The converter is a MultiTransformer that takes two PrVeloTracks as input and returns - * Allen::Views::Velo::Consolidated::Tracks and beamline states. - * - */ - class PrVeloToGaudiAllenVeloTracks final + /** + * + * Converter from PrVeloTracks to Allen::Views::Velo::Consolidated::Tracks and beamline states. + * The converter is a MultiTransformer that takes two PrVeloTracks as input and returns + * Allen::Views::Velo::Consolidated::Tracks and beamline states. + * + */ + class PrVeloToGaudiAllenVeloTracks final : public Gaudi::Functional::MultiTransformer< AllenOutType( LHCb::Pr::Velo::Tracks const&, -- GitLab From e67bd26b414e91afa8d8e8617fb24f561bf80dc9 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Tue, 22 Jul 2025 11:14:18 +0200 Subject: [PATCH 20/23] Remove WARNING when compiling --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 8957ed4e873..3797d3741c6 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -977,8 +977,6 @@ namespace GaudiAllen::Converters::v3 { allen_states_view.emplace_back(reinterpret_cast(ptr_states), offset_tracks.get(), n_events - 1, n_events); std::vector allen_tracks_view; allen_tracks_view.emplace_back(ptr_tracks, offset_tracks.get(), n_events - 1); - Allen::Views::Velo::Consolidated::Tracks* ptr_tracks_view = - new Allen::Views::Velo::Consolidated::Tracks(ptr_tracks, offset_tracks.get(), n_events - 1); std::vector number_of_tracks; number_of_tracks.push_back(static_cast(allen_tracks_view[0].size())); -- GitLab From 48bd2dcbcbe5f0b3cbd07cfeafc7c50d94e29882 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Thu, 24 Jul 2025 11:21:26 +0200 Subject: [PATCH 21/23] Make unique name to Allen PV finding algorithms run in Moore --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 3 --- .../python/AllenConf/primary_vertex_reconstruction.py | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 3797d3741c6..8cd6bad0706 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -916,15 +916,12 @@ namespace GaudiAllen::Converters::v3 { auto const xbeam = pos.x().cast() + tx * dz; auto const ybeam = pos.y().cast() + ty * dz; auto const zbeam = pos.z().cast() + dz; - pos.y().cast(); auto const Vx = (covX.x().cast() + 2.f * dz * covX.y() + dz2 * covX.z().cast()).cast(); auto const Vy = (covY.x().cast() + 2.f * dz * covY.y() + dz2 * covY.z().cast()).cast(); auto const Vxy = covX.y().cast() + dz * covX.z().cast(); auto const Vyx = covY.y().cast() + dz * covY.z().cast(); auto const Wx = Vx != 0 ? 1. / Vx : 1.f; auto const Wy = Vy != 0 ? 1. / Vy : 1.f; - // auto const zweight = tx * Wx * tx + ty * Wy * ty; - // auto const zerr = zweight!=0 ? 1. / std::sqrt(zweight) : 1.f; auto const blchi2 = dx * Wx * dx + dy * Wy * dy; // Fill the state parameters diff --git a/configuration/python/AllenConf/primary_vertex_reconstruction.py b/configuration/python/AllenConf/primary_vertex_reconstruction.py index fcdb4eacc07..e430bfeadbd 100644 --- a/configuration/python/AllenConf/primary_vertex_reconstruction.py +++ b/configuration/python/AllenConf/primary_vertex_reconstruction.py @@ -53,6 +53,9 @@ def make_pvs(velo_tracks, velo_states = run_velo_kalman_filter(velo_tracks, pv_name) velo_states_view = velo_states["dev_velo_kalman_beamline_states_view"] + if use_converted_tracks: + pv_name += "_{hash}" + pv_beamline_extrapolate = make_algorithm( pv_beamline_extrapolate_t, name="pv_beamline_extrapolate" + pv_name, -- GitLab From 6cf158b17c93ca5b526de1c87d58342c8d23386f Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Tue, 5 Aug 2025 10:19:28 +0200 Subject: [PATCH 22/23] Update comments for documentation --- .../src/GaudiAllenTrackViewsToV3Tracks.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index 8cd6bad0706..b8237725971 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -874,7 +874,7 @@ namespace GaudiAllen::Converters::v3 { const unsigned n_tracks = (pr_tracks_forward.size() + pr_tracks_backward.size()) / SIMDWrapper::type_map_t::size; // total number of tracks - auto offset_tracks = std::make_unique(n_events + 1); // memory for the tracks + auto offset_tracks = std::make_unique(n_events + 1); // memory for the track offsets offset_tracks[n_events - 1] = 0; offset_tracks[n_events] = n_tracks; @@ -882,9 +882,10 @@ namespace GaudiAllen::Converters::v3 { unsigned nb_elements_state = 6; // number of parameters in the state unsigned nb_elements_cov = 8; // number of elements in the covariance matrix auto ptr_states = new float[n_tracks * (nb_elements_state + nb_elements_cov)]; // memory for the states - std::vector ptr_hits; // memory for the hits + std::vector ptr_hits; // pointer to hits + // it is necessary to instantiate the Consolidated::Hits object auto hits = new Allen::Views::Velo::Consolidated::Hits[n_tracks]; // memory for the hits - auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hits + auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hit offsets unsigned i_track = 0; // track index unsigned tot_hits = 0; // total number of hits @@ -930,16 +931,18 @@ namespace GaudiAllen::Converters::v3 { ptr_states[i_track * nb_elements_state + 2] = zbeam; ptr_states[i_track * nb_elements_state + 3] = tx; ptr_states[i_track * nb_elements_state + 4] = ty; - // no qop in the PrVeloTracks, needs to be extracted from the first hit - ptr_states[i_track * nb_elements_state + 5] = get_qop(track); + // no qop in the PrVeloTracks, it should be extracted from the first hit + // we can use the function get_qop to get the value, but it is not used anywhere + // in the Allen PV finding algorithm, so set it to 0 + ptr_states[i_track * nb_elements_state + 5] = 0; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = Vx; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = Vxy; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] = covX.z().cast(); ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 3] = Vy; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] = Vyx; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 5] = covY.z().cast(); - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 6] = blchi2; // DEBUG - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 7] = 5; // default + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 6] = blchi2; + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 7] = 5; // default ndf (x,y,z,tx,ty) // Get the number of hits unsigned n_hits = track.nHits().cast(); -- GitLab From 0a642261697a9122469b796b5f95cd4be316a103 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Tue, 5 Aug 2025 08:20:07 +0000 Subject: [PATCH 23/23] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Allen/-/jobs/59791437 --- Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp index b8237725971..fcf38b7e112 100644 --- a/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp +++ b/Rec/Allen/src/GaudiAllenTrackViewsToV3Tracks.cpp @@ -883,9 +883,9 @@ namespace GaudiAllen::Converters::v3 { unsigned nb_elements_cov = 8; // number of elements in the covariance matrix auto ptr_states = new float[n_tracks * (nb_elements_state + nb_elements_cov)]; // memory for the states std::vector ptr_hits; // pointer to hits - // it is necessary to instantiate the Consolidated::Hits object - auto hits = new Allen::Views::Velo::Consolidated::Hits[n_tracks]; // memory for the hits - auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hit offsets + // it is necessary to instantiate the Consolidated::Hits object + auto hits = new Allen::Views::Velo::Consolidated::Hits[n_tracks]; // memory for the hits + auto offset_hits = std::make_unique(n_tracks + 1); // memory for the hit offsets unsigned i_track = 0; // track index unsigned tot_hits = 0; // total number of hits @@ -934,7 +934,7 @@ namespace GaudiAllen::Converters::v3 { // no qop in the PrVeloTracks, it should be extracted from the first hit // we can use the function get_qop to get the value, but it is not used anywhere // in the Allen PV finding algorithm, so set it to 0 - ptr_states[i_track * nb_elements_state + 5] = 0; + ptr_states[i_track * nb_elements_state + 5] = 0; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov] = Vx; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 1] = Vxy; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 2] = covX.z().cast(); @@ -942,7 +942,7 @@ namespace GaudiAllen::Converters::v3 { ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 4] = Vyx; ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 5] = covY.z().cast(); ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 6] = blchi2; - ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 7] = 5; // default ndf (x,y,z,tx,ty) + ptr_states[n_tracks * nb_elements_state + i_track * nb_elements_cov + 7] = 5; // default ndf (x,y,z,tx,ty) // Get the number of hits unsigned n_hits = track.nHits().cast(); -- GitLab