tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
TTTRRange.h
Go to the documentation of this file.
1#ifndef TTTRLIB_TTTRRANGE_H
2#define TTTRLIB_TTTRRANGE_H
3
4#include <memory> /* std::shared_ptr */
5#include <set>
6#include <vector>
7//#include<boost/container/flat_set.hpp>
8#include "itlib/flat_set.hpp"
9
10#include "TTTR.h"
11
15class TTTRRange {
16
17protected:
18
19 //boost::container::flat_set<int> _tttr_indices{};
20 //std::flat_set<int> _tttr_indices{};
21
23 itlib::flat_set<int> _tttr_indices{};
24
25public:
26
33 TTTRRange(int start, int stop);
34
45 TTTRRange(int start=-1, int stop=-1, TTTRRange* other = nullptr){
46 if((start >=0) && (stop >= 0)){
47 _tttr_indices.insert(start);
48 _tttr_indices.insert(stop);
49 } else if(other != nullptr){
50 _tttr_indices.insert(other->get_start());
51 _tttr_indices.insert(other->get_stop());
52 }
53 }
54
60 virtual size_t size(){
61 return _tttr_indices.size();
62 }
63
69 TTTRRange(const TTTRRange& p2);
70
76 std::vector<int> get_tttr_indices(){
77 std::vector<int> v(_tttr_indices.begin(), _tttr_indices.end());
78 return v;
79 }
80
86 int get_start() const{
87 if(!_tttr_indices.empty()){
88 return *_tttr_indices.begin();
89 } else{
90 return -1;
91 }
92 }
93
99 int get_stop() const{
100 if(!_tttr_indices.empty()){
101 return *_tttr_indices.rbegin();
102 } else{
103 return -1;
104 }
105 }
106
112 std::vector<int> get_start_stop(){
113 return {
114 get_start(),
115 get_stop()
116 };
117 }
118
125 unsigned long get_stop_time(TTTR* tttr) const{
126 unsigned long time = 0;
127 if(tttr!= nullptr){
128 time = tttr->macro_times[*_tttr_indices.rbegin()];
129 } else{
130 std::cerr << "Access to TTTRRange::get_stop_time without TTTR object" << std::endl;
131 }
132 return time;
133 }
134
141 unsigned long get_start_time(TTTR* tttr) const{
142 unsigned long start_time = 0;
143 if(tttr!= nullptr){
144 start_time = tttr->macro_times[*_tttr_indices.begin()];
145 } else{
146 std::cerr << "Access to TTTRRange::get_start_time without TTTR object" << std::endl;
147 }
148 return start_time;
149 }
150
157 std::vector<unsigned long> get_start_stop_time(TTTR* tttr){
158 return {
159 get_start_time(tttr),
160 get_stop_time(tttr)
161 };
162 }
163
170 unsigned int get_duration(TTTR* tttr){
171 return get_stop_time(tttr) - get_start_time(tttr);
172 }
173
179 void insert(int idx){
180 _tttr_indices.insert(idx);
181 }
182
186 void clear(){
187 _tttr_indices.clear();
188 }
189
199 int strip(const std::vector<int> &tttr_indices, int offset = 0){
200 if(!_tttr_indices.empty()){
201 for(; offset < tttr_indices.size(); offset++){
202 int v = tttr_indices[offset];
203 if(v >= *_tttr_indices.rbegin()){
204 break;
205 } else {
206 _tttr_indices.erase(v);
207 }
208 }
209 }
210 return offset;
211 }
212
225 TTTR* tttr_data,
226 double microtime_resolution = -1.0,
227 int minimum_number_of_photons = 1
228 ){
229 auto v = get_tttr_indices();
230 return tttr_data->get_mean_microtime(
231 &v,
232 microtime_resolution,
233 minimum_number_of_photons
234 );
235 }
236
248 std::shared_ptr<TTTR> tttr,
249 double** histogram, int* n_histogram,
250 double** time, int* n_time,
251 unsigned short micro_time_coarsening
252 ){
253 auto v = get_tttr_indices();
255 tttr.get(),
256 histogram, n_histogram,
257 time, n_time,
258 micro_time_coarsening,
259 &v
260 );
261 }
262
284 TTTR *tttr_data,
285 int minimum_number_of_photons = 3,
286 TTTR *tttr_irf = nullptr,
287 double m0_irf = 1.0, double m1_irf = 1.0,
288 double dt = 1.0,
289 std::vector<double> *background = nullptr,
290 double m0_bg = 0.0, double m1_bg = 0.0,
291 double background_fraction = -1.0
292 );
293
319 std::vector<int> &tttr_indices,
320 TTTR *tttr_data,
321 int minimum_number_of_photons = 3,
322 TTTR *tttr_irf = nullptr,
323 double m0_irf = 1.0, double m1_irf = 1.0,
324 double dt = 1.0,
325 std::vector<double> *background = nullptr,
326 double m0_bg = 0.0, double m1_bg = 0.0,
327 double background_fraction = -1.0
328 );
329
336 bool operator==(const TTTRRange& other) const {
337 return _tttr_indices == other._tttr_indices;
338 }
339
346 bool operator!=(const TTTRRange& other) const
347 {
348 return !operator==(other);
349 }
350
358 for(auto &v: rhs._tttr_indices){
360 }
361 return *this;
362 }
363
364
365};
366
367#endif //TTTRLIB_TTTRRANGE_H
Time-Tagged Time-Resolved (TTTR) data class.
Definition TTTR.h:195
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.
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
Represents a range of TTTR indices.
Definition TTTRRange.h:15
int strip(const std::vector< int > &tttr_indices, int offset=0)
Strips TTTR indices from a range starting at tttr_indices[offset].
Definition TTTRRange.h:199
void insert(int idx)
Inserts an index into the TTTR index vector.
Definition TTTRRange.h:179
TTTRRange(const TTTRRange &p2)
Copy constructor.
unsigned long get_stop_time(TTTR *tttr) const
Gets the stop time of the TTTR range.
Definition TTTRRange.h:125
std::vector< int > get_start_stop()
Gets a vector of the start and stop TTTR indices of the range.
Definition TTTRRange.h:112
double get_mean_lifetime(TTTR *tttr_data, int minimum_number_of_photons=3, TTTR *tttr_irf=nullptr, double m0_irf=1.0, double m1_irf=1.0, double dt=1.0, std::vector< double > *background=nullptr, double m0_bg=0.0, double m1_bg=0.0, double background_fraction=-1.0)
Computes the mean lifetime for the TTTRRange.
int get_start() const
Gets the start index of the TTTR range.
Definition TTTRRange.h:86
double get_mean_microtime(TTTR *tttr_data, double microtime_resolution=-1.0, int minimum_number_of_photons=1)
Computes the mean microtime in units of the microtime resolution.
Definition TTTRRange.h:224
bool operator!=(const TTTRRange &other) const
Inequality operator.
Definition TTTRRange.h:346
TTTRRange(int start=-1, int stop=-1, TTTRRange *other=nullptr)
Constructs a TTTRRange.
Definition TTTRRange.h:45
TTTRRange & operator+=(const TTTRRange &rhs)
Compound assignment addition operator.
Definition TTTRRange.h:357
unsigned int get_duration(TTTR *tttr)
Gets the duration between the start and stop times of the TTTR range.
Definition TTTRRange.h:170
int get_stop() const
Gets the stop index of the TTTR range.
Definition TTTRRange.h:99
unsigned long get_start_time(TTTR *tttr) const
Gets the start time of the TTTR range.
Definition TTTRRange.h:141
std::vector< int > get_tttr_indices()
Gets the vector of TTTR indices assigned to the range.
Definition TTTRRange.h:76
void get_microtime_histogram(std::shared_ptr< TTTR > tttr, double **histogram, int *n_histogram, double **time, int *n_time, unsigned short micro_time_coarsening)
Gets the microtime histogram for the TTTRRange.
Definition TTTRRange.h:247
virtual size_t size()
Gets the number of TTTR indices in the range.
Definition TTTRRange.h:60
TTTRRange(int start, int stop)
Constructs a TTTRRange with the specified start and stop indices.
std::vector< unsigned long > get_start_stop_time(TTTR *tttr)
Gets a vector of the start and stop times of the TTTR range.
Definition TTTRRange.h:157
itlib::flat_set< int > _tttr_indices
Set of TTTR indices in the range.
Definition TTTRRange.h:23
void clear()
Clears the TTTR index set.
Definition TTTRRange.h:186
static double compute_mean_lifetime(std::vector< int > &tttr_indices, TTTR *tttr_data, int minimum_number_of_photons=3, TTTR *tttr_irf=nullptr, double m0_irf=1.0, double m1_irf=1.0, double dt=1.0, std::vector< double > *background=nullptr, double m0_bg=0.0, double m1_bg=0.0, double background_fraction=-1.0)
Computes the mean lifetime for a set of TTTR indices.
bool operator==(const TTTRRange &other) const
Equality operator.
Definition TTTRRange.h:336