Skip to content

[PWGLF] K1(1270): shared selection core and ML training-table exporter - #18167

Open
BongHwi wants to merge 9 commits into
AliceO2Group:masterfrom
BongHwi:reso-k1-ml-prep
Open

BongHwi wants to merge 9 commits into
AliceO2Group:masterfrom
BongHwi:reso-k1-ml-prep

Conversation

@BongHwi

@BongHwi BongHwi commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Modernizes the K1(1270) micro analysis and adds a derived-table exporter for ML training, with the selection shared between both tasks.

Changes

  • PWGLF/Core/ResoAnalysisSelectionCore.h (new): generic event, track-quality, TOF-requirement and PID selection of resonance daughters for full and micro (quantised DCA/nSigma) v001 tracks, including grid-consistency checks of the cuts for micro tracks. PID is species-agnostic (PIDCutConfig), so other resonance tasks can reuse it.
  • PWGLF/Core/K1AnalysisMicroCore.h (new): K1 selection (secondary/candidate cuts), truth classification and the (pion, pion, kaon) candidate enumeration with cut-flow instrumentation. Tasks receive the selected pairs/candidates through hooks.
  • k1AnalysisMicro.cxx: updated to the v001 resonance tables and the shared core; all analysis histograms are registered and filled in the task.
  • k1TrainingTable.cxx (new workflow k1-training-table) + PWGLF/DataModel/LFK1MlTables.h + PWGLF/Core/K1MlFeatures.h: writes unlike-sign candidates at the loose or selected stage with canonical tracks, master features, pass bits and MC truth.

BongHwi and others added 8 commits September 30, 2026 06:23
- Use v001 resonance tables (ResoCollisions_001, ResoMicroTracks_001,
  ResoMCMicroTracks_001, ResoMCParents_001); keep ResoTracks as fallback
- Unify full/micro track selection and PID in a single code path,
  handling quantised v001 DCA/nSigma values and producer pT-dependent
  DCA bits
- Apply pion PID on micro tracks; apply cUseOnlyTOFTrackPi to both
  pions and cUseOnlyTOFTrackKa to the kaon; add cByPassTOF and
  optional pT-dependent PID/DCA
- Restore secondary-resonance and K1 candidate cuts (mass window,
  other-pair masses, opening angle, pair asymmetry); -999 disables a
  cut and skips its computation; fill QAcut and kaon QA
- Iterate unordered pion pairs to stop double-filling triplets, with a
  canonical pion assignment for role-dependent quantities
- Cache per-collision selections, record cut-flow from the selection
  functions, add event cuts and init-time config validation
- Replace TLorentzVector with ROOT::Math vectors, use PDG constants,
  remove unused options
- Use const references in range-based loops over configured PID cuts
- Replace magic numbers in init checks with named constants
…isMicroCore.h

Split the K1(1270) microtrack histogram task into a reusable core header
and a thin workflow, so that other K1 workflows can share one selection
and candidate loop implementation instead of copying it.

- PWGLF/Core/K1AnalysisMicroCore.h (new): event, track, PID, secondary
  and candidate configurable groups (no group prefix, so all JSON keys and
  defaults are unchanged), the track quality/PID stages, the quantised
  DCA/nSigma grid checks, the sibling-based truth classification, the
  unordered triplet loop with its selection cache and cut-flow
  histograms, and the histogram registration. No using-directives, no
  runDataProcessing.h.
- k1AnalysisMicro.cxx: struct K1AnalysisMicro now owns the configurable
  groups, the histogram registry and the process functions, and calls the
  core. Process switches, configurable names/defaults, histogram names and
  the selection are unchanged.
Add a derived-table workflow that writes the unlike-sign K1(1270) micro
candidates selected by the shared K1 core, together with the canonical
tracks and a 125-entry feature vector for ML training.

- PWGLF/Core/K1MlFeatures.h (new): canonical unlike-sign role assignment
  (kaon, same-sign pion, opposite-sign pion) and the master feature
  builder of the frozen feature contract (FeatureContractSha256), with
  compile-time checks of the feature-name count and of the projection
  indices. The pion mass keeps the contract value 0.13957039 GeV
  (O2 MassPionCharged is 0.1395704 and would change the features).
- PWGLF/DataModel/LFK1MlTables.h (new): K1MlEvents, K1MlTracks,
  K1MlCandidates, K1MlInputs (float[125] features), K1MlTruth and
  K1MlGenAudit. Relations point only to the derived tables.
- K1AnalysisMicroCore.h: optional candidate callback and loose-stage
  traversal (pass bits 1/2/4/8/16; selected = 31), loose cut-flow
  histograms. The histogram task does not use them and is unchanged.
  Candidates at the selected stage are emitted only if they satisfy the
  canonical/feature contract, as at the loose stage.
