Skip to content

Micromegas decoder update#4297

Open
hupereir wants to merge 21 commits into
sPHENIX-Collaboration:masterfrom
hupereir:micromegas-decoder-update
Open

Micromegas decoder update#4297
hupereir wants to merge 21 commits into
sPHENIX-Collaboration:masterfrom
hupereir:micromegas-decoder-update

Conversation

@hupereir

@hupereir hupereir commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This is TPOT fix for overlapping time frames, similar to #4292
TPOT decoder still uses taggers (GTM and enddat) to associate FEE data to 40bits gtm BCO, unlike the TPC, but this is really an orthogonal change.

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)

Micromegas decoder update (TPOT): fix overlapping time frames

Motivation / context

TPOT Micromegas decoding could mis-associate FEE data to neighboring 40-bit GTM BCOs when time frames overlap. This PR improves the rollover-aware GTM↔FEE BCO matching and updates the streaming/pool filling workflow so evaluation and (optional) truncated/overlapping waveform recovery are driven by a target BCO.

Key changes

  • Rollover-aware BCO matching utilities + tuning
    • Added signed/unsigned clock-difference helpers and updated GTM↔FEE matching logic to use them consistently.
    • Updated matching parameters: m_max_gtm_bco_diff = 60 and m_max_fee_sync_time = 1024 * 96.
  • Target-BCO driven streaming/pool filling
    • FillPool(...) API changed to FillPool(const uint64_t target_bco) and is now filled in a loop controlled by is_more_data_required(target_bco).
    • After pool filling, it calls fill_evaluation_tree(target_bco) and (if enabled) recover_truncated_waveforms(target_bco).
    • In FillMicromegasPool() the streaming manager computes/passes a ref_bco_minus_range into micromegas FillPool(...).
  • Waveform recovery for truncated/overlapping channels
    • Implemented recover_truncated_waveforms(target_bco) to scan for an overlapping BCO, create shifted/truncated waveform copies for missing channels, and reinsert recovered hits for downstream use.
    • Added an enable/disable flag: m_recover_truncated_waveforms / SetRecoverTruncatedWaveforms(...).
  • Micromegas raw-hit interface + minor fixes
    • MicromegasRawHitv3 now exposes get_adc_waveforms() for waveform access.
    • Minor messaging cleanup in MicromegasRawHitv3.cc (typo in warning text).

Potential risk areas

  • Reconstruction behavior changes: BCO association rules/tolerances and the reference computation path were modified, which can change which BCOs/waveforms are treated as matched and/or recovered.
  • Streaming/pool workflow changes: FillPool signature and the “fill → evaluate → recover” sequencing are changed; verify downstream expectations for evaluation-tree fields and stored raw-hit bookkeeping.
  • Interface/data-structure impacts: SingleMicromegas pool internals were refactored (including raw-hit storage patterns) and MicromegasRawHitv3 added a public accessor—confirm consumer compatibility.
  • Performance: waveform recovery adds additional scanning/copying work for overlapping/truncated scenarios; validate timing/CPU under high occupancy.

Possible future improvements

  • Add focused regression tests specifically covering rollover boundaries and overlapping time-frame recovery (including negative/offset adjustments between Tagger and GL1/target BCO path).
  • Profile recovery scanning/allocation patterns and reduce copying where possible.
  • Consolidate and document the signed/unsigned diff conventions to reduce future drift across decoders.
  • AI can make mistakes—please validate against the matching/recovery code paths and relevant QA outputs before approving.

hupereir added 10 commits June 11, 2026 15:15
check the difference between the requested BCO and the last BCO found in the TPOT data stream, including some extra delay corresponding to how much time it takes for TPOT to send all the data for said trigger.
- also store per FEE packet id.
- do not save hits for which there is no waveforms.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 87cf2245-d91d-4b93-a4dc-125a667b4305

📥 Commits

Reviewing files that changed from the base of the PR and between d062341 and d55e4d3.

📒 Files selected for processing (3)
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc

📝 Walkthrough

Walkthrough

This PR refactors Micromegas BCO matching and raw-hit processing to use rollover-aware signed/unsigned clock-difference utilities, restructure internal state from separate "first" fields to a paired reference type, and change FillPool from event-count-based to target-BCO-driven control flow with per-FEE waveform recovery.

Changes

BCO Matching and Raw-Hit Refactor

