Skip to content

mods for mbd calib passes to work with waveform fit dsts#4262

Merged
pinkenburg merged 6 commits into
sPHENIX-Collaboration:masterfrom
mchiu-bnl:master
May 8, 2026
Merged

mods for mbd calib passes to work with waveform fit dsts#4262
pinkenburg merged 6 commits into
sPHENIX-Collaboration:masterfrom
mchiu-bnl:master

Conversation

@mchiu-bnl
Copy link
Copy Markdown
Contributor

@mchiu-bnl mchiu-bnl commented May 7, 2026

comment: Changes needed for the MBD calibrations to work with the waveform fit DSTs.

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)

MBD Calibration Module Updates for Waveform-Fit DSTs

Motivation

This PR extends the MBD (Muon Background Detector) calibration pipeline to function with waveform-fit DSTs by introducing a new histogram-based calibration processor (MbdCalibReco) and refining the calibration pass logic in the main event processor to support multi-pass calibration workflows with local calibration file fallbacks.

Key Changes

  • New MbdCalibReco subsystem processor (header + implementation):

    • Inherits from SubsysReco and manages per-event histogram booking for calibration analysis
    • Configurable via SetSubPass(), SetCalDir(), and SetCDBTag()
    • Supports loading baseline calibrations from either CDB global tags or local .calib files
    • Enforces "MBD N&S" trigger requirement and vertex cuts (|z_vtx| > 60 cm) for subpass ≥ 1
    • Books per-PMT and global histograms (timing, charge, slew corrections)
    • Writes accumulated histograms to per-run, per-subpass ROOT output files
  • MbdEvent.cc calibration logic refinement:

    • Adds C++17 <filesystem> checks for local calibration files before attempting CDB/hardcoded loads
    • Modifies _calpass handling: gates "on-the-fly" sampmax determination to _calpass == 0 (was _calpass != 1)
    • For _calpass == 2, conditionally loads pass-2-specific calibration files (mbd_tt_t0.calib, mbd_tq_t0.calib, mbd_qfit.calib) instead of unconditionally resetting corrections
    • Enables multi-pass workflows where later passes inherit corrections from earlier passes
  • Build system: Exports new MbdCalibReco.h header and adds MbdCalibReco.cc to library sources

Potential Risk Areas

⚠️ Reconstruction behavior changes:

  • Trigger masking and vertex cuts are now enforced in the new processor; verify integration with existing event selection
  • Modified _calpass logic may alter sampling, pedestal, and timing-correction completeness conditions across the three-pass workflow

⚠️ I/O and file dependencies:

  • New reliance on local .calib files in results/<run>/ directory; missing files silently degrade to defaults rather than failing
  • Output structure changes: new per-subpass ROOT files from MbdCalibReco alongside existing outputs

⚠️ Calibration data consistency:

  • Multi-pass inherits (pass N reads pass N−1 outputs) may propagate accumulated errors if earlier passes have poor data quality

⚠️ Note on code review:
AI-generated summaries can contain inaccuracies. Review histogram allocation logic, calibration file path construction, and trigger/vertex cut thresholds manually.

Possible Future Improvements

  • Document calibration pass workflow, file naming conventions, and fallback behavior
  • Add validation checks for missing calibration files to provide explicit warnings
  • Consider adding configuration options for vertex cut thresholds
  • Profile performance impact of histogram filling in the new processor on event loop throughput

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@mchiu-bnl has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 44 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4be31737-2a49-414e-a18c-61b07983fab0

📥 Commits

Reviewing files that changed from the base of the PR and between 5bbb0c2 and c7e5387.

📒 Files selected for processing (1)
  • offline/packages/mbd/MbdCalibReco.cc
📝 Walkthrough

Walkthrough

Adds a new MbdCalibReco SubsysReco (declarations, lifecycle, histogram management, output file) and integrates it into the offline build; updates MbdEvent to conditionally load local calibration files via std::filesystem and to restrict on-the-fly sampmax completion to pass0.

Changes

MBD Calibration Subsystem (MbdCalibReco)

Layer / File(s) Summary
Class Definition and Public API
offline/packages/mbd/MbdCalibReco.h
Declares MbdCalibReco (inherits SubsysReco) with Init, InitRun, process_event, EndRun, setters (SetSubPass, SetCalDir, SetCDBTag), private helpers (getNodes, BookHistograms, DeleteHistograms) and members for trigger/run state, framework pointers, per‑PMT histogram arrays, and output TFile owner.
Core Implementation
offline/packages/mbd/MbdCalibReco.cc
Implements Init (allocates MbdCalib), InitRun (derive run number, create run dir, load CDB or local .calib files with subpass gating, set _mbias_trigger_mask, open per‑subpass ROOT output, book histograms), getNodes (resolve required nodes), process_event (trigger/vertex filtering; fill per‑PMT, global and conditional slew histograms), and EndRun (write and close output file).
Histogram Initialization
offline/packages/mbd/MbdCalibReco.cc
BookHistograms/DeleteHistograms manage per‑PMT TH1/THnSparseF and global TH2 allocations, conditionally allocate per‑PMT slew TH2 when _subpass >= 1, and support rebooking by deleting existing histograms.
Build Configuration
offline/packages/mbd/Makefile.am
Adds MbdCalibReco.h to pkginclude_HEADERS and MbdCalibReco.cc to libmbd_la_SOURCES in the non-USE_ONLINE offline build branch.

MbdEvent Calibration File Loading Integration

Layer / File(s) Summary
Filesystem Support and Conditional Calibration Loading
offline/packages/mbd/MbdEvent.cc
Adds #include <filesystem> and refactors InitRun to use std::filesystem::exists to check for results/<run>/mbd_sampmax.calib, mbd_ped.calib, and pass2+ mbd_tt_t0.calib/mbd_tq_t0.calib/mbd_qfit.calib; missing files are logged and skipped and pass2 components are only reset when local files are absent.
Sampmax On-The-Fly Triggering
offline/packages/mbd/MbdEvent.cc
Changes FillSampMaxCalib() completion condition from (_calpass != 1) to (_calpass == 0), restricting on‑the‑fly sampmax calibration commit to pass0 only.

Sequence Diagram(s)

sequenceDiagram
  participant Framework
  participant MbdCalibReco
  participant MbdCalib
  participant TFile
  Framework->>MbdCalibReco: Init()
  MbdCalibReco->>MbdCalib: construct & configure
  Framework->>MbdCalibReco: InitRun(topNode)
  MbdCalibReco->>MbdCalib: load baseline calibs (CDB or local)
  MbdCalibReco->>TFile: open per-subpass output
  Framework->>MbdCalibReco: process_event()
  MbdCalibReco->>MbdCalib: read hits, fill histograms
  Framework->>MbdCalibReco: EndRun(runnumber)
  MbdCalibReco->>TFile: write histograms & close
Loading

Possibly related PRs

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
offline/packages/mbd/MbdEvent.cc (1)

168-199: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Major: silent miscalibration risk when local pass1 calibs are absent at calpass ≥ 2.

For _calpass > 1 you only log "skipping" when mbd_sampmax.calib / mbd_ped.calib are missing (lines 174–177, 185–188). The on‑the‑fly sampmax fallback at line 194 is now gated on _calpass == 0, so at calpass ≥ 2 a missing sampmax (from both local file and CDB) leaves _mbdcal with default values, and _mbdsig[ifeech].SetEventPed0PreSamp(... _mbdcal->get_sampmax(ifeech)) is then called with that bogus value — silently producing wrong charge/time calibrations rather than aborting. Please either return Fun4AllReturnCodes::ABORTRUN (or equivalent) when scheck < 0 at _calpass > 1, or assert that Download_All() populated sampmax before reaching the pre-sample setup.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3195982-c147-43e1-bfcc-735f8a2dbe88

📥 Commits

Reviewing files that changed from the base of the PR and between 41051e8 and 157bed5.

📒 Files selected for processing (4)
  • offline/packages/mbd/Makefile.am
  • offline/packages/mbd/MbdCalibReco.cc
  • offline/packages/mbd/MbdCalibReco.h
  • offline/packages/mbd/MbdEvent.cc

