Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
fab15ba
introducing mapping file for channels
joshgreaves332 Dec 12, 2025
c92c6fe
Apply clang-format --style=Google
github-actions[bot] Dec 12, 2025
ded19bb
create masked channel vector and print it out to terminal
joshgreaves332 Dec 12, 2025
525d53c
Apply clang-format --style=Google
github-actions[bot] Dec 12, 2025
afaf58a
adding mask file to /build/
joshgreaves332 Dec 12, 2025
7ab397f
adding commented out code for skipping channel
joshgreaves332 Dec 12, 2025
51244af
Apply clang-format --style=Google
github-actions[bot] Dec 12, 2025
c69680e
stoi to atoi
joshgreaves332 Dec 12, 2025
9a39ada
ditch first line
joshgreaves332 Dec 12, 2025
bc6e9e3
uncommenting skipping code
joshgreaves332 Dec 12, 2025
56f758c
Apply clang-format --style=Google
github-actions[bot] Dec 12, 2025
529197e
Add workflow_run trigger for clang-format completion (#335)
tvami Dec 12, 2025
c23ccdc
created align_phase and align_word, calling from the main function (#…
joshgreaves332 Dec 12, 2025
88a530b
Fix timestamp type in MultiSampleECONDEventPacket (#334)
tvami Dec 12, 2025
b977e5e
Add status for ROC (#333)
tvami Dec 12, 2025
dd72a79
Fix HT_EBO, data underflow for no data (#336)
tvami Dec 12, 2025
b14b4c4
Fix CRC header check (#328)
cmantill Dec 12, 2025
1e4a7de
add a marker at start of events to help the eye
tomeichlersmith Dec 12, 2025
71f46d5
check if PUSM is a known state before deref
tomeichlersmith Dec 12, 2025
3455e69
adding to get_adc_medians to mask out channels from calc
joshgreaves332 Dec 12, 2025
445db24
Apply clang-format --style=Google
github-actions[bot] Dec 12, 2025
a43d21c
commenting out MASKED paramname
joshgreaves332 Dec 13, 2025
8d7f9da
commenting out masking code entirely
joshgreaves332 Dec 13, 2025
e21821c
removing all masking to test if it actually works. how did i break it?
joshgreaves332 Dec 13, 2025
71baca8
test
joshgreaves332 Dec 13, 2025
e36d96f
adding back in masking
joshgreaves332 Dec 13, 2025
7c8a63e
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
fc145a8
testing commenting out medians = 0 for makes because of apparent over…
joshgreaves332 Dec 13, 2025
3af2cfa
testing commenting out medians = 0 for makes because of apparent over…
joshgreaves332 Dec 13, 2025
6fc8447
testing commenting out medians = 0 for makes because of apparent over…
joshgreaves332 Dec 13, 2025
ffbd9ba
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
17b1d87
debugging baseline
joshgreaves332 Dec 13, 2025
5d69ee2
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
14120c2
passing masked runs through to get_Toa_efficiencies where appropriate
joshgreaves332 Dec 13, 2025
89b5e40
forgot to include passing of masked_channels in get_toa explicit temp…
joshgreaves332 Dec 13, 2025
fc10ed4
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
448817c
beginning code for masking in get_toa_Efficiencies
joshgreaves332 Dec 13, 2025
84fd472
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
e98dfb1
beginning code for masking in get_toa_Efficiencies
joshgreaves332 Dec 13, 2025
9569f77
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
35e6fce
adding test outputs
joshgreaves332 Dec 13, 2025
067c5a8
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
4ce0e1c
adding test outputs
joshgreaves332 Dec 13, 2025
858edc9
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
ff29545
adding test outputs
joshgreaves332 Dec 13, 2025
1b4ca32
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
ec6d88f
adding test outputs
joshgreaves332 Dec 13, 2025
7b34253
Apply clang-format --style=Google
github-actions[bot] Dec 13, 2025
a9e062f
adding test outputs
joshgreaves332 Dec 13, 2025
9c4ae51
removed erroneous files
joshgreaves332 Dec 14, 2025
8e89421
removed erroneous files
joshgreaves332 Dec 14, 2025
9754547
adding test outputs
joshgreaves332 Dec 14, 2025
3287c06
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
bd7d069
adding test outputs
joshgreaves332 Dec 14, 2025
cb4698e
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
56fe28b
adding test outputs
joshgreaves332 Dec 14, 2025
f4694c1
adding test outputs
joshgreaves332 Dec 14, 2025
0b2c044
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
5a6634f
adding test outputs
joshgreaves332 Dec 14, 2025
096d813
adding test outputs
joshgreaves332 Dec 14, 2025
748701e
adding test outputs
joshgreaves332 Dec 14, 2025
0c6bc9a
adding test outputs
joshgreaves332 Dec 14, 2025
bc5ee06
adding test outputs
joshgreaves332 Dec 14, 2025
c6c78d6
adding test outputs. change to 1 event
joshgreaves332 Dec 14, 2025
ca00331
adding test outputs. change to 1 event
joshgreaves332 Dec 14, 2025
f5749c7
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
5df129c
after buffer reset FC removing comments and testing with 100 events a…
joshgreaves332 Dec 14, 2025
7e6ecb2
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
a3038a5
adding in code again for masking
joshgreaves332 Dec 14, 2025
650ef99
completing masking code addition to trim_toa_scan and get_toa_Efficie…
joshgreaves332 Dec 14, 2025
dca54b9
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
7d2b497
check if PUSM is a known state before deref
tomeichlersmith Dec 12, 2025
fb6c028
Update CSV header to include timestamp and i_sample (#339)
tvami Dec 13, 2025
36b50ed
Merge remote-tracking branch 'origin/main' into 314-mask-unused-channels
joshgreaves332 Dec 14, 2025
9ad9209
include limits in get efficiencies
joshgreaves332 Dec 14, 2025
6fc06e7
Apply clang-format --style=Google
github-actions[bot] Dec 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,067 changes: 1,067 additions & 0 deletions ana/pedestal/Promptdata_analysis.py

Large diffs are not rendered by default.

1,930 changes: 1,930 additions & 0 deletions ana/pedestal/Promptdata_analysis.py.ipynb

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions app/tool/algorithm/get_toa_efficiencies.cxx
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
#include "get_toa_efficiencies.h"

#include <limits>

#include "pflib/utility/efficiency.h"

namespace pflib::algorithm {

// helper function
bool is_masked(int ch, const std::vector<int>& masked_channels) {
return (count(masked_channels.begin(), masked_channels.end(), ch) > 0);
}

template <class EventPacket>
std::array<double, 72> get_toa_efficiencies(
const std::vector<EventPacket>& data) {
const std::vector<EventPacket>& data,
const std::vector<int>& masked_channels) {
std::array<double, 72> efficiencies;
/// reserve a vector of the appropriate size to avoid repeating allocation
/// time for all 72 channels
// fill with NANs so that channels can be masked out
efficiencies.fill(std::numeric_limits<double>::quiet_NaN());
std::vector<int> toas(data.size());
int i_ch = 0; // 0–35
int i_link = 0;

for (int ch{0}; ch < 72; ch++) {
if (is_masked(ch, masked_channels)) {
continue; // leave NaN
}

i_link = (ch / 36);
i_ch = ch % 36;
for (std::size_t i{0}; i < toas.size(); i++) {
Expand Down Expand Up @@ -46,9 +60,11 @@ std::array<double, 72> get_toa_efficiencies(
// get toa efficiencies
template std::array<double, 72>
pflib::algorithm::get_toa_efficiencies<pflib::packing::SingleROCEventPacket>(
const std::vector<pflib::packing::SingleROCEventPacket>& data);
const std::vector<pflib::packing::SingleROCEventPacket>& data,
const std::vector<int>& masked_channels);
template std::array<double, 72> pflib::algorithm::get_toa_efficiencies<
pflib::packing::MultiSampleECONDEventPacket>(
const std::vector<pflib::packing::MultiSampleECONDEventPacket>& data);
const std::vector<pflib::packing::MultiSampleECONDEventPacket>& data,
const std::vector<int>& masked_channels);

} // namespace pflib::algorithm
3 changes: 2 additions & 1 deletion app/tool/algorithm/get_toa_efficiencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace pflib::algorithm {
// templated to match any event packet type
template <class EventPacket>
std::array<double, 72> get_toa_efficiencies(
const std::vector<EventPacket>& data);
const std::vector<EventPacket>& data,
const std::vector<int>& masked_channels);

// std::array<double, 72> get_toa_efficiencies(
// const std::vector<pflib::packing::SingleROCEventPacket>& data);
Expand Down
78 changes: 69 additions & 9 deletions app/tool/algorithm/level_pedestals.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,35 @@ static int get_adc(const EventPacket& p, int ch) {
* TOT/TOA and the sample Tp/Tc flags are ignored.
*/
template <class EventPacket>
static std::array<int, 72> get_adc_medians(
const std::vector<EventPacket>& data) {
static std::array<int, 72> get_adc_medians(const std::vector<EventPacket>& data,
std::vector<int>& masked_channels) {
std::array<int, 72> medians;
/// reserve a vector of the appropriate size to avoid repeating allocation
/// time for all 72 channels
std::vector<int> adcs(data.size());
for (int ch{0}; ch < 72; ch++) {
if (count(masked_channels.begin(), masked_channels.end(), ch) > 0) {
// Do Not include masked channels in the median calculation
medians[ch] = -999; // to maintain length of medians
continue;
}

for (std::size_t i{0}; i < adcs.size(); i++) {
adcs[i] = get_adc(data[i], ch);

// // print out multi sample event packet p here
// if constexpr (std::is_same_v<
// EventPacket,
// pflib::packing::MultiSampleECONDEventPacket>) {
// std::cout << "p.soi, ch, ilink, adc: " << data[i].i_soi << ", " << ch
// << ", " << ch / 36 << ", " << adcs[i] << std::endl;
// } else {
// std::cout << "NOT MULTI " << std::endl;
// }
}
medians[ch] = pflib::utility::median(adcs);
// medians[ch] = pflib::utility::median(adcs);
// std::cout << "here: ch, median " << ch << ", " << medians[ch] <<
// std::endl;
}
return medians;
}
Expand All @@ -72,7 +90,8 @@ template <class EventPacket> // any use of <EventPacket> is a placeholder for
static void pedestal_runs(Target* tgt, ROC& roc, std::array<int, 72>& baseline,
std::array<int, 72>& highend,
std::array<int, 72>& lowend,
std::array<int, 2>& target, size_t n_events) {
std::array<int, 2>& target, size_t n_events,
std::vector<int>& masked_channels) {
/// TODO for multi-ROC set ups, we could dynamically determine the number
// of ROCs and the number of channels from the Target
DecodeAndBuffer<EventPacket> buffer{n_events, 2};
Expand All @@ -87,8 +106,12 @@ static void pedestal_runs(Target* tgt, ROC& roc, std::array<int, 72>& baseline,
.apply();
daq_run(tgt, "PEDESTAL", buffer, n_events, 100);
pflib_log(trace) << "baseline run done, getting channel medians";
auto medians = get_adc_medians<EventPacket>(buffer.get_buffer());
auto medians =
get_adc_medians<EventPacket>(buffer.get_buffer(), masked_channels);
baseline = medians;
// for (int i = 0; i < 72; i++) {
// pflib_log(info) << "baseline: " << baseline[i];
// }
pflib_log(trace) << "got channel medians, getting link medians";
for (int i_link{0}; i_link < 2; i_link++) {
auto start{medians.begin() + 36 * i_link};
Expand All @@ -108,7 +131,8 @@ static void pedestal_runs(Target* tgt, ROC& roc, std::array<int, 72>& baseline,
.add_all_channels("TRIM_INV", 63)
.apply();
daq_run(tgt, "PEDESTAL", buffer, n_events, 100);
highend = get_adc_medians<EventPacket>(buffer.get_buffer());
highend =
get_adc_medians<EventPacket>(buffer.get_buffer(), masked_channels);
}

{ // lowend run
Expand All @@ -119,14 +143,28 @@ static void pedestal_runs(Target* tgt, ROC& roc, std::array<int, 72>& baseline,
.add_all_channels("TRIM_INV", 0)
.apply();
daq_run(tgt, "PEDESTAL", buffer, n_events, 100);
lowend = get_adc_medians<EventPacket>(buffer.get_buffer());
lowend = get_adc_medians<EventPacket>(buffer.get_buffer(), masked_channels);
}
}

std::map<std::string, std::map<std::string, uint64_t>> level_pedestals(
Target* tgt, ROC roc) {
static auto the_log_{::pflib::logging::get("level_pedestals")};

// Load CHANNEL MASK file
std::string mask_file_path = pftool::readline("Path to maskfile: ", "");
bool use_mask = !mask_file_path.empty();
std::vector<int> masked_channels;
std::string line;
if (use_mask) {
std::ifstream mask_file(mask_file_path);
std::getline(mask_file, line); // ditch first line
while (std::getline(mask_file, line)) {
int int_ch = std::atoi(line.c_str());
masked_channels.push_back(int_ch);
}
}

/// do three runs of 100 samples each to have well defined pedestals
static const std::size_t n_events = 100;

Expand All @@ -142,12 +180,12 @@ std::map<std::string, std::map<std::string, uint64_t>> level_pedestals(

if (pftool::state.daq_format_mode == Target::DaqFormat::SIMPLEROC) {
pedestal_runs<pflib::packing::SingleROCEventPacket>(
tgt, roc, baseline, highend, lowend, target, n_events);
tgt, roc, baseline, highend, lowend, target, n_events, masked_channels);

} else if (pftool::state.daq_format_mode ==
Target::DaqFormat::ECOND_SW_HEADERS) {
pedestal_runs<pflib::packing::MultiSampleECONDEventPacket>(
tgt, roc, baseline, highend, lowend, target, n_events);
tgt, roc, baseline, highend, lowend, target, n_events, masked_channels);

} else {
pflib_log(warn) << "Unsupported DAQ format ("
Expand All @@ -157,9 +195,30 @@ std::map<std::string, std::map<std::string, uint64_t>> level_pedestals(

pflib_log(info) << "sample collections done, deducing settings";
std::map<std::string, std::map<std::string, uint64_t>> settings;

for (int ch{0}; ch < 72; ch++) {
std::string page{pflib::utility::string_format("CH_%d", ch)};

// SKIP IF CHANNEL IS MASKED
if (count(masked_channels.begin(), masked_channels.end(), ch) > 0) {
pflib_log(info) << "Channel " << ch
<< " is masked; skipping pedestal leveling.";

// Explicitly mark it masked
// settings[page]["MASKED"] = 1;

continue;

// } else {
// settings[page]["MASKED"] = 0;
}

int i_link = ch / 36;

pflib_log(info) << "Channel, Baseline, Lowend, Highend: " << ch << ", "
<< baseline[ch] << ", " << lowend[ch] << ", " << highend[ch]
<< std::endl;

if (baseline.at(ch) < target.at(i_link)) {
pflib_log(debug) << "Channel " << ch
<< " is below target, setting TRIM_INV";
Expand Down Expand Up @@ -216,6 +275,7 @@ std::map<std::string, std::map<std::string, uint64_t>> level_pedestals(
<< " is above target, setting SIGN_DAC=1 and DACB";
settings[page]["SIGN_DAC"] = 1;
settings[page]["DACB"] = val;
pflib_log(info) << "Channel " << ch << " has val: " << val << ".";
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions app/tool/algorithm/toa_vref_scan.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace pflib::algorithm {

// Templated helpder function
// Templated helper function
template <class EventPacket>
static void toa_vref_runs(Target* tgt, ROC& roc, size_t n_events,
std::array<int, 2>& target) {
Expand All @@ -18,6 +18,20 @@ static void toa_vref_runs(Target* tgt, ROC& roc, size_t n_events,

// loop over runs, from toa_vref = 0 to = 255
for (int toa_vref{0}; toa_vref < 256; toa_vref++) {
// Load CHANNEL MASK file
std::string mask_file_path = pftool::readline("Path to maskfile: ", "");
bool use_mask = !mask_file_path.empty();
std::vector<int> masked_channels;
std::string line;
if (use_mask) {
std::ifstream mask_file(mask_file_path);
std::getline(mask_file, line); // ditch first line
while (std::getline(mask_file, line)) {
int int_ch = std::atoi(line.c_str());
masked_channels.push_back(int_ch);
}
}

pflib_log(info) << "testing toa_vref = " << toa_vref;
auto test_handle = roc.testParameters()
.add("REFERENCEVOLTAGE_0", "TOA_VREF", toa_vref)
Expand All @@ -27,7 +41,8 @@ static void toa_vref_runs(Target* tgt, ROC& roc, size_t n_events,
daq_run(tgt, "PEDESTAL", buffer, n_events, 100);
pflib_log(trace) << "finished toa_vref = " << toa_vref
<< ", getting efficiencies";
auto efficiencies = get_toa_efficiencies(buffer.get_buffer());
auto efficiencies =
get_toa_efficiencies(buffer.get_buffer(), masked_channels);
pflib_log(trace)
<< "got channel efficiencies, getting max efficiency per link";
for (int i_link{0}; i_link < 2; i_link++) {
Expand Down
26 changes: 21 additions & 5 deletions app/tool/algorithm/trim_toa_scan.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ namespace pflib::algorithm {
template <class EventPacket>
static void trim_tof_runs(
Target* tgt, ROC& roc, size_t n_events,
std::array<std::array<std::array<double, 72>, 8>, 200>& final_data) {
std::array<std::array<std::array<double, 72>, 8>, 200>& final_data,
std::vector<int>& masked_channels) {
// working in buffer, not in writer
DecodeAndBuffer<EventPacket> buffer{n_events, 2};
static auto the_log_{::pflib::logging::get("toa_vref_scan")};
Expand Down Expand Up @@ -98,7 +99,8 @@ static void trim_tof_runs(

pflib_log(trace) << "finished trim_toa = " << trim_toa
<< ", and calib = " << calib << ", getting efficiencies";
auto efficiencies = get_toa_efficiencies(buffer.get_buffer());
auto efficiencies =
get_toa_efficiencies(buffer.get_buffer(), masked_channels);
pflib_log(trace) << "got channel efficiencies, storing now";
for (int ch{0}; ch < 72; ch++) {
// need to divide by 4 because index is value/4 from final_data
Expand All @@ -124,6 +126,20 @@ std::map<std::string, std::map<std::string, uint64_t>> trim_toa_scan(

static const std::size_t n_events = 100;

// Load CHANNEL MASK file
std::string mask_file_path = pftool::readline("Path to maskfile: ", "");
bool use_mask = !mask_file_path.empty();
std::vector<int> masked_channels;
std::string line;
if (use_mask) {
std::ifstream mask_file(mask_file_path);
std::getline(mask_file, line); // ditch first line
while (std::getline(mask_file, line)) {
int int_ch = std::atoi(line.c_str());
masked_channels.push_back(int_ch);
}
}

tgt->setup_run(1, pftool::state.daq_format_mode, 1);

// trim_toa is a channel-wise parameter (1 value per channel)
Expand All @@ -134,12 +150,12 @@ std::map<std::string, std::map<std::string, uint64_t>> trim_toa_scan(
std::array<std::array<std::array<double, 72>, 8>, 200> final_data;

if (pftool::state.daq_format_mode == Target::DaqFormat::SIMPLEROC) {
trim_tof_runs<pflib::packing::SingleROCEventPacket>(tgt, roc, n_events,
final_data);
trim_tof_runs<pflib::packing::SingleROCEventPacket>(
tgt, roc, n_events, final_data, masked_channels);
} else if (pftool::state.daq_format_mode ==
Target::DaqFormat::ECOND_SW_HEADERS) {
trim_tof_runs<pflib::packing::MultiSampleECONDEventPacket>(
tgt, roc, n_events, final_data);
tgt, roc, n_events, final_data, masked_channels);
} else {
pflib_log(warn) << "Unsupported DAQ format ("
<< static_cast<int>(pftool::state.daq_format_mode)
Expand Down
25 changes: 25 additions & 0 deletions build/hcal_channel_mask.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Mask
8
17
26
27
28
29
30
31
32
33
34
35
44
53
62
63
64
65
66
67
68
69
70
71
Loading