Skip to content

Fix covariance matrices' indexing scheme in DEventWriterROOT - #1176

Open
jase231 wants to merge 1 commit into
JeffersonLab:masterfrom
jase231:jserwe_fix_eventwriter
Open

jase231 wants to merge 1 commit into
JeffersonLab:masterfrom
jase231:jserwe_fix_eventwriter

Conversation

@jase231

@jase231 jase231 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Currently, one covariance matrix is written into a branch per event by role, e.g. Photon1__ErrMatrix, PiPlus__ErrMatrix, etc. However, which shower or track is assigned to which role varies by combo. Therefore in the current scheme, each __ErrMatrix slot is filled once per combo per event, with each combo overwriting the previous combo's matrix elements. Any consumer of written covariance matrices therefore reads another particle's matrix whenever its track/shower in that role differs from the assignment of the last combo written.

This PR fixes the issue by indexing the covariance matrices based on the reconstructed particles they belong to (ie. via the ChargedHypo and NeutralHypo arrays). Matrices can now be accessed by first getting the correct hypothesis index from the Role__ChargedIndex or Role__NeutralIndex arrays, then using that index to access the array: &ChargedHypo__ErrMatrix[hypo_index * numEntries_ParticleErrM]. That obtains a pointer to the first element of the packed covariance matrix, with elements 0 through numEntries_ParticleErrM - 1 accessible via pointer arithmetic. Role__ErrMatrix branches are no longer written, replaced by ChargedHypo__ErrMatrix, NeutralHypo__ErrMatrix, and the length counters NumChargedHypoErrM / NumNeutralHypoErrM.

Additionally, this PR fixes a bug in numEntries_ShowerErrM's sizing: it was hardcoded to 15, but P4-only fits write the 7×7 neutral particle matrix (28 elements), so only the first 15 elements were saved. Its value now depends on the kinfit type.

Neutral hypotheses would access NeutralHypo__ErrMatrix with stride numEntries_ShowerErrM.

All the covariance matrix related logic has been moved out of Create_Branches_KinFitData() and Fill_KinFitData() and spread between the Create_Branches_*Hypotheses and Fill functions.

@aaust

aaust commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

For security reason, the pull request test does not run code from forks. I will try to find a workaround.

@jase231

jase231 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Hey Alex, sorry about that. I remember that being an issue previously as well. Is there some alternative way for me to open PRs? I'm assuming I can't just push my branch to this upstream repo right?

@aaust

aaust commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

No worry, I triggered the test manually and even found a bug in the reporting.
You should be able to push a branch to this repository and open a PR from here. This is what most people do and you may try it next time.

@gluex

gluex commented Oct 26, 2026

Copy link
Copy Markdown

Test status for this pull request: SUCCESS

Summary: summary.txt
Logs: results/log

Build log: make_jserwe_fix_eventwriter.log
Build report: report_jserwe_fix_eventwriter.txt

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.

3 participants