1#define _CRT_SECURE_NO_DEPRECATE
21#include <boost/bimap.hpp>
24#ifdef BUILD_PHOTON_HDF
64 int **output,
int *n_output,
65 unsigned long long *time,
int n_time,
66 double time_window,
int n_ph_max,
67 double macro_time_calibration=1.0,
68 bool invert=
false,
bool make_mask=
false
91 int **output,
int *n_output,
92 unsigned long long *input,
int n_input,
93 double minimum_window_length,
94 double maximum_window_length = -1,
95 int minimum_number_of_photons_in_time_window = -1,
96 int maximum_number_of_photons_in_time_window = -1,
97 double macro_time_calibration = 1.0,
126 int **output,
int *n_output,
127 unsigned long long *input,
int n_input,
128 double time_window_length,
129 double macro_time_resolution = 1.0
154 size_t n_valid_events,
159 *n_out =
static_cast<int>(n_valid_events);
160 *out =
static_cast<T*
>(malloc(
sizeof(T) * n_valid_events));
162 for (
size_t i = 0; i < n_valid_events; ++i) {
163 (*out)[i] = array[i];
195class TTTR :
public std::enable_shared_from_this<TTTR>{
205 uint64_t overflow_counter;
208 std::string filename;
213 boost::bimap<std::string, int> container_names = {};
215 typedef bool (*processRecord_t)(
224 std::map<int, processRecord_t> processRecord_map = {
253 int tttr_container_type;
256 std::string tttr_container_type_str;
257 int tttr_record_type;
262#ifdef BUILD_PHOTON_HDF
268 size_t fp_records_begin;
279 bool (*processRecord)(
289 unsigned long long *macro_times;
292 unsigned short *micro_times;
295 signed char *routing_channels;
298 signed char *event_types;
301 size_t n_records_in_file = 0;
304 size_t n_records_read = 0;
307 size_t n_valid_events = 0;
322 void allocate_memory_for_records(
size_t n_rec);
333 void deallocate_memory_of_records();
344 int read_hdf_file(
const char *fn);
358 void read_records(
size_t n_rec,
bool rewind,
size_t chunk);
368 void read_records(
size_t n_rec);
403 std::shared_ptr<TTTR>
Get() {
return shared_from_this(); }
429 int read_file(
const char *fn =
nullptr,
int container_type = -1);
448 size_t bytes_per_record
470 unsigned long long *macro_times,
int n_macrotimes,
471 unsigned short *micro_times,
int n_microtimes,
472 signed char *routing_channels,
int n_routing_channels,
473 signed char *event_types,
int n_event_types,
475 long long macro_time_offset = 0
492 unsigned long long macro_time,
493 unsigned short micro_time,
494 signed char routing_channel,
495 signed char event_type,
497 long long macro_time_offset = 0
513 long long macro_time_offset=0
629 return tttr_container_type_str;
642 std::shared_ptr<TTTR>
select(
int *selection,
int n_selection);
674 TTTR(
const char *filename,
int container_type,
bool read_input);
689 TTTR(
const char *filename,
int container_type);
704 TTTR(
const char *filename,
const char* container_type);
722 TTTR(
unsigned long long *macro_times,
int n_macrotimes,
723 unsigned short *micro_times,
int n_microtimes,
724 signed char *routing_channels,
int n_routing_channels,
725 signed char *event_types,
int n_event_types,
726 bool find_used_channels =
true
742 int *selection,
int n_selection,
743 bool find_used_channels =
true);
767 auto p = std::make_shared<TTTR>(*
this, selection, n_selection,
true);
790 int **output,
int *n_output,
791 double minimum_window_length,
792 double maximum_window_length=-1,
793 int minimum_number_of_photons_in_time_window=-1,
794 int maximum_number_of_photons_in_time_window=-1,
795 double macro_time_calibration = -1,
798 if(macro_time_calibration < 0){
803 macro_times, n_valid_events,
804 minimum_window_length,
805 maximum_window_length,
806 minimum_number_of_photons_in_time_window,
807 maximum_number_of_photons_in_time_window,
808 macro_time_calibration,
825 int **output,
int *n_output,
826 signed char *input,
int n_input
859 int **output,
int *n_output,
860 double time_window,
int n_ph_max,
861 bool invert=
false,
bool make_mask=
false
877 double time_window,
int n_ph_max,
878 bool invert=
false,
bool make_mask=
false
883 time_window, n_ph_max,
908 int **output,
int *n_output,
909 double minimum_window_length,
910 int minimum_number_of_photons_in_time_window,
911 int maximum_number_of_photons_in_time_window=-1,
912 double maximum_window_length=-1.0,
913 double macro_time_calibration=-1,
986 auto re =
new TTTR();
987 re->copy_from(*
this,
true);
1005 double** output,
int* n_output,
1006 double **time,
int *n_time,
1007 unsigned short micro_time_coarsening = 1,
1008 std::vector<int> *tttr_indices =
nullptr
1021 double **histogram,
int *n_histogram,
1022 double **time,
int *n_time,
1023 unsigned short micro_time_coarsening = 1
1026 this, histogram, n_histogram,
1028 micro_time_coarsening
1055 TTTR *tttr_irf =
nullptr,
1056 double m0_irf = 1,
double m1_irf = 0,
1057 std::vector<int> *tttr_indices =
nullptr,
1059 int minimum_number_of_photons = 1,
1060 std::vector<double> *background =
nullptr,
1061 double m0_bg = 0.0,
double m1_bg = 0.0,
1062 double background_fraction = -1.0
1077 TTTR *tttr_irf =
nullptr,
1078 int m0_irf = 1,
int m1_irf = 1,
1079 std::vector<int> *tttr_indices =
nullptr,
1085 tttr_irf, m0_irf, m1_irf,
1086 tttr_indices, dt, min_ph
1100 std::vector<int> *tttr_indices =
nullptr,
1101 double macrotime_resolution = -1.0
1112 std::vector<int> *tttr_indices =
nullptr,
1113 double macrotime_resolution = -1.0
1129 std::vector<int> *tttr_indices =
nullptr,
1130 double microtime_resolution = -1.0,
1131 int minimum_number_of_photons = 1
1144 std::vector<int> *tttr_indices =
nullptr,
1145 double microtime_resolution = -1.0,
1146 int minimum_number_of_photons = 1
1150 microtime_resolution, minimum_number_of_photons);
void selection_by_count_rate(int **output, int *n_output, unsigned long long *time, int n_time, double time_window, int n_ph_max, double macro_time_calibration=1.0, bool invert=false, bool make_mask=false)
A count rate (cr) filter that returns an array containing a list of indices where the cr was smaller ...
void compute_intensity_trace(int **output, int *n_output, unsigned long long *input, int n_input, double time_window_length, double macro_time_resolution=1.0)
Computes the intensity trace for a sequence of time events.
void get_array(size_t n_valid_events, T *array, T **out, int *n_out)
Extracts a subarray of valid events from the input array.
Definition TTTR.h:153
void ranges_by_time_window(int **output, int *n_output, unsigned long long *input, int n_input, double minimum_window_length, double maximum_window_length=-1, int minimum_number_of_photons_in_time_window=-1, int maximum_number_of_photons_in_time_window=-1, double macro_time_calibration=1.0, bool invert=false)
Returns time windows (tw), i.e., the start and stop indices for a minimum tw size and a minimum numbe...
bool ProcessCzRaw(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessSPC130(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessPHT3(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessSPC600_256(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessHHT3v1(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessHHT3v2(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessHHT2v1(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessSPC600_4096(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessPHT2(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
bool ProcessHHT2v2(uint32_t &TTTRRecord, uint64_t &overflow_counter, uint64_t &true_nsync, uint32_t µ_time, int16_t &channel, int16_t &record_type)
Definition CLSMImage.h:161
CorrelatorPhotonStream class gathers event times and weights.
Definition CorrelatorPhotonStream.h:14
Time-Tagged Time-Resolved (TTTR) data class.
Definition TTTR.h:195
TTTR(const char *filename, int container_type)
std::shared_ptr< TTTR > get_tttr_by_count_rate(double time_window, int n_ph_max, bool invert=false, bool make_mask=false)
Get a TTTR object filtered by count rate criteria.
Definition TTTR.h:876
void append_events(unsigned long long *macro_times, int n_macrotimes, unsigned short *micro_times, int n_microtimes, signed char *routing_channels, int n_routing_channels, signed char *event_types, int n_event_types, bool shift_macro_time=true, long long macro_time_offset=0)
Appends events to the TTTR object.
void write_header(std::string &fn, TTTRHeader *header=nullptr)
Writes the header information to a TTTR file.
void set_header(TTTRHeader *v)
Set the header for the TTTR object.
static double compute_mean_microtime(TTTR *tttr_data, std::vector< int > *tttr_indices=nullptr, double microtime_resolution=-1.0, int minimum_number_of_photons=1)
Computes the mean microtime.
void append_event(unsigned long long macro_time, unsigned short micro_time, signed char routing_channel, signed char event_type, bool shift_macro_time=true, long long macro_time_offset=0)
Appends a single event to the TTTR object.
void shift_macro_time(int shift)
Shifts the macro time by adding an integer value to each macro time entry.
TTTR(unsigned long long *macro_times, int n_macrotimes, unsigned short *micro_times, int n_microtimes, signed char *routing_channels, int n_routing_channels, signed char *event_types, int n_event_types, bool find_used_channels=true)
static double compute_mean_lifetime(TTTR *tttr_data, TTTR *tttr_irf=nullptr, double m0_irf=1, double m1_irf=0, std::vector< int > *tttr_indices=nullptr, double dt=-1.0, int minimum_number_of_photons=1, std::vector< double > *background=nullptr, double m0_bg=0.0, double m1_bg=0.0, double background_fraction=-1.0)
Computes the mean lifetime by the moments of the decay and the instrument response function.
size_t size()
Returns the number of valid events in the TTTR data.
Definition TTTR.h:524
void get_selection_by_count_rate(int **output, int *n_output, double time_window, int n_ph_max, bool invert=false, bool make_mask=false)
Get indices where the count rate is below a specified maximum.
size_t get_n_valid_events()
Returns the number of valid events in the TTTR file.
void append(const TTTR *other, bool shift_macro_time=true, long long macro_time_offset=0)
Appends events from another TTTR object to the current TTTR object.
void write_spc132_events(FILE *fp, TTTR *tttr)
Write events from the TTTR object to a file as SPC-132.
TTTR(const TTTR &p2)
Copy constructor for the TTTR (Time-Tagged Time-Resolved) class.
static void compute_microtime_histogram(TTTR *tttr_data, double **output, int *n_output, double **time, int *n_time, unsigned short micro_time_coarsening=1, std::vector< int > *tttr_indices=nullptr)
Computes a histogram of the TTTR data's micro times.
int read_file(const char *fn=nullptr, int container_type=-1)
Reads TTTR data from a file into the TTTR object.
TTTR(const char *filename, int container_type, bool read_input)
std::string get_filename()
std::string get_tttr_container_type()
Returns the container type used to open the TTTR file.
Definition TTTR.h:628
double mean_lifetime(TTTR *tttr_irf=nullptr, int m0_irf=1, int m1_irf=1, std::vector< int > *tttr_indices=nullptr, double dt=-1.0, int min_ph=1)
Computes the mean lifetime by moments of decay and instrument response.
Definition TTTR.h:1076
void get_selection_by_channel(int **output, int *n_output, signed char *input, int n_input)
Get events indices by the routing channel number.
void copy_from(const TTTR &p2, bool include_big_data=true)
Copies information from another TTTR object.
double get_mean_microtime(std::vector< int > *tttr_indices=nullptr, double microtime_resolution=-1.0, int minimum_number_of_photons=1)
Gets the mean microtime.
Definition TTTR.h:1143
void get_microtime_histogram(double **histogram, int *n_histogram, double **time, int *n_time, unsigned short micro_time_coarsening=1)
Computes and returns a histogram of the TTTR data's micro times.
Definition TTTR.h:1020
TTTR * operator+(const TTTR *other) const
Adds the events of another TTTR object to the current TTTR object.
Definition TTTR.h:985
void get_used_routing_channels(signed char **output, int *n_output)
Retrieves the used routing channel numbers from the TTTR data.
std::shared_ptr< TTTR > select(int *selection, int n_selection)
Creates a new TTTR object by selecting specific events based on the provided indices.
void get_ranges_by_time_window(int **output, int *n_output, double minimum_window_length, double maximum_window_length=-1, int minimum_number_of_photons_in_time_window=-1, int maximum_number_of_photons_in_time_window=-1, double macro_time_calibration=-1, bool invert=false)
Returns time windows (tw), i.e., the start and the stop indices for a minimum tw size,...
Definition TTTR.h:789
std::shared_ptr< TTTR > get_tttr_by_selection(int *selection, int n_selection)
Definition TTTR.h:766
void find_used_routing_channels()
Traverses the routing channel array and identifies used routing channel numbers.
size_t get_n_events()
Returns the number of events in the TTTR file, or the number of selected events if a selection is app...
void get_micro_times(unsigned short **output, int *n_output)
Retrieves the micro times of valid TTTR events.
TTTRHeader * get_header()
Get the header as a map of strings.
std::vector< signed char > used_routing_channels
A routing channel is a numeric identifier associated with each photon in the time-tagged time-resolve...
Definition TTTR.h:391
void get_time_window_ranges(int **output, int *n_output, double minimum_window_length, int minimum_number_of_photons_in_time_window, int maximum_number_of_photons_in_time_window=-1, double maximum_window_length=-1.0, double macro_time_calibration=-1, bool invert=false)
Get time windows (tw) based on specified criteria.
void get_intensity_trace(int **output, int *n_output, double time_window_length=1.0)
Computes and returns an intensity trace for a specified integration window.
static size_t get_number_of_records_by_file_size(std::FILE *fp, size_t offset, size_t bytes_per_record)
Determines the number of records in a TTTR file (not for use with HDF5).
TTTR()
Default constructor for the TTTR (Time-Tagged Time-Resolved) class.
void write_hht3v2_events(FILE *fp, TTTR *tttr)
Write events from the TTTR object to a file as HHT3v2.
unsigned int get_number_of_micro_time_channels()
Returns the number of micro time channels that fit between two macro time clocks.
void get_macro_times(unsigned long long **output, int *n_output)
Retrieves the macro times of valid TTTR events.
std::shared_ptr< TTTR > Get()
Returns a shared pointer to the current instance of TTTR.
Definition TTTR.h:403
double get_count_rate(std::vector< int > *tttr_indices=nullptr, double macrotime_resolution=-1.0)
Gets the count rate.
Definition TTTR.h:1111
void get_event_type(signed char **output, int *n_output)
Returns an array containing the event types of the valid TTTR events.
TTTR(const char *filename, const char *container_type)
static double compute_count_rate(TTTR *tttr_data, std::vector< int > *tttr_indices=nullptr, double macrotime_resolution=-1.0)
Computes the count rate.
std::shared_ptr< TTTR > get_tttr_by_channel(signed char *input, int n_input)
Get a TTTR object based on a selection by routing channel numbers.
Definition TTTR.h:839
TTTR(const TTTR &parent, int *selection, int n_selection, bool find_used_channels=true)
void get_routing_channel(signed char **output, int *n_output)
Returns an array containing the routing channel numbers of the valid TTTR events.
bool write(std::string filename, TTTRHeader *header=nullptr)
Writes the contents of an opened TTTR file to a new TTTR file.
Represents a range of TTTR indices.
Definition TTTRRange.h:15