Skip to content

Track based distortions update#4318

Merged
osbornjd merged 9 commits into
sPHENIX-Collaboration:masterfrom
hupereir:track-based-distortions-update
Jun 25, 2026
Merged

Track based distortions update#4318
osbornjd merged 9 commits into
sPHENIX-Collaboration:masterfrom
hupereir:track-based-distortions-update

Conversation

@hupereir

@hupereir hupereir commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR adds a number of functionalities to further test the Matrix inversion method for track-based distortion corrections.
Namely:

  • the possibility to remove Edge clustesr
  • the possibility to store charge-dependent matrix containers in addition to the default charge-inclusive container.
    In addition the default minimum PT cut for the Micromegas-TPC matching module is moved back to 0.2 GeV.
    It can be set manually in the steering macro (@pedroanietom used to have it at 0.5)
    This increases by about x2 the number of TPC tracks correctly matched to TPOT. (TPOT clusters being later ignored in the track fit anyway).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

This PR extends the TPC distortion-correction workflow to further test the matrix inversion approach on TPOT-related studies, improving track/cluster handling and enabling charge-dependent matrix storage. It also restores the Micromegas–TPC matching module’s default minimum pT cut to 0.2 GeV to increase the number of matched TPC tracks (while still ignoring TPOT clusters later in the track fit).

Key changes:

  • PHTpcResiduals
    • Added an ignoreEdgeClusters option (setIgnoreEdgeClusters(bool)) to optionally skip edge TPC clusters.
    • Added charge-separated space-charge matrix containers:
      • m_matrix_container_pos
      • m_matrix_container_neg
    • Updated track processing to tighten cluster accounting:
      • Increment total-cluster count only for TPC clusters
      • Skip missing clusters
      • Skip edge clusters when enabled
      • Fill matrices for accepted clusters via a loop over the container set determined by track charge (default/inclusive container is still updated, plus the sign-specific one).
    • Extended grid-dimension configuration so it applies to the inclusive, pos, and neg containers.
    • Updated output behavior to conditionally create/write the ROOT output file and to write whichever matrix containers exist.
    • Added initialization/diagnostic printout for m_ignoreEdgeClusters.
  • Matrix container introspection for inversion
    • Added virtual int get_entries() const to TpcSpaceChargeMatrixContainer (default 0).
    • Implemented get_entries() in TpcSpaceChargeMatrixContainerv2 to return the total entries across m_entries (via std::accumulate).
    • Enhanced TpcSpaceChargeMatrixInversion verbose logging to print loaded filenames/object names and entry counts (including via m_matrix_container->get_entries() after load/guard).
  • Micromegas–TPC matching default pT
    • Restored default _pt_cut to 0.2 GeV (still overrideable via the existing steering setter).

Potential risk areas:

  • ROOT I/O / object layout changes: additional _pos and _neg matrix containers may affect downstream code expecting only the original inclusive container names.
  • Reconstruction behavior changes: enabling edge-cluster rejection and restoring the lower default pT cut can alter which tracks/clusters contribute to the residuals and thus the produced correction matrices.
  • Interface compatibility: downstream consumers of matrix containers may need to accommodate the new get_entries() virtual method if they use custom container subclasses.
  • Performance: extra bookkeeping and writing additional containers (pos/neg) may slightly impact runtime and output size.

Possible future improvements:

  • Add validation/monitoring comparing inclusive vs. charge-separated matrices (and quantifying differences in inversion/corrections).
  • Document the edge-cluster option and default pT behavior more explicitly in steering examples.
  • Add regression tests that exercise both (i) edge-cluster removal enabled/disabled and (ii) inclusive-only vs. inclusive+charge-separated outputs.

AI can make mistakes—please use best judgment when reviewing the implementation details and assumptions.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b235c9c4-36a4-4986-afbd-b4b9967c074e

📥 Commits

Reviewing files that changed from the base of the PR and between 4d747f2 and 81cccb7.

📒 Files selected for processing (3)
  • offline/packages/tpccalib/PHTpcResiduals.cc
  • offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.cc
  • offline/packages/tpccalib/TpcSpaceChargeMatrixInversion.cc
✅ Files skipped from review due to trivial changes (1)
  • offline/packages/tpccalib/TpcSpaceChargeMatrixInversion.cc