- k1TrainingTable.cxx (new, workflow k1-training-table): struct
  K1TrainingTable reuses the core loop; invalid candidates are skipped and
  counted in ML/exportSkipped by build status instead of aborting.
…ilder

The K1 ML feature contract SHA covers the 125 feature names and the three
projection index lists only, so switching the pion mass from the local
literal to o2::constants::physics::MassPionCharged does not change the
contract identity. Feature values change at the 1e-8 relative level for
the pair masses; exports written with the previous literal are therefore
not byte-identical to new exports.
Initialize the TPC n-sigma once from the species instead of overwriting
a NaN default in both branches. The selection is unchanged.
Move the event, track-quality, TOF-requirement and PID selection of
resonance daughters into PWGLF/Core/ResoAnalysisSelectionCore.h. The K1
core keeps the K1 selection, truth classification, candidate loop and
its cut-flow/ML audit histograms, and hands the selected pion pairs and
candidates to the task through hooks. The K1 analysis histograms are now
registered and filled in k1AnalysisMicro.cxx; the training-table task
writes only the ML tables, CutFlow/*, ML/* and MCReco event counters.

The selection, all configurable names and the ML table output are
unchanged.
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

O2 linter results: ❌ 0 errors, ⚠️ 1 warnings, 🔕 0 disabled

@BongHwi

BongHwi commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Hello @omvazque , could you approve this PR?

@alibuild

alibuild commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 0ac4b3f at 2026-10-04 17:06:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'Found 5 errors and 17 warnings.'
Found 5 errors and 17 warnings.
++ [[ 5 -gt 0 ]]
++ cat /sw/BUILD/39404b7abaca86a15b5c77186730c961ae9fb622/O2Physics-code-check/errors.txt
PWGLF/Core/K1AnalysisMicroCore.h:24:1: error: included header LFResonanceTables.h is not used directly [misc-include-cleaner,-warnings-as-errors]
PWGLF/Core/K1AnalysisMicroCore.h:156:15: error: no header providing "ROOT::Math::PxPyPzMVector" is directly included [misc-include-cleaner,-warnings-as-errors]
PWGLF/Tasks/Resonances/k1AnalysisMicro.cxx:21:1: error: included header PhysicsConstants.h is not used directly [misc-include-cleaner,-warnings-as-errors]
PWGLF/Tasks/Resonances/k1AnalysisMicro.cxx:389:71: error: no header providing "ROOT::Math::PxPyPzMVector" is directly included [misc-include-cleaner,-warnings-as-errors]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:201:17: error: no header providing "ROOT::Math::PxPyPzMVector" is directly included [misc-include-cleaner,-warnings-as-errors]
++ [[ 17 -gt 0 ]]
++ cat /sw/BUILD/39404b7abaca86a15b5c77186730c961ae9fb622/O2Physics-code-check/warnings.txt
PWGLF/Core/K1AnalysisMicroCore.h:524:29: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
PWGLF/Core/K1AnalysisMicroCore.h:557:11: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
PWGLF/Core/K1AnalysisMicroCore.h:558:11: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
PWGLF/Core/K1AnalysisMicroCore.h:559:11: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
PWGLF/Core/K1AnalysisMicroCore.h:560:11: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
PWGLF/Core/K1MlFeatures.h:172:12: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/Core/K1MlFeatures.h:175:12: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/Core/K1MlFeatures.h:177:10: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/Core/K1MlFeatures.h:183:12: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/Core/K1MlFeatures.h:186:10: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/Core/K1MlFeatures.h:801:106: warning: use designated initializer list to initialize 'EncodedValue' [modernize-use-designated-initializers]
PWGLF/DataModel/LFK1MlTables.h:66:56: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:148:22: warning: redundant explicit casting to the same type 'int64_t' (aka 'long') as the sub-expression, remove this casting [readability-redundant-casting]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:160:20: warning: redundant explicit casting to the same type 'int64_t' (aka 'long') as the sub-expression, remove this casting [readability-redundant-casting]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:171:13: warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:212:22: warning: redundant explicit casting to the same type 'int64_t' (aka 'long') as the sub-expression, remove this casting [readability-redundant-casting]
PWGLF/Tasks/Resonances/k1TrainingTable.cxx:269:20: warning: redundant explicit casting to the same type 'int64_t' (aka 'long') as the sub-expression, remove this casting [readability-redundant-casting]
++ [[ 5 -gt 0 ]]
++ exit 1
--

Full log here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants