Skip to content

Conversation

@mchiu-bnl
Copy link
Contributor

@mchiu-bnl mchiu-bnl commented Jan 30, 2026

comment: Changed so that calibrations are only downloaded for real data, not sims. Previously this worked because if it didn't find the calibs, the code would just ignore that the calibs didn't exist, or used default values which did nothing.

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 Download for Simulations - Conditional Check

Motivation / Context
The MBD calibration loading code attempted to download and validate calibration files even for simulation runs, causing unnecessary I/O and reliance on calibrations that are not applicable to sims. The change gates calibration downloads and related initialization to real-data runs and adds a text output helper for time-correction data.

Key changes

  • MbdEvent::InitRun()
    • Calibration download and validation are now executed only when _simflag == 0 (real data).
    • Download_All() is called inside the real-data branch; a -1 return from Download_All() now causes InitRun to return Fun4AllReturnCodes::ABORTRUN.
    • Per-channel initialization (pedestal/template setup) reorganized so sampmax/pedestal logic is conditional on calpass/online/simulation state.
    • Local pass1 calibs are still loaded for calpass>1 but only during real-data runs.
  • MbdCalib
    • Added public method int Write_TimeCorr(const std::string& dbfile); implemented in MbdCalib.cc to write time-correction data to a text file (per-channel metadata + tcorr values).
    • No other public API changes beyond the added writer.
  • Minor: commented debug block added in ProcessRawContainer (no functional change).

Potential risk areas

  • Reconstruction behavior changes: Simulations will no longer attempt on-the-fly sampmax/pedestal downloads or validations; if code expects those calibs for certain sim analyses, behavior will differ. Conversely this avoids false failures from missing real-data calibs.
  • Data type detection: Correct behavior depends on accurate _simflag setting; misconfiguration could skip required calibs for real data or force downloads for sims.
  • Error handling semantics: Download_All() failures now abort run for real data; ensure this is desired in all deployment contexts.
  • IO / format: New Write_TimeCorr outputs a plain-text format; consumers that might start using this file must agree on its structure. No changes to existing calibration input formats were made.
  • Thread-safety & performance: Moving Download_All() into the real-data branch reduces unnecessary I/O for sims (positive performance effect). No explicit thread-safety changes observed, but calibrations and file I/O remain non-threaded; concurrent InitRun usages should be reviewed if multi-threaded runs are used.

Possible future improvements

  • Move Download_All() entirely out of simulation paths (currently only guarded for checks) — consider skipping any CDB lookups for sims to avoid any network attempts.
  • Add explicit logging (info/warning) when simulation mode is detected to clarify skipped calibration steps.
  • Add unit/integration tests that verify InitRun behavior for both _simflag == 0 and _simflag != 0, including Download_All() failure handling.
  • Document the new Write_TimeCorr text format and consider adding a symmetric Read_TimeCorr if text-based round-trip is desired.

Note: AI-assisted summary — please review the diffs directly; automated summarization can make mistakes or miss subtle contextual details.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Adds a text-file writer for per-channel time-correction data (new MbdCalib::Write_TimeCorr) and refactors InitRun/channel initialization control flow in MbdEvent (conditional Download_All for real data and reordered pedestal/template setup). No new public types beyond the Write_TimeCorr declaration.

Changes

Cohort / File(s) Summary
Mbd calibration write API
offline/packages/mbd/MbdCalib.h
New public method declaration: int Write_TimeCorr(const std::string& dbfile);.
Time Correction File Export (implementation)
offline/packages/mbd/MbdCalib.cc
Added MbdCalib::Write_TimeCorr implementation that opens a text file, iterates fee channels (skips q-channels), writes per-channel metadata (_tcorr_npts, _tcorr_minrange, _tcorr_maxrange) and tcorr values, formatting 10 values per line. Note: implementation appears duplicated in the diff.
InitRun & per-channel initialization
offline/packages/mbd/MbdEvent.cc
Moved Download_All calibration retrieval into the real-data branch (_simflag == 0) with failure checked (returns ABORTRUN on -1). Reordered per-ifeech initialization: SetCalib(_mbdcal) retained; pedestal setup made conditional (`_calpass==1
✨ Finishing touches
  • 📝 Generate docstrings

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
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

@mchiu-bnl mchiu-bnl changed the title doesn't try to download sampmax calibs etc for sims does not try to download sampmax calibs etc for sims Jan 30, 2026
Copy link
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: 0

Caution

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

⚠️ Outside diff range comments (3)
offline/packages/mbd/MbdCalib.h (1)

149-156: ⚠️ Potential issue | 🟠 Major

Document downstream impact of the new public Write_TimeCorr API.

Line 155 adds a new public method; please include compatibility notes and any downstream update requirements (e.g., macros/tools that will call it) so consumers can adjust.

As per coding guidelines: If interfaces change, ask for compatibility notes and any needed downstream updates.

offline/packages/mbd/MbdEvent.cc (2)

155-214: ⚠️ Potential issue | 🟠 Major

Simulation runs now skip per‑channel signal initialization.

Line 186–214 moved SetCalib, pedestal config, and template setup under _simflag==0. For simulations, those calls are skipped, but later processing still uses _mbdsig and _mbdcal (e.g., sampmax/tcorr), risking null/unstable defaults and altered sim output or crashes. Consider keeping the per‑channel initialization outside the real‑data download guard, with a safe pedestal path for sims.

✅ Suggested fix (keep download data‑only, but always init channels)
-  if ( _simflag == 0 )  // do following for real data
-  {
-    // Download calibrations
-    int status = _mbdcal->Download_All();
-    if ( status == -1 )
-    {
-      return Fun4AllReturnCodes::ABORTRUN;
-    }
+  if ( _simflag == 0 )  // do following for real data
+  {
+    // Download calibrations
+    int status = _mbdcal->Download_All();
+    if ( status == -1 )
+    {
+      return Fun4AllReturnCodes::ABORTRUN;
+    }
     ...
-    for (int ifeech = 0; ifeech < MbdDefs::BBC_N_FEECH; ifeech++)
-    {
-      _mbdsig[ifeech].SetCalib(_mbdcal);
-      if ( _calpass==1 || _is_online || _no_sampmax>0 )
-      {
-        _mbdsig[ifeech].SetEventPed0Range(0,1);
-      }
-      else
-      {
-        const int presamp = 5;
-        const int nsamps = -1;
-        _mbdsig[ifeech].SetEventPed0PreSamp(presamp, nsamps, _mbdcal->get_sampmax(ifeech));
-      }
-      if ( do_templatefit && _mbdgeom->get_type(ifeech)==1 )
-      {
-        _mbdsig[ifeech].SetTemplate(_mbdcal->get_shape(ifeech), _mbdcal->get_sherr(ifeech));
-        _mbdsig[ifeech].SetMinMaxFitTime(_mbdcal->get_sampmax(ifeech) - 2 - 3, _mbdcal->get_sampmax(ifeech) - 2 + 3);
-      }
-    }
-  }
+  }
+
+  for (int ifeech = 0; ifeech < MbdDefs::BBC_N_FEECH; ifeech++)
+  {
+    _mbdsig[ifeech].SetCalib(_mbdcal);
+    const bool use_simple_ped = (_simflag != 0) || _calpass==1 || _is_online || _no_sampmax>0;
+    if ( use_simple_ped )
+    {
+      _mbdsig[ifeech].SetEventPed0Range(0,1);
+    }
+    else
+    {
+      const int presamp = 5;
+      const int nsamps = -1;
+      _mbdsig[ifeech].SetEventPed0PreSamp(presamp, nsamps, _mbdcal->get_sampmax(ifeech));
+    }
+    if ( do_templatefit && _mbdgeom->get_type(ifeech)==1 )
+    {
+      _mbdsig[ifeech].SetTemplate(_mbdcal->get_shape(ifeech), _mbdcal->get_sherr(ifeech));
+      _mbdsig[ifeech].SetMinMaxFitTime(_mbdcal->get_sampmax(ifeech) - 2 - 3, _mbdcal->get_sampmax(ifeech) - 2 + 3);
+    }
+  }

155-214: ⚠️ Potential issue | 🟠 Major

Please document analysis impact / reprocessing for sim‑behavior change.

This change alters simulation behavior by skipping calibration downloads and initialization flow. Please state the expected analysis impact and whether any reprocessing is required.

Based on learnings: If the PR changes reconstruction outputs, calibration constants, or simulation behavior, ensure the description states expected analysis impact and whether reprocessing is required.

@sphenix-jenkins-ci
Copy link

Build & test report

Report for commit 5a30bf17e5be129d13c314818e7238da22084f35:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci
Copy link

Build & test report

Report for commit fde222e972808184602e8af9ca51cef370d1286c:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@pinkenburg
Copy link
Contributor

clang-tidy errors are from changed includes in other packages

@pinkenburg pinkenburg merged commit 30fc305 into sPHENIX-Collaboration:master Jan 31, 2026
19 of 22 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Feb 1, 2026
5 tasks
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