Layer / File(s) Summary
Raw hit waveform accessor and typo fix
offline/framework/ffarawobjects/MicromegasRawHitv3.cc, offline/framework/ffarawobjects/MicromegasRawHitv3.h
New public get_adc_waveforms() const accessor exposes the internal waveform vector, and a constructor warning message typo ("moethod" → "method") is corrected.
BCO clock difference utilities and matching pair type
offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h
Declares public alias m_bco_matching_pair_t for the paired BCO reference type, getter for the matched reference, static setter and backing member for m_max_fee_sync_time, and static utility declarations for computing signed and unsigned GTM and FEE BCO differences with rollover handling.
BCO diff helper implementations and constants
offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Defines GTM and FEE clock bit-width constants, masks, and half/full ranges; implements signed and unsigned clock-difference helpers; updates static configuration values m_max_gtm_bco_diff (100 → 60) and m_max_fee_sync_time (→ 1024 × 96).
BCO matching computation refactor
offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Predicted fee BCO now derives GTM delta from m_bco_reference.second using signed diffs; is_more_data_required uses signed diffs against sync-time bounds; reference initialization and verification use the paired type; tolerance checks and closest-candidate selection use unsigned fee diffs; cleanup and multiplier adjustment use rollover-aware signed diffs.
SingleMicromegasPoolInput header restructuring
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
FillPool signature changes from nevents count to target_bco parameter; GetSomeMoreEvents() removed; SetBcoPoolSize becomes deprecated no-op; constants extended with MAX_FEECHANNELCOUNT; fee data buffer changed to fixed std::array; raw-hit storage refactored to per-FEE maps keyed by GTM BCO; prior FEE/BCO stack tracking state removed; evaluation struct BCO fields reorganized into separate tagger/GL1 variants.
SingleMicromegasPoolInput implementation refactor
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
FillPool loops on is_more_data_required(target_bco) and invokes waveform recovery; Print and CleanupUsedPackets simplified for per-FEE storage; ClearCurrentEvent replaced with deprecation notice; FEE decoding records packet IDs and processes via paired BCO matching reference; raw hits stored in m_MicromegasRawHitMap[fee][gtm_bco] with conditional StreamingInputManager registration; new recover_truncated_waveforms restores missing-channel waveforms by creating shifted/truncated copies; evaluation-tree filling moved to separate helper using matched BCO reference and predicted BCOs.
Streaming manager integration with target BCO
offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
FillMicromegasPool() computes ref_bco_minus_range from reference BCO and negative range, passes it to each input's FillPool(target_bco) call; minor formatting adjustments in INTT and MVTX methods.

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.

@hupereir

Copy link
Copy Markdown
Contributor Author
Screenshot_20260611_152259

@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: 5

Caution

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

⚠️ Outside diff range comments (1)
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc (1)

964-990: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Do not publish zero-waveform hits.

This path always allocates and registers a MicromegasRawHit, even if waveform extraction produced no ADC segments. That creates hits with no payload in both the streaming manager and the per-FEE cache, which is the same invalid state the recovery path already filters out.

Suggested fix
-    // create new hit
+    if (payload.waveforms.empty())
+    {
+      continue;
+    }
+
+    // create new hit
     auto newhit = std::make_unique<MicromegasRawHit_impl>();

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6bf1576-7fe2-427d-814d-4c545b5f1eaf

📥 Commits

Reviewing files that changed from the base of the PR and between 0ffd526 and a2a8dfb.

📒 Files selected for processing (7)
  • offline/framework/ffarawobjects/MicromegasRawHitv3.cc
  • offline/framework/ffarawobjects/MicromegasRawHitv3.h
  • offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h

Comment thread offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
Comment thread offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Comment thread offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h
Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc Outdated
Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h Outdated
@hupereir hupereir marked this pull request as draft June 12, 2026 00:14
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit a2a8dfbcd55646e696c2446241acc63d192faa92:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit ad81fd1d7703e94161f65b0c495008fade9bd1fe:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 820ad8a3b0a3d82fc1023177660ee072d82270bd:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@hupereir hupereir marked this pull request as ready for review June 12, 2026 13:55
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit ac03253aeb9b091d5e4169a3df5808e4d4e7b3af:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

hupereir added 3 commits June 15, 2026 11:23
… to the next GTM BCO.

60 FEE clocks corresponds to 16 GTM BCO which is the minimum distance between two consecutive triggers.
@hupereir

hupereir commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

None of the Clang-tidy errors are related to this commit.
The Varlgrind "unstable" is worrysome, but runs from a macro that do not execute this code (this is a simulation macro) The valgrind result on the Streaming reconstruction is green.
The last batch of commits is about cleanup and consolidation.
The code ran on 4 full runs without issue, namely 79527, 79564, 80279 and 80287

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 945a40aa-ade7-43b2-90c5-cf5d6626e331

📥 Commits

Reviewing files that changed from the base of the PR and between ac03253 and d062341.

📒 Files selected for processing (3)
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h

Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc Outdated
Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc Outdated
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit d06234147a0d8aa68b1a91bbf3c73b580d397069:
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 d55e4d36719f1e24eae377541e6e18e4a0496f9e:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

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.

1 participant