369 using namespace util::quantities::time_literals;
370 using namespace detinfo::timescales;
379 double const expectedFrequency = timings.clockData().OpticalClock().Frequency();
381 auto const frequency = timings.OpticalClockFrequency();
384 if (frequency.value() == expectedFrequency) {
385 mf::LogVerbatim(
"DetectorTimingsStandard_test")
386 <<
"DetectorTimings::OpticalClockFrequency() => " << frequency;
390 mf::LogProblem(
"DetectorTimingsStandard_test")
391 <<
"Optical clock frequency expected to be " << expectedFrequency <<
" MHz, but got "
392 << frequency <<
" instead";
396 double const expectedPeriod = timings.clockData().OpticalClock().TickPeriod();
398 auto const period = timings.OpticalClockPeriod();
401 if (period.value() == expectedPeriod) {
402 mf::LogVerbatim(
"DetectorTimingsStandard_test")
403 <<
"DetectorTimings::OpticalClockPeriod() => " << period;
407 mf::LogProblem(
"DetectorTimingsStandard_test")
408 <<
"Optical clock period expected to be " << expectedPeriod <<
" us, but got " << period
412 if (
std::abs(period.quantity() * frequency - 1.0) > 1
e-4) {
414 mf::LogProblem(
"DetectorTimingsStandard_test")
415 <<
"Optical clock period (" << period <<
") and frequency (" << frequency
416 <<
" should have been one the inverse of the other! (their product is "
417 << (period.quantity() * frequency) <<
")";
427 auto const expectedStartTime = 0_us;
429 auto const startTime = timings.startTime<
optical_time>();
433 if (startTime == expectedStartTime) {
434 mf::LogVerbatim(
"DetectorTimingsStandard_test")
435 <<
"DetectorTimings::startTime<optical_time>() => " << startTime;
439 mf::LogProblem(
"DetectorTimingsStandard_test")
440 <<
"Start of optical time scale is expected to be " << expectedStartTime
441 <<
" in electronics time, but got " << startTime <<
" instead";
445 auto const expectedTrigStartTime = expectedStartTime - timings.detClocksUnits().TriggerTime();
451 if (trigStartTime == expectedTrigStartTime) {
452 mf::LogVerbatim(
"DetectorTimingsStandard_test")
453 <<
"DetectorTimings::startTime<optical_time, trigger_time>() => " << trigStartTime;
457 mf::LogProblem(
"DetectorTimingsStandard_test")
458 <<
"Start of optical time scale is expected to be " << expectedTrigStartTime
459 <<
" in trigger time, but got " << trigStartTime <<
" instead";
465 double const inputTick_count = 900.5;
470 double const expectedTime_us = inputTick_count * timings.clockData().OpticalClock().TickPeriod();
475 auto const time = timings.toElectronicsTime(inputTick_d);
478 if (time.value() == expectedTime_us) {
479 mf::LogVerbatim(
"DetectorTimingsStandard_test")
480 <<
"DetectorTimings::toElectronicsTime<optical_tick_d>(" << inputTick_d <<
") => " << time;
484 mf::LogProblem(
"DetectorTimingsStandard_test")
485 <<
"Optical tick #" << inputTick_count <<
" is expected to be " << expectedTime_us
486 <<
" us in electronics time, but got " << time <<
" instead";
493 if (
tick == inputTick_d) {
494 mf::LogVerbatim(
"DetectorTimingsStandard_test")
495 <<
"DetectorTimings::toTick<optical_tick_d, "
501 mf::LogProblem(
"DetectorTimingsStandard_test")
503 <<
" is expected to be optical tick " << inputTick_d <<
", but got " <<
tick <<
" instead";
508 double const expectedTrigTime_us = expectedTime_us - timings.clockData().TriggerTime();
509 double const expectedTrigTime_truncated_us =
510 static_cast<int>(inputTick_count) * timings.clockData().OpticalClock().TickPeriod() -
511 timings.clockData().TriggerTime();
513 auto const inputTick = optical_tick::castFrom(inputTick_count);
516 auto const trigTime = timings.toTriggerTime(inputTick);
520 if (trigTime.value() == expectedTrigTime_truncated_us) {
521 mf::LogVerbatim(
"DetectorTimingsStandard_test")
522 <<
"DetectorTimings::toTriggerTime<optical_tick>(" << inputTick <<
") => " << trigTime;
526 mf::LogProblem(
"DetectorTimingsStandard_test")
527 <<
"Optical tick " << inputTick <<
" is expected to be " << expectedTrigTime_truncated_us
528 <<
" us in trigger time, but got " << trigTime <<
" instead";
537 if (trigTick == inputTick) {
538 mf::LogVerbatim(
"DetectorTimingsStandard_test")
539 <<
"DetectorTimings::toTick<optical_tick, trigger_time>(" << expectedTrigTime_us <<
") => "
544 mf::LogProblem(
"DetectorTimingsStandard_test")
545 <<
"Trigger time " << expectedTrigTime_us <<
" us is expected to be optical tick "
546 << inputTick <<
", but got " << trigTick <<
" instead";
559 if (elecTick == expectedElecTick) {
560 mf::LogVerbatim(
"DetectorTimingsStandard_test")
561 <<
"DetectorTimings::toTick<electronics_tick>(" << inputTick <<
") => "
566 mf::LogProblem(
"DetectorTimingsStandard_test")
567 <<
"Optical tick #" << inputTick_count <<
" is expected to be "
568 << expectedElecTick <<
" (electronics tick), but got "
569 << elecTick <<
" instead";
574 = timings.toTick<
optical_tick>(timings.toElectronicsTime(expectedElecTick));
576 auto const tickFromElecTick = timings.toTick<
optical_tick>(elecTick);
582 if (tickFromElecTick == expectedOptTick) {
583 mf::LogVerbatim(
"DetectorTimingsStandard_test")
584 <<
"DetectorTimings::toTick<optical_tick, "
586 <<
">(" << elecTick <<
") => " << tickFromElecTick;
590 mf::LogProblem(
"DetectorTimingsStandard_test")
593 <<
" is expected to be optical tick " << expectedOptTick
594 <<
", but got " << tickFromElecTick <<
" instead";
601 double const inputInterval_us = 200.008;
608 double const expectedTicksD = inputInterval_us / timings.clockData().OpticalClock().TickPeriod();
614 mf::LogVerbatim(
"DetectorTimingsStandard_test")
615 <<
"DetectorTimings::toTicks<optical_time_ticks_d>(" << inputInterval <<
") => " <<
ticks_d;
619 mf::LogProblem(
"DetectorTimingsStandard_test")
620 <<
"Time interval " << inputInterval <<
" is expected to last " << expectedTicksD
621 <<
" optical ticks, but got " <<
ticks_d <<
" instead";
625 int const expectedTicks =
static_cast<int>(expectedTicksD);
631 mf::LogVerbatim(
"DetectorTimingsStandard_test")
632 <<
"DetectorTimings::toTicks<optical_time_ticks>(" << inputInterval <<
") => " <<
ticks;
636 mf::LogProblem(
"DetectorTimingsStandard_test")
637 <<
"Time interval " << inputInterval <<
" is expected to last " << expectedTicks
638 <<
" optical integer ticks, but got " <<
ticks <<
" instead";
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
tick_d ticks_d
Alias for common language habits.
A collection of traits for a time scale.
constexpr value_t value() const
Returns the value of the quantity.
tick ticks
Alias for common language habits.
timescale_traits< OpticalTimeCategory >::tick_interval_d_t optical_time_ticks_d
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
A value measured in the specified unit.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
timescale_traits< OpticalTimeCategory >::time_point_t optical_time
A point in time on the optical detector electronics time scale.
An interval (duration, length, distance) between two quantity points.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
timescale_traits< OpticalTimeCategory >::tick_d_t optical_tick_d