CalPatRec code review: 26 issues identified across the package#1788
CalPatRec code review: 26 issues identified across the package#1788
Conversation
…e package Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/23aa289b-bce0-4124-9da6-e052cee9af45 Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com>
|
Hi @Copilot,
which require these tests: build. @Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main. 📝 The author of this pull request is not a member of the Mu2e github organisation. |
Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/23aa289b-bce0-4124-9da6-e052cee9af45 Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com>
…stead Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/4376776e-355e-4158-8204-38fdf6998859 Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com>
- Fix #1: Buffer overflow in DeltaCandidate::removeSeed() - add bounds checks - Fix #2: Stale facez pointer in CalHelixFinderAlg - set to ibest.face - Fix #3: Division-by-zero guards in DeltaSeed/DeltaCandidate/ProtonCandidate accessors - Fix #4: Guard zero determinant in DeltaSeed::CalculateCogAndChi2 and DeltaCandidate - Fix #5: Guard rho==0 in DeltaCandidate direction calculation - Fix #6: Null pointer dereference in PrefetchData_module - check _shpcol - Fix #7: Division by zero in PhiClusterFinder::initCluster() - guard weight - Fix #9: Memory leak - use unique_ptr for DeltaFinderAlg in DeltaFinder_module - Fix #10: Out-of-bounds in DeltaFinderAlg - skip invalid indices instead of continuing - Fix #11: Update coordinate accumulators in DeltaSeed::ReplaceFirstHit() - Fix #12: Guard division by zero in time-vs-z fit (MergeDeltaCandidate, ProtonCandidate) - Fix #13: Guard weight==0 in CalHelixFinderAlg phi weight calculations - Fix #14: Guard _dfdz==0 in CalHelixFinderAlg helix calculations - Fix #15: Early return on radius==0 or _dfdz==0 in defineHelixParams - Fix #16: Guard timeVar()==0 in TZClusterFinder - Fix #17: Clean up TCanvas in TZClusterFinder destructor, init _c1 to nullptr - Fix #19: Add indexArray bounds check in ComboHitFilter - Fix #21: Use nullptr instead of 0 in CalHelixFinder_module error handling - Fix #25: Replace NULL with nullptr throughout CalPatRec Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/f71e1120-4e72-45c3-9734-76ea0561201d Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com>
|
@FNALbuild run build test |
|
⌛ The following tests have been triggered for 6e09f2c: build (Build queue - API unavailable) |
|
☀️ The build tests passed at 6e09f2c.
N.B. These results were obtained from a build of this Pull Request at 6e09f2c after being merged into the base branch at 5ec09f9. For more information, please check the job page here. |
michaelmackenzie
left a comment
There was a problem hiding this comment.
Mostly this looks okay to me, a large part is either NULL to nullptr (transparent) or checking for cases that should be impossible or caught earlier (combo hits with no hits, 0 radius helices, etc.). There are a few logic changes that should be better understood and confirmed by original authors if possible.
| double rho = sqrt(xc*xc+yc*yc); | ||
| fNx = xc/rho; | ||
| fNy = yc/rho; | ||
| //----------------------------------------------------------------------------- |
There was a problem hiding this comment.
Please restore this comment
There was a problem hiding this comment.
@copilot please address this comment
| fT0 = tm-fDtDz*zm; | ||
| fSigT0 = sqrt((t2m-tm*tm)/(fNSeeds-0.9999)); | ||
| } | ||
| else { |
There was a problem hiding this comment.
Does this change behavior for fNSeeds == 1? Is fNSeeds == 1 not allowed?
There was a problem hiding this comment.
You're right — the original code didn't have an fNSeeds > 1 guard here (unlike removeSeed and AddSeed). MergeDeltaCandidate should always produce fNSeeds >= 2 after merging, so the extra guard was unnecessary and changed behavior. Reverted to only guard denom != 0 in 307a15d.
| if ((of < 0) || (of >= kNFaces )) printf(" >>> ERROR: wrong face number: %i\n",of); | ||
| if ((op < 0) || (op >= kNPanelsPerFace)) printf(" >>> ERROR: wrong panel number: %i\n",op); | ||
| } | ||
| continue; |
There was a problem hiding this comment.
Is the behavior fine when continuing from here, which wasn't done before?
There was a problem hiding this comment.
The continue skips adding this single hit to the face data structures when the station/face/panel indices are out of range. Previously the code would print the error but then proceed to use the invalid indices for array access (_data->fFaceData[os][of]), which is undefined behavior. The continue prevents the out-of-bounds access and just drops the problematic hit, which should be safe since these errors indicate corrupted input data that shouldn't be processed anyway.
|
|
||
| fSumEDep = Hd->fHit->energyDep()*Hd->fHit->nStrawHits(); | ||
| fSumT = Hd->fCorrTime*Hd->fHit->nStrawHits(); | ||
| fSumT = Hd->fCorrTime; |
There was a problem hiding this comment.
Why remove the N(straws) weight to the summed time? How are these fields used?
There was a problem hiding this comment.
Reverted in 307a15d. The nStrawHits() weighting is consistent with how fSumEDep is calculated on the line above, and TMean() divides by fNHits (combo hits, not straw hits), so the original weighting may be intentional. This needs confirmation from the original author.
| //----------------------------------------------------------------------------- | ||
| // also update the coordinate-sum accumulators | ||
| //----------------------------------------------------------------------------- | ||
| fSnx2 = Hd->fNx2; |
There was a problem hiding this comment.
Were these missing in previous evaluations or are they not currently used from these values?
There was a problem hiding this comment.
Reverted in 307a15d. These accumulators were not previously set in ReplaceFirstHit, and ReplaceFirstHit is only called when replacing the first hit in the same face of a seed that was just initialized via Init(). The coordinate sums from Init() would already include the original hit's contribution. Whether the stale values cause issues in subsequent CalculateCogAndChi2 calls needs confirmation from the original author.
…laceFirstHit and MergeDeltaCandidate - Restore "update time" section comment in DeltaCandidate::removeSeed() - Revert fNSeeds>1 guard in MergeDeltaCandidate (keep only denom!=0 guard) - Revert fSumT change in ReplaceFirstHit (restore nStrawHits weighting) - Revert coordinate accumulator additions in ReplaceFirstHit Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/17a94fec-a18a-41e3-9e62-a7b8916ccccd Co-authored-by: michaelmackenzie <30634463+michaelmackenzie@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@FNALbuild run build test |
|
⌛ The following tests have been triggered for 307a15d: build (Build queue - API unavailable) |
|
☀️ The build tests passed at 307a15d.
N.B. These results were obtained from a build of this Pull Request at 307a15d after being merged into the base branch at fa82e62. For more information, please check the job page here. |
michaelmackenzie
left a comment
There was a problem hiding this comment.
I think this looks okay at this point.
… check Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/8bc3b260-e547-44b2-a226-1f6a86376acc Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com>
Review feedback addressed:
Not fixed (by design):