diff --git a/PWGLF/Tasks/Resonances/f0phiproxy.cxx b/PWGLF/Tasks/Resonances/f0phiproxy.cxx index 1792f20da65..78a5935c374 100644 --- a/PWGLF/Tasks/Resonances/f0phiproxy.cxx +++ b/PWGLF/Tasks/Resonances/f0phiproxy.cxx @@ -86,11 +86,23 @@ struct F0phiproxy { Configurable trackEtaMax{"trackEtaMax", 0.8f, "Maximum track |eta|"}; Configurable requireGlobalTrack{"requireGlobalTrack", true, "Require global track selection"}; Configurable requirePVContributor{"requirePVContributor", true, "Require PV contributor"}; - Configurable pionTPC{"pionTPC", 3.f, "Pion TPC nSigma cut"}; - Configurable pionTOF{"pionTOF", 3.f, "Pion TOF veto when matched"}; - Configurable kaonTPC{"kaonTPC", 3.f, "Kaon TPC nSigma cut"}; - Configurable kaonTOF{"kaonTOF", 3.f, "Kaon TOF veto when matched"}; - Configurable requireTOF{"requireTOF", false, "Require TOF for both species instead of veto-only"}; + Configurable pionTPC{"pionTPC", 3.f, "Pion TPC base/fallback cut; also the matched TPC cap except in uncapped radial mode"}; + Configurable pionTOF{"pionTOF", 3.f, "Pion rectangular TOF cut in modes 0, 1 and 2; radial modes use pionCombined"}; + Configurable kaonTPC{"kaonTPC", 3.f, "Kaon TPC base/fallback cut; also the matched TPC cap except in uncapped radial mode"}; + Configurable kaonTOF{"kaonTOF", 3.f, "Kaon rectangular TOF cut in modes 0, 1 and 2; radial modes use kaonCombined"}; + Configurable requireTOF{"requireTOF", false, "Legacy PID mode 0 only: require TOF rather than use a conditional veto"}; + Configurable pionPIDMode{"pionPIDMode", 0, "0=legacy requireTOF, 1=TPC+TOF veto, 2=TPC+TOF required, 3=TPC only, 4=radial TOF veto, 5=radial veto with TPC cap"}; + Configurable kaonPIDMode{"kaonPIDMode", 0, "0=legacy requireTOF, 1=TPC+TOF veto, 2=TPC+TOF required, 3=TPC only, 4=radial TOF veto, 5=radial veto with TPC cap"}; + Configurable pionCombined{"pionCombined", 3.f, "Pion sqrt(nSigmaTPC^2+nSigmaTOF^2) cut in radial modes"}; + Configurable kaonCombined{"kaonCombined", 3.f, "Kaon sqrt(nSigmaTPC^2+nSigmaTOF^2) cut in radial modes"}; + Configurable pionTPCWithTOF{"pionTPCWithTOF", -1.f, "Matched pion TPC cut; -1 inherits pionTPC or momentum profile; unused in TPC-only and uncapped radial modes"}; + Configurable kaonTPCWithTOF{"kaonTPCWithTOF", -1.f, "Matched kaon TPC cut; -1 inherits kaonTPC or momentum profile; unused in TPC-only and uncapped radial modes"}; + Configurable> pionTPCMomentumEdges{"pionTPCMomentumEdges", std::vector{}, "Optional increasing total track p boundaries (GeV/c), not pT"}; + Configurable> pionTPCMomentumCuts{"pionTPCMomentumCuts", std::vector{}, "Pion TPC cuts in total-p intervals; one more cut than edges; empty uses pionTPC"}; + Configurable> kaonTPCMomentumEdges{"kaonTPCMomentumEdges", std::vector{}, "Optional increasing total track p boundaries (GeV/c), not pT"}; + Configurable> kaonTPCMomentumCuts{"kaonTPCMomentumCuts", std::vector{}, "Kaon TPC cuts in total-p intervals; one more cut than edges; empty uses kaonTPC"}; + Configurable pionRejectKaonCompatible{"pionRejectKaonCompatible", false, "Optional reflection control: reject a pion if it also passes the configured kaon PID before overlap vetoes"}; + Configurable kaonRejectPionCompatible{"kaonRejectPionCompatible", false, "Optional reflection control: reject a kaon if it also passes the configured pion PID before overlap vetoes"}; Configurable dipionYMax{"dipionYMax", 0.5f, "Maximum dipion |y|"}; Configurable proxyYMax{"proxyYMax", 0.5f, "Maximum proxy+bachelor and standard-control |y|"}; Configurable dipionMassMin{"dipionMassMin", 0.6f, "Lower dipion mass for proxy construction"}; @@ -107,6 +119,7 @@ struct F0phiproxy { Configurable enableCompactProxy{"enableCompactProxy", true, "Proxy maps retaining mass, pT, dipion mass, grouped multiplicity, charges and TOF"}; Configurable enableFullProxySparse{"enableFullProxySparse", false, "Diagnostic 7D maps including multiplicity, bachelor charge and TOF; expensive to merge"}; Configurable enablePidQA{"enablePidQA", false, "Book/fill the four PID QA histograms"}; + Configurable enablePidSelectionQA{"enablePidSelectionQA", false, "Joint before/after PID, selected marginals and decision overlap; enable once per shared track sample"}; Configurable multiplicityBins{"multiplicityBins", 100, "Multiplicity bins in dipion/control and full diagnostic maps; identical settings required for merging"}; Configurable proxyDipionMassBins{"proxyDipionMassBins", 300, "Dipion mass bins in compact proxy maps; default preserves original 5 MeV resolution"}; ConfigurableAxis proxyMultiplicityAxis{"proxyMultiplicityAxis", {0., 0., 20., 50., 200., 1000000.}, "Compact proxy NPV intervals; first zero selects variable-width bins"}; @@ -136,6 +149,105 @@ struct F0phiproxy { int resolvedF0Code = 0; std::vector ft0mEdges{}; + // BEGIN PID selection helpers: also compiled verbatim by the standalone regression test. + enum class PIDMode : int { + Legacy = 0, + TPCWithTOFVeto = 1, + TPCWithTOFRequired = 2, + TPCOnly = 3, + RadialWithTPCFallback = 4, + RadialWithTPCCap = 5 + }; + struct PIDSelection { + int mode = 0; + float tpc = 3.f; + float tof = 3.f; + float combined = 3.f; + float tpcWithTOF = -1.f; + bool requireTOF = false; + std::vector momentumEdges{}; + std::vector momentumCuts{}; + }; + + static void validatePID(PIDSelection const& selection) + { + auto positive = [](float value) { return std::isfinite(value) && value > 0.f; }; + if (selection.mode < static_cast(PIDMode::Legacy) || selection.mode > static_cast(PIDMode::RadialWithTPCCap) || + !positive(selection.tpc) || !positive(selection.tof) || !positive(selection.combined) || + (selection.tpcWithTOF != -1.f && !positive(selection.tpcWithTOF))) { + throw std::runtime_error("Invalid PID mode or nSigma threshold"); + } + if (!selection.momentumEdges.empty() || !selection.momentumCuts.empty()) { + if (selection.momentumCuts.size() != selection.momentumEdges.size() + 1 || + !std::all_of(selection.momentumEdges.begin(), selection.momentumEdges.end(), positive) || + !std::all_of(selection.momentumCuts.begin(), selection.momentumCuts.end(), positive) || + std::adjacent_find(selection.momentumEdges.begin(), selection.momentumEdges.end(), [](float a, float b) { return a >= b; }) != selection.momentumEdges.end()) { + throw std::runtime_error("Invalid total-momentum PID profile: increasing positive edges and one more positive cut are required"); + } + } + } + + static PIDMode resolvedPIDMode(PIDSelection const& selection) + { + const auto mode = static_cast(selection.mode); + return mode == PIDMode::Legacy ? (selection.requireTOF ? PIDMode::TPCWithTOFRequired : PIDMode::TPCWithTOFVeto) : mode; + } + + static float tpcPIDThreshold(PIDSelection const& selection, bool useMatchedCut, float momentum) + { + if (useMatchedCut && selection.tpcWithTOF > 0.f) { + return selection.tpcWithTOF; + } + if (selection.momentumCuts.empty()) { + return selection.tpc; + } + if (!std::isfinite(momentum) || momentum < 0.f) { + return std::numeric_limits::quiet_NaN(); + } + const auto interval = static_cast(std::upper_bound(selection.momentumEdges.begin(), selection.momentumEdges.end(), momentum) - selection.momentumEdges.begin()); + return selection.momentumCuts[interval]; + } + + static bool acceptPID(PIDSelection const& selection, float tpc, float tof, bool matched, float momentum) + { + if (!std::isfinite(tpc)) { + return false; + } + const auto mode = resolvedPIDMode(selection); + if (mode == PIDMode::TPCWithTOFRequired && !matched) { + return false; + } + if (mode == PIDMode::TPCOnly) { + return std::abs(tpc) < tpcPIDThreshold(selection, false, momentum); + } + if (mode == PIDMode::RadialWithTPCFallback && matched) { + // This ALICE alternative deliberately has no separate TPC cap for matched tracks. + return std::isfinite(tof) && static_cast(tpc) * tpc + static_cast(tof) * tof < static_cast(selection.combined) * selection.combined; + } + if (!(std::abs(tpc) < tpcPIDThreshold(selection, matched, momentum))) { + return false; + } + if (!matched) { + return mode == PIDMode::TPCWithTOFVeto || mode == PIDMode::RadialWithTPCFallback || mode == PIDMode::RadialWithTPCCap; + } + if (!std::isfinite(tof)) { + return false; + } + if (mode == PIDMode::RadialWithTPCCap) { + // November-9 K* note: TPC cap AND radial cut; unmatched tracks use TPC only. + return static_cast(tpc) * tpc + static_cast(tof) * tof < static_cast(selection.combined) * selection.combined; + } + return (mode == PIDMode::TPCWithTOFVeto || mode == PIDMode::TPCWithTOFRequired) && std::abs(tof) < selection.tof; + } + + static std::pair resolvePIDOverlap(bool pionPass, bool kaonPass, bool rejectKaonCompatiblePion, bool rejectPionCompatibleKaon) + { + // Use both original decisions, so enabling both vetoes removes both ambiguous assignments. + return {pionPass && !(rejectKaonCompatiblePion && kaonPass), kaonPass && !(rejectPionCompatibleKaon && pionPass)}; + } + // END PID selection helpers. + PIDSelection pionSelection{}, kaonSelection{}; + struct TruthInfo { int64_t id = -1; int collisionId = -1; @@ -168,6 +280,12 @@ struct F0phiproxy { std::shared_ptr eventStagesByActivity{}, activityVsNPV{}, activityVsVertex{}, mixPartnersByActivity{}; std::array, 4> pidQA{}; std::array, 4> pidQAByActivity{}; + // Joint maps are matched-track only; post-TPC marginals also include accepted unmatched tracks. + std::array, 2>, 2> pidSelectionJoint{}; + std::array, 4> pidSelectionAfter{}; + std::array, 4> pidSelectionAfterByActivity{}; + std::shared_ptr pidSelectionByActivity{}; + std::shared_ptr pidSelectionNonfinite{}; std::array, NMixClasses> dipionSpectra{}; std::array, NMixClasses>, NChannels> compactProxy{}, fullProxy{}; @@ -273,6 +391,10 @@ struct F0phiproxy { void init(InitContext const&) { + pionSelection = {pionPIDMode.value, pionTPC.value, pionTOF.value, pionCombined.value, pionTPCWithTOF.value, requireTOF.value, pionTPCMomentumEdges.value, pionTPCMomentumCuts.value}; + kaonSelection = {kaonPIDMode.value, kaonTPC.value, kaonTOF.value, kaonCombined.value, kaonTPCWithTOF.value, requireTOF.value, kaonTPCMomentumEdges.value, kaonTPCMomentumCuts.value}; + validatePID(pionSelection); + validatePID(kaonSelection); if (doprocess && doprocessMCReco) { throw std::runtime_error("Enable either process (data) or processMCReco, never both"); } @@ -357,6 +479,42 @@ struct F0phiproxy { } } } + if (enablePidSelectionQA.value) { + const AxisSpec pidPt{std::vector{0., 0.15, 0.3, 0.5, 0.8, 1., 1.5, 2., 3., 4., 6., 10., 20.}, "track p_{T} (GeV/c); overflow retained"}; + const AxisSpec pidNSigmaTPC{60, -6., 6., "TPC n#sigma; flow retained"}; + const AxisSpec pidNSigmaTOF{60, -6., 6., "TOF n#sigma; flow retained"}; + const std::array, 2> jointNames{{{"hPionTPCvsTOFBeforePID", "hPionTPCvsTOFAfterPID"}, {"hKaonTPCvsTOFBeforePID", "hKaonTPCvsTOFAfterPID"}}}; + for (size_t species = 0; species < jointNames.size(); ++species) { + for (size_t stage = 0; stage < jointNames[species].size(); ++stage) { + pidSelectionJoint[species][stage] = histos.add(recoName(jointNames[species][stage]).c_str(), stage == 0 ? "Matched quality tracks with finite TPC/TOF, before species PID" : "Matched accepted tracks with finite TPC/TOF, after species PID", HistType::kTH3F, {pidPt, pidNSigmaTPC, pidNSigmaTOF}); + pidSelectionJoint[species][stage]->Sumw2(); + } + } + const std::array afterNames{"hPionTPCAfterPID", "hPionTOFAfterPID", "hKaonTPCAfterPID", "hKaonTOFAfterPID"}; + for (size_t index = 0; index < afterNames.size(); ++index) { + const AxisSpec& response = index % 2 == 0 ? pidNSigmaTPC : pidNSigmaTOF; + pidSelectionAfter[index] = histos.add(recoName(afterNames[index]).c_str(), "After final species PID; TPC all accepted, TOF matched accepted;track pT;nSigma", HistType::kTH2F, {pidPt, response}); + pidSelectionAfter[index]->Sumw2(); + if (useFT0M.value) { + const std::string name = std::string(afterNames[index]).append("ByMultiplicity"); + pidSelectionAfterByActivity[index] = histos.add(recoName(name).c_str(), "After final species PID; TPC all accepted, TOF matched accepted", HistType::kTH3F, {pidPt, response, compactMult}); + pidSelectionAfterByActivity[index]->Sumw2(); + } + } + const AxisSpec selectionStage{7, -0.5, 6.5, "PID decision category (not exclusive)"}; + pidSelectionByActivity = histos.add(recoName("hPIDSelectionByActivity").c_str(), "Track-level PID decisions;track pT;activity;decision category", HistType::kTH3D, {pidPt, compactMult, selectionStage}); + pidSelectionByActivity->Sumw2(); + const std::array selectionNames{"Quality", "TOF matched", "Pion accepted (final)", "Kaon accepted (final)", "Both accepted (final)", "Neither accepted (final)", "Both accepted before ambiguity veto"}; + for (size_t index = 0; index < selectionNames.size(); ++index) { + pidSelectionByActivity->GetZaxis()->SetBinLabel(static_cast(index + 1), selectionNames[index]); + } + pidSelectionNonfinite = histos.add(recoName("hPIDSelectionNonfinite").c_str(), "Nonfinite responses excluded from numerical PID QA;response;Tracks", HistType::kTH1D, {{5, -0.5, 4.5}}); + pidSelectionNonfinite->Sumw2(); + const std::array nonfiniteNames{"Track pT", "Pion TPC", "Pion TOF (matched)", "Kaon TPC", "Kaon TOF (matched)"}; + for (size_t index = 0; index < nonfiniteNames.size(); ++index) { + pidSelectionNonfinite->GetXaxis()->SetBinLabel(static_cast(index + 1), nonfiniteNames[index]); + } + } const std::array dipionNames{"hDipionSE", "hDipionME"}; for (size_t mix = 0; mix < dipionNames.size(); ++mix) { if (mix != 0 && !mixingEnabled()) { @@ -392,6 +550,74 @@ struct F0phiproxy { } } + void fillPIDSelectionQA(float trackPt, float activity, bool matched, + float pionTPCValue, float pionTOFValue, float kaonTPCValue, float kaonTOFValue, + bool pionPIDAccepted, bool kaonPIDAccepted, bool pionAccepted, bool kaonAccepted) + { + if (!enablePidSelectionQA.value) { + return; + } + if (!std::isfinite(trackPt)) { + pidSelectionNonfinite->Fill(0.); + return; + } + pidSelectionByActivity->Fill(trackPt, activity, 0.); + if (matched) { + pidSelectionByActivity->Fill(trackPt, activity, 1.); + } + if (pionAccepted) { + pidSelectionByActivity->Fill(trackPt, activity, 2.); + } + if (kaonAccepted) { + pidSelectionByActivity->Fill(trackPt, activity, 3.); + } + if (pionAccepted && kaonAccepted) { + pidSelectionByActivity->Fill(trackPt, activity, 4.); + } + if (!pionAccepted && !kaonAccepted) { + pidSelectionByActivity->Fill(trackPt, activity, 5.); + } + if (pionPIDAccepted && kaonPIDAccepted) { + pidSelectionByActivity->Fill(trackPt, activity, 6.); + } + const std::array tpcValues{pionTPCValue, kaonTPCValue}; + const std::array tofValues{pionTOFValue, kaonTOFValue}; + const std::array accepted{pionAccepted, kaonAccepted}; + for (size_t species = 0; species < accepted.size(); ++species) { + const bool finiteTPC = std::isfinite(tpcValues[species]); + const bool finiteTOF = matched && std::isfinite(tofValues[species]); + const size_t tpcIndex = 2 * species; + const size_t tofIndex = tpcIndex + 1; + if (!finiteTPC) { + pidSelectionNonfinite->Fill(static_cast(tpcIndex + 1)); + } + if (matched && !finiteTOF) { + pidSelectionNonfinite->Fill(static_cast(tofIndex + 1)); + } + if (finiteTPC && finiteTOF) { + pidSelectionJoint[species][0]->Fill(trackPt, tpcValues[species], tofValues[species]); + if (accepted[species]) { + pidSelectionJoint[species][1]->Fill(trackPt, tpcValues[species], tofValues[species]); + } + } + if (!accepted[species]) { + continue; + } + auto fillAfter = [&](size_t index, float value) { + pidSelectionAfter[index]->Fill(trackPt, value); + if (pidSelectionAfterByActivity[index]) { + pidSelectionAfterByActivity[index]->Fill(trackPt, value, activity); + } + }; + if (finiteTPC) { + fillAfter(tpcIndex, tpcValues[species]); + } + if (finiteTOF) { + fillAfter(tofIndex, tofValues[species]); + } + } + } + void bookMC() { const AxisSpec pt{100, 0., 10., "pair pT (GeV/c)"}; @@ -448,11 +674,6 @@ struct F0phiproxy { } } - bool passPID(float tpc, float tof, bool matched, float tpcCut, float tofCut) const - { - return std::isfinite(tpc) && std::abs(tpc) < tpcCut && (!requireTOF.value || matched) && - (!matched || (std::isfinite(tof) && std::abs(tof) < tofCut)); - } static int chargeCategory(int a, int b) { return a != b ? 0 : (a > 0 ? 1 : 2); } static FourVector constituent(FourVector const& dipion) { @@ -701,10 +922,17 @@ struct F0phiproxy { if constexpr (IsMC) { candidate.truth = trackTruth(track, collision.mcCollisionId()); } - if (passPID(track.tpcNSigmaPi(), track.tofNSigmaPi(), tof, pionTPC.value, pionTOF.value)) { + const float momentum = track.p(); + const bool pionPIDAccepted = acceptPID(pionSelection, track.tpcNSigmaPi(), track.tofNSigmaPi(), tof, momentum); + const bool kaonPIDAccepted = acceptPID(kaonSelection, track.tpcNSigmaKa(), track.tofNSigmaKa(), tof, momentum); + const auto accepted = resolvePIDOverlap(pionPIDAccepted, kaonPIDAccepted, pionRejectKaonCompatible.value, kaonRejectPionCompatible.value); + const bool pionAccepted = accepted.first; + const bool kaonAccepted = accepted.second; + fillPIDSelectionQA(track.pt(), mult, tof, track.tpcNSigmaPi(), track.tofNSigmaPi(), track.tpcNSigmaKa(), track.tofNSigmaKa(), pionPIDAccepted, kaonPIDAccepted, pionAccepted, kaonAccepted); + if (pionAccepted) { event.pions.push_back(candidate); } - if (passPID(track.tpcNSigmaKa(), track.tofNSigmaKa(), tof, kaonTPC.value, kaonTOF.value)) { + if (kaonAccepted) { event.kaons.push_back(candidate); } }