Skip to content

Iss407 pedestal refactor - #455

Open
duncanswilmot wants to merge 4 commits into
mainfrom
iss407-pedestal-refactor
Open

Iss407 pedestal refactor#455
duncanswilmot wants to merge 4 commits into
mainfrom
iss407-pedestal-refactor

Conversation

@duncanswilmot

@duncanswilmot duncanswilmot commented Aug 7, 2026

Copy link
Copy Markdown

Opening a PR but may need to do some extra work before merging.

For local pedestal leveling, change baseline TRIM_INV from 0 to 32, add adaptive support for both ECAL and HCAL ROCs, and mask dead channels (i.e., those with 0 standard deviation). Seeing some difficulty leveling for ECAL (see image). May just be running out of range with TRIM_INV, but someone should try to run this on their own to verify behavior.

Note: did not yet test for HCAL

ecal_smm_pedestal_local

@tomeichlersmith tomeichlersmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just a first pass - I have not tried to run it myself yet, but the actual algorithm looks good. I just want to avoid one pitfall and drop one extra local variable that I don't believe is necessary.

auto [i_erx, i_ch] = mapping.toErxChannel(i_roc, ch);
adcs[i] = data[i].soi().channel(i_erx, i_ch).adc();
}
stdevs[ch] = pflib::utility::stdev(adcs);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is silently converting the double into an int, probably just truncating off everything after the decimal point. This is a problem because a channel could be quiet and have a noise of 0.9 ADC which then gets truncated to 0 and ignored later in the tuning.

My suggestion is to never do the sqrt, just use the variance so that we never convert to double. That way, we can check for dead channels by exact equality with zero.

daq_run(tgt, "PEDESTAL", buffer, n_events, 100);
pflib_log(trace) << "baseline run done, getting channel medians";
std::map<int, std::array<int, 72>> medians;
std::map<int, std::array<int, 72>> stdevs;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While it is probably optimized out, there is no reason to go through this extra stdevs local variable. The only reason I have the local medains variable is so that we can compute the target later (which requires sorting) after copying out the values on a per-channel basis (where we want to keep the original, channel-indexed order).

@duncanswilmot
duncanswilmot force-pushed the iss407-pedestal-refactor branch from 66d513e to 9393cb4 Compare August 12, 2026 15:51
@duncanswilmot

Copy link
Copy Markdown
Author

I couldn't avoid running into the same issue with variance as standard deviation, so I just attempted to keep is as double the whole way rather than adding new code for a variance function. Does this work?

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