From a0e5e55723454cca27438b4ab2609349d765e805 Mon Sep 17 00:00:00 2001 From: Thomas-Otavio Peulen Date: Tue, 17 Dec 2024 10:01:52 +0100 Subject: [PATCH] Add mapping of macro time to micro time TO handle ALEX experiments map macro time modulo period to micro times. --- include/TTTR.h | 16 ++++++++++++++++ src/TTTR.cpp | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/include/TTTR.h b/include/TTTR.h index a02df6a3..f68f8c62 100644 --- a/include/TTTR.h +++ b/include/TTTR.h @@ -501,6 +501,22 @@ class TTTR : public std::enable_shared_from_this{ long long macro_time_offset = 0 ); + /** + * @brief Assigns a microtime based on the alternating-laser excitation (ALEX) period. + * + * This method computes a microtime for each macrotime value by taking the modulo + * operation of the macrotime with respect to the specified ALEX period. Optionally, + * a period shift can be applied to adjust the macrotime before the computation. + * + * microtime = (macrotime - period_shift) modulo alex_period + * + * @param alex_period The ALEX period in units of macrotime. + * @param period_shift An optional shift applied to the macrotime before computing + * the microtime. Default is 0. + * + */ + void alex_to_microtime(unsigned long alex_period, int period_shift=0); + /*! * \brief Appends a single event to the TTTR object. * diff --git a/src/TTTR.cpp b/src/TTTR.cpp index 32f82900..f7c08825 100644 --- a/src/TTTR.cpp +++ b/src/TTTR.cpp @@ -375,6 +375,13 @@ int TTTR::read_sm_file(const char *filename){ } +void TTTR::alex_to_microtime(unsigned long alex_period, int period_shift) { + for (size_t i = 0; i < n_valid_events; ++i) { + int64_t m = macro_times[i] - period_shift; + micro_times[i] = static_cast(m % alex_period); + } +} + int TTTR::read_file(const char *fn, int container_type) { #ifdef VERBOSE_TTTRLIB std::clog << "READING TTTR FILE" << std::endl;