Comment thread offline/packages/mbd/MbdCalibReco.cc
Comment thread offline/packages/mbd/MbdCalibReco.cc
Comment thread offline/packages/mbd/MbdCalibReco.cc Outdated
Comment thread offline/packages/mbd/MbdCalibReco.cc
Comment thread offline/packages/mbd/MbdCalibReco.cc Outdated
Comment thread offline/packages/mbd/MbdCalibReco.cc Outdated
Comment thread offline/packages/mbd/MbdCalibReco.h
Comment thread offline/packages/mbd/MbdEvent.cc
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
offline/packages/mbd/MbdCalibReco.cc (2)

56-57: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Propagate getNodes failure in InitRun to prevent null dereferences later

At Line 56, getNodes(topNode) is called but its status is ignored. If any required node is missing, getNodes returns ABORTRUN, yet initialization continues; process_event then dereferences pointers like _gl1packet (Line 312) and _mbdout (Line 324).

Proposed fix
-  getNodes(topNode);
+  const int node_status = getNodes(topNode);
+  if (node_status != Fun4AllReturnCodes::EVENT_OK)
+  {
+    return node_status;
+  }

As per coding guidelines, for **/*.{cc,cpp,cxx,c} prioritize correctness, memory safety, error handling, and thread-safety.


237-242: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Histogram rebooking currently leaves dangling pointers and skips re-allocation

At Lines 237-242, BookHistograms() deletes existing histograms and immediately returns, so nothing is rebooked for the new run. Combined with Lines 281-305 (pointers not nulled after delete), later accesses in process_event/EndRun can hit freed objects or double-delete paths.

Proposed fix
 void MbdCalibReco::BookHistograms()
 {
   // Delete histograms if they have already have been booked.
   if ( h2_tt )
   {
     DeleteHistograms();
-    return;
   }
   ...
 }

 void MbdCalibReco::DeleteHistograms()
 {
   for (int ipmt = 0; ipmt < MbdDefs::MBD_N_PMT; ipmt++)
   {
-    if ( h_tt[ipmt] )
-    {
-      delete h_tt[ipmt];
-    }
-    if ( h_tq[ipmt] )
-    {
-      delete h_tq[ipmt];
-    }
-    if ( h_qp[ipmt] )
-    {
-      delete h_qp[ipmt];
-    }
-    if ( h2_slew[ipmt] )
-    {
-      delete h2_slew[ipmt];
-    }
+    if (h_tt[ipmt]) { delete h_tt[ipmt]; h_tt[ipmt] = nullptr; }
+    if (h_tq[ipmt]) { delete h_tq[ipmt]; h_tq[ipmt] = nullptr; }
+    if (h_qp[ipmt]) { delete h_qp[ipmt]; h_qp[ipmt] = nullptr; }
+    if (h2_slew[ipmt]) { delete h2_slew[ipmt]; h2_slew[ipmt] = nullptr; }
   }

-  delete h2_tt;
-  delete h2_tq;
+  delete h2_tt; h2_tt = nullptr;
+  delete h2_tq; h2_tq = nullptr;
 }

As per coding guidelines, for **/*.{cc,cpp,cxx,c} prioritize correctness, memory safety, error handling, and thread-safety, and flag unclear lifetime assumptions.

Also applies to: 281-305


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 02d2fe25-88d9-412c-babe-8280357ae61e

📥 Commits

Reviewing files that changed from the base of the PR and between 157bed5 and 5bbb0c2.

📒 Files selected for processing (3)
  • offline/packages/mbd/MbdCalibReco.cc
  • offline/packages/mbd/MbdCalibReco.h
  • offline/packages/mbd/MbdEvent.cc
🚧 Files skipped from review as they are similar to previous changes (2)
  • offline/packages/mbd/MbdCalibReco.h
  • offline/packages/mbd/MbdEvent.cc

Comment thread offline/packages/mbd/MbdCalibReco.cc
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit 157bed5a43cd6ef8ce18239de8f4a06c78b147c9:
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 3a6becdf82fb2b9aa2bdcacf780d8479081c082b:
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 94ccd3502c6acd8184d8bdd5b7f095becd5e5867:
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 5bbb0c2aeab8a1aeffc98ef9699109adcbccc1bd:
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 4134ac0bf46aaf1f7c7ce15fb4a455c3e865d121:
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 c7e5387d425f592730b11c385a61624a9ad46d2d:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@pinkenburg pinkenburg merged commit e7a8cb6 into sPHENIX-Collaboration:master May 8, 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