|
| 1 | +#include "charge_timescan.h" |
| 2 | + |
| 3 | +#include <nlohmann/json.hpp> |
| 4 | + |
| 5 | +#include "../daq_run.h" |
| 6 | +#include "../econ_links.h" |
| 7 | +#include "pflib/utility/string_format.h" |
| 8 | + |
| 9 | +ENABLE_LOGGING(); |
| 10 | + |
| 11 | +template <class EventPacket> |
| 12 | +static void vref_2d_scan_writer(Target* tgt, pflib::ROC& roc, size_t nevents, |
| 13 | + bool isLED, int channel, int link, int i_ch, |
| 14 | + std::string fname, int calib, bool highrange, |
| 15 | + int start_bx, int n_bx) { |
| 16 | + if constexpr (std::is_same_v<EventPacket, |
| 17 | + pflib::packing::MultiSampleECONDEventPacket>) { |
| 18 | + n_links = determine_n_links(tgt); |
| 19 | + } |
| 20 | + |
| 21 | + int ch = 0; |
| 22 | + int inv_vref = 0; |
| 23 | + int noinv_vref = 0; |
| 24 | + |
| 25 | + DecodeAndWriteToCSV<EventPacket> writer{ |
| 26 | + fname, |
| 27 | + [&](std::ofstream& f) { |
| 28 | + nlohmann::json header; |
| 29 | + f << std::boolalpha << "# " << header << '\n' |
| 30 | + << "noinv_vref, inv_vref, ch," << pflib::packing::Sample::to_csv_header << '\n'; |
| 31 | + }, |
| 32 | + [&](std::ofstream& f, const EventPacket& ep) { |
| 33 | + for (ch = 0; ch < 72; ch++) { |
| 34 | + f << noinv_vref << ',' << inv_vref << ',' << ch << ','; |
| 35 | + if constexpr (std::is_same_v< |
| 36 | + EventPacket, |
| 37 | + pflib::packing::MultiSampleECONDEventPacket>) { |
| 38 | + ep.samples[ep.i_soi].channel(link, ch).to_csv(f); |
| 39 | + } else if constexpr (std::is_same_v< |
| 40 | + EventPacket, |
| 41 | + pflib::packing::SingleROCEventPacket>) { |
| 42 | + ep.channel(ch).to_csv(f); |
| 43 | + } else { |
| 44 | + PFEXCEPTION_RAISE("BadConf", |
| 45 | + "Unable to do all_channels_to_csv for the " |
| 46 | + "currently configured format."); |
| 47 | + } |
| 48 | + f << '\n'; |
| 49 | + } |
| 50 | + }, |
| 51 | + n_links}; |
| 52 | + |
| 53 | + tgt->setup_run(1 /* dummy - not stored */, pftool::state.daq_format_mode, |
| 54 | + 1 /* dummy */); |
| 55 | + |
| 56 | + auto phase_strobe_test_handle = |
| 57 | + roc.testParameters().add("TOP", "PHASE_STROBE", phase_strobe).apply(); |
| 58 | + for (noinv_vref = 0; noinv_vref < 1024; noinv_vref = noinv_vref + stepsize) { |
| 59 | + auto noinv_param = roc.testParameters() |
| 60 | + .add("REFERENCEVOLTAGE_0", "NOINV_VREF", noinv_vref) |
| 61 | + .add("REFERENCEVOLTAGE_1", "NOINV_VREF", noinv_vref) |
| 62 | + .apply() |
| 63 | + for (inv_vref = 0; inv_vref < 1024; inv_vref = inv_vref + stepsize) { |
| 64 | + auto noinv_param = roc.testParameters() |
| 65 | + .add("REFERENCEVOLTAGE_0", "INV_VREF", inv_vref) |
| 66 | + .add("REFERENCEVOLTAGE_1", "INV_VREF", inv_vref) |
| 67 | + .apply() |
| 68 | + daq_run(tgt, "PEDESTAL", writer, nevents, pftool::state.daq_rate); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +void charge_timescan(Target* tgt) { |
| 74 | + int nevents = pftool::readline_int("How many events per time point? ", 100); |
| 75 | + int stepsize = pftool::realine_int("How big stepsize between vref values? ", 20); |
| 76 | + pflib::ROC roc{tgt->roc(pftool::state.iroc)}; |
| 77 | + std::string fname; |
| 78 | + fname = pftool::readline_path("vref_2d_scan", ".csv"); |
| 79 | + if (pftool::state.daq_format_mode == Target::DaqFormat::SIMPLEROC) { |
| 80 | + charge_timescan_writer<pflib::packing::SingleROCEventPacket>( |
| 81 | + tgt, roc, nevents, fname); |
| 82 | + } else if (pftool::state.daq_format_mode == |
| 83 | + Target::DaqFormat::ECOND_SW_HEADERS) { |
| 84 | + charge_timescan_writer<pflib::packing::MultiSampleECONDEventPacket>( |
| 85 | + tgt, roc, nevents, fname); |
| 86 | + } |
| 87 | +} |
0 commit comments