From c63fe60121ea411cca58058ea88a5877b8a7f392 Mon Sep 17 00:00:00 2001 From: jryu Date: Mon, 30 Nov 2026 00:18:38 +0900 Subject: [PATCH 1/2] [PWGJE] Add optional PV-TOF selection and QA to UPC jet QA Use the standard PV-TOF event-selection bit for data and detector-level MC. Add optional timing and jet QA by PV-TOF group and audit the selected BC and ZDC inputs. --- PWGJE/Tasks/jetUpcQa.cxx | 158 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 153 insertions(+), 5 deletions(-) diff --git a/PWGJE/Tasks/jetUpcQa.cxx b/PWGJE/Tasks/jetUpcQa.cxx index ed86c080f57..f1f88ffbce8 100644 --- a/PWGJE/Tasks/jetUpcQa.cxx +++ b/PWGJE/Tasks/jetUpcQa.cxx @@ -83,6 +83,46 @@ DECLARE_SOA_TABLE(UpcJetEvents, "AOD", "UPCJETEVENT", upcjetevent::CollisionIndex); using UpcJetEvent = UpcJetEvents::iterator; +// Optional provenance output. It records the existing selection decision and +// BC lookup without modifying event, neutron, or track selection. +namespace upczdcbcaudit +{ +DECLARE_SOA_COLUMN(IsMC, isMC, bool); +DECLARE_SOA_COLUMN(OriginalGlobalBC, originalGlobalBC, int64_t); +DECLARE_SOA_COLUMN(FoundGlobalBC, foundGlobalBC, int64_t); +DECLARE_SOA_COLUMN(SelectedGlobalBC, selectedGlobalBC, int64_t); +DECLARE_SOA_COLUMN(HasSelectedBC, hasSelectedBC, bool); +DECLARE_SOA_COLUMN(HasZDCRecord, hasZDCRecord, bool); +DECLARE_SOA_COLUMN(EnergyPresentA, energyPresentA, bool); +DECLARE_SOA_COLUMN(EnergyPresentC, energyPresentC, bool); +DECLARE_SOA_COLUMN(TimePresentA, timePresentA, bool); +DECLARE_SOA_COLUMN(TimePresentC, timePresentC, bool); +DECLARE_SOA_COLUMN(IsAccepted, isAccepted, bool); +} // namespace upczdcbcaudit +DECLARE_SOA_TABLE(UpcZdcBCAudits, "AOD", "UPCZDCBCAUDIT", + upcjetevent::CollisionIndex, upczdcbcaudit::IsMC, + upczdcbcaudit::OriginalGlobalBC, upczdcbcaudit::FoundGlobalBC, + upczdcbcaudit::SelectedGlobalBC, upczdcbcaudit::HasSelectedBC, + upczdcbcaudit::HasZDCRecord, upczdcbcaudit::EnergyPresentA, + upczdcbcaudit::EnergyPresentC, upczdcbcaudit::TimePresentA, + upczdcbcaudit::TimePresentC, upcjetevent::GapSide, + upcjetevent::PosZ, upcjetevent::EnergyCommonZNA, + upcjetevent::EnergyCommonZNC, upcjetevent::TimeZNA, + upcjetevent::TimeZNC, upczdcbcaudit::IsAccepted); + +namespace upcpvtofqa +{ +DECLARE_SOA_COLUMN(NumPVContributors, numPVContributors, int); +DECLARE_SOA_COLUMN(NumPVTOF, numPVTOF, int); +DECLARE_SOA_COLUMN(CollisionTimeRes, collisionTimeRes, float); +DECLARE_SOA_COLUMN(VertexTOFMatched, vertexTOFMatched, bool); +} // namespace upcpvtofqa +DECLARE_SOA_TABLE(UpcPVTOFQAs, "AOD", "UPCPVTOFQA", + upcjetevent::CollisionIndex, upczdcbcaudit::IsMC, + upcpvtofqa::NumPVContributors, upcpvtofqa::NumPVTOF, + upcpvtofqa::CollisionTimeRes, upcpvtofqa::VertexTOFMatched, + upczdcbcaudit::IsAccepted); + namespace upcjet { DECLARE_SOA_INDEX_COLUMN(UpcJetEvent, upcJetEvent); @@ -322,6 +362,8 @@ struct JetUpcQa { Produces upcTrackTable; Produces upcTrackTableMCD; Produces upcTrackTableMCP; + Produces upcZdcBCAuditTable; + Produces upcPVTOFQATable; // Type aliases using BCsWithSel = soa::Join; @@ -371,8 +413,11 @@ struct JetUpcQa { Configurable cfgJetEtaMax{"cfgJetEtaMax", 0.5f, "Max jet |eta|"}; Configurable cfgZDCEnergyCut{"cfgZDCEnergyCut", 10.f, "ZDC common energy threshold for Xn tagging"}; Configurable cfgZDCTimeCut{"cfgZDCTimeCut", 2.f, "ZDC time window for Xn tagging (ns)"}; + Configurable cfgWriteZDCBCAudit{"cfgWriteZDCBCAudit", false, "Write existing selected-BC lookup and acceptance provenance"}; + Configurable cfgWritePVTOFQA{"cfgWritePVTOFQA", false, "Record timing and jet QA for both PV TOF match groups"}; Configurable cfgUseGapTagging{"cfgUseGapTagging", true, "Require SGSelector gap tag for event selection"}; Configurable cfgUseZDCTagging{"cfgUseZDCTagging", false, "Require ZDC neutron tag for event selection"}; + Configurable cfgRequireVertexTOFMatched{"cfgRequireVertexTOFMatched", false, "Require at least one PV contributor matched to TOF"}; Configurable cfgRequiredGapSide{"cfgRequiredGapSide", 0, "Required gap side when gap tagging is enabled (0 = any selected gap, 1 = SingleGapA, 2 = SingleGapC, 3 = DoubleGap)"}; Configurable cfgRequiredNeutronClass{"cfgRequiredNeutronClass", 0, "Required neutron class when ZDC tagging is enabled (0 = any valid class, 1 = XnXn, 2 = Xn0n, 3 = 0nXn, 4 = 0n0n)"}; @@ -382,11 +427,20 @@ struct JetUpcQa { float timeZNA = -999.f; float timeZNC = -999.f; int neutronClass = 0; + bool hasRecord = false; + bool energyPresentA = false; + bool energyPresentC = false; + bool timePresentA = false; + bool timePresentC = false; }; struct GapSelectionInfo { int gapSide = o2::aod::sgselector::NoGap; ZDCTagInfo zdc; + int64_t originalGlobalBC = -1; + int64_t foundGlobalBC = -1; + int64_t selectedGlobalBC = -1; + bool hasSelectedBC = false; }; SGSelector sgSelector; @@ -451,6 +505,18 @@ struct JetUpcQa { registry.add("hNeutronClassMCD", "Neutron class (MCD);class;Counts", {HistType::kTH1F, {{5, -0.5, 4.5}}}); registry.add("hSelectionBits", "Selection bits (Data);0 all 1 gap 2 zdc 3 accepted;Counts", {HistType::kTH1F, {{4, -0.5, 3.5}}}); registry.add("hSelectionBitsMCD", "Selection bits (MCD);0 all 1 gap 2 zdc 3 accepted;Counts", {HistType::kTH1F, {{4, -0.5, 3.5}}}); + + if (cfgWritePVTOFQA) { + const AxisSpec tofGroups{2, -0.5, 1.5, "TOF-matched PV tracks (0: none, 1: at least one)"}; + const AxisSpec timeResolution{1000, 0., 1000., "Collision time resolution (ns)"}; + const AxisSpec jetPt{200, 0., 200., "Jet pT (GeV/c)"}; + registry.add("hCollisionTimeResByPVTOF", "Reconstructed collision time resolution (Data)", HistType::kTH2F, {timeResolution, tofGroups}); + registry.add("hCollisionTimeResByPVTOFMCD", "Reconstructed collision time resolution (MCD)", HistType::kTH2F, {timeResolution, tofGroups}); + registry.add("hAcceptedCollisionsByPVTOF", "Accepted collisions (Data)", HistType::kTH1F, {tofGroups}); + registry.add("hAcceptedCollisionsByPVTOFMCD", "Accepted collisions (MCD)", HistType::kTH1F, {tofGroups}); + registry.add("hJetPtByPVTOF", "Charged jets by collision PV TOF group (Data)", HistType::kTH2F, {jetPt, tofGroups}); + registry.add("hJetPtByPVTOFMCD", "Charged jets by collision PV TOF group (MCD)", HistType::kTH2F, {jetPt, tofGroups}); + } } template @@ -555,11 +621,13 @@ struct JetUpcQa { return zdc.neutronClass > 0; } - bool isAcceptedEvent(bool isGapTagged, bool isZDCTagged, float posZ) const + template + bool isAcceptedEvent(TCollision const& collision, bool isGapTagged, bool isZDCTagged) const { - return std::abs(posZ) <= cfgVertexZCut.value && + return std::abs(collision.posZ()) <= cfgVertexZCut.value && (!cfgUseGapTagging.value || isGapTagged) && - (!cfgUseZDCTagging.value || isZDCTagged); + (!cfgUseZDCTagging.value || isZDCTagged) && + (!cfgRequireVertexTOFMatched.value || collision.selection_bit(aod::evsel::kIsVertexTOFmatched)); } void fillSelectionBits(bool isMCD, bool isGapTagged, bool isZDCTagged, bool isAccepted) @@ -603,6 +671,11 @@ struct JetUpcQa { zdcInfo.energyCommonZNC = zdc.energyCommonZNC(); zdcInfo.timeZNA = zdc.timeZNA(); zdcInfo.timeZNC = zdc.timeZNC(); + zdcInfo.hasRecord = true; + zdcInfo.energyPresentA = std::isfinite(zdcInfo.energyCommonZNA); + zdcInfo.energyPresentC = std::isfinite(zdcInfo.energyCommonZNC); + zdcInfo.timePresentA = std::isfinite(zdcInfo.timeZNA); + zdcInfo.timePresentC = std::isfinite(zdcInfo.timeZNC); zdcInfo.neutronClass = getNeutronClass(zdcInfo); return zdcInfo; } @@ -618,11 +691,18 @@ struct JetUpcQa { GapSelectionInfo selection; + if (cfgWriteZDCBCAudit && collision.bcId() >= 0) { + selection.originalGlobalBC = collision.template bc_as().globalBC(); + } + if (!collision.has_foundBC()) { return selection; } auto const bc = collision.template foundBC_as(); + if (cfgWriteZDCBCAudit) { + selection.foundGlobalBC = bc.globalBC(); + } auto const bcRange = udhelpers::compatibleBCs(collision, sgCuts.NDtcoll(), bcs, sgCuts.minNBCs()); auto const result = sgSelector.IsSelected(sgCuts, collision, bcRange, bc, @@ -632,6 +712,10 @@ struct JetUpcQa { selection.gapSide = result.value; if (result.bc) { selection.zdc = getZDCTagInfo(*result.bc); + if (cfgWriteZDCBCAudit) { + selection.selectedGlobalBC = result.bc->globalBC(); + selection.hasSelectedBC = true; + } } if (!isSelectedGap(selection.gapSide)) { @@ -645,6 +729,60 @@ struct JetUpcQa { return selection; } + template + void writeZDCBCAudit(TCollision const& collision, GapSelectionInfo const& selection, bool isMC, bool accepted) + { + if (!cfgWriteZDCBCAudit) { + return; + } + auto const& zdc = selection.zdc; + upcZdcBCAuditTable(collision.globalIndex(), isMC, + selection.originalGlobalBC, selection.foundGlobalBC, + selection.selectedGlobalBC, selection.hasSelectedBC, + zdc.hasRecord, zdc.energyPresentA, zdc.energyPresentC, + zdc.timePresentA, zdc.timePresentC, selection.gapSide, + collision.posZ(), zdc.energyCommonZNA, zdc.energyCommonZNC, + zdc.timeZNA, zdc.timeZNC, accepted); + } + + template + int fillPVTOFQA(TCollision const& collision, TTracks const& tracks, bool accepted) + { + if (!cfgWritePVTOFQA) { + return 0; + } + + int numPVTOF = 0; + for (auto const& track : tracks) { + if (track.collisionId() == collision.globalIndex() && track.isPVContributor() && track.hasTOF()) { + ++numPVTOF; + } + } + const int group = numPVTOF > 0; + const auto timeRes = collision.collisionTimeRes(); + const bool vertexTOFMatched = collision.selection_bit(aod::evsel::kIsVertexTOFmatched); + upcPVTOFQATable(collision.globalIndex(), IsMC, collision.numContrib(), numPVTOF, + timeRes, vertexTOFMatched, accepted); + + const bool hasValidTimeRes = std::isfinite(timeRes) && timeRes >= 0.f; + if constexpr (IsMC) { + if (hasValidTimeRes) { + registry.fill(HIST("hCollisionTimeResByPVTOFMCD"), timeRes, group); + } + if (accepted) { + registry.fill(HIST("hAcceptedCollisionsByPVTOFMCD"), group); + } + } else { + if (hasValidTimeRes) { + registry.fill(HIST("hCollisionTimeResByPVTOF"), timeRes, group); + } + if (accepted) { + registry.fill(HIST("hAcceptedCollisionsByPVTOF"), group); + } + } + return group; + } + // Helper: jet finding for detector-level tracks template void runJetFindingDet(TTracks const& tracks, @@ -799,7 +937,9 @@ struct JetUpcQa { int gapSide = gapInfo.gapSide; bool isGapTagged = isSelectedGap(gapSide); bool isZDCTagged = isSelectedZDC(gapInfo.zdc); - bool isAccepted = isAcceptedEvent(isGapTagged, isZDCTagged, collision.posZ()); + bool isAccepted = isAcceptedEvent(collision, isGapTagged, isZDCTagged); + writeZDCBCAudit(collision, gapInfo, false, isAccepted); + const int pvTOFGroup = fillPVTOFQA(collision, tracks, isAccepted); registry.fill(HIST("hGapSide"), gapSide); registry.fill(HIST("hZNAEnergy"), gapInfo.zdc.energyCommonZNA); registry.fill(HIST("hZNCEnergy"), gapInfo.zdc.energyCommonZNC); @@ -880,6 +1020,9 @@ struct JetUpcQa { jet.area(), static_cast(constituents.size())); + if (cfgWritePVTOFQA) { + registry.fill(HIST("hJetPtByPVTOF"), jet.pt(), pvTOFGroup); + } int jetIdx = upcJetTable.lastIndex(); for (auto const& c : constituents) { @@ -901,7 +1044,9 @@ struct JetUpcQa { int gapSide = gapInfo.gapSide; bool isGapTagged = isSelectedGap(gapSide); bool isZDCTagged = isSelectedZDC(gapInfo.zdc); - bool isAccepted = isAcceptedEvent(isGapTagged, isZDCTagged, collision.posZ()); + bool isAccepted = isAcceptedEvent(collision, isGapTagged, isZDCTagged); + writeZDCBCAudit(collision, gapInfo, true, isAccepted); + const int pvTOFGroup = fillPVTOFQA(collision, tracks, isAccepted); registry.fill(HIST("hGapSideMCD"), gapSide); registry.fill(HIST("hZNAEnergyMCD"), gapInfo.zdc.energyCommonZNA); registry.fill(HIST("hZNCEnergyMCD"), gapInfo.zdc.energyCommonZNC); @@ -978,6 +1123,9 @@ struct JetUpcQa { jet.area(), static_cast(constituents.size())); + if (cfgWritePVTOFQA) { + registry.fill(HIST("hJetPtByPVTOFMCD"), jet.pt(), pvTOFGroup); + } int jetIdx = upcJetTableMCD.lastIndex(); for (auto const& c : constituents) { From ec382b8493fda62a76b252317e25bfaceda868dc Mon Sep 17 00:00:00 2001 From: jryu Date: Mon, 30 Nov 2026 10:44:18 +0900 Subject: [PATCH 2/2] [PWGJE] Include the event-selection bit declaration in UPC jet QA --- PWGJE/Tasks/jetUpcQa.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/PWGJE/Tasks/jetUpcQa.cxx b/PWGJE/Tasks/jetUpcQa.cxx index f1f88ffbce8..8300558ac52 100644 --- a/PWGJE/Tasks/jetUpcQa.cxx +++ b/PWGJE/Tasks/jetUpcQa.cxx @@ -16,6 +16,7 @@ #include "PWGUD/Core/SGCutParHolder.h" #include "PWGUD/Core/SGSelector.h" +#include "Common/CCDB/EventSelectionParams.h" #include "Common/DataModel/Centrality.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/Multiplicity.h"