21 #include "messagefacility/MessageLogger/MessageLogger.h"
29 using namespace detinfo::timescales;
30 static_assert(!is_tick_v<electronics_time>);
31 static_assert( is_tick_v<electronics_tick>);
32 static_assert( is_tick_v<electronics_tick_d>);
33 static_assert( is_tick_v<electronics_time_ticks>);
34 static_assert( is_tick_v<electronics_time_ticks_d>);
35 static_assert(!is_tick_v<TPCelectronics_time>);
36 static_assert( is_tick_v<TPCelectronics_tick>);
37 static_assert( is_tick_v<TPCelectronics_tick_d>);
38 static_assert( is_tick_v<TPCelectronics_time_ticks>);
39 static_assert( is_tick_v<TPCelectronics_time_ticks_d>);
40 static_assert(!is_tick_v<trigger_time>);
41 static_assert( is_tick_v<trigger_tick>);
42 static_assert( is_tick_v<trigger_tick_d>);
43 static_assert( is_tick_v<trigger_time_ticks>);
44 static_assert( is_tick_v<trigger_time_ticks_d>);
45 static_assert(!is_tick_v<simulation_time>);
46 static_assert(!is_tick_v<optical_time>);
47 static_assert( is_tick_v<optical_tick>);
48 static_assert( is_tick_v<optical_tick_d>);
49 static_assert( is_tick_v<optical_time_ticks>);
50 static_assert( is_tick_v<optical_time_ticks_d>);
68 close_in_value(
double const a,
double const b)
70 return std::abs(a - b) < std::numeric_limits<double>::epsilon();
92 if (time.value() == expectedTime) {
93 mf::LogVerbatim(
"DetectorTimingsStandard_test") <<
"DetectorTimings::TriggerTime() => " << time;
97 mf::LogProblem(
"DetectorTimingsStandard_test")
98 <<
"Trigger time expected to be " << expectedTime <<
" us in electronics time, but got "
99 << time <<
" instead";
120 if (close_in_value(time.value(), expectedTime)) {
121 mf::LogVerbatim(
"DetectorTimingsStandard_test")
122 <<
"DetectorTimings::BeamGateTime() => " << time;
126 mf::LogProblem(
"DetectorTimingsStandard_test")
127 <<
"Beam gate time expected to be " << expectedTime <<
" us in electronics time, but got "
128 << time <<
" instead";
139 using namespace detinfo::timescales;
152 microsecond const expectedStartTime{expectedStartTime_us};
159 if (startTime == expectedStartTime) {
160 mf::LogVerbatim(
"DetectorTimingsStandard_test")
161 <<
"DetectorTimings::startTime<simulation_time>() => " << startTime;
165 mf::LogProblem(
"DetectorTimingsStandard_test")
166 <<
"Simulation time expected to start at " << expectedStartTime
167 <<
" in electronics time, but got " << startTime <<
" instead";
175 if (elecStartTime == -expectedStartTime) {
176 mf::LogVerbatim(
"DetectorTimingsStandard_test")
177 <<
"DetectorTimings::startTime<electronics_time, simulation_time>() => " << elecStartTime;
181 mf::LogProblem(
"DetectorTimingsStandard_test")
182 <<
"Electronics time expected to start at " << (-expectedStartTime)
183 <<
" in simulation time, but got " << elecStartTime <<
" instead";
191 double const inputTime_ns = 100.0;
201 if (time.value() == expectedTime) {
202 mf::LogVerbatim(
"DetectorTimingsStandard_test")
203 <<
"DetectorTimings::toElectronicsTime<simulation_time>(" << inputTime <<
") => " << time;
207 mf::LogProblem(
"DetectorTimingsStandard_test")
208 <<
"A simulation time of " << inputTime <<
" is expected to be " << expectedTime
209 <<
" us in electronics time, but got " << time <<
" instead";
218 if (simulTime.value() == inputTime_ns) {
219 mf::LogVerbatim(
"DetectorTimingsStandard_test")
220 <<
"DetectorTimings::toTimeScale<electronics_time>(" << expectedTime <<
") => " << simulTime;
224 mf::LogProblem(
"DetectorTimingsStandard_test")
225 <<
"An electronics time of " << expectedTime <<
" us is expected to be " << inputTime
226 <<
" in simulation time, but got " << simulTime <<
" instead";
233 if (cmp.equal(TPCtick.value(), expectedTPCtick)) {
234 mf::LogVerbatim(
"DetectorTimingsStandard_test")
235 <<
"DetectorTimings::toTick<TPCelectronics_tick_d>(" << inputTime <<
") => " << TPCtick;
239 mf::LogProblem(
"DetectorTimingsStandard_test")
240 <<
"A simulation time of " << inputTime <<
" is expected to be at " << expectedTPCtick
241 <<
" TPC electronics tick, but got " << TPCtick <<
" instead";
255 if (simulTick == expectedSimulTick) {
256 mf::LogVerbatim(
"DetectorTimingsStandard_test")
257 <<
"DetectorTimings::toTimeScale<simulation_time>(" << trigTime <<
" + " << tickOffset
258 <<
" = " <<
tick <<
") => " << simulTick;
262 mf::LogProblem(
"DetectorTimingsStandard_test")
263 <<
"An offset of " << tickOffset <<
" on trigger time (" << trigTime <<
") is expected to be "
264 << expectedSimulTick <<
" in simulation time, but got " << simulTick <<
" instead";
275 using namespace detinfo::timescales;
291 if (startTime.value() == expectedStartTime) {
292 mf::LogVerbatim(
"DetectorTimingsStandard_test")
293 <<
"DetectorTimings::startTime<trigger_time>() => " << startTime;
297 mf::LogProblem(
"DetectorTimingsStandard_test")
298 <<
"Trigger time expected to start at " << expectedStartTime
299 <<
" us in electronics time, but got " << startTime <<
" instead";
307 if (elecStartTime.value() == -expectedStartTime) {
308 mf::LogVerbatim(
"DetectorTimingsStandard_test")
309 <<
"DetectorTimings::startTime<electronics_time, trigger_time>() => " << elecStartTime;
313 mf::LogProblem(
"DetectorTimingsStandard_test")
314 <<
"Electronics time expected to start at " << (-expectedStartTime)
315 <<
" us in trigger time, but got " << elecStartTime <<
" instead";
323 double const inputTime_us = 100.0;
333 if (time.value() == expectedTime) {
334 mf::LogVerbatim(
"DetectorTimingsStandard_test")
335 <<
"DetectorTimings::toElectronicsTime<trigger_time>(" << inputTime <<
") => " << time;
339 mf::LogProblem(
"DetectorTimingsStandard_test")
340 <<
"A trigger time of " << inputTime <<
" is expected to be " << expectedTime
341 <<
" us in electronics time, but got " << time <<
" instead";
350 if (trigTime.value() == inputTime_us) {
351 mf::LogVerbatim(
"DetectorTimingsStandard_test")
352 <<
"DetectorTimings::toTriggerTime<electronics_time>(" << expectedTime <<
") => " << trigTime;
356 mf::LogProblem(
"DetectorTimingsStandard_test")
357 <<
"An electronics time of " << expectedTime <<
" us is expected to be " << inputTime
358 <<
" in trigger time, but got " << trigTime <<
" instead";
369 using namespace util::quantities::time_literals;
370 using namespace detinfo::timescales;
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";
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;
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";
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;
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";
509 double const expectedTrigTime_truncated_us =
513 auto const inputTick = optical_tick::castFrom(inputTick_count);
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";
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;
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";
663 main(
int argc,
char const** argv)
677 std::cerr <<
"FHiCL configuration file path required as first argument!" << std::endl;
715 using namespace detinfo::timescales;
718 mf::LogVerbatim(
"DetectorTimingsStandard_test")
729 if (nErrors > 0) { mf::LogError(
"clocks_test") << nErrors <<
" errors detected!"; }
731 return (nErrors > 0U)? 1: 0;
unsigned int testOpticalClockTimings(detinfo::DetectorTimings const &timings)
electronics_time BeamGateTime() const
Dimensioned variables representing frequency quantities.
Prov const * Provider() const
Return the specified provider (throws if not available)
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
megahertz OpticalClockFrequency() const
Returns the frequency of the optical clock tick.
BEGIN_PROLOG could also be cerr
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Provides simple real number checks.
Ticks toTicks(time_interval time) const
Returns the number of ticks corresponding to a time interval.
trigger_time toTriggerTime(FromTime time) const
Converts a time point into trigger time scale.
detinfo::DetectorClocksData const & clockData() const
Returns the detector clocks data.
double TPCG4Time2Tick(double const g4time) const
Given G4 time returns electronics clock count [tdc].
Class holding a configuration for a test environment.
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.
unsigned int testBeamGateTime(detinfo::DetectorTimings const &timings)
tick ticks
Alias for common language habits.
Class for approximate comparisons.
timescale_traits< OpticalTimeCategory >::tick_interval_d_t optical_time_ticks_d
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
timescale_traits< TPCelectronicsTimeCategory >::tick_d_t TPCelectronics_tick_d
A point on the TPC electronics time scale expressed in its ticks (real).
Interface to detinfo::DetectorClocks.
constexpr double TickPeriod() const noexcept
A single tick period in microseconds.
Helper functions for support of DetectorClocksService in LArSoft tests.
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
Prov * SimpleProviderSetup()
Oversimplified provider setup.
detinfo::DetectorClocksWithUnits const & detClocksUnits() const
Returns a DetectorClocksWithUnits object.
timescale_traits< ElectronicsTimeCategory >::tick_interval_t electronics_time_ticks
An interval on the electronics time scale expressed in its ticks.
electronics_time toElectronicsTime(FromTime time) const
Converts a time point into electronics time scale.
time_interval_for< TimeScale > ClockPeriodFor() const
Returns the period of the clock for the specified time scale.
double BeamGateTime() const
Beam gate electronics clock time in [us].
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
A value measured in the specified unit.
simulation_time toSimulationTime(FromTime time) const
Converts a time point into simulation time scale.
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.
unsigned int testSimulationTimes(detinfo::DetectorTimings const &timings)
An interval (duration, length, distance) between two quantity points.
unsigned int testTriggerTime(detinfo::DetectorTimings const &timings)
electronics_time TriggerTime() const
double TriggerTime() const
Trigger electronics clock time in [us].
ElecClock const & OpticalClock() const noexcept
Borrow a const Optical clock with time set to Trigger time [us].
Class used for the conversion of times between different formats and references.
A test environment with some support for service providers.
DetectorClocksData DataForJob() const override
Returns a complete detinfo::DetectorClocksData object.
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
TargetTime toTimeScale(FromTime time) const
Returns a time point in a different time scale.
Functions to help debugging by instrumenting code.
double G4ToElecTime(double const g4_time) const
TargetTick toTick(FromTime time) const
Returns a time point as a tick on a different time scale.
Dimensioned variables representing space or time quantities.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
unsigned int testTriggerTimes(detinfo::DetectorTimings const &timings)
constexpr double Frequency() const
Frequency in MHz.
timescale_traits< OpticalTimeCategory >::tick_d_t optical_tick_d
auto OpticalClockPeriod() const
Returns the duration of the optical clock period and tick.
int main(int argc, char **argv)
Base class for unit tests using FHiCL configuration.
microsecond TriggerTime() const
Equivalent to detinfo::DetectorClocksData::TriggerTime().
void SetServiceParameterSetPath(std::string service_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
void SetMainTesterParameterSetPath(std::string path)
Sets the FHiCL path for the configuration of the main test algorithm.
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.
constexpr TimeScale startTime() const
Returns the start time of the specified time scale.