Repository navigation
Detector sim 4/4: raw readouts, MC decoder, bad-channel list, validation tooling #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
SFBayLaser
wants to merge
22
commits into
feature/usher_detsim_truth_output
from
feature/usher_detsim_bad_channels
Draft
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 cfca9ac
Add hit-level detector-simulation validation script
SFBayLaser e65d3f1
Add DetSimStageScan app and stage-by-stage plot page scripts
SFBayLaser 086a631
DetSimStageScan: add position mode (PE and time vs distance from read…
SFBayLaser d637539
Stage page: add position-along-the-bar panels
SFBayLaser 0b551ce
DetSimStageScan: center the reference bar and scan to the full 16 mm …
SFBayLaser 9275519
Per-particle light breakdown in the output; pileup, far-end timing an…
SFBayLaser 556d404
Stage page: say segments for the hand-cut test crossings, Geant4 step…
SFBayLaser bad8df5
Response-element pipeline: raw readouts and an MC decoder
SFBayLaser e3cdcf3
Decoder: drop readouts from channels in a bad channel list
SFBayLaser 0800a47
Bad channel scan tools: DumpChannels and a random list generator
SFBayLaser b4ae702
Makefile build: compile TMS_Decoder and TMS_BadChannels
SFBayLaser 9330f18
Address review (bad channels and validation tooling)
SFBayLaser effc1fa
app/Makefile: do not build the harnesses that assign TG4PrimaryPartic…
SFBayLaser a161d12
Address review round 3 (bad channels and validation tooling)
SFBayLaser cc58685
Address review round 4 (stage scan and stage page robustness)
SFBayLaser 51b2138
Stage page: null-safe formatting of every data tooltip, robust timing…
SFBayLaser b772eb0
Stage page and validation: guard percentiles on empty samples
SFBayLaser 5a24b36
Share the light-contribution columns between the tree writers; warn w…
SFBayLaser dcf1572
Address review round 5 (bad channels and validation tooling)
SFBayLaser 5da82b1
DetSimStageScan: fail when the reference bar makes no hit (header-onl…
SFBayLaser 7d37d47
Final review fixes: stage scan always probes the reference bar, decod…
SFBayLaser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.