tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
Correlator.h
Go to the documentation of this file.
1#ifndef TTTRLIB_CORRELATOR_H
2#define TTTRLIB_CORRELATOR_H
3
4#include <iostream>
5#include <cstdio>
6#include <vector>
7#include <list>
8#include <iterator>
9#include <functional>
10#include <utility> /* std::pair */
11#include <algorithm>
12#include <climits>
13#include <map>
14
15#include "TTTR.h"
17#include "CorrelatorCurve.h"
18#include "CLSMImage.h"
19
20
22
23 friend class CorrelatorCurve;
24 friend class CLSMImage;
25
26private:
27
28 std::string correlation_method = "wahl";
29
32 bool is_valid = false;
33
34protected:
35
50 static void ccf_felekyan(
51 const unsigned long long *t1,
52 const unsigned long long *t2,
53 const double *weights1,
54 const double *weights2,
55 unsigned int nc,
56 unsigned int nb,
57 unsigned int np1,
58 unsigned int np2,
59 const unsigned long long *xdat, double *corrl
60 );
61
76 std::vector<unsigned long long> &x_axis,
77 std::vector<double> &corr,
78 std::vector<unsigned long long> &x_axis_normalized,
79 std::vector<double> &corr_normalized,
80 double cr1, double cr2,
81 unsigned int n_bins,
82 unsigned int n_casc,
83 unsigned long long maximum_macro_time
84 );
85
106 static void ccf_wahl(
107 size_t n_casc, size_t n_bins,
108 std::vector<unsigned long long> &taus,
109 std::vector<double> &corr,
112 );
113
137 double np1, uint64_t dt1,
138 double np2, uint64_t dt2,
139 std::vector<unsigned long long> &x_axis,
140 std::vector<double> &corr,
141 size_t n_bins
142 );
143
156 static void ccf_laurence(
157 std::vector<unsigned long long> &taus,
158 std::vector<double> &corr,
161 );
162
176 std::vector<unsigned long long> &x_axis,
177 std::vector<double> &corr,
178 std::vector<double> &corr_normalized
179 );
180
191 static void normalize(Correlator* correlator, CorrelatorCurve &curve);
192
193public:
194
198
207 uint64_t dt();
208
222 std::shared_ptr<TTTR> tttr = nullptr,
223 std::string method = "wahl",
224 int n_bins = 17,
225 int n_casc = 25,
226 bool make_fine = false
227 );
228
229
230 ~Correlator() = default;
231
240 void set_n_casc(int n_casc) {
241 curve.set_n_casc(n_casc);
242 is_valid = false;
243 }
244
245
254 if (!is_valid) run();
255 return &curve;
256 }
257
258
266 unsigned int get_n_casc() {
267 return curve.get_n_casc();
268 }
269
278 void set_n_bins(int v) {
279 curve.set_n_bins(v);
280 is_valid = false;
281 }
282
290 unsigned int get_n_bins() const {
291 return curve.settings.n_bins;
292 }
293
294
310 void set_correlation_method(std::string cm) {
311 is_valid = false;
312 correlation_method = cm;
313 }
314
315
324 return correlation_method;
325 }
326
339 unsigned short *tac_1, int n_tac_1,
340 unsigned short *tac_2, int n_tac_2,
341 unsigned int number_of_microtime_channels
342 );
343
355 unsigned long long *t1, int n_t1,
356 unsigned long long *t2, int n_t2
357 );
358
366 std::pair<std::vector<unsigned long long>, std::vector<unsigned long long>> get_macrotimes() {
367 return {this->p1.times, this->p2.times};
368 }
369
370
386 unsigned long long *t1, int n_t1,
387 double *weight_ch1, int n_weights_ch1,
388 unsigned long long *t2, int n_t2,
389 double *weight_ch2, int n_weights_ch2
390 );
391
392
404 double *weight_ch1, int n_weights_ch1,
405 double *weight_ch2, int n_weights_ch2
406 );
407
415 std::pair<std::vector<double>, std::vector<double>> get_weights(){
416 return {this->p1.weights, this->p2.weights};
417 }
418
426 void get_x_axis(double **output, int *n_output);
427
434 void get_corr_normalized(double **output, int *n_output);
435
443 void get_corr(double** output, int* n_output);
444
453 void run();
454
470 std::shared_ptr<TTTR> tttr_1,
471 std::shared_ptr<TTTR> tttr_2 = nullptr ,
472 bool make_fine = false
473 );
474
475 std::pair<std::shared_ptr<TTTR>, std::shared_ptr<TTTR>> get_tttr();
476
491 const std::map<short, std::vector<double>> &filter,
492 const std::vector<unsigned int> &micro_times_1,
493 const std::vector<signed char> &routing_channels_1,
494 const std::vector<unsigned int> &micro_times_2,
495 const std::vector<signed char> &routing_channels_2
496 );
497
498};
499
500#endif //TTTRLIB_CORRELATOR_H
Definition CLSMImage.h:161
Definition CorrelatorCurve.h:33
unsigned int get_n_casc() const
Get the number of cascades (blocks) in the correlation curve.
Definition CorrelatorCurve.h:178
CorrelationCurveSettings settings
Stores the settings of the correlation curve, i.e., the number of correlation bins.
Definition CorrelatorCurve.h:93
void set_n_casc(int v)
Set the number of cascades (blocks) in the correlation curve and update the correlation axis.
Definition CorrelatorCurve.h:166
void set_n_bins(int v)
Set the number of equally spaced correlation channels per block.
Definition CorrelatorCurve.h:142
Definition Correlator.h:21
std::pair< std::vector< unsigned long long >, std::vector< unsigned long long > > get_macrotimes()
Get event times of the first and second correlation channel.
Definition Correlator.h:366
static void normalize_ccf_wahl(double np1, uint64_t dt1, double np2, uint64_t dt2, std::vector< unsigned long long > &x_axis, std::vector< double > &corr, size_t n_bins)
Normalize computed correlation.
static void normalize_ccf_laurence(CorrelatorPhotonStream &p1, CorrelatorPhotonStream &p2, std::vector< unsigned long long > &x_axis, std::vector< double > &corr, std::vector< double > &corr_normalized)
Normalize the correlation.
CorrelatorPhotonStream p1
Definition Correlator.h:195
uint64_t dt()
Compute the time difference in macro time units between the first and the last event.
std::pair< std::vector< double >, std::vector< double > > get_weights()
Get weights used for correlation.
Definition Correlator.h:415
std::string get_correlation_method()
Get the name of the used correlation method.
Definition Correlator.h:323
static void ccf_laurence(std::vector< unsigned long long > &taus, std::vector< double > &corr, CorrelatorPhotonStream &p1, CorrelatorPhotonStream &p2)
Compute correlation on arbitray correlation axis.
void set_events(unsigned long long *t1, int n_t1, double *weight_ch1, int n_weights_ch1, unsigned long long *t2, int n_t2, double *weight_ch2, int n_weights_ch2)
Set time events and weights for the first and second correlation channels.
Correlator(std::shared_ptr< TTTR > tttr=nullptr, std::string method="wahl", int n_bins=17, int n_casc=25, bool make_fine=false)
Correlator Constructor.
void set_n_bins(int v)
Set the number of equally spaced correlation channels per block.
Definition Correlator.h:278
void run()
compute the correlation
void set_microtimes(unsigned short *tac_1, int n_tac_1, unsigned short *tac_2, int n_tac_2, unsigned int number_of_microtime_channels)
Add microtime information to the event stream.
void set_tttr(std::shared_ptr< TTTR > tttr_1, std::shared_ptr< TTTR > tttr_2=nullptr, bool make_fine=false)
Sets the time and the weights using TTTR objects.
void set_macrotimes(unsigned long long *t1, int n_t1, unsigned long long *t2, int n_t2)
Add macrotimes information to the event stream.
void set_weights(double *weight_ch1, int n_weights_ch1, double *weight_ch2, int n_weights_ch2)
Set weights used for correlation.
~Correlator()=default
unsigned int get_n_bins() const
Get the number of equally spaced correlation channels per block.
Definition Correlator.h:290
static void normalize(Correlator *correlator, CorrelatorCurve &curve)
Normalize the correlation curve.
void set_n_casc(int n_casc)
Set the number of cascades (blocks) of the correlation curve.
Definition Correlator.h:240
void get_x_axis(double **output, int *n_output)
Get correlation bins (axis)
void get_corr(double **output, int *n_output)
Get the (unnormalized) correlation.
CorrelatorCurve curve
Definition Correlator.h:197
CorrelatorPhotonStream p2
Definition Correlator.h:196
static void normalize_ccf_felekyan(std::vector< unsigned long long > &x_axis, std::vector< double > &corr, std::vector< unsigned long long > &x_axis_normalized, std::vector< double > &corr_normalized, double cr1, double cr2, unsigned int n_bins, unsigned int n_casc, unsigned long long maximum_macro_time)
void get_corr_normalized(double **output, int *n_output)
Get the normalized correlation.
CorrelatorCurve * get_curve()
Get the correlation curve.
Definition Correlator.h:253
void set_correlation_method(std::string cm)
Set the correlation method.
Definition Correlator.h:310
static void ccf_wahl(size_t n_casc, size_t n_bins, std::vector< unsigned long long > &taus, std::vector< double > &corr, CorrelatorPhotonStream &p1, CorrelatorPhotonStream &p2)
Calculates the cross-correlation between two event streams.
unsigned int get_n_casc()
Get the number of correlation blocks.
Definition Correlator.h:266
std::pair< std::shared_ptr< TTTR >, std::shared_ptr< TTTR > > get_tttr()
static void ccf_felekyan(const unsigned long long *t1, const unsigned long long *t2, const double *weights1, const double *weights2, unsigned int nc, unsigned int nb, unsigned int np1, unsigned int np2, const unsigned long long *xdat, double *corrl)
void set_filter(const std::map< short, std::vector< double > > &filter, const std::vector< unsigned int > &micro_times_1, const std::vector< signed char > &routing_channels_1, const std::vector< unsigned int > &micro_times_2, const std::vector< signed char > &routing_channels_2)
Update weights based on a filter map and event information.
CorrelatorPhotonStream class gathers event times and weights.
Definition CorrelatorPhotonStream.h:14
std::vector< unsigned long long > times
The array containing the time points of the first correlation channel.
Definition CorrelatorPhotonStream.h:50
std::vector< double > weights
The array containing the weights of the first correlation channel.
Definition CorrelatorPhotonStream.h:55
unsigned int n_bins
The number of bins (correlation channels) per cascade.
Definition CorrelatorCurve.h:21