🚧 Files skipped from review as they are similar to previous changes (2)
  • offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.cc
  • offline/packages/tpccalib/PHTpcResiduals.cc

📝 Walkthrough

Walkthrough

The PR adds a get_entries() accessor to TPC space-charge matrix containers, extends PHTpcResiduals with edge-cluster filtering and charge-separated matrix containers, and lowers the default _pt_cut in PHMicromegasTpcTrackMatching.

Changes

TPC residuals and matrix handling

Layer / File(s) Summary
Matrix entry count accessor
offline/packages/tpccalib/TpcSpaceChargeMatrixContainer.h, offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.h, offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.cc, offline/packages/tpccalib/TpcSpaceChargeMatrixInversion.cc
TpcSpaceChargeMatrixContainer declares get_entries(), TpcSpaceChargeMatrixContainerv2 implements it from m_entries, and TpcSpaceChargeMatrixInversion prints the entry count when loading and using matrices.
Residuals options and container setup
offline/packages/tpccalib/PHTpcResiduals.h, offline/packages/tpccalib/PHTpcResiduals.cc
PHTpcResiduals adds setIgnoreEdgeClusters, stores the flag, allocates m_matrix_container_pos and m_matrix_container_neg, and logs the edge-cluster setting during Init.
Cluster filtering in processTrack
offline/packages/tpccalib/PHTpcResiduals.cc
processTrack now counts only TPC clusters, skips missing clusters, and skips edge clusters when the option is enabled.
Charge-split matrix fill and output
offline/packages/tpccalib/PHTpcResiduals.cc
setGridDimensions, matrix filling, and End are extended to m_matrix_container, m_matrix_container_pos, and m_matrix_container_neg.

Micromegas track matching default

Layer / File(s) Summary
Default pT cut
offline/packages/trackreco/PHMicromegasTpcTrackMatching.h
PHMicromegasTpcTrackMatching now initializes _pt_cut to 0.2 instead of 0.5.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.cc

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.18][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

offline/packages/tpccalib/PHTpcResiduals.cc

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.19][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

offline/packages/tpccalib/TpcSpaceChargeMatrixInversion.cc

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.17][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 55a636c8-1e4a-4b8d-88ec-3dcd97f2df9c

📥 Commits

Reviewing files that changed from the base of the PR and between 802edc3 and 4d747f2.

📒 Files selected for processing (7)
  • offline/packages/tpccalib/PHTpcResiduals.cc
  • offline/packages/tpccalib/PHTpcResiduals.h
  • offline/packages/tpccalib/TpcSpaceChargeMatrixContainer.h
  • offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.cc
  • offline/packages/tpccalib/TpcSpaceChargeMatrixContainerv2.h
  • offline/packages/tpccalib/TpcSpaceChargeMatrixInversion.cc
  • offline/packages/trackreco/PHMicromegasTpcTrackMatching.h

Comment on lines 194 to 195
std::unique_ptr<TFile> outputfile(TFile::Open(m_outputfile.c_str(), "RECREATE"));
outputfile->cd();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard against a failed TFile::Open before dereferencing.

TFile::Open returns nullptr if the output file cannot be created (bad path, permissions, disk full). The subsequent outputfile->cd() would then dereference a null pointer and crash the job at End. Note that add_from_file already guards its TFile::Open with a null check, so this path is inconsistent.

🛡️ Proposed guard
     std::unique_ptr<TFile> outputfile(TFile::Open(m_outputfile.c_str(), "RECREATE"));
+    if (!outputfile)
+    {
+      std::cout << "PHTpcResiduals::End - could not create output file " << m_outputfile << std::endl;
+      return Fun4AllReturnCodes::EVENT_OK;
+    }
     outputfile->cd();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
std::unique_ptr<TFile> outputfile(TFile::Open(m_outputfile.c_str(), "RECREATE"));
outputfile->cd();
std::unique_ptr<TFile> outputfile(TFile::Open(m_outputfile.c_str(), "RECREATE"));
if (!outputfile)
{
std::cout << "PHTpcResiduals::End - could not create output file " << m_outputfile << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}
outputfile->cd();

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 4d747f2e15e21f59a40bfe960c5ba05ae9b14265:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 81cccb72de6ca28c7b943bb8c909381778112a1c:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd osbornjd merged commit 7ef1f2b into sPHENIX-Collaboration:master Jun 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants