Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 154 additions & 5 deletions PWGJE/Tasks/jetUpcQa.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,6 +84,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);
Expand Down Expand Up @@ -322,6 +363,8 @@ struct JetUpcQa {
Produces<aod::UpcTracks> upcTrackTable;
Produces<aod::UpcTracksMCD> upcTrackTableMCD;
Produces<aod::UpcTracksMCP> upcTrackTableMCP;
Produces<aod::UpcZdcBCAudits> upcZdcBCAuditTable;
Produces<aod::UpcPVTOFQAs> upcPVTOFQATable;

// Type aliases
using BCsWithSel = soa::Join<aod::BCsWithTimestamps, aod::BcSels, aod::Run3MatchedToBCSparse>;
Expand Down Expand Up @@ -371,8 +414,11 @@ struct JetUpcQa {
Configurable<float> cfgJetEtaMax{"cfgJetEtaMax", 0.5f, "Max jet |eta|"};
Configurable<float> cfgZDCEnergyCut{"cfgZDCEnergyCut", 10.f, "ZDC common energy threshold for Xn tagging"};
Configurable<float> cfgZDCTimeCut{"cfgZDCTimeCut", 2.f, "ZDC time window for Xn tagging (ns)"};
Configurable<bool> cfgWriteZDCBCAudit{"cfgWriteZDCBCAudit", false, "Write existing selected-BC lookup and acceptance provenance"};
Configurable<bool> cfgWritePVTOFQA{"cfgWritePVTOFQA", false, "Record timing and jet QA for both PV TOF match groups"};
Configurable<bool> cfgUseGapTagging{"cfgUseGapTagging", true, "Require SGSelector gap tag for event selection"};
Configurable<bool> cfgUseZDCTagging{"cfgUseZDCTagging", false, "Require ZDC neutron tag for event selection"};
Configurable<bool> cfgRequireVertexTOFMatched{"cfgRequireVertexTOFMatched", false, "Require at least one PV contributor matched to TOF"};
Configurable<int> cfgRequiredGapSide{"cfgRequiredGapSide", 0, "Required gap side when gap tagging is enabled (0 = any selected gap, 1 = SingleGapA, 2 = SingleGapC, 3 = DoubleGap)"};
Configurable<int> cfgRequiredNeutronClass{"cfgRequiredNeutronClass", 0, "Required neutron class when ZDC tagging is enabled (0 = any valid class, 1 = XnXn, 2 = Xn0n, 3 = 0nXn, 4 = 0n0n)"};

Expand All @@ -382,11 +428,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;
Expand Down Expand Up @@ -451,6 +506,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 <typename TTrack>
Expand Down Expand Up @@ -555,11 +622,13 @@ struct JetUpcQa {
return zdc.neutronClass > 0;
}

bool isAcceptedEvent(bool isGapTagged, bool isZDCTagged, float posZ) const
template <typename TCollision>
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)
Expand Down Expand Up @@ -603,6 +672,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;
}
Expand All @@ -618,11 +692,18 @@ struct JetUpcQa {

GapSelectionInfo selection;

if (cfgWriteZDCBCAudit && collision.bcId() >= 0) {
selection.originalGlobalBC = collision.template bc_as<BCsWithSel>().globalBC();
}

if (!collision.has_foundBC()) {
return selection;
}

auto const bc = collision.template foundBC_as<BCsWithSel>();
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,
Expand All @@ -632,6 +713,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)) {
Expand All @@ -645,6 +730,60 @@ struct JetUpcQa {
return selection;
}

template <typename TCollision>
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 <bool IsMC, typename TCollision, typename TTracks>
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 <typename TTracks, typename TJetTable, typename TTrkTable>
void runJetFindingDet(TTracks const& tracks,
Expand Down Expand Up @@ -799,7 +938,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<false>(collision, tracks, isAccepted);
registry.fill(HIST("hGapSide"), gapSide);
registry.fill(HIST("hZNAEnergy"), gapInfo.zdc.energyCommonZNA);
registry.fill(HIST("hZNCEnergy"), gapInfo.zdc.energyCommonZNC);
Expand Down Expand Up @@ -880,6 +1021,9 @@ struct JetUpcQa {
jet.area(),
static_cast<int>(constituents.size()));

if (cfgWritePVTOFQA) {
registry.fill(HIST("hJetPtByPVTOF"), jet.pt(), pvTOFGroup);
}
int jetIdx = upcJetTable.lastIndex();

for (auto const& c : constituents) {
Expand All @@ -901,7 +1045,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<true>(collision, tracks, isAccepted);
registry.fill(HIST("hGapSideMCD"), gapSide);
registry.fill(HIST("hZNAEnergyMCD"), gapInfo.zdc.energyCommonZNA);
registry.fill(HIST("hZNCEnergyMCD"), gapInfo.zdc.energyCommonZNC);
Expand Down Expand Up @@ -978,6 +1124,9 @@ struct JetUpcQa {
jet.area(),
static_cast<int>(constituents.size()));

if (cfgWritePVTOFQA) {
registry.fill(HIST("hJetPtByPVTOFMCD"), jet.pt(), pvTOFGroup);
}
int jetIdx = upcJetTableMCD.lastIndex();

for (auto const& c : constituents) {
Expand Down
Loading