From e49c149e10ab470b81a496a62aa54484085499f6 Mon Sep 17 00:00:00 2001 From: Swati Saha Date: Tue, 1 Dec 2026 21:50:52 +0530 Subject: [PATCH 1/3] Task for net-charge cumulants --- PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt | 5 + .../Tasks/netChargeCumulants.cxx | 1562 +++++++++++++++++ 2 files changed, 1567 insertions(+) create mode 100644 PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx diff --git a/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt b/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt index 2ca1ae99968..e1c44514906 100644 --- a/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt +++ b/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt @@ -94,3 +94,8 @@ o2physics_add_dpl_workflow(mult-and-pt-fluctuations PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCFCore COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(net-charge-cumulants + SOURCES netChargeCumulants.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCF\ +Core + COMPONENT_NAME Analysis) diff --git a/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx b/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx new file mode 100644 index 00000000000..e7e96c9b629 --- /dev/null +++ b/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx @@ -0,0 +1,1562 @@ +// 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 netChargeCumulants.cxx +/// \brief Task for calculating net-charge cumulants (uncorrected moments and efficiency-corrected profiles). +/// \author Swati Saha + +#include "Common/CCDB/EventSelectionParams.h" +#include "Common/DataModel/Centrality.h" +#include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/TrackSelectionTables.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; + +namespace o2::aod +{ + +// ===== Event columns ===== +DECLARE_SOA_COLUMN(EventId, eventId, int); +DECLARE_SOA_COLUMN(MyCent, myCent, float); +DECLARE_SOA_COLUMN(Vz, vz, float); +DECLARE_SOA_COLUMN(Ntrk, ntrk, int); +DECLARE_SOA_COLUMN(Npos, npos, int); +DECLARE_SOA_COLUMN(Nneg, nneg, int); + +// ===== Track columns ===== +DECLARE_SOA_COLUMN(Pt, pt, float); +DECLARE_SOA_COLUMN(Eta, eta, float); +DECLARE_SOA_COLUMN(Pid, pid, int); //! charge sign of the track (+1 / -1) +DECLARE_SOA_COLUMN(Eff, eff, float); + +// ===== Tables ===== +DECLARE_SOA_TABLE(EventTable, "AOD", "NCHGEVENT", + EventId, + MyCent, + Vz, + Ntrk, + Npos, + Nneg); + +DECLARE_SOA_TABLE(MYTrackTable, "AOD", "NCHGTRACK", + EventId, + Pt, + Eta, + Pid, + Eff); + +} // namespace o2::aod + +// Order of the highest moment of the net-charge distribution that is stored, <(N+ - N-)^k>, k = 1..NumMoments +static constexpr int NumMoments = 8; +// Highest power of the efficiency weights (1/eff)^i that is stored (i = 1..NumPowers - 1) +static constexpr int NumPowers = 7; + +// ===== Efficiency-corrected quantities ===== +// One entry of the table below: name of the quantity (the profiles are called Prof_ / Prof2D_) and its value in the event. +// fTCP0[i] = sum over tracks of (1/eff)^i for N+ plus N-, fTCP1[i] = same for N+ minus N- (the q_{r,s} of the cumulant formulas) +struct QEntry { + const char* name; + float value; +}; +static constexpr int NumQuantities = 244; +// Upper pT limit of the accepted tracks and particles (GeV/c), as in the proton task +static constexpr float PtUpperLimit = 5.0f; +// Number of track categories of the purity QA (all, primary correct sign, primary wrong sign, primary other species, secondary, fake) +static constexpr int NumCategories = 6; +// Minimum number of edges that define a centrality class +static constexpr std::size_t MinNumEdges = 2; + +inline std::array computeQ(const std::array& fTCP0, const std::array& fTCP1) +{ + return {{ + {"Q11_1", static_cast(fTCP1[1])}, + {"Q11_2", static_cast(std::pow(fTCP1[1], 2))}, + {"Q11_3", static_cast(std::pow(fTCP1[1], 3))}, + {"Q11_4", static_cast(std::pow(fTCP1[1], 4))}, + {"Q21_1", static_cast(fTCP0[1])}, + {"Q22_1", static_cast(fTCP0[2])}, + {"Q31_1", static_cast(fTCP1[1])}, + {"Q32_1", static_cast(fTCP1[2])}, + {"Q33_1", static_cast(fTCP1[3])}, + {"Q41_1", static_cast(fTCP0[1])}, + {"Q42_1", static_cast(fTCP0[2])}, + {"Q43_1", static_cast(fTCP0[3])}, + {"Q44_1", static_cast(fTCP0[4])}, + {"Q21_2", static_cast(std::pow(fTCP0[1], 2))}, + {"Q22_2", static_cast(std::pow(fTCP0[2], 2))}, + {"Q1121_11", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q1121_01", static_cast(fTCP0[1])}, + {"Q1121_10", static_cast(fTCP1[1])}, + {"Q1121_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1121_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[1])}, + {"Q1122_11", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q1122_01", static_cast(fTCP0[2])}, + {"Q1122_10", static_cast(fTCP1[1])}, + {"Q1122_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1122_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[2])}, + {"Q1131_11", static_cast(fTCP1[1] * fTCP1[1])}, + {"Q1131_01", static_cast(fTCP1[1])}, + {"Q1131_10", static_cast(fTCP1[1])}, + {"Q1132_11", static_cast(fTCP1[1] * fTCP1[2])}, + {"Q1132_01", static_cast(fTCP1[2])}, + {"Q1132_10", static_cast(fTCP1[1])}, + {"Q1133_11", static_cast(fTCP1[1] * fTCP1[3])}, + {"Q1133_01", static_cast(fTCP1[3])}, + {"Q1133_10", static_cast(fTCP1[1])}, + {"Q2122_11", static_cast(fTCP0[1] * fTCP0[2])}, + {"Q2122_01", static_cast(fTCP0[2])}, + {"Q2122_10", static_cast(fTCP0[1])}, + {"Q3132_11", static_cast(fTCP1[1] * fTCP1[2])}, + {"Q3132_01", static_cast(fTCP1[2])}, + {"Q3132_10", static_cast(fTCP1[1])}, + {"Q3133_11", static_cast(fTCP1[1] * fTCP1[3])}, + {"Q3133_01", static_cast(fTCP1[3])}, + {"Q3133_10", static_cast(fTCP1[1])}, + {"Q3233_11", static_cast(fTCP1[2] * fTCP1[3])}, + {"Q3233_01", static_cast(fTCP1[3])}, + {"Q3233_10", static_cast(fTCP1[2])}, + {"Q2241_11", static_cast(fTCP0[2] * fTCP0[1])}, + {"Q2241_01", static_cast(fTCP0[1])}, + {"Q2241_10", static_cast(fTCP0[2])}, + {"Q2242_11", static_cast(fTCP0[2] * fTCP0[2])}, + {"Q2242_01", static_cast(fTCP0[2])}, + {"Q2242_10", static_cast(fTCP0[2])}, + {"Q2243_11", static_cast(fTCP0[2] * fTCP0[3])}, + {"Q2243_01", static_cast(fTCP0[3])}, + {"Q2243_10", static_cast(fTCP0[2])}, + {"Q2244_11", static_cast(fTCP0[2] * fTCP0[4])}, + {"Q2244_01", static_cast(fTCP0[4])}, + {"Q2244_10", static_cast(fTCP0[2])}, + {"Q2141_11", static_cast(fTCP0[1] * fTCP0[1])}, + {"Q2141_01", static_cast(fTCP0[1])}, + {"Q2141_10", static_cast(fTCP0[1])}, + {"Q2142_11", static_cast(fTCP0[1] * fTCP0[2])}, + {"Q2142_01", static_cast(fTCP0[2])}, + {"Q2142_10", static_cast(fTCP0[1])}, + {"Q2143_11", static_cast(fTCP0[1] * fTCP0[3])}, + {"Q2143_01", static_cast(fTCP0[3])}, + {"Q2143_10", static_cast(fTCP0[1])}, + {"Q2144_11", static_cast(fTCP0[1] * fTCP0[4])}, + {"Q2144_01", static_cast(fTCP0[4])}, + {"Q2144_10", static_cast(fTCP0[1])}, + {"Q1151_11", static_cast(fTCP1[1] * fTCP1[1])}, + {"Q1151_01", static_cast(fTCP1[1])}, + {"Q1151_10", static_cast(fTCP1[1])}, + {"Q1152_11", static_cast(fTCP1[1] * fTCP1[2])}, + {"Q1152_01", static_cast(fTCP1[2])}, + {"Q1152_10", static_cast(fTCP1[1])}, + {"Q1153_11", static_cast(fTCP1[1] * fTCP1[3])}, + {"Q1153_01", static_cast(fTCP1[3])}, + {"Q1153_10", static_cast(fTCP1[1])}, + {"Q1154_11", static_cast(fTCP1[1] * fTCP1[4])}, + {"Q1154_01", static_cast(fTCP1[4])}, + {"Q1154_10", static_cast(fTCP1[1])}, + {"Q1155_11", static_cast(fTCP1[1] * fTCP1[5])}, + {"Q1155_01", static_cast(fTCP1[5])}, + {"Q1155_10", static_cast(fTCP1[1])}, + {"Q112233_001", static_cast(fTCP1[3])}, + {"Q112233_010", static_cast(fTCP0[2])}, + {"Q112233_100", static_cast(fTCP1[1])}, + {"Q112233_011", static_cast(fTCP0[2] * fTCP1[3])}, + {"Q112233_101", static_cast(fTCP1[1] * fTCP1[3])}, + {"Q112233_110", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q112232_001", static_cast(fTCP1[2])}, + {"Q112232_010", static_cast(fTCP0[2])}, + {"Q112232_100", static_cast(fTCP1[1])}, + {"Q112232_011", static_cast(fTCP0[2] * fTCP1[2])}, + {"Q112232_101", static_cast(fTCP1[1] * fTCP1[2])}, + {"Q112232_110", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q112231_001", static_cast(fTCP1[1])}, + {"Q112231_010", static_cast(fTCP0[2])}, + {"Q112231_100", static_cast(fTCP1[1])}, + {"Q112231_011", static_cast(fTCP0[2] * fTCP1[1])}, + {"Q112231_101", static_cast(fTCP1[1] * fTCP1[1])}, + {"Q112231_110", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q112133_001", static_cast(fTCP1[3])}, + {"Q112133_010", static_cast(fTCP0[1])}, + {"Q112133_100", static_cast(fTCP1[1])}, + {"Q112133_011", static_cast(fTCP0[1] * fTCP1[3])}, + {"Q112133_101", static_cast(fTCP1[1] * fTCP1[3])}, + {"Q112133_110", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q112132_001", static_cast(fTCP1[2])}, + {"Q112132_010", static_cast(fTCP0[1])}, + {"Q112132_100", static_cast(fTCP1[1])}, + {"Q112132_011", static_cast(fTCP0[1] * fTCP1[2])}, + {"Q112132_101", static_cast(fTCP1[1] * fTCP1[2])}, + {"Q112132_110", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q112131_001", static_cast(fTCP1[1])}, + {"Q112131_010", static_cast(fTCP0[1])}, + {"Q112131_100", static_cast(fTCP1[1])}, + {"Q112131_011", static_cast(fTCP0[1] * fTCP1[1])}, + {"Q112131_101", static_cast(fTCP1[1] * fTCP1[1])}, + {"Q112131_110", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q2221_11", static_cast(fTCP0[2] * fTCP0[1])}, + {"Q2221_01", static_cast(fTCP0[1])}, + {"Q2221_10", static_cast(fTCP0[2])}, + {"Q2221_21", static_cast(std::pow(fTCP0[2], 2) * fTCP0[1])}, + {"Q2221_20", static_cast(std::pow(fTCP0[2], 2))}, + {"Q2122_21", static_cast(std::pow(fTCP0[1], 2) * fTCP0[2])}, + {"Q2122_20", static_cast(std::pow(fTCP0[1], 2))}, + {"Q1121_02", static_cast(std::pow(fTCP0[1], 2))}, + {"Q1121_12", static_cast(fTCP1[1] * std::pow(fTCP0[1], 2))}, + {"Q1121_22", static_cast(std::pow(fTCP1[1], 2) * std::pow(fTCP0[1], 2))}, + {"Q1122_02", static_cast(std::pow(fTCP0[2], 2))}, + {"Q1122_12", static_cast(fTCP1[1] * std::pow(fTCP0[2], 2))}, + {"Q1122_22", static_cast(std::pow(fTCP1[1], 2) * std::pow(fTCP0[2], 2))}, + {"Q112221_001", static_cast(fTCP0[1])}, + {"Q112221_010", static_cast(fTCP0[2])}, + {"Q112221_100", static_cast(fTCP1[1])}, + {"Q112221_011", static_cast(fTCP0[2] * fTCP0[1])}, + {"Q112221_101", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q112221_110", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q112221_200", static_cast(std::pow(fTCP1[1], 2))}, + {"Q112221_201", static_cast(std::pow(fTCP1[1], 2) * fTCP0[1])}, + {"Q112221_210", static_cast(std::pow(fTCP1[1], 2) * fTCP0[2])}, + {"Q112221_211", static_cast(std::pow(fTCP1[1], 2) * fTCP0[2] * fTCP0[1])}, + {"Q1131_21", static_cast(std::pow(fTCP1[1], 2) * fTCP1[1])}, + {"Q1131_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1131_31", static_cast(std::pow(fTCP1[1], 3) * fTCP1[1])}, + {"Q1131_30", static_cast(std::pow(fTCP1[1], 3))}, + {"Q1132_21", static_cast(std::pow(fTCP1[1], 2) * fTCP1[2])}, + {"Q1132_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1132_31", static_cast(std::pow(fTCP1[1], 3) * fTCP1[2])}, + {"Q1132_30", static_cast(std::pow(fTCP1[1], 3))}, + {"Q1133_21", static_cast(std::pow(fTCP1[1], 2) * fTCP1[3])}, + {"Q1133_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1133_31", static_cast(std::pow(fTCP1[1], 3) * fTCP1[3])}, + {"Q1133_30", static_cast(std::pow(fTCP1[1], 3))}, + {"Q11_5", static_cast(std::pow(fTCP1[1], 5))}, + {"Q11_6", static_cast(std::pow(fTCP1[1], 6))}, + {"Q1121_30", static_cast(std::pow(fTCP1[1], 3))}, + {"Q1121_31", static_cast(std::pow(fTCP1[1], 3) * fTCP0[1])}, + {"Q1121_40", static_cast(std::pow(fTCP1[1], 4))}, + {"Q1121_41", static_cast(std::pow(fTCP1[1], 4) * fTCP0[1])}, + {"Q1122_30", static_cast(std::pow(fTCP1[1], 3))}, + {"Q1122_31", static_cast(std::pow(fTCP1[1], 3) * fTCP0[2])}, + {"Q1122_40", static_cast(std::pow(fTCP1[1], 4))}, + {"Q1122_41", static_cast(std::pow(fTCP1[1], 4) * fTCP0[2])}, + {"Q2211_11", static_cast(fTCP0[2] * fTCP1[1])}, + {"Q2211_01", static_cast(fTCP1[1])}, + {"Q2211_10", static_cast(fTCP0[2])}, + {"Q2211_20", static_cast(std::pow(fTCP0[2], 2))}, + {"Q2211_21", static_cast(std::pow(fTCP0[2], 2) * fTCP1[1])}, + {"Q2111_11", static_cast(fTCP0[1] * fTCP1[1])}, + {"Q2111_01", static_cast(fTCP1[1])}, + {"Q2111_10", static_cast(fTCP0[1])}, + {"Q2111_20", static_cast(std::pow(fTCP0[1], 2))}, + {"Q2111_21", static_cast(std::pow(fTCP0[1], 2) * fTCP1[1])}, + {"Q112122_001", static_cast(fTCP0[2])}, + {"Q112122_010", static_cast(fTCP0[1])}, + {"Q112122_100", static_cast(fTCP1[1])}, + {"Q112122_011", static_cast(fTCP0[1] * fTCP0[2])}, + {"Q112122_101", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q112122_110", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q1141_11", static_cast(fTCP1[1] * fTCP0[1])}, + {"Q1141_01", static_cast(fTCP0[1])}, + {"Q1141_10", static_cast(fTCP1[1])}, + {"Q1141_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1141_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[1])}, + {"Q1142_11", static_cast(fTCP1[1] * fTCP0[2])}, + {"Q1142_01", static_cast(fTCP0[2])}, + {"Q1142_10", static_cast(fTCP1[1])}, + {"Q1142_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1142_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[2])}, + {"Q1143_11", static_cast(fTCP1[1] * fTCP0[3])}, + {"Q1143_01", static_cast(fTCP0[3])}, + {"Q1143_10", static_cast(fTCP1[1])}, + {"Q1143_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1143_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[3])}, + {"Q1144_11", static_cast(fTCP1[1] * fTCP0[4])}, + {"Q1144_01", static_cast(fTCP0[4])}, + {"Q1144_10", static_cast(fTCP1[1])}, + {"Q1144_20", static_cast(std::pow(fTCP1[1], 2))}, + {"Q1144_21", static_cast(std::pow(fTCP1[1], 2) * fTCP0[4])}, + {"Q2131_11", static_cast(fTCP0[1] * fTCP1[1])}, + {"Q2131_01", static_cast(fTCP1[1])}, + {"Q2131_10", static_cast(fTCP0[1])}, + {"Q2132_11", static_cast(fTCP0[1] * fTCP1[2])}, + {"Q2132_01", static_cast(fTCP1[2])}, + {"Q2132_10", static_cast(fTCP0[1])}, + {"Q2133_11", static_cast(fTCP0[1] * fTCP1[3])}, + {"Q2133_01", static_cast(fTCP1[3])}, + {"Q2133_10", static_cast(fTCP0[1])}, + {"Q2231_11", static_cast(fTCP0[2] * fTCP1[1])}, + {"Q2231_01", static_cast(fTCP1[1])}, + {"Q2231_10", static_cast(fTCP0[2])}, + {"Q2232_11", static_cast(fTCP0[2] * fTCP1[2])}, + {"Q2232_01", static_cast(fTCP1[2])}, + {"Q2232_10", static_cast(fTCP0[2])}, + {"Q2233_11", static_cast(fTCP0[2] * fTCP1[3])}, + {"Q2233_01", static_cast(fTCP1[3])}, + {"Q2233_10", static_cast(fTCP0[2])}, + {"Q51_1", static_cast(fTCP1[1])}, + {"Q52_1", static_cast(fTCP1[2])}, + {"Q53_1", static_cast(fTCP1[3])}, + {"Q54_1", static_cast(fTCP1[4])}, + {"Q55_1", static_cast(fTCP1[5])}, + {"Q21_3", static_cast(std::pow(fTCP0[1], 3))}, + {"Q22_3", static_cast(std::pow(fTCP0[2], 3))}, + {"Q31_2", static_cast(std::pow(fTCP1[1], 2))}, + {"Q32_2", static_cast(std::pow(fTCP1[2], 2))}, + {"Q33_2", static_cast(std::pow(fTCP1[3], 2))}, + {"Q61_1", static_cast(fTCP0[1])}, + {"Q62_1", static_cast(fTCP0[2])}, + {"Q63_1", static_cast(fTCP0[3])}, + {"Q64_1", static_cast(fTCP0[4])}, + {"Q65_1", static_cast(fTCP0[5])}, + {"Q66_1", static_cast(fTCP0[6])}, + {"Q112122_111", static_cast(fTCP1[1] * fTCP0[1] * fTCP0[2])}, + {"Q112131_111", static_cast(fTCP1[1] * fTCP0[1] * fTCP1[1])}, + {"Q112132_111", static_cast(fTCP1[1] * fTCP0[1] * fTCP1[2])}, + {"Q112133_111", static_cast(fTCP1[1] * fTCP0[1] * fTCP1[3])}, + {"Q112231_111", static_cast(fTCP1[1] * fTCP0[2] * fTCP1[1])}, + {"Q112232_111", static_cast(fTCP1[1] * fTCP0[2] * fTCP1[2])}, + {"Q112233_111", static_cast(fTCP1[1] * fTCP0[2] * fTCP1[3])}, + {"Q112221_111", static_cast(fTCP1[1] * fTCP0[2] * fTCP0[1])}, + }}; +} + +struct NetChargeCumulants { + // events + Configurable cfgCutVertex{"cfgCutVertex", 10.0f, "Accepted z-vertex range"}; + // MC + Configurable cfgIsMC{"cfgIsMC", true, "Run MC"}; + // tracks + Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; + Configurable cfgCutPtUpper{"cfgCutPtUpper", 3.0f, "Higher pT cut"}; + Configurable cfgCutEtaMin{"cfgCutEtaMin", -0.8f, "Lower edge of the eta window"}; + Configurable cfgCutEtaMax{"cfgCutEtaMax", 0.8f, "Upper edge of the eta window"}; + Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; + Configurable cfgCutDCAxy{"cfgCutDCAxy", 2.0f, "DCAxy range for tracks"}; + Configurable cfgCutDCAz{"cfgCutDCAz", 2.0f, "DCAz range for tracks"}; + Configurable cfgITScluster{"cfgITScluster", 4, "Minimum Number of ITS cluster"}; + // ITS-only tracks (cfgTrackType = 0): the DCA selection is the same as in heavyionMultiplicity.cxx + Configurable cfgItsDcaStandardCuts{"cfgItsDcaStandardCuts", true, "ITS-only tracks: standard DCA cuts, kDCAxy track flag and |DCAz| <= cfgItsDcaZ"}; + Configurable cfgItsDcaZ{"cfgItsDcaZ", 0.2f, "ITS-only tracks: custom DCAz cut of the standard DCA cuts (cm)"}; + Configurable cfgItsDcaCustomCuts{"cfgItsDcaCustomCuts", false, "ITS-only tracks: custom pT-dependent DCA cuts |DCA| <= P0 + P1 / pT^P2"}; + Configurable cfgItsDcazP0{"cfgItsDcazP0", 1.0f, "ITS-only tracks: dcaz parameter0"}; + Configurable cfgItsDcazP1{"cfgItsDcazP1", 1.0f, "ITS-only tracks: dcaz parameter1"}; + Configurable cfgItsDcazP2{"cfgItsDcazP2", 1.0f, "ITS-only tracks: dcaz parameter2"}; + Configurable cfgItsDcaxyP0{"cfgItsDcaxyP0", 1.0f, "ITS-only tracks: dcaxy parameter0"}; + Configurable cfgItsDcaxyP1{"cfgItsDcaxyP1", 1.0f, "ITS-only tracks: dcaxy parameter1"}; + Configurable cfgItsDcaxyP2{"cfgItsDcaxyP2", 1.0f, "ITS-only tracks: dcaxy parameter2"}; + Configurable cfgTrackType{"cfgTrackType", 0, "Track type: 0 = ITS-only tracks, 1 = ITS-TPC (global) tracks"}; + // used only for ITS-TPC (global) tracks, cfgTrackType = 1 + Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl (ITS-TPC tracks)"}; + Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster (ITS-TPC tracks)"}; + Configurable cfgTPCcrossedRowsOverFindable{"cfgTPCcrossedRowsOverFindable", 0.8, "Min crossedRows/findable ratio (ITS-TPC tracks)"}; + Configurable cfgUseTPCratioCut{"cfgUseTPCratioCut", true, "Apply crossedRows/findable cut"}; + Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows (ITS-TPC tracks)"}; + Configurable cfgUseTPCcrossedRowsCut{"cfgUseTPCcrossedRowsCut", true, "Apply crossed rows cut"}; + Configurable cfgUseTPCclusterCut{"cfgUseTPCclusterCut", true, "Apply TPC cluster cut"}; + Configurable cfgIfMandatoryTOF{"cfgIfMandatoryTOF", true, "Mandatory TOF requirement to remove pileup (ITS-TPC tracks)"}; + + // Calculation of cumulants central/error + Configurable cfgNSubsample{"cfgNSubsample", 10, "Number of subsamples for ERR"}; + Configurable cfgIsCalculateCentral{"cfgIsCalculateCentral", true, "Calculate Central value"}; + Configurable cfgIsCalculateError{"cfgIsCalculateError", false, "Calculate Error"}; + + // Efficiencies (used if cfgLoadEff = false): pT bins and efficiency per bin, one value per bin (number of edges - 1) + Configurable> cfgPtBins{"cfgPtBins", {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0}, "Pt Bins for Efficiency of charged particles"}; + Configurable> cfgPositiveEff{"cfgPositiveEff", {0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9}, "Efficiency of positive particles"}; + Configurable> cfgNegativeEff{"cfgNegativeEff", {0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9}, "Efficiency of negative particles"}; + + Configurable cfgLoadEff{"cfgLoadEff", true, "Load efficiency from file"}; + Configurable cfgEvSelkNoSameBunchPileup{"cfgEvSelkNoSameBunchPileup", true, "Pileup removal"}; + Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; + Configurable cfgEvSelkIsVertexTOFmatched{"cfgEvSelkIsVertexTOFmatched", true, "If matched with TOF, for pileup"}; + Configurable cfgEvSelkIsGoodZvtxFT0vsPV{"cfgEvSelkIsGoodZvtxFT0vsPV", false, "Apply kIsGoodZvtxFT0vsPV event selection"}; + ConfigurableAxis cfgEtaBins{"cfgEtaBins", {16, -0.8, 0.8}, "eta axis of the histograms (the pT-eta maps and the purity QA), set it together with cfgCutEtaMin/Max"}; + // binomial response test (processMCBinomial) + Configurable cfgBinomSplitMode{"cfgBinomSplitMode", 0, "Split MC collisions (more than one selected reco collision): 0 = use the reco collision with the most accepted tracks, 1 = reject the MC collision"}; + Configurable> cfgBinomCentEdges{"cfgBinomCentEdges", {0.f, 100.f}, "Edges of the FT0C centrality classes of the binomial test, e.g. 0, 5, 10, 20, 30, 40, 50, 60, 70, 80 (one set of histograms per class; the default is one class, integrated)"}; + ConfigurableAxis cfgBinomMultBins{"cfgBinomMultBins", {1001, -0.5, 1000.5}, "generated/reconstructed positive or negative particle number axis of the binomial test"}; + ConfigurableAxis cfgBinomMultBins2D{"cfgBinomMultBins2D", {100, 0., 1000.}, "coarser generated particle number axis for the 2D profiles of the binomial test"}; + ConfigurableAxis cfgBinomNetBins{"cfgBinomNetBins", {801, -400.5, 400.5}, "net-charge axis of the binomial test"}; + ConfigurableAxis cfgCentralityBins{"cfgCentralityBins", {90, 0., 90.}, "Centrality/Multiplicity percentile bining"}; + // axes of the multiplicity histograms (the proton ones, 20 bins, are far too small for charged particles) + ConfigurableAxis cfgNetChargeBins{"cfgNetChargeBins", {801, -400.5, 400.5}, "net-charge number axis"}; + ConfigurableAxis cfgChargeBins{"cfgChargeBins", {2001, -0.5, 2000.5}, "positive/negative particle number axis"}; + ConfigurableAxis cfgNTracksBins{"cfgNTracksBins", {1000, 0., 4000.}, "number of accepted tracks axis"}; + Configurable cfgUsePtDepDCAxy{"cfgUsePtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + Configurable cfgUsePtDepDCAz{"cfgUsePtDepDCAz", true, "Use pt-dependent DCAz cut"}; + Configurable cfgDCAxyFunc{"cfgDCAxyFunc", "(0.0010+0.0080/(x^0.73))", "DCAxy function"}; + Configurable cfgDCAzFunc{"cfgDCAzFunc", "(0.0020+0.0100/(x^0.70))", "DCAz function"}; + // Connect to ccdb + Service ccdb; + Configurable ccdbNoLaterThan{"ccdbNoLaterThan", std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"}; + Configurable ccdbUrl{"ccdbUrl", "https://alice-ccdb.cern.ch", "url of the ccdb repository"}; + // Path for the object must be a rootfile containing TList with the TH2F hRatio2DEtaVsPtPositive and hRatio2DEtaVsPtNegative (eff(pT, eta) = hrec2DEtaVsPt.. / hgen2DEtaVsPt..) + Configurable ccdbPath{"ccdbPath", "Users/s/swati/EtavsPtEfficiency_NetCharge", "CCDB path to ccdb object containing eff(pt, eta) in 2D hist"}; + + Service pdgService{}; // Particle data group service (charge of the generated particles) + + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + + Produces eventTable; + Produces trackTable; + + int eventCounter = 0; + int eventId = 0; + + // event variables + int nTrkEvent = 0; + int nPosEvent = 0; + int nNegEvent = 0; + + float centEvent = 0; + float vzEvent = 0; + + // track variables + float ptTrack = 0; + float etaTrack = 0; + int pidTrack = 0; + float effTrack = 0; + + TRandom3* fRndm = new TRandom3(0); + + // Eff histograms 2d: eff(pT, eta) + TH2F* hRatio2DEtaVsPtPositive = nullptr; + TH2F* hRatio2DEtaVsPtNegative = nullptr; + TF1* fPtDepDCAxy = nullptr; + TF1* fPtDepDCAz = nullptr; + + // Profiles of the moments <(N+ - N-)^k>, index = k - 1 (and of the efficiency-corrected quantities, index in the order of computeQ) + std::vector> profMu, profQ, genProfMu; + std::vector> prof2DMu, prof2DQ, genProf2DMu; + + // Filter command for rec (data)*********** + Filter collisionFilter = nabs(aod::collision::posZ) < cfgCutVertex; + Filter trackFilter = (aod::track::eta > cfgCutEtaMin) && (aod::track::eta < cfgCutEtaMax) && (aod::track::pt > cfgCutPtLower) && (aod::track::pt < PtUpperLimit) && (aod::track::itsChi2NCl < cfgCutItsChi2NCl) && (nabs(aod::track::dcaZ) < cfgCutDCAz) && (nabs(aod::track::dcaXY) < cfgCutDCAxy); + + // filtering collisions and tracks for real data*********** + using AodCollisions = soa::Filtered>; + using AodTracks = soa::Filtered>; + + // filtering collisions and tracks for MC rec data*********** + using MyMCRecCollisions = soa::Filtered>; + using MyMCRecCollision = MyMCRecCollisions::iterator; + using MyMCTracks = soa::Filtered>; + using EventCandidatesMC = soa::Join; + + // Registration of the profiles of the moments and of the efficiency-corrected quantities + template + std::shared_ptr addProfile(const std::string& name, const AxisSpec& centAxis) + { + return std::get>(histos.add(name.c_str(), "", {HistType::kTProfile, {centAxis}})); + } + template + std::shared_ptr addProfile2D(const std::string& name, const AxisSpec& centAxis, const AxisSpec& subsampleAxis) + { + return std::get>(histos.add(name.c_str(), "", {HistType::kTProfile2D, {centAxis, subsampleAxis}})); + } + + // Equivalent of the AliRoot task UserCreateOutputObjects + void init(o2::framework::InitContext&) + { + // Loading efficiency histograms from ccdb + if (cfgLoadEff) { + + // Accessing eff histograms + ccdb->setURL(ccdbUrl.value); + // Enabling object caching, otherwise each call goes to the CCDB server + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + ccdb->setCreatedNotAfter(ccdbNoLaterThan.value); + LOGF(info, "Getting object %s", ccdbPath.value.data()); + TList* lst = ccdb->getForTimeStamp(ccdbPath.value, ccdbNoLaterThan.value); + if (!lst) { + LOGF(fatal, "Could not get the efficiency object %s from CCDB", ccdbPath.value.data()); + } + hRatio2DEtaVsPtPositive = dynamic_cast(lst->FindObject("hRatio2DEtaVsPtPositive")); + hRatio2DEtaVsPtNegative = dynamic_cast(lst->FindObject("hRatio2DEtaVsPtNegative")); + if (!hRatio2DEtaVsPtPositive || !hRatio2DEtaVsPtNegative) { + LOGF(fatal, "Could not get efficiency histograms hRatio2DEtaVsPtPositive/Negative from %s ---------> check", ccdbPath.value.data()); + } + } + + // Define your axes + // Constant bin width axis + AxisSpec vtxZAxis = {100, -20, 20}; + // Variable bin width axis + std::vector ptBinning = {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0}; + AxisSpec ptAxis = {ptBinning, "#it{p}_{T} (GeV/#it{c})"}; + const AxisSpec etaAxis{cfgEtaBins, "#it{#eta}"}; + const AxisSpec centAxis{cfgCentralityBins, "Multiplicity percentile from FT0C (%)"}; + const AxisSpec netChargeAxis{cfgNetChargeBins, "net-charge number"}; + const AxisSpec positiveAxis{cfgChargeBins, "positive particle number"}; + const AxisSpec negativeAxis{cfgChargeBins, "negative particle number"}; + const AxisSpec nTracksAxis{cfgNTracksBins, "N tracks"}; + + auto noSubsample = static_cast(cfgNSubsample); + float maxSubsample = 1.0 * noSubsample; + AxisSpec subsampleAxis = {noSubsample, 0.0, maxSubsample, "subsample no."}; + + // histograms for events + histos.add("hZvtx_after", "Vertex dist. after event selection;Z (cm)", kTH1F, {vtxZAxis}); + histos.add("hCentrec", "MCRec Multiplicity percentile from FT0C (%)", kTH1F, {{100, 0.0, 100.0}}); + // tracks Rec level histograms + // Purity QA (MC only): all accepted reconstructed tracks with the same selection as in data, classified by origin + const AxisSpec categoryAxis{NumCategories, -0.5, 5.5, "track category"}; + auto hPurityPt = std::get>(histos.add("hPurityVsPt", "Accepted tracks by category vs pT;#it{p}_{T} (GeV/#it{c});category", kTH2F, {ptAxis, categoryAxis})); + auto hPurityEta = std::get>(histos.add("hPurityVsEta", "Accepted tracks by category vs #eta;#it{#eta};category", kTH2F, {etaAxis, categoryAxis})); + auto hPurityCent = std::get>(histos.add("hPurityVsCent", "Accepted tracks by category vs centrality;centrality (%);category", kTH2F, {centAxis, categoryAxis})); + const char* categoryLabels[NumCategories] = {"all", "primary, correct sign", "primary, wrong sign", "primary, other species", "secondary", "fake"}; + for (int i = 0; i < NumCategories; ++i) { + hPurityPt->GetYaxis()->SetBinLabel(i + 1, categoryLabels[i]); + hPurityEta->GetYaxis()->SetBinLabel(i + 1, categoryLabels[i]); + hPurityCent->GetYaxis()->SetBinLabel(i + 1, categoryLabels[i]); + } + + histos.add("hTPCcrossedRows", "TPC crossed rows;N crossed rows;Counts", kTH1F, {{160, 0, 160}}); + histos.add("hTPCclusters", "TPC clusters;N clusters;Counts", kTH1F, {{160, 0, 160}}); + histos.add("hTPCclusters_afterCrossedRows", "TPC clusters after crossed rows cut;N clusters;Counts", kTH1F, {{160, 0, 160}}); + + histos.add("hrecPtAll", "Reconstructed All particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPtPositive", "Reconstructed positive particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPtNegative", "Reconstructed negative particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPhiAll", "Reconstructed All particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hrecPhiPositive", "Reconstructed positive particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hrecPhiNegative", "Reconstructed negative particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hrecEtaAll", "Reconstructed All particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hrecEtaPositive", "Reconstructed positive particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hrecEtaNegative", "Reconstructed negative particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hrecDcaXYAll", "Reconstructed All particles;DCA_{xy} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecDcaXYPositive", "Reconstructed positive particles;DCA_{xy} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecDcaXYNegative", "Reconstructed negative particles;DCA_{xy} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecDcaZAll", "Reconstructed All particles;DCA_{z} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecDcaZPositive", "Reconstructed positive particles;DCA_{z} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecDcaZNegative", "Reconstructed negative particles;DCA_{z} (in cm)", kTH1F, {{400, -2.0, 2.0}}); + histos.add("hrecPtDistPositiveVsCentrality", "Reconstructed positive particle number vs centrality in 2D", kTH2F, {ptAxis, centAxis}); + histos.add("hrecPtDistNegativeVsCentrality", "Reconstructed negative particle number vs centrality in 2D", kTH2F, {ptAxis, centAxis}); + histos.add("hrecNetChargeVsCentrality", "Reconstructed net-charge number vs centrality in 2D", kTH2F, {netChargeAxis, centAxis}); + histos.add("hrecPositiveVsCentrality", "Reconstructed positive particle number vs centrality in 2D", kTH2F, {positiveAxis, centAxis}); + histos.add("hrecNegativeVsCentrality", "Reconstructed negative particle number vs centrality in 2D", kTH2F, {negativeAxis, centAxis}); + histos.add("hrecProfileTotalCharge", "Reconstructed total charged particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hrecProfilePositive", "Reconstructed positive particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hrecProfileNegative", "Reconstructed negative particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hCorrProfileTotalCharge", "Eff. Corrected total charged particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hCorrProfilePositive", "Eff. Corrected positive particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hCorrProfileNegative", "Eff. Corrected negative particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hrec2DEtaVsPtPositive", "2D hist of Reconstructed positive particles y: eta vs. x: pT", kTH2F, {ptAxis, etaAxis}); + histos.add("hrec2DEtaVsPtNegative", "2D hist of Reconstructed negative particles y: eta vs. x: pT", kTH2F, {ptAxis, etaAxis}); + histos.add("hgen2DEtaVsPtPositive", "2D hist of Generated positive particles y: eta vs. x: pT", kTH2F, {ptAxis, etaAxis}); + histos.add("hgen2DEtaVsPtNegative", "2D hist of Generated negative particles y: eta vs. x: pT", kTH2F, {ptAxis, etaAxis}); + histos.add("hNTracksVsCent", "N_{ch} vs FT0C centrality;Centrality (%);N tracks", kTH2F, {centAxis, nTracksAxis}); + histos.add("hDCAxyVsPt_before", + "DCAxy vs pT (before cut);pT;DCAxy", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + histos.add("hDCAzVsPt_before", + "DCAz vs pT (before cut);pT;DCAz", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + histos.add("hDCAxyVsPt_after", + "DCAxy vs pT (after cut);pT;DCAxy", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + histos.add("hDCAzVsPt_after", + "DCAz vs pT (after cut);pT;DCAz", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + histos.add("hDCAxyVsPt_afterSel", + "DCAxy vs pT after DCA+track selection;pT;DCAxy", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + histos.add("hDCAzVsPt_afterSel", + "DCAz vs pT after DCA+track selection;pT;DCAz", + kTH2F, + {{100, 0.5, 1.5}, {200, -0.3, 0.3}}); + + // Profiles of the moments (uncorrected) and of the efficiency-corrected quantities + const auto qNames = computeQ(std::array{}, std::array{}); + if (cfgIsCalculateCentral) { + for (int k = 1; k <= NumMoments; k++) { + profMu.push_back(addProfile(Form("Prof_mu%d_netcharge", k), centAxis)); + } + // eff. corrected + for (const auto& q : qNames) { + profQ.push_back(addProfile(std::string("Prof_") + q.name, centAxis)); + } + } + + if (cfgIsCalculateError) { + for (int k = 1; k <= NumMoments; k++) { + prof2DMu.push_back(addProfile2D(Form("Prof2D_mu%d_netcharge", k), centAxis, subsampleAxis)); + } + // eff. corrected + for (const auto& q : qNames) { + prof2DQ.push_back(addProfile2D(std::string("Prof2D_") + q.name, centAxis, subsampleAxis)); + } + } + + if (doprocessMCBinomial) { + // Binomial response test: generated number (per charge sign) against the reconstructed one, event by event, + // for each centrality class given by cfgBinomCentEdges + const AxisSpec nMultAxis{cfgBinomMultBins, "number of particles"}; + const AxisSpec nMultAxis2D{cfgBinomMultBins2D, "number of particles"}; + const AxisSpec nNetAxis{cfgBinomNetBins, "net-charge number"}; + histos.add("hBinomNRecoCollisions", "Selected reco collisions per MC collision;N reco collisions;Counts", kTH1F, {{11, -0.5, 10.5}}); + const std::vector& edges = cfgBinomCentEdges.value; + if (edges.size() < MinNumEdges) { + LOGF(fatal, "cfgBinomCentEdges needs at least two edges"); + } + for (std::size_t i = 0; i + 1 < edges.size(); ++i) { + TString suffix = TString::Format("_cent%g_%g", edges[i], edges[i + 1]); + suffix.ReplaceAll(".", "p"); + const TString title = TString::Format(" (FT0C %g-%g%%)", edges[i], edges[i + 1]); + auto name = [&suffix](const char* base) { return std::string(base) + suffix.Data(); }; + auto titleOf = [&title](const char* base) { return std::string(base) + title.Data(); }; + BinomialHistos h; + h.genVsRecPos = std::get>(histos.add(name("hBinomGenVsRecPositive").c_str(), (titleOf("Positive particles;N_{gen};N_{rec}")).c_str(), kTH2F, {nMultAxis, nMultAxis})); + h.genVsRecNeg = std::get>(histos.add(name("hBinomGenVsRecNegative").c_str(), (titleOf("Negative particles;N_{gen};N_{rec}")).c_str(), kTH2F, {nMultAxis, nMultAxis})); + h.genVsRecNet = std::get>(histos.add(name("hBinomGenVsRecNetCharge").c_str(), (titleOf("Net charge;N_{gen}^{+}-N_{gen}^{-};N_{rec}^{+}-N_{rec}^{-}")).c_str(), kTH2F, {nNetAxis, nNetAxis})); + // profiles versus N_gen: , (variance = - ^2), expected , + h.recPos = std::get>(histos.add(name("hBinomProfRecPositive").c_str(), " vs N_{gen}^{+};N_{gen}^{+};", kTProfile, {nMultAxis})); + h.recSqPos = std::get>(histos.add(name("hBinomProfRecSqPositive").c_str(), "<(N_{rec}^{+})^{2}> vs N_{gen}^{+};N_{gen}^{+};<(N_{rec}^{+})^{2}>", kTProfile, {nMultAxis})); + h.expMeanPos = std::get>(histos.add(name("hBinomProfExpMeanPositive").c_str(), "<#Sigma #epsilon> vs N_{gen}^{+};N_{gen}^{+};<#Sigma #epsilon>", kTProfile, {nMultAxis})); + h.expVarPos = std::get>(histos.add(name("hBinomProfExpVarPositive").c_str(), "<#Sigma #epsilon(1-#epsilon)> vs N_{gen}^{+};N_{gen}^{+};<#Sigma #epsilon(1-#epsilon)>", kTProfile, {nMultAxis})); + h.recNeg = std::get>(histos.add(name("hBinomProfRecNegative").c_str(), " vs N_{gen}^{-};N_{gen}^{-};", kTProfile, {nMultAxis})); + h.recSqNeg = std::get>(histos.add(name("hBinomProfRecSqNegative").c_str(), "<(N_{rec}^{-})^{2}> vs N_{gen}^{-};N_{gen}^{-};<(N_{rec}^{-})^{2}>", kTProfile, {nMultAxis})); + h.expMeanNeg = std::get>(histos.add(name("hBinomProfExpMeanNegative").c_str(), "<#Sigma #epsilon> vs N_{gen}^{-};N_{gen}^{-};<#Sigma #epsilon>", kTProfile, {nMultAxis})); + h.expVarNeg = std::get>(histos.add(name("hBinomProfExpVarNegative").c_str(), "<#Sigma #epsilon(1-#epsilon)> vs N_{gen}^{-};N_{gen}^{-};<#Sigma #epsilon(1-#epsilon)>", kTProfile, {nMultAxis})); + // covariance of N_rec^+ and N_rec^- at fixed (N_gen^+, N_gen^-): cov = - (zero for independent detection) + h.recPosNeg2D = std::get>(histos.add(name("hBinomProfRecPosNeg2D").c_str(), ";N_{gen}^{+};N_{gen}^{-}", kTProfile2D, {nMultAxis2D, nMultAxis2D})); + h.recPos2D = std::get>(histos.add(name("hBinomProfRecPos2D").c_str(), ";N_{gen}^{+};N_{gen}^{-}", kTProfile2D, {nMultAxis2D, nMultAxis2D})); + h.recNeg2D = std::get>(histos.add(name("hBinomProfRecNeg2D").c_str(), ";N_{gen}^{+};N_{gen}^{-}", kTProfile2D, {nMultAxis2D, nMultAxis2D})); + binomialHistos.push_back(h); + } + } + + if (cfgIsMC) { + // MC event counts + histos.add("hMC", "MC Event statistics", kTH1F, {{10, 0.0f, 10.0f}}); + histos.add("hCentgen", "MCGen Multiplicity percentile from FT0C (%)", kTH1F, {{100, 0.0, 100.0}}); + // tracks Gen level histograms + histos.add("hgenPtAll", "Generated All particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hgenPtPositive", "Generated positive particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hgenPtNegative", "Generated negative particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPartPtAll", "Reconstructed All particles filled mcparticle pt;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPartPtPositive", "Reconstructed positive particles filled mcparticle pt;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecPartPtNegative", "Reconstructed negative particles filled mcparticle pt;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hgenPhiAll", "Generated All particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hgenPhiPositive", "Generated positive particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hgenPhiNegative", "Generated negative particles;#phi", kTH1F, {{100, 0., 7.}}); + histos.add("hgenEtaAll", "Generated All particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hgenEtaPositive", "Generated positive particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hgenEtaNegative", "Generated negative particles;#eta", kTH1F, {{100, -2.01, 2.01}}); + histos.add("hgenPtDistPositiveVsCentrality", "Generated positive particle number vs centrality in 2D", kTH2F, {ptAxis, centAxis}); + histos.add("hgenPtDistNegativeVsCentrality", "Generated negative particle number vs centrality in 2D", kTH2F, {ptAxis, centAxis}); + histos.add("hrecTruePtPositive", "Reconstructed pdgcode verified positive particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hrecTruePtNegative", "Reconstructed pdgcode verified negative particles;#it{p}_{T} (GeV/#it{c})", kTH1F, {ptAxis}); + histos.add("hgenNetChargeVsCentrality", "Generated net-charge number vs centrality in 2D", kTH2F, {netChargeAxis, centAxis}); + histos.add("hgenPositiveVsCentrality", "Generated positive particle number vs centrality in 2D", kTH2F, {positiveAxis, centAxis}); + histos.add("hgenNegativeVsCentrality", "Generated negative particle number vs centrality in 2D", kTH2F, {negativeAxis, centAxis}); + histos.add("hgenProfileTotalCharge", "Generated total charged particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hgenProfilePositive", "Generated positive particle number vs. centrality", kTProfile, {centAxis}); + histos.add("hgenProfileNegative", "Generated negative particle number vs. centrality", kTProfile, {centAxis}); + + if (cfgIsCalculateCentral) { + for (int k = 1; k <= NumMoments; k++) { + genProfMu.push_back(addProfile(Form("GenProf_mu%d_netcharge", k), centAxis)); + } + } + + if (cfgIsCalculateError) { + for (int k = 1; k <= NumMoments; k++) { + genProf2DMu.push_back(addProfile2D(Form("GenProf2D_mu%d_netcharge", k), centAxis, subsampleAxis)); + } + } + } + if (cfgUsePtDepDCAxy) { + fPtDepDCAxy = new TF1("ptDepDCAxy", cfgDCAxyFunc->c_str(), 0.001, 10.0); + } + + if (cfgUsePtDepDCAz) { + fPtDepDCAz = new TF1("ptDepDCAz", cfgDCAzFunc->c_str(), 0.001, 10.0); + } + + } // end init() + + // =================================================================================================== + // Selections shared by the MC and data processing + // =================================================================================================== + + // Event selection. applyGoodZvtxFT0vsPV = false reproduces the generated-level selection of the proton task (kIsGoodZvtxFT0vsPV not applied) + template + bool isEventSelected(const TCollision& coll, const bool applyGoodZvtxFT0vsPV) + { + if (!coll.sel8()) { + return false; + } + if (cfgUseGoodITSLayerAllCut && !(coll.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll))) { + return false; + } + if (cfgEvSelkNoSameBunchPileup && !(coll.selection_bit(o2::aod::evsel::kNoSameBunchPileup))) { + return false; + } + if (cfgEvSelkIsVertexTOFmatched && !(coll.selection_bit(o2::aod::evsel::kIsVertexTOFmatched))) { + return false; + } + if (applyGoodZvtxFT0vsPV && cfgEvSelkIsGoodZvtxFT0vsPV && !(coll.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV))) { + return false; + } + return true; + } + + // Track type selection, identical for MC and data. The common cuts (eta, pT, ITS chi2, DCA) are in the track filter + // cfgTrackType = 0 : ITS-only tracks, ITS quality selection, with ITS information and without TPC information + // cfgTrackType = 1 : ITS-TPC tracks, global track (or global SDD) with TPC chi2 cut and PV contributor + template + bool passTrackType(const T& track) + { + if (cfgTrackType == 0) { + // ITS quality track (flags kTrackType, kITSNCls, kITSChi2NDF, kITSRefit, kITSHits), with ITS information, no TPC information + // and at least cfgITScluster ITS clusters. The DCA selection is in passDcaCuts + if (!track.isQualityTrackITS() || !track.hasITS() || track.hasTPC()) { + return false; + } + if (track.itsNCls() < cfgITScluster) { + return false; + } + return true; + } + if (!(track.isGlobalTrack() || track.isGlobalTrackSDD())) { + return false; + } + if (!(track.tpcChi2NCl() < cfgCutTpcChi2NCl)) { + return false; + } + if (!track.isPVContributor()) { //! track check as used in data + return false; + } + return true; + } + + // TPC crossed rows / clusters / ratio cuts, only for ITS-TPC tracks (always true for ITS-only tracks) + template + bool passTpcQualityCuts(const T& track, const bool fillHistos = true) + { + if (cfgTrackType == 0) { + return true; + } + if (fillHistos) { + histos.fill(HIST("hTPCcrossedRows"), track.tpcNClsCrossedRows()); + histos.fill(HIST("hTPCclusters"), track.tpcNClsFound()); + } + if (cfgUseTPCcrossedRowsCut && track.tpcNClsCrossedRows() < cfgTPCnCrossedRows) { + return false; + } + if (fillHistos) { + histos.fill(HIST("hTPCclusters_afterCrossedRows"), track.tpcNClsFound()); + } + if (cfgUseTPCclusterCut && track.tpcNClsFound() < cfgTPCcluster) { + return false; + } + if (cfgUseTPCratioCut) { + const float crossedRows = track.tpcNClsCrossedRows(); + const float findable = track.tpcNClsFindable(); + if (findable > 0 && (crossedRows / findable) < cfgTPCcrossedRowsOverFindable) { + return false; + } + } + return true; + } + + // Mandatory TOF to remove pileup, only for ITS-TPC tracks (always true for ITS-only tracks) + template + bool passTofCut(const T& track) + { + if (cfgTrackType == 0) { + return true; + } + return !cfgIfMandatoryTOF || track.hasTOF(); + } + + // pT-dependent DCA cuts + template + bool passDcaCuts(const T& track) + { + if (cfgTrackType == 0) { + // ITS-only tracks: same DCA selection as heavyionMultiplicity.cxx + if (cfgItsDcaStandardCuts) { + if (!(std::abs(track.dcaZ()) <= cfgItsDcaZ) || !o2::aod::track::TrackSelectionFlags::checkFlag(track.trackCutFlag(), o2::aod::track::TrackSelectionFlags::kDCAxy)) { + return false; + } + } + if (cfgItsDcaCustomCuts) { + if (std::abs(track.dcaXY()) > cfgItsDcaxyP0 + cfgItsDcaxyP1 / std::pow(track.pt(), cfgItsDcaxyP2)) { + return false; + } + if (std::abs(track.dcaZ()) > cfgItsDcazP0 + cfgItsDcazP1 / std::pow(track.pt(), cfgItsDcazP2)) { + return false; + } + } + return true; + } + if (cfgUsePtDepDCAxy && !(std::abs(track.dcaXY()) < fPtDepDCAxy->Eval(track.pt()))) { + return false; + } + if (cfgUsePtDepDCAz && !(std::abs(track.dcaZ()) < fPtDepDCAz->Eval(track.pt()))) { + return false; + } + return true; + } + + // Purity QA (MC): classify an accepted reconstructed track, using the same selection as for data (reconstructed quantities) + // category 0: all accepted tracks, 1: physical primary with correct charge sign, 2: physical primary with wrong charge sign, + // 3: physical primary of a charged species that is not generated/counted (not e, mu, pi, K, p), 4: secondary, 5: fake (no MC particle or MC collision) + // purity = category 1 / category 0, wrong-sign fraction = category 2 / category 0 + template + void fillPurityQA(const T& track, const float cent) + { + if (!passTrackType(track)) { + return; + } + if ((track.pt() < cfgCutPtLower) || (track.pt() > PtUpperLimit) || (track.eta() < cfgCutEtaMin) || (track.eta() > cfgCutEtaMax)) { + return; + } + if (!passTpcQualityCuts(track, false) || !passDcaCuts(track) || !passTofCut(track)) { + return; + } + int category = 5; + if (track.has_mcParticle()) { + const auto particle = track.mcParticle(); + if (particle.has_mcCollision()) { + if (!particle.isPhysicalPrimary()) { + category = 4; + } else { + const int mcCharge = getMcCharge(particle.pdgCode()); + if (mcCharge == 0) { + category = 3; + } else if ((mcCharge > 0) == (track.sign() > 0)) { + category = 1; + } else { + category = 2; + } + } + } + } + histos.fill(HIST("hPurityVsPt"), track.pt(), 0); + histos.fill(HIST("hPurityVsPt"), track.pt(), category); + histos.fill(HIST("hPurityVsEta"), track.eta(), 0); + histos.fill(HIST("hPurityVsEta"), track.eta(), category); + histos.fill(HIST("hPurityVsCent"), cent, 0); + histos.fill(HIST("hPurityVsCent"), cent, category); + } + + // Generated primaries of a MC collision, same selection as in processMCGen, with the expected mean and variance of the + // reconstructed number for a binomial (independent detection with the efficiency of each particle) response + // Histograms of the binomial response test of one centrality class + struct BinomialHistos { + std::shared_ptr genVsRecPos, genVsRecNeg, genVsRecNet; + std::shared_ptr recPos, recSqPos, expMeanPos, expVarPos, recNeg, recSqNeg, expMeanNeg, expVarNeg; + std::shared_ptr recPosNeg2D, recPos2D, recNeg2D; + }; + std::vector binomialHistos; // one per centrality class + + struct BinomialGenCounts { + float nPos = 0.0; + float nNeg = 0.0; + float expMeanPos = 0.0; // sum of eff + float expMeanNeg = 0.0; + float expVarPos = 0.0; // sum of eff * (1 - eff) + float expVarNeg = 0.0; + }; + + template + BinomialGenCounts countGeneratedBinomial(const TParticles& mcParticles) + { + BinomialGenCounts counts; + for (const auto& mcParticle : mcParticles) { + if (!mcParticle.has_mcCollision() || !mcParticle.isPhysicalPrimary()) { + continue; + } + if (!((mcParticle.pt() > cfgCutPtLower) && (mcParticle.pt() < PtUpperLimit) && (mcParticle.eta() > cfgCutEtaMin) && (mcParticle.eta() < cfgCutEtaMax))) { + continue; + } + if (!(mcParticle.pt() < cfgCutPtUpper)) { + continue; + } + const int charge = getMcCharge(mcParticle.pdgCode()); + if (charge == 0) { + continue; + } + const float eff = getEfficiencyFromKinematics(mcParticle.pt(), mcParticle.eta(), charge); + if (charge > 0) { + counts.nPos += 1.0; + counts.expMeanPos += eff; + counts.expVarPos += eff * (1.0 - eff); + } else { + counts.nNeg += 1.0; + counts.expMeanNeg += eff; + counts.expVarNeg += eff * (1.0 - eff); + } + } + return counts; + } + + // Accepted reconstructed primaries of a reco collision: same selection as the counting in processMCRec (keep them in sync) + template + std::pair countReconstructedBinomial(const TTracks& tracks) + { + float nPos = 0.0; + float nNeg = 0.0; + for (const auto& track : tracks) { + if (!track.has_collision() || !track.has_mcParticle()) { + continue; + } + if (!passTrackType(track)) { + continue; + } + auto particle = track.mcParticle(); + if (!particle.has_mcCollision()) { + continue; + } + if ((particle.pt() < cfgCutPtLower) || (particle.pt() > PtUpperLimit) || (particle.eta() < cfgCutEtaMin) || (particle.eta() > cfgCutEtaMax)) { + continue; + } + if (!passTpcQualityCuts(track, false)) { + continue; + } + if (!particle.isPhysicalPrimary() || !passDcaCuts(track) || !passTofCut(track)) { + continue; + } + if (!(particle.pt() < cfgCutPtUpper)) { + continue; + } + if (track.sign() > 0) { + nPos += 1.0; + } + if (track.sign() < 0) { + nNeg += 1.0; + } + } + return {nPos, nNeg}; + } + + // Charge sign of a generated particle, 0 if it is not one of the charged primary species (e, mu, pi, K, p) + int getMcCharge(const int pdgCode) + { + const int absPdg = std::abs(pdgCode); + if (absPdg != PDG_t::kElectron && absPdg != PDG_t::kMuonMinus && absPdg != PDG_t::kPiPlus && absPdg != PDG_t::kKPlus && absPdg != PDG_t::kProton) { + return 0; + } + auto* pd = pdgService->GetParticle(pdgCode); + if (pd == nullptr) { + return 0; + } + return static_cast(pd->Charge() / 3.0); + } + + // Function to check which pt bin the track lies in and assign the corresponding efficiency + + template + float getEfficiency(const T& candidate) + { + return getEfficiencyFromKinematics(candidate.pt(), candidate.eta(), candidate.sign()); + } + + // Efficiency from pT, eta and charge sign (maps from CCDB or the pT-dependent configurables) + float getEfficiencyFromKinematics(const float pt, const float eta, const int sign) + { + // Load eff from histograms in CCDB + if (cfgLoadEff) { + if (sign > 0) { + float effmeanval = hRatio2DEtaVsPtPositive->GetBinContent(hRatio2DEtaVsPtPositive->FindBin(pt, eta)); + return effmeanval; + } + if (sign < 0) { + float effmeanval = hRatio2DEtaVsPtNegative->GetBinContent(hRatio2DEtaVsPtNegative->FindBin(pt, eta)); + return effmeanval; + } + return 0.0; + } else { + // Find the pt bin index based on the track's pt value + int binIndex = -1; + + for (int i = 0; i + 1 < static_cast(cfgPtBins.value.size()); ++i) { + if (pt >= cfgPtBins.value[i] && pt < cfgPtBins.value[i + 1]) { + binIndex = i; + break; + } + } + // If the pt is outside the defined bins, return a default efficiency or handle it differently + if (binIndex == -1) { + return 0.0; // Default efficiency (0% if outside bins) + } + if (sign > 0) + return cfgPositiveEff.value[binIndex]; + if (sign < 0) + return cfgNegativeEff.value[binIndex]; + return 0.0; + } + } + + // =================================================================================================== + // Filling of the profiles (shared by generated, MC reconstructed and data) + // =================================================================================================== + + // Moments <(N+ - N-)^k> of the net-charge distribution, k = 1..NumMoments + template + void fillMoments1D(TProfiles& profiles, const float cent, const float netCharge) + { + for (int k = 1; k <= NumMoments; k++) { + profiles[k - 1]->Fill(cent, std::pow(netCharge, static_cast(k))); + } + } + template + void fillMoments2D(TProfiles& profiles, const float cent, const int sampleIndex, const float netCharge) + { + for (int k = 1; k <= NumMoments; k++) { + profiles[k - 1]->Fill(cent, sampleIndex, std::pow(netCharge, static_cast(k))); + } + } + + // Generated level: moments only + void fillGenProfiles(const float cent, const float netCharge) + { + if (cfgIsCalculateCentral) { + fillMoments1D(genProfMu, cent, netCharge); + } + + if (cfgIsCalculateError) { + float lRandom = fRndm->Rndm(); + int sampleIndex = static_cast(cfgNSubsample * lRandom); + fillMoments2D(genProf2DMu, cent, sampleIndex, netCharge); + } + } + + // Reconstructed level: moments and efficiency-corrected quantities. + // powerEffPos/Neg[i] = sum over the tracks of (1/eff)^i + void fillRecProfiles(const float cent, const float netCharge, const std::array& powerEffPos, const std::array& powerEffNeg) + { + // Calculating q_{r,s} as required + std::array fTCP0 = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + std::array fTCP1 = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + for (int i = 1; i < NumPowers; i++) { + fTCP0[i] = powerEffPos[i] + powerEffNeg[i]; + fTCP1[i] = powerEffPos[i] - powerEffNeg[i]; + } + const auto qValues = computeQ(fTCP0, fTCP1); + + if (cfgIsCalculateCentral) { + // uncorrected + fillMoments1D(profMu, cent, netCharge); + // eff. corrected + for (int i = 0; i < NumQuantities; i++) { + profQ[i]->Fill(cent, qValues[i].value); + } + } + + if (cfgIsCalculateError) { + // selecting subsample and filling profiles + float lRandom = fRndm->Rndm(); + int sampleIndex = static_cast(cfgNSubsample * lRandom); + + fillMoments2D(prof2DMu, cent, sampleIndex, netCharge); + for (int i = 0; i < NumQuantities; i++) { + prof2DQ[i]->Fill(cent, sampleIndex, qValues[i].value); + } + } + } + + // Event-level histograms of the reconstructed multiplicities + void fillRecEventHistos(const float cent, const float nPos, const float nNeg, const std::array& powerEffPos, const std::array& powerEffNeg) + { + float netCharge = nPos - nNeg; + float nTracks = nPos + nNeg; + histos.fill(HIST("hNTracksVsCent"), cent, nTracks); + histos.fill(HIST("hrecNetChargeVsCentrality"), netCharge, cent); + histos.fill(HIST("hrecPositiveVsCentrality"), nPos, cent); + histos.fill(HIST("hrecNegativeVsCentrality"), nNeg, cent); + histos.fill(HIST("hrecProfileTotalCharge"), cent, (nPos + nNeg)); + histos.fill(HIST("hrecProfilePositive"), cent, nPos); + histos.fill(HIST("hrecProfileNegative"), cent, nNeg); + histos.fill(HIST("hCorrProfileTotalCharge"), cent, (powerEffPos[1] + powerEffNeg[1])); + histos.fill(HIST("hCorrProfilePositive"), cent, powerEffPos[1]); + histos.fill(HIST("hCorrProfileNegative"), cent, powerEffNeg[1]); + } + + // Sum of (1/eff)^i of a track + static void addEfficiencyPowers(std::array& powerEff, const float eff) + { + for (int i = 1; i < NumPowers; i++) { + powerEff[i] += std::pow(1.0 / eff, i); + } + } + + // =================================================================================================== + // Process functions + // =================================================================================================== + + void processMCGen(aod::McCollision const& mcCollision, aod::McParticles const& mcParticles, const soa::SmallGroups& collisions) + { + histos.fill(HIST("hMC"), 0.5); + if (std::abs(mcCollision.posZ()) < cfgCutVertex) { + histos.fill(HIST("hMC"), 1.5); + } + float cent = 0.0; + + int nchInel = 0; + for (const auto& mcParticle : mcParticles) { + auto pdgcode = std::abs(mcParticle.pdgCode()); + if (mcParticle.isPhysicalPrimary() && (pdgcode == PDG_t::kPiPlus || pdgcode == PDG_t::kKPlus || pdgcode == PDG_t::kProton || pdgcode == PDG_t::kElectron || pdgcode == PDG_t::kMuonMinus)) { + if (std::abs(mcParticle.eta()) < 1.0) { + nchInel = nchInel + 1; + } + } + } + if (nchInel > 0 && std::abs(mcCollision.posZ()) < cfgCutVertex) + histos.fill(HIST("hMC"), 2.5); + std::vector selectedEvents(collisions.size()); + int nevts = 0; + + for (const auto& collision : collisions) { + // as in the proton task, kIsGoodZvtxFT0vsPV is not applied at the generated level + if (!isEventSelected(collision, false) || std::abs(collision.mcCollision().posZ()) > cfgCutVertex) { + continue; + } + + cent = collision.centFT0C(); + + selectedEvents[nevts++] = collision.mcCollision_as().globalIndex(); + } + selectedEvents.resize(nevts); + const auto evtReconstructedAndSelected = std::find(selectedEvents.begin(), selectedEvents.end(), mcCollision.globalIndex()) != selectedEvents.end(); + histos.fill(HIST("hMC"), 3.5); + if (!evtReconstructedAndSelected) { // Check that the event is reconstructed and that the reconstructed events pass the selection + return; + } + histos.fill(HIST("hMC"), 4.5); + histos.fill(HIST("hCentgen"), cent); + + // creating phi, pt, eta dstribution of generted MC particles + + float nPos = 0.0; + float nNeg = 0.0; + + for (const auto& mcParticle : mcParticles) { + if (!mcParticle.has_mcCollision()) + continue; + + if (mcParticle.isPhysicalPrimary()) { + if ((mcParticle.pt() > cfgCutPtLower) && (mcParticle.pt() < PtUpperLimit) && (mcParticle.eta() > cfgCutEtaMin) && (mcParticle.eta() < cfgCutEtaMax)) { + histos.fill(HIST("hgenPtAll"), mcParticle.pt()); + histos.fill(HIST("hgenEtaAll"), mcParticle.eta()); + histos.fill(HIST("hgenPhiAll"), mcParticle.phi()); + + const int charge = getMcCharge(mcParticle.pdgCode()); + if (charge > 0) { + histos.fill(HIST("hgenPtPositive"), mcParticle.pt()); //! hist for positive gen + histos.fill(HIST("hgenPtDistPositiveVsCentrality"), mcParticle.pt(), cent); + histos.fill(HIST("hgen2DEtaVsPtPositive"), mcParticle.pt(), mcParticle.eta()); + histos.fill(HIST("hgenEtaPositive"), mcParticle.eta()); + histos.fill(HIST("hgenPhiPositive"), mcParticle.phi()); + if (mcParticle.pt() < cfgCutPtUpper) + nPos = nPos + 1.0; + } + if (charge < 0) { + histos.fill(HIST("hgenPtNegative"), mcParticle.pt()); //! hist for negative gen + histos.fill(HIST("hgenPtDistNegativeVsCentrality"), mcParticle.pt(), cent); + histos.fill(HIST("hgen2DEtaVsPtNegative"), mcParticle.pt(), mcParticle.eta()); + histos.fill(HIST("hgenEtaNegative"), mcParticle.eta()); + histos.fill(HIST("hgenPhiNegative"), mcParticle.phi()); + if (mcParticle.pt() < cfgCutPtUpper) + nNeg = nNeg + 1.0; + } + } + } + } //! end particle loop + + float netCharge = nPos - nNeg; + histos.fill(HIST("hgenNetChargeVsCentrality"), netCharge, cent); + histos.fill(HIST("hgenPositiveVsCentrality"), nPos, cent); + histos.fill(HIST("hgenNegativeVsCentrality"), nNeg, cent); + histos.fill(HIST("hgenProfileTotalCharge"), cent, (nPos + nNeg)); + histos.fill(HIST("hgenProfilePositive"), cent, nPos); + histos.fill(HIST("hgenProfileNegative"), cent, nNeg); + + // Profiles for generated level cumulants + fillGenProfiles(cent, netCharge); + } + PROCESS_SWITCH(NetChargeCumulants, processMCGen, "Process Generated", true); + + // Binomial response test: event by event, the generated number of primaries of the MC collision is compared with the number + // reconstructed in the matching reco collision (same cuts as processMCGen and processMCRec). + // If several reco collisions of the MC collision pass the event selection (split collision), cfgBinomSplitMode decides: + // 0 = use the reco collision with the most accepted tracks, 1 = reject the MC collision. The multiplicity of reco collisions is always filled + Preslice perCollisionMCTracks = aod::track::collisionId; + + void processMCBinomial(aod::McCollision const& mcCollision, aod::McParticles const& mcParticles, const soa::SmallGroups& collisions, MyMCTracks const& tracks) + { + if (std::abs(mcCollision.posZ()) > cfgCutVertex) { + return; + } + + int nSelected = 0; + float bestNPos = 0.0; + float bestNNeg = 0.0; + float bestNTracks = -1.0; + float bestCent = 0.0; + for (const auto& collision : collisions) { + if (!isEventSelected(collision, true) || std::abs(collision.posZ()) > cfgCutVertex) { + continue; + } + ++nSelected; + auto tracksThisCollision = tracks.sliceBy(perCollisionMCTracks, collision.globalIndex()); + const auto [nRecPos, nRecNeg] = countReconstructedBinomial(tracksThisCollision); + if (nRecPos + nRecNeg > bestNTracks) { + bestNTracks = nRecPos + nRecNeg; + bestNPos = nRecPos; + bestNNeg = nRecNeg; + bestCent = collision.centFT0C(); + } + } + histos.fill(HIST("hBinomNRecoCollisions"), nSelected); + if (nSelected == 0) { + return; + } + if (nSelected > 1 && cfgBinomSplitMode == 1) { + return; + } + + // centrality class of the event, the events outside of cfgBinomCentEdges are not used + const std::vector& edges = cfgBinomCentEdges.value; + int iClass = -1; + for (std::size_t i = 0; i + 1 < edges.size(); ++i) { + if (bestCent >= edges[i] && bestCent < edges[i + 1]) { + iClass = static_cast(i); + break; + } + } + if (iClass < 0) { + return; + } + auto& h = binomialHistos[iClass]; + + const auto gen = countGeneratedBinomial(mcParticles); + const double nRecPos = bestNPos; + const double nRecNeg = bestNNeg; + + h.genVsRecPos->Fill(gen.nPos, nRecPos); + h.genVsRecNeg->Fill(gen.nNeg, nRecNeg); + h.genVsRecNet->Fill(gen.nPos - gen.nNeg, nRecPos - nRecNeg); + + h.recPos->Fill(gen.nPos, nRecPos); + h.recSqPos->Fill(gen.nPos, nRecPos * nRecPos); + h.expMeanPos->Fill(gen.nPos, gen.expMeanPos); + h.expVarPos->Fill(gen.nPos, gen.expVarPos); + h.recNeg->Fill(gen.nNeg, nRecNeg); + h.recSqNeg->Fill(gen.nNeg, nRecNeg * nRecNeg); + h.expMeanNeg->Fill(gen.nNeg, gen.expMeanNeg); + h.expVarNeg->Fill(gen.nNeg, gen.expVarNeg); + + h.recPosNeg2D->Fill(gen.nPos, gen.nNeg, nRecPos * nRecNeg); + h.recPos2D->Fill(gen.nPos, gen.nNeg, nRecPos); + h.recNeg2D->Fill(gen.nPos, gen.nNeg, nRecNeg); + } + PROCESS_SWITCH(NetChargeCumulants, processMCBinomial, "Process binomial response test (generated vs reconstructed numbers)", false); + + void processMCRec(MyMCRecCollision const& collision, MyMCTracks const& tracks, aod::McCollisions const&, aod::McParticles const&) + { + if (!collision.has_mcCollision()) { + return; + } + + if (!isEventSelected(collision, true)) { + return; + } + + auto cent = collision.centFT0C(); + histos.fill(HIST("hCentrec"), cent); + histos.fill(HIST("hMC"), 5.5); + histos.fill(HIST("hZvtx_after"), collision.posZ()); + + float nPos = 0.0; + float nNeg = 0.0; + std::array powerEffPos = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + std::array powerEffNeg = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + + // Start of the Monte-Carlo reconstructed tracks + for (const auto& track : tracks) { + if (!track.has_collision()) { + continue; + } + + fillPurityQA(track, cent); //! purity QA, does not change the selection below + + if (!track.has_mcParticle()) //! check if track has corresponding MC particle + { + continue; + } + if (!passTrackType(track)) //! ITS-only or ITS-TPC tracks + { + continue; + } + + auto particle = track.mcParticle(); + if (!particle.has_mcCollision()) + continue; + if ((particle.pt() < cfgCutPtLower) || (particle.pt() > PtUpperLimit) || (particle.eta() < cfgCutEtaMin) || (particle.eta() > cfgCutEtaMax)) { + continue; + } + + if (!passTpcQualityCuts(track)) { + continue; + } + + if (particle.isPhysicalPrimary()) { + histos.fill(HIST("hrecPartPtAll"), particle.pt()); + histos.fill(HIST("hrecPtAll"), track.pt()); + histos.fill(HIST("hrecEtaAll"), particle.eta()); + histos.fill(HIST("hrecPhiAll"), particle.phi()); + histos.fill(HIST("hrecDcaXYAll"), track.dcaXY()); + histos.fill(HIST("hrecDcaZAll"), track.dcaZ()); + histos.fill(HIST("hDCAxyVsPt_before"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_before"), track.pt(), track.dcaZ()); + + if (!passDcaCuts(track)) { + continue; + } + + histos.fill(HIST("hDCAxyVsPt_after"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_after"), track.pt(), track.dcaZ()); + + // required tracks with TOF mandatory to avoid pileup (ITS-TPC tracks) + if (!passTofCut(track)) { + continue; + } + + // all the accepted charged tracks are used (no particle identification) + histos.fill(HIST("hDCAxyVsPt_afterSel"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_afterSel"), track.pt(), track.dcaZ()); + const int mcCharge = getMcCharge(particle.pdgCode()); + if (track.sign() > 0) { + histos.fill(HIST("hrecPartPtPositive"), particle.pt()); //! hist for positive rec + histos.fill(HIST("hrecPtPositive"), track.pt()); //! hist for positive rec + histos.fill(HIST("hrecPtDistPositiveVsCentrality"), particle.pt(), cent); + histos.fill(HIST("hrec2DEtaVsPtPositive"), particle.pt(), particle.eta()); + histos.fill(HIST("hrecEtaPositive"), particle.eta()); + histos.fill(HIST("hrecPhiPositive"), particle.phi()); + histos.fill(HIST("hrecDcaXYPositive"), track.dcaXY()); + histos.fill(HIST("hrecDcaZPositive"), track.dcaZ()); + if (particle.pt() < cfgCutPtUpper) { + nPos = nPos + 1.0; + float pEff = getEfficiency(track); // get efficiency of track + if (pEff != 0) { + addEfficiencyPowers(powerEffPos, pEff); + } + } + if (mcCharge > 0) { + histos.fill(HIST("hrecTruePtPositive"), particle.pt()); //! hist for positive purity + } + } + if (track.sign() < 0) { + histos.fill(HIST("hrecPartPtNegative"), particle.pt()); //! hist for negative rec + histos.fill(HIST("hrecPtNegative"), track.pt()); //! hist for negative rec + histos.fill(HIST("hrecPtDistNegativeVsCentrality"), particle.pt(), cent); + histos.fill(HIST("hrec2DEtaVsPtNegative"), particle.pt(), particle.eta()); + histos.fill(HIST("hrecEtaNegative"), particle.eta()); + histos.fill(HIST("hrecPhiNegative"), particle.phi()); + histos.fill(HIST("hrecDcaXYNegative"), track.dcaXY()); + histos.fill(HIST("hrecDcaZNegative"), track.dcaZ()); + if (particle.pt() < cfgCutPtUpper) { + nNeg = nNeg + 1.0; + float pEff = getEfficiency(track); // get efficiency of track + if (pEff != 0) { + addEfficiencyPowers(powerEffNeg, pEff); + } + } + if (mcCharge < 0) { + histos.fill(HIST("hrecTruePtNegative"), particle.pt()); //! hist for negative purity + } + } + } //! checking if primary + } //! end track loop + + fillRecEventHistos(cent, nPos, nNeg, powerEffPos, powerEffNeg); + fillRecProfiles(cent, nPos - nNeg, powerEffPos, powerEffNeg); + } + PROCESS_SWITCH(NetChargeCumulants, processMCRec, "Process MC reconstructed", true); + + void processDataRec(AodCollisions::iterator const& coll, aod::BCsWithTimestamps const&, AodTracks const& inputTracks) + { + + // reset per event + nTrkEvent = 0; + nPosEvent = 0; + nNegEvent = 0; + + // assign event ID + eventId = eventCounter++; + + // store event info + centEvent = coll.centFT0C(); + vzEvent = coll.posZ(); + if (!isEventSelected(coll, true)) { + return; + } + + histos.fill(HIST("hZvtx_after"), coll.posZ()); + // variables + auto cent = coll.centFT0C(); + histos.fill(HIST("hCentrec"), cent); + + float nPos = 0.0; + float nNeg = 0.0; + std::array powerEffPos = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + std::array powerEffNeg = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + + // Start of the reconstructed tracks + for (const auto& track : inputTracks) { + if (!track.has_collision()) { + continue; + } + + if (!passTrackType(track)) //! ITS-only or ITS-TPC tracks + { + continue; + } + if ((track.pt() < cfgCutPtLower) || (track.pt() > PtUpperLimit) || (track.eta() < cfgCutEtaMin) || (track.eta() > cfgCutEtaMax)) { + continue; + } + + if (!passTpcQualityCuts(track)) { + continue; + } + + histos.fill(HIST("hrecPtAll"), track.pt()); + histos.fill(HIST("hrecEtaAll"), track.eta()); + histos.fill(HIST("hrecPhiAll"), track.phi()); + histos.fill(HIST("hrecDcaXYAll"), track.dcaXY()); + histos.fill(HIST("hrecDcaZAll"), track.dcaZ()); + histos.fill(HIST("hDCAxyVsPt_before"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_before"), track.pt(), track.dcaZ()); + + if (!passDcaCuts(track)) { + continue; + } + + histos.fill(HIST("hDCAxyVsPt_after"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_after"), track.pt(), track.dcaZ()); + + // required tracks with TOF mandatory to avoid pileup (ITS-TPC tracks) + if (!passTofCut(track)) { + continue; + } + nTrkEvent++; + + // all the accepted charged tracks are used (no particle identification) + histos.fill(HIST("hDCAxyVsPt_afterSel"), track.pt(), track.dcaXY()); + histos.fill(HIST("hDCAzVsPt_afterSel"), track.pt(), track.dcaZ()); + // for positive particles + if (track.sign() > 0) { + histos.fill(HIST("hrecPtPositive"), track.pt()); //! hist for positive rec + histos.fill(HIST("hrecPtDistPositiveVsCentrality"), track.pt(), cent); + histos.fill(HIST("hrecEtaPositive"), track.eta()); + histos.fill(HIST("hrecPhiPositive"), track.phi()); + histos.fill(HIST("hrecDcaXYPositive"), track.dcaXY()); + histos.fill(HIST("hrecDcaZPositive"), track.dcaZ()); + + if (track.pt() < cfgCutPtUpper) { + nPos = nPos + 1.0; + nPosEvent++; + float pEff = getEfficiency(track); // get efficiency of track + if (pEff != 0) { + addEfficiencyPowers(powerEffPos, pEff); + ptTrack = track.pt(); + etaTrack = track.eta(); + pidTrack = +1; + effTrack = pEff; + + trackTable(eventId, ptTrack, etaTrack, pidTrack, effTrack); + } + } + } + // for negative particles + if (track.sign() < 0) { + histos.fill(HIST("hrecPtNegative"), track.pt()); //! hist for negative rec + histos.fill(HIST("hrecPtDistNegativeVsCentrality"), track.pt(), cent); + histos.fill(HIST("hrecEtaNegative"), track.eta()); + histos.fill(HIST("hrecPhiNegative"), track.phi()); + histos.fill(HIST("hrecDcaXYNegative"), track.dcaXY()); + histos.fill(HIST("hrecDcaZNegative"), track.dcaZ()); + if (track.pt() < cfgCutPtUpper) { + nNeg = nNeg + 1.0; + nNegEvent++; + float pEff = getEfficiency(track); // get efficiency of track + if (pEff != 0) { + addEfficiencyPowers(powerEffNeg, pEff); + ptTrack = track.pt(); + etaTrack = track.eta(); + pidTrack = -1; + effTrack = pEff; + + trackTable(eventId, ptTrack, etaTrack, pidTrack, effTrack); + } + } + } + } //! end track loop + + eventTable(eventId, centEvent, vzEvent, nTrkEvent, nPosEvent, nNegEvent); + + fillRecEventHistos(cent, nPos, nNeg, powerEffPos, powerEffNeg); + fillRecProfiles(cent, nPos - nNeg, powerEffPos, powerEffNeg); + } + PROCESS_SWITCH(NetChargeCumulants, processDataRec, "Process real data", false); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{ + adaptAnalysisTask(cfgc)}; +} From 7d1930edb857fb55218ff3f65ced143a60d6e669 Mon Sep 17 00:00:00 2001 From: Swati Saha Date: Tue, 1 Dec 2026 22:11:07 +0530 Subject: [PATCH 2/3] correction of the typo in CMakeLists.txt --- PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt b/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt index e1c44514906..8bdde9b1eeb 100644 --- a/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt +++ b/PWGCF/EbyEFluctuations/Tasks/CMakeLists.txt @@ -95,7 +95,6 @@ o2physics_add_dpl_workflow(mult-and-pt-fluctuations COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(net-charge-cumulants - SOURCES netChargeCumulants.cxx - PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCF\ -Core - COMPONENT_NAME Analysis) + SOURCES netChargeCumulants.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCFCore + COMPONENT_NAME Analysis) From 3924d282302f53b77d882c41545974614733fc4b Mon Sep 17 00:00:00 2001 From: Swati Saha Date: Tue, 1 Dec 2026 22:55:08 +0530 Subject: [PATCH 3/3] fix of MegaLinter error --- PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx b/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx index e7e96c9b629..b11f037dcf0 100644 --- a/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/netChargeCumulants.cxx @@ -510,6 +510,7 @@ struct NetChargeCumulants { TList* lst = ccdb->getForTimeStamp(ccdbPath.value, ccdbNoLaterThan.value); if (!lst) { LOGF(fatal, "Could not get the efficiency object %s from CCDB", ccdbPath.value.data()); + return; // LOGF(fatal) aborts; the return only makes the null check explicit for static analysers (cppcheck) } hRatio2DEtaVsPtPositive = dynamic_cast(lst->FindObject("hRatio2DEtaVsPtPositive")); hRatio2DEtaVsPtNegative = dynamic_cast(lst->FindObject("hRatio2DEtaVsPtNegative"));