From f45987d2007565eab9630bcc414a496aa73d3012 Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Tue, 9 Sep 2025 14:56:58 +0200 Subject: [PATCH 1/4] [DPG] Added unit test for validating reconstruction software --- DPG/Tasks/AOTTrack/CMakeLists.txt | 5 + .../AOTTrack/unitTestForReconstruction.cxx | 101 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx diff --git a/DPG/Tasks/AOTTrack/CMakeLists.txt b/DPG/Tasks/AOTTrack/CMakeLists.txt index b125419f6d0..bd055664fd8 100644 --- a/DPG/Tasks/AOTTrack/CMakeLists.txt +++ b/DPG/Tasks/AOTTrack/CMakeLists.txt @@ -80,6 +80,11 @@ o2physics_add_dpl_workflow(qa-tracksplitting PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(unit-test-for-reconstruction + SOURCES unitTestForReconstruction.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + COMPONENT_NAME Analysis) + o2physics_add_dpl_workflow(tag-and-probe-dmesons SOURCES tagAndProbeDmesons.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DetectorsVertexing O2Physics::MLCore diff --git a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx new file mode 100644 index 00000000000..51163e46e34 --- /dev/null +++ b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx @@ -0,0 +1,101 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license 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. +/// +/// \file unitTestForReconstruction.cxx +/// +/// \brief Unit test for validating the reconstruction software +/// \author Alberto Caliva (alberto.caliva@cern.ch), Catalin-Lucian Ristea (catalin.ristea@cern.ch) +/// \since September 9, 2025 + + +#include "Framework/ASoA.h" +#include "Framework/ASoAHelpers.h" +#include "Framework/AnalysisDataModel.h" +#include "Framework/AnalysisTask.h" +#include "Framework/DataTypes.h" +#include "Framework/HistogramRegistry.h" +#include "Framework/Logger.h" +#include "Framework/RunningWorkflowInfo.h" +#include "Framework/runDataProcessing.h" +#include "ReconstructionDataFormats/DCA.h" +#include "ReconstructionDataFormats/Track.h" + +#include +#include +#include +#include +#include + +using namespace o2::soa; +using namespace o2::aod; +using namespace o2::framework; +using namespace o2::framework::expressions; +using namespace o2::constants::physics; +using namespace o2::constants::math; + +struct UnitTestForReconstruction { + + // Histogram registry + HistogramRegistry registryData{"registryData", {}, OutputObjHandlingPolicy::AnalysisObject, true, true}; + + // global IDs of events to be inspected + Configurable> eventNr{"eventNr", {1, 5, 12, 44, 76, 99, 102, 115, 180, 220}, "eventNr"}; + std::unordered_set eventSet; + + void init(InitContext const&) + { + // Define histogram to monitor event counts at different selection stages + registryData.add("eventCounter", "eventCounter", HistType::kTH1F, {{10, 0, 10, ""}}); + + // Define histogram for the transverse momentum spectrum of reconstructed charged tracks + registryData.add("ptChargedTracks", "ptChargedTracks", HistType::kTH2F, {{11, 0, 11, "event"}, {1000, 0, 10, "#it{p}_{T} (GeV/#it{c})"}}); + + // Fast lookup set from configurable event list + eventSet = std::unordered_set(eventNr->begin(), eventNr->end()); + } + + // Process Data + void processData(o2::aod::Collisions const& collisions, o2::aod::Tracks const& tracks) + { + // Event index + int eventIndex = 0; + + // Loop over reconstructed events + for (const auto& collision : collisions) { + + // Event counter: before event selection + registryData.fill(HIST("eventCounter"), 0.5); + + // Check if event global index is in the list of events to process + int ev = collision.globalIndex(); + if (eventSet.count(ev)) { + + // Increment event index + eventIndex++; + + // Fill event counter + registryData.fill(HIST("eventCounter"), 1.5); + + // Loop over reconstructed tracks + for (auto const& track : tracks) { + registryData.fill(HIST("ptChargedTracks"), 0, track.pt()); + registryData.fill(HIST("ptChargedTracks"), eventIndex, track.pt()); + } + } + } + } + PROCESS_SWITCH(UnitTestForReconstruction, processData, "Process Data", true); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +} From 2fad66f754c272e17cc2a83e04dab7879bd0b645 Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Tue, 9 Sep 2025 14:58:58 +0200 Subject: [PATCH 2/4] fixed white space --- DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx index 51163e46e34..008f5554b9d 100644 --- a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx +++ b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx @@ -15,7 +15,6 @@ /// \author Alberto Caliva (alberto.caliva@cern.ch), Catalin-Lucian Ristea (catalin.ristea@cern.ch) /// \since September 9, 2025 - #include "Framework/ASoA.h" #include "Framework/ASoAHelpers.h" #include "Framework/AnalysisDataModel.h" From 6fa2094a75621da10c42595953f7c018c70218cc Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Tue, 9 Sep 2025 18:26:42 +0200 Subject: [PATCH 3/4] added include to fix Megalinter --- DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx index 008f5554b9d..49eee18ba11 100644 --- a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx +++ b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include using namespace o2::soa; From bfe34e86838d8d45b651394fbca215bb769c27e8 Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Wed, 10 Sep 2025 09:53:13 +0200 Subject: [PATCH 4/4] added var --- DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx index 49eee18ba11..a5e6016d9fb 100644 --- a/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx +++ b/DPG/Tasks/AOTTrack/unitTestForReconstruction.cxx @@ -67,6 +67,7 @@ struct UnitTestForReconstruction { { // Event index int eventIndex = 0; + static constexpr int indexAllEvts = 0; // Loop over reconstructed events for (const auto& collision : collisions) { @@ -86,7 +87,7 @@ struct UnitTestForReconstruction { // Loop over reconstructed tracks for (auto const& track : tracks) { - registryData.fill(HIST("ptChargedTracks"), 0, track.pt()); + registryData.fill(HIST("ptChargedTracks"), indexAllEvts, track.pt()); registryData.fill(HIST("ptChargedTracks"), eventIndex, track.pt()); } }