tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
Pda.h
Go to the documentation of this file.
1#ifndef TTTRLIB_PDA_H
2#define TTTRLIB_PDA_H
3
4#include <vector>
5#include <iostream>
6#include <cmath>
7
8#include "TTTR.h"
9#include "PdaCallback.h"
10
11
14class Pda {
15
16private:
19 bool _is_valid_sgsr = false;
20 PdaCallback* _histogram_function;
21
23 std::vector<double> _probability_ch1;
24
26 std::vector<double> _amplitudes;
27
28
29protected:
30
32 unsigned int _n_2d_max = 300;
33
35 unsigned int _n_2d_min = 3;
36
38 double _bg_ch1 = 0.0;
39
41 double _bg_ch2 = 0.0;
42
45 std::vector<double> _S1S2;
46
48 std::vector<double> pF;
49
50
51public:
52
60 void evaluate();
61
74 int hist2d_nmax=300,
75 int hist2d_nmin=5,
76 double background_ch1=0.0,
77 double background_ch2=0.0,
78 std::vector<double> pF = std::vector<double>()
79 ){
80 set_max_number_of_photons(std::abs(hist2d_nmax));
81 _n_2d_min = std::abs(hist2d_nmin);
82 _histogram_function = new PdaCallback();
83 _bg_ch1 = background_ch1;
84 _bg_ch2 = background_ch2;
85 setPF(pF.data(), pF.size());
86 }
87
88 ~Pda() = default;
89
100 void append(double amplitude, double probability_ch1) {
101 _is_valid_sgsr = false;
102 _amplitudes.push_back(amplitude);
103 _probability_ch1.push_back(probability_ch1);
104 }
105
110 _is_valid_sgsr = false;
111 _amplitudes.clear();
112 _probability_ch1.clear();
113 }
114
121 void get_amplitudes(double **output_view, int *n_output) {
122 *n_output = _amplitudes.size();
123 *output_view = _amplitudes.data();
124 }
125
132 void set_amplitudes(double *input, int n_input) {
133 _amplitudes.clear();
134 _is_valid_sgsr = false;
135 for(int i = 0; i < n_input; i++)
136 _amplitudes.emplace_back(input[i]);
137 }
138
149 _histogram_function = cb;
150 }
151
152public:
153
162 void get_S1S2_matrix(double **output, int *n_output1, int *n_output2){
163 if(!_is_valid_sgsr) evaluate();
164 auto* t = (double *) malloc(_S1S2.size() * sizeof(double));
165 for(unsigned int i = 0; i < _S1S2.size(); i++)
166 t[i] = _S1S2[i];
167 *output = t;
168 *n_output1 = int (_n_2d_max + 1);
169 *n_output2 = int (_n_2d_max + 1);
170 }
171
182 void set_probability_spectrum_ch1(double *input, int n_input){
183 _is_valid_sgsr = false;
184 _amplitudes.clear();
185 _probability_ch1.clear();
186 int n_components = n_input / 2;
187 for(int i=0; i < n_components; i++){
188 double amplitude = input[2 * i];
189 double probability_green = input[(2 * i) + 1];
190 _amplitudes.emplace_back(amplitude);
191 _probability_ch1.emplace_back(probability_green);
192 }
193 }
194
201 void get_probabilities_ch1(double **output_view, int *n_output) {
202 *n_output = _probability_ch1.size();
203 *output_view = _probability_ch1.data();
204 }
205
213 void set_probabilities_ch1(double *input, int n_input) {
214 _probability_ch1.clear();
215 _is_valid_sgsr = false;
216 for(int i = 0; i < n_input; i++)
217 _probability_ch1.emplace_back(input[i]);
218 }
219
220
231 void get_probability_spectrum_ch1(double** output, int* n_output) {
232 int n = (int)_amplitudes.size() * 2;
233 auto temp = (double*) malloc(sizeof(double) * n);
234 for(unsigned int i=0; i < _amplitudes.size(); i++){
235 temp[2 * i] = _amplitudes[i];
236 temp[2 * i + 1] = _probability_ch1[i];
237 }
238 *n_output = n;
239 *output = temp;
240 }
241
248 void setPF(double *input, int n_input){
249#ifdef VERBOSE_TTTRLIB
250 std::clog << "-- Setting pF " << std::endl;
251#endif
252 _is_valid_sgsr = false;
253 pF.assign(input, input + n_input);
254 }
255
262 void getPF(double** output_view, int* n_output){
263 *n_output = pF.size();
264 *output_view = pF.data();
265 }
266
296 double **histogram_x, int *n_histogram_x,
297 double **histogram_y, int *n_histogram_y,
298 double x_max=1000.0, double x_min=0.01, int n_bins=81,
299 bool log_x=true,
300 std::vector<double> s1s2 = std::vector<double>(),
301 int n_min=-1,
302 bool skip_zero_photon=true,
303 std::vector<double> amplitudes = std::vector<double>(),
304 std::vector<double> probabilities_ch1 = std::vector<double>()
305 );
306
334 TTTR* tttr_data,
335 double** s1s2, int* dim1, int* dim2,
336 double** ps, int* dim_ps,
337 int** tttr_indices, int* n_tttr_indices,
338 std::vector<int> channels_1,
339 std::vector<int> channels_2,
340 int maximum_number_of_photons,
341 int minimum_number_of_photons,
342 double minimum_time_window_length
343 );
344
358 static void S1S2_pF(
359 std::vector<double> &S1S2,
360 std::vector<double> &pF,
361 unsigned int Nmax,
362 double background_ch1,
363 double background_ch2,
364 std::vector<double> &p_ch1,
365 std::vector<double> &amplitudes
366 );
367
381 static void conv_pF(
382 std::vector<double> &S1S2,
383 const std::vector<double> &F1F2,
384 unsigned int Nmax,
385 double background_ch1,
386 double background_ch2
387 );
388
401 static void poisson_0toN(
402 std::vector<double> &return_p,
403 int start_idx,
404 double lam,
405 int return_dim
406 );
407
408
417 unsigned int get_max_number_of_photons() const{
418 return _n_2d_max;
419 }
420
431 void set_max_number_of_photons(unsigned int nmax){
432 _n_2d_max = nmax;
433 _S1S2.resize((_n_2d_max + 1) * (_n_2d_max + 1));
434 _is_valid_sgsr = false;
435 }
436
445 unsigned int get_min_number_of_photons() const{
446 return this->_n_2d_min;
447 }
448
458 void set_min_number_of_photons(unsigned int nmin){
459 this->_n_2d_min = nmin;
460 _is_valid_sgsr = false;
461 }
462
470 double get_ch1_background() const{
471 return _bg_ch1;
472 }
473
481 void set_ch1_background(double bg){
482 _is_valid_sgsr = false;
483 _bg_ch1 = bg;
484 }
485
493 double get_ch2_background() const{
494 return _bg_ch2;
495 }
496
504 void set_ch2_background(double br) {
505 _bg_ch2 = br;
506 _is_valid_sgsr = false;
507 }
508
518 bool is_valid_sgsr() const{
519 return _is_valid_sgsr;
520 }
521
530 void set_valid_sgsr(bool v){
531 _is_valid_sgsr = v;
532 }
533
534};
535
536
537#endif //TTTRLIB_PDA_H
Definition PdaCallback.h:4
Photon Distribution Analysis class for computing histograms.
Definition Pda.h:14
void setPF(double *input, int n_input)
Set the probability P(F).
Definition Pda.h:248
void get_probability_spectrum_ch1(double **output, int *n_output)
Get the theoretical probability spectrum of detecting a photon in the first channel.
Definition Pda.h:231
double get_ch1_background() const
Get the background in the green channel.
Definition Pda.h:470
void set_probabilities_ch1(double *input, int n_input)
Sets the theoretical probabilities for detecting a species in the first channel.
Definition Pda.h:213
double get_ch2_background() const
Get the background in the second channel.
Definition Pda.h:493
void set_probability_spectrum_ch1(double *input, int n_input)
Definition Pda.h:182
unsigned int _n_2d_min
Minimum number of photons.
Definition Pda.h:35
double _bg_ch1
Background in the first channel (in FRET green channel)
Definition Pda.h:38
void set_min_number_of_photons(unsigned int nmin)
Set the minimum number of photons in the S1S2 matrix.
Definition Pda.h:458
unsigned int get_min_number_of_photons() const
Get the minimum number of photons in the S1S2 matrix.
Definition Pda.h:445
Pda(int hist2d_nmax=300, int hist2d_nmin=5, double background_ch1=0.0, double background_ch2=0.0, std::vector< double > pF=std::vector< double >())
Constructor for creating a new Pda object.
Definition Pda.h:73
void set_max_number_of_photons(unsigned int nmax)
Set the maximum number of photons in the S1S2 matrix.
Definition Pda.h:431
void clear_probability_ch1()
Clears the model and removes all species from the Pda object.
Definition Pda.h:109
void evaluate()
Computes the S1S2 histogram.
bool is_valid_sgsr() const
Check if the S1S2 histogram is valid.
Definition Pda.h:518
static void S1S2_pF(std::vector< double > &S1S2, std::vector< double > &pF, unsigned int Nmax, double background_ch1, double background_ch2, std::vector< double > &p_ch1, std::vector< double > &amplitudes)
Calculates p(G,R) for several ratios using the same P(F).
void set_ch1_background(double bg)
Set the background in the first channel.
Definition Pda.h:481
unsigned int get_max_number_of_photons() const
Get the maximum number of photons in the S1S2 matrix.
Definition Pda.h:417
void set_callback(PdaCallback *cb)
Set the callback (cb) for the computation of a 1D histogram.
Definition Pda.h:148
void set_amplitudes(double *input, int n_input)
Sets the amplitudes of the species.
Definition Pda.h:132
static void conv_pF(std::vector< double > &S1S2, const std::vector< double > &F1F2, unsigned int Nmax, double background_ch1, double background_ch2)
Convolves the fluorescence matrix F1F2 with the background to yield the signal matrix S1S2.
std::vector< double > _S1S2
Definition Pda.h:45
void get_probabilities_ch1(double **output_view, int *n_output)
Returns the amplitudes of the species.
Definition Pda.h:201
void get_1dhistogram(double **histogram_x, int *n_histogram_x, double **histogram_y, int *n_histogram_y, double x_max=1000.0, double x_min=0.01, int n_bins=81, bool log_x=true, std::vector< double > s1s2=std::vector< double >(), int n_min=-1, bool skip_zero_photon=true, std::vector< double > amplitudes=std::vector< double >(), std::vector< double > probabilities_ch1=std::vector< double >())
Computes a 1D histogram from the 2D counting array of the two channels.
std::vector< double > pF
Probability P(F) of having a certain amount of photons.
Definition Pda.h:48
static void poisson_0toN(std::vector< double > &return_p, int start_idx, double lam, int return_dim)
Writes a Poisson distribution with an average lam for 0..N into a vector starting at a specified inde...
~Pda()=default
void get_S1S2_matrix(double **output, int *n_output1, int *n_output2)
Definition Pda.h:162
void set_ch2_background(double br)
Set the background in the second channel.
Definition Pda.h:504
double _bg_ch2
Background in the second channel (in FRET red channel)
Definition Pda.h:41
void append(double amplitude, double probability_ch1)
Appends a species to the Pda object.
Definition Pda.h:100
void get_amplitudes(double **output_view, int *n_output)
Returns the amplitudes of the species.
Definition Pda.h:121
unsigned int _n_2d_max
Maximum number of photons in the SgSr histogram.
Definition Pda.h:32
void set_valid_sgsr(bool v)
Set the S1S2 histogram validity (for testing purposes).
Definition Pda.h:530
void getPF(double **output_view, int *n_output)
Get the probability P(F).
Definition Pda.h:262
static void compute_experimental_histograms(TTTR *tttr_data, double **s1s2, int *dim1, int *dim2, double **ps, int *dim_ps, int **tttr_indices, int *n_tttr_indices, std::vector< int > channels_1, std::vector< int > channels_2, int maximum_number_of_photons, int minimum_number_of_photons, double minimum_time_window_length)
Computes experimental histograms.
Time-Tagged Time-Resolved (TTTR) data class.
Definition TTTR.h:195