Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8df6974
Write each true hit's path length (TrueHitDx) to Truth_Info
SFBayLaser Oct 1, 2026
cfca9ac
Add hit-level detector-simulation validation script
SFBayLaser Oct 2, 2026
e65d3f1
Add DetSimStageScan app and stage-by-stage plot page scripts
SFBayLaser Oct 4, 2026
086a631
DetSimStageScan: add position mode (PE and time vs distance from read…
SFBayLaser Oct 4, 2026
d637539
Stage page: add position-along-the-bar panels
SFBayLaser Oct 4, 2026
0b551ce
DetSimStageScan: center the reference bar and scan to the full 16 mm …
SFBayLaser Oct 4, 2026
9275519
Per-particle light breakdown in the output; pileup, far-end timing an…
SFBayLaser Oct 4, 2026
556d404
Stage page: say segments for the hand-cut test crossings, Geant4 step…
SFBayLaser Oct 4, 2026
bad8df5
Response-element pipeline: raw readouts and an MC decoder
SFBayLaser Oct 6, 2026
e3cdcf3
Decoder: drop readouts from channels in a bad channel list
SFBayLaser Oct 19, 2026
0800a47
Bad channel scan tools: DumpChannels and a random list generator
SFBayLaser Oct 19, 2026
b4ae702
Makefile build: compile TMS_Decoder and TMS_BadChannels
SFBayLaser Nov 12, 2026
9330f18
Address review (bad channels and validation tooling)
SFBayLaser Nov 13, 2026
effc1fa
app/Makefile: do not build the harnesses that assign TG4PrimaryPartic…
SFBayLaser Nov 13, 2026
a161d12
Address review round 3 (bad channels and validation tooling)
SFBayLaser Nov 13, 2026
cc58685
Address review round 4 (stage scan and stage page robustness)
SFBayLaser Nov 13, 2026
51b2138
Stage page: null-safe formatting of every data tooltip, robust timing…
SFBayLaser Nov 13, 2026
b772eb0
Stage page and validation: guard percentiles on empty samples
SFBayLaser Nov 13, 2026
5a24b36
Share the light-contribution columns between the tree writers; warn w…
SFBayLaser Nov 13, 2026
dcf1572
Address review round 5 (bad channels and validation tooling)
SFBayLaser Nov 13, 2026
5da82b1
DetSimStageScan: fail when the reference bar makes no hit (header-onl…
SFBayLaser Nov 13, 2026
7d37d47
Final review fixes: stage scan always probes the reference bar, decod…
SFBayLaser Nov 14, 2026
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
74 changes: 74 additions & 0 deletions app/BadChannelsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Unit test for the bad channel list (TMS_BadChannels) and the decoder's use of it. Writes small
// lists to the directory given as the first argument (default: the current directory). Exits
// non-zero if any check fails. Needs TMS_DIR set, as the managers do.
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

#include "TMS_BadChannels.h"
#include "TMS_Decoder.h"

namespace {

int n_failed = 0;

void Check(bool ok, const char* what) {
std::cout << (ok ? "PASS " : "FAIL ") << what << "\n";
if (!ok) n_failed++;
}

std::string Write(const std::string& dir, const std::string& name, const std::string& text) {
const std::string path = dir + "/" + name;
std::ofstream(path) << text;
return path;
Comment thread
Copilot marked this conversation as resolved.
Resolved
}

template <typename F> bool Throws(F f) {
try { f(); } catch (const std::exception&) { return true; }
return false;
}

} // namespace

int main(int argc, char** argv) {
// TMS_BadChannels resolves a relative file name under $TMS_DIR, so hand it absolute paths
std::string dir = argc > 1 ? argv[1] : ".";
if (dir.empty() || dir[0] != '/') {
char* resolved = realpath(dir.empty() ? "." : dir.c_str(), nullptr);
if (resolved == nullptr) { std::cerr << "Cannot resolve directory " << dir << "\n"; return 2; }
dir = resolved;
free(resolved);
}

Check(TMS_BadChannels("").Size() == 0, "empty file name: no bad channels");
Check(TMS_BadChannels(Write(dir, "bc_empty.toml", "# nothing\n")).Size() == 0, "file without entries: no bad channels");

const TMS_BadChannels list(Write(dir, "bc_two.toml",
"[[BadChannel]]\nPlane = 12\nBar = 40\nView = 3\nStatus = \"dead\"\nReason = \"broken fiber\"\n"
"[[BadChannel]]\nPlane = 12\nBar = 41\nView = 3\nStatus = \"missing\"\n"));
Check(list.Size() == 2, "two entries read");
Check(list.GetStatus({12, 40, 3}) == TMS_BadChannels::Status::Dead, "dead entry");
Check(list.GetStatus({12, 41, 3}) == TMS_BadChannels::Status::Missing, "missing entry");
Check(list.GetChannels().at({12, 40, 3}).Reason == "broken fiber", "reason kept");
Check(list.IsBad({12, 40, 3}) && list.IsBad({12, 41, 3}), "dead and missing are bad");
Check(!list.IsBad({12, 40, 1}), "same plane and bar, other view: good");
Check(!list.IsBad({13, 40, 3}), "same bar number, other plane: good");

Check(Throws([&] { TMS_BadChannels(Write(dir, "bc_state.toml", "[[BadChannel]]\nPlane=1\nBar=1\nView=1\nStatus=\"flaky\"\n")); }),
"unknown status is an error");
Check(Throws([&] { TMS_BadChannels(Write(dir, "bc_dup.toml",
"[[BadChannel]]\nPlane=1\nBar=1\nView=1\nStatus=\"dead\"\n[[BadChannel]]\nPlane=1\nBar=1\nView=1\nStatus=\"missing\"\n")); }),
"channel listed twice is an error");
Check(Throws([&] { TMS_BadChannels(Write(dir, "bc_key.toml", "[[BadChannel]]\nPlane=1\nBar=1\nStatus=\"dead\"\n")); }),
"missing key is an error");
Check(Throws([&] { TMS_BadChannels(dir + "/does_not_exist.toml"); }), "missing file is an error");

// The shipped list is empty, so the decoder keeps every readout (the decoder's own use of
// the list is exercised by the real-spill comparison, as it needs the geometry for TMS_Bar).
Check(TMS_BadChannels::GetInstance().Size() == 0, "list named in the main TOML is empty by default");

std::cout << (n_failed ? "FAILED" : "ALL PASSED") << "\n";
return n_failed ? 1 : 0;
}
9 changes: 9 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ add_executable(RealDataSmokeTest RealDataSmokeTest.cpp)
add_executable(ArtificialResegmentationTest ArtificialResegmentationTest.cpp)
add_executable(PassageUtilsTest PassageUtilsTest.cpp)
add_executable(ChannelReadoutTest ChannelReadoutTest.cpp)
add_executable(BadChannelsTest BadChannelsTest.cpp)
add_executable(DumpChannels DumpChannels.cpp)
add_executable(DetSimStageScan DetSimStageScan.cpp)
Comment thread
SFBayLaser marked this conversation as resolved.
Resolved

target_link_libraries(BField_tester LINK_PUBLIC TMS_Prod ROOT::EG)
target_link_libraries(BetheBloch_Example LINK_PUBLIC TMS_Prod)
Expand All @@ -26,6 +29,9 @@ target_link_libraries(RealDataSmokeTest LINK_PUBLIC TMS_Prod)
target_link_libraries(ArtificialResegmentationTest LINK_PUBLIC TMS_Prod)
target_link_libraries(PassageUtilsTest LINK_PUBLIC TMS_Prod)
target_link_libraries(ChannelReadoutTest LINK_PUBLIC TMS_Prod)
target_link_libraries(BadChannelsTest LINK_PUBLIC TMS_Prod)
target_link_libraries(DumpChannels LINK_PUBLIC TMS_Prod)
target_link_libraries(DetSimStageScan LINK_PUBLIC TMS_Prod)

install(TARGETS BField_tester RUNTIME DESTINATION bin)
install(TARGETS BetheBloch_Example RUNTIME DESTINATION bin)
Expand All @@ -39,3 +45,6 @@ install(TARGETS RealDataSmokeTest RUNTIME DESTINATION bin)
install(TARGETS ArtificialResegmentationTest RUNTIME DESTINATION bin)
install(TARGETS PassageUtilsTest RUNTIME DESTINATION bin)
install(TARGETS ChannelReadoutTest RUNTIME DESTINATION bin)
install(TARGETS BadChannelsTest RUNTIME DESTINATION bin)
install(TARGETS DumpChannels RUNTIME DESTINATION bin)
install(TARGETS DetSimStageScan RUNTIME DESTINATION bin)
Loading
Loading