Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions ana/pedestal/text-summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
parser.add_argument('pedestals', help='decoded pedestal CSV file to summarize')
args = parser.parse_args()

samples = pd.read_csv(args.pedestals).groupby(['link','channel'])
samples = pd.read_csv(args.pedestals).groupby(['i_link','channel'])

summary = pd.DataFrame({
'mean': samples.adc.mean(),
Expand All @@ -17,4 +17,6 @@
# could sort index so the channels appear in non dictionary order
# but can't figure out the correct key function right now

print(summary.to_string())
# ignore channels where the standard deviation is exactly zero
# these are broken or turned off
print(summary[summary['std'] > 0].to_string())
Comment thread
tomeichlersmith marked this conversation as resolved.
8 changes: 7 additions & 1 deletion ana/plot-fw-histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
parser.add_argument('--stc', type=int, help='only plot input STC if given')
parser.add_argument('--roc-adc-th', type=int, help='digitalhalf_#.adc_th setting on the ROCs being used')
parser.add_argument('--trigger-th', type=int, help='trigger threshold being used')
parser.add_argument('--raw-counts', action='store_true', help='plot raw counts instead of scaling by collection time to estimate the rate')
args = parser.parse_args()

if args.output is None:
Expand All @@ -28,6 +29,8 @@
data = json.load(file, object_hook=uhi.io.json.object_hook)

h = hist.Hist(data)
if not args.raw_counts:
h /= data['metadata']['collection_time']
if args.stc is not None and len(h.axes) > 1:
h[f'STC{args.stc}',:].plot(yerr = args.error_bars)
plt.annotate(
Expand All @@ -54,5 +57,8 @@
rotation = 90,
)
plt.yscale('log')
plt.ylabel('Events / bin')
if args.raw_counts:
plt.ylabel('Events / bin')
else:
plt.ylabel('Rate / Hz')
plt.savefig(args.output, bbox_inches='tight')
11 changes: 7 additions & 4 deletions app/tool/trig/FWHistoPool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ std::array<uint32_t, 256> FWHistoPool::read(int ihist) {
}

nlohmann::json FWHistoPool::to_json(const std::array<uint32_t, 256>& data,
int ihist) {
int ihist, double collection_time) {
nlohmann::json hist;
hist["uhi_schema"] = 1;
hist["writer_info"]["pftool.FWHistoPool"]["version"] =
pflib::version::debug();
hist["writer_info"]["trigpath-firmware"]["version"] = FW_VERSION;
hist["metadata"]["_variance_known"] = true;
hist["metadata"]["collection_time"] = collection_time;

nlohmann::json axis;
axis["type"] = "regular";
Expand All @@ -88,19 +89,21 @@ nlohmann::json FWHistoPool::to_json(const std::array<uint32_t, 256>& data,
axis["metadata"]["label"] = name + " Encoded Sum";

hist["axes"] = {axis};
hist["storage"]["type"] = "int";
hist["storage"]["type"] = "double";
hist["storage"]["values"] = data;
return hist;
}

nlohmann::json FWHistoPool::to_json(
const std::array<std::array<uint32_t, 256>, 8>& data) {
const std::array<std::array<uint32_t, 256>, 8>& data,
double collection_time) {
nlohmann::json hist;
hist["uhi_schema"] = 1;
hist["writer_info"]["pftool.FWHistoPool"]["version"] =
pflib::version::debug();
hist["writer_info"]["trigpath-firmware"]["version"] = FW_VERSION;
hist["metadata"]["_variance_known"] = true;
hist["metadata"]["collection_time"] = collection_time;

nlohmann::json cat;
cat["type"] = "category_str";
Expand All @@ -122,7 +125,7 @@ nlohmann::json FWHistoPool::to_json(
reg["metadata"]["label"] = "Encoded Sum";

hist["axes"] = {cat, reg};
hist["storage"]["type"] = "int";
hist["storage"]["type"] = "double";
hist["storage"]["values"] = data;
return hist;
}
11 changes: 9 additions & 2 deletions app/tool/trig/FWHistoPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ class FWHistoPool {
*
* @param[in] hist histogram to serialize into UHI JSON
* @param[in] ihist histogram index to include in labeling
* @param[in] collection_time time in s that data was collected,
* included in the histograms 'metadata' in the JSON for scaling
* the plot later if desired
* @return JSON representation of histogram
*/
static nlohmann::json to_json(const std::array<uint32_t, 256>& hist,
int ihist);
int ihist, double collection_time);

/**
* convert the input set of many histograms into a JSON
Expand All @@ -105,10 +108,14 @@ class FWHistoPool {
* ```
*
* @param[in] data set of histograms to serialize into JSON
* @param[in] collection_time time in s that data was collected,
* included in the histograms 'metadata' in the JSON for scaling
* the plot later if desired
* @return JSON representation of list of histograms
*/
static nlohmann::json to_json(
const std::array<std::array<uint32_t, 256>, 8>& data);
const std::array<std::array<uint32_t, 256>, 8>& data,
double collection_time);
};

#endif
67 changes: 54 additions & 13 deletions app/tool/trig/histo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,38 @@
*/
#include "histo.h"

#include <chrono>
#include <fstream>

#include "FWHistoPool.h"
#include "pflib/TRIG.h"
#include "pflib/utility/string_format.h"

using pflib::utility::string_format;
using the_clock = std::chrono::high_resolution_clock;
using a_time_point = std::chrono::time_point<the_clock>;
static std::optional<a_time_point> time_of_last_clear{};

ENABLE_LOGGING();

std::optional<double> get_collection_time(a_time_point now) {
using namespace std::literals;
if (time_of_last_clear) {
return (now - time_of_last_clear.value()) / 1.0s;
} else {
pflib_log(warn) << "There hasn't be a CLEAR recently,"
" so we don't know the collection time and"
" the histograms are probably saturated!";
return {};
}
}

void histo(const std::string& cmd, Target* tgt) {
static FWHistoPool hist_pool{0};

if (cmd == "CLEAR") {
hist_pool.clear();
time_of_last_clear = the_clock::now();
}

if (cmd == "DEBUG") {
Expand All @@ -26,9 +46,24 @@ void histo(const std::string& cmd, Target* tgt) {
if (cmd == "READ") {
static int ihist = 0;
ihist = pftool::readline_int("Which histogram?", ihist);
auto now = the_clock::now();
std::array<uint32_t, 256> hist = hist_pool.read(ihist);
std::optional<double> collection_time = get_collection_time(now);
pflib_log(info) << "accumulated histogram for "
<< collection_time.value_or(0) << "s";
bool raw_counts = true;
if (collection_time) {
raw_counts =
pftool::readline_bool("Show raw counts (y) or rate (n)?", raw_counts);
}
for (std::size_t i{0}; i < hist.size(); i++) {
printf("%3d %u\n", i, hist[i]);
printf("%3ld ", i);
if (raw_counts) {
printf("%u", hist[i]);
} else {
printf("%0.4e", hist[i] / collection_time.value());
}
printf("\n");
}
if (pftool::readline_bool("Store histogram in JSON file for plotting?",
false)) {
Expand All @@ -38,7 +73,7 @@ void histo(const std::string& cmd, Target* tgt) {
if (not file.is_open()) {
PFEXCEPTION_RAISE("FileOpen", "Unable to open " + path);
}
file << FWHistoPool::to_json(hist, ihist);
file << FWHistoPool::to_json(hist, ihist, collection_time.value_or(0));
}
}

Expand All @@ -47,28 +82,34 @@ void histo(const std::string& cmd, Target* tgt) {
// we read BEFORE asking what to write to enable a RESET->DUMP to
// be able to happen quickly
std::array<std::array<uint32_t, 256>, 8> hists;
std::array<unsigned int, 8> total;
total.fill(0);
auto now = the_clock::now();
for (int ihist{0}; ihist < hists.size(); ihist++) {
hists[ihist] = hist_pool.read(ihist);
}

std::optional<double> collection_time = get_collection_time(now);
pflib_log(info) << "accumulated histogram for "
<< collection_time.value_or(0) << "s";

if (pftool::readline_bool("Show histograms in terminal?", true)) {
bool raw_counts = true;
if (collection_time) {
raw_counts = pftool::readline_bool("Show raw counts (y) or rate (n)?",
raw_counts);
}
printf("bin : %10u %10u %10u %10u %10u %10u %10u %10u\n", 0, 1, 2, 3, 4,
5, 6, 7);
for (std::size_t i{0}; i < hists[0].size(); i++) {
printf("%3d :", i);
printf("%3ld :", i);
for (int ihist{0}; ihist < hists.size(); ihist++) {
printf(" %10u", hists[ihist][i]);
total[ihist] += hists[ihist][i];
if (raw_counts) {
printf(" %10u", hists[ihist][i]);
} else {
printf(" %10.4e", hists[ihist][i] / collection_time.value());
}
}
printf("\n");
}
printf("tot :");
for (int ihist{0}; ihist < total.size(); ihist++) {
printf(" %10u", total[ihist]);
}
printf("\n");
}

if (pftool::readline_bool("Store histograms in JSON file for plotting?",
Expand All @@ -78,7 +119,7 @@ void histo(const std::string& cmd, Target* tgt) {
if (not file.is_open()) {
PFEXCEPTION_RAISE("FileOpen", "Unable to open " + path);
}
file << FWHistoPool::to_json(hists);
file << FWHistoPool::to_json(hists, collection_time.value_or(0));
}
}
}
2 changes: 2 additions & 0 deletions app/tool/trig/trig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "pflib/packing/SingleECONTCaptureFrame.h"
#include "self_trig.h"
#include "timein.h"
#include "watch_run.h"
using pflib::packing::SingleECONTCaptureFrame;

#include <optional>
Expand Down Expand Up @@ -156,6 +157,7 @@ auto menu_trig =
"SETUP",
"apply time offset parameters deduced from TIMEIN and/or SELF_TRIG",
setup)
->line("WATCH_RUN", "collect data following self-trigger", watch_run)
->line("ELINK_SPY", "spy on the six TRIG elinks", trig)
->line("EVENT_SPY", "attempt to read the last captured event", trig);

Expand Down
Loading