tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
DecayFit.h
Go to the documentation of this file.
1#ifndef TTTRLIB_DECAYFIT_H
2#define TTTRLIB_DECAYFIT_H
3
4#include <iostream>
5#include <cmath>
6#include <algorithm>
7#include <string>
8#include <sstream>
9
10#include "i_lbfgs.h"
11#include "LvArrays.h"
12#include "DecayConvolution.h"
13#include "DecayStatistics.h"
14
15
17
18 double gamma = 0.0;
19 double g = 1.0;
20 double l1 = 0.0;
21 double l2 = 0.0;
22 double period = 1000;
24
25 void set_gamma(double v){
26 if (v < 0.)
27 gamma = 0.; // 0 < gamma < 0.999
28 else if (v > 0.999)
29 gamma = 0.999;
30 else
31 gamma = v;
32 }
33
34 std::string str(){
35 auto s = std::stringstream();
36 s << "-- Correction factors:\n";
37 s << "-- g-factor: " << g << std::endl;
38 s << "-- l1, l2: " << l1 << ", " << l2 << std::endl;
39 s << "-- period: " << period << std::endl;
40 s << "-- convolution_stop: " << convolution_stop << std::endl;
41 return s.str();
42 }
43
45 double gamma = 0.0,
46 double g = 1.0,
47 double l1 = 0.0,
48 double l2 = 0.0,
49 double period = 1000,
50 int convolution_stop = 0
51 ) {
52 this->gamma = gamma;
53 this->g = g;
54 this->l1 = l1;
55 this->l2 = l2;
56 this->period = period;
57 this->convolution_stop = convolution_stop;
58 }
59
60};
61
62
64
65 int fixedrho = 0;
66 int softbifl = 0;
67 int p2s_twoIstar = 0;
68 int firstcall = 1;
69 double penalty = 0.0;
70
71 std::string str(){
72 auto s = std::stringstream();
73 s << "DECAYFITSETTINGS: " << std::endl;
74 s << "-- fixedrho: " << fixedrho << std::endl;
75 s << "-- softbifl: " << softbifl << std::endl;
76 s << "-- p2s_twoIstar: " << p2s_twoIstar << std::endl;
77 s << "-- firstcall: " << firstcall << std::endl;
78 s << "-- penalty: " << penalty << std::endl;
79 return s.str();
80 }
81};
82
83
85
87
89 double Sp = 0.0;
90
92 double Ss = 0.0;
93
95 double Bp = 0.0;
96
98 double Bs = 0.0;
99
101 double B = 0.0;
102
104 double Bexpected = 0.0;
105
106
107 double Fp(){
108 double g = 1.0;
109 if(corrections != nullptr){
110 g = corrections->g;
111 }
112 if(g == 1.0){
113 return (Sp - Bp);
114 } else{
115 return (Sp - g * Bp) / (1. - g);
116 }
117 }
118
119 double Fs(){
120 double g = 1.0;
121 if(corrections != nullptr){
122 g = corrections->g;
123 }
124 if(g == 1.0){
125 return (Ss - Bs);
126 } else{
127 return (Ss - g * Bs) / (1. - g);
128 }
129 }
130
131 double r(){
132 double fp = Fp();
133 double fs = Fs();
134 double g = 1.0, l1 = 0.0, l2 = 0.0;
135 if(corrections != nullptr){
136 g = corrections->g;
137 l1 = corrections->l1;
138 l2 = corrections->l2;
139 }
140 double nom = (fp - g * fs);
141 double denom = (fp * (1. - 3. * l2) + (2. - 3. * l1) * g * fs);
142 return nom / denom;
143 }
144
145 double rho(double tau, double r0){
146 double rh = tau / (r0 / r() - 1.); // rho = tau/(r0/r-1)
147 return std::max(rh, 1.e-4);
148 }
149
150 double rs(){
151 double g = 1.0, l1 = 0.0, l2 = 0.0;
152 if(corrections != nullptr){
153 g = corrections->g;
154 l1 = corrections->l1;
155 l2 = corrections->l2;
156 }
157 return (Sp - g * Ss) / (Sp * (1. - 3. * l2) + (2. - 3. * l1) * g * Ss);
158 }
159
169
182 void normM(double *M, int Nchannels);
183
193 void normM(double *M, double s, int Nchannels);
194
195
207 void normM_p2s(double *M, int Nchannels);
208
209
210 std::string str(){
211 auto s = std::stringstream();
212 s << "-- Signals: " << std::endl;
213 s << "-- Bp, Bs: " << Bp << ", " << Bs << std::endl;
214 s << "-- Sp, Ss: " << Sp << ", " << Ss << std::endl;
215 s << "-- Fp, Fs: " << Fp() << ", " << Fs() << std::endl;
216 s << "-- r: " << r() << std::endl;
217 return s.str();
218 }
219
221 this->corrections = corrections;
222 }
223
224};
225
226
228
229
230public:
231
246 static int modelf(double *param,
247 double *irf,
248 double *bg,
249 int Nchannels,
250 double dt,
251 double *corrections,
252 double *mfunction
253 ) {
254 return 0;
255 };
256
268 static double targetf(double *x, void *pv){
269 return 0.0;
270 };
271
272
282 static double fit(double* x, short* fixed, MParam* p){
283 return 0.0;
284 };
285
286
297 static void correct_input(double *x, double *xm, LVDoubleArray *corrections, int return_r){};
298
299};
300
301
302#endif //TTTRLIB_DECAYFIT_H
Definition DecayFit.h:227
static double targetf(double *x, void *pv)
Target function (to minimize)
Definition DecayFit.h:268
static void correct_input(double *x, double *xm, LVDoubleArray *corrections, int return_r)
Definition DecayFit.h:297
static double fit(double *x, short *fixed, MParam *p)
Definition DecayFit.h:282
static int modelf(double *param, double *irf, double *bg, int Nchannels, double dt, double *corrections, double *mfunction)
Function to compute a model fluorescence decay.
Definition DecayFit.h:246
Definition DecayFit.h:16
double l1
Definition DecayFit.h:20
std::string str()
Definition DecayFit.h:34
void set_gamma(double v)
Definition DecayFit.h:25
double g
Definition DecayFit.h:19
DecayFitCorrections(double gamma=0.0, double g=1.0, double l1=0.0, double l2=0.0, double period=1000, int convolution_stop=0)
Definition DecayFit.h:44
double period
Definition DecayFit.h:22
double l2
Definition DecayFit.h:21
int convolution_stop
Definition DecayFit.h:23
double gamma
Definition DecayFit.h:18
Definition DecayFit.h:84
void normM(double *M, double s, int Nchannels)
double rho(double tau, double r0)
Definition DecayFit.h:145
void compute_signal_and_background(MParam *p)
double Ss
Total signal perpendicular.
Definition DecayFit.h:92
double Fs()
Definition DecayFit.h:119
double Bs
Total background signal perpendicular.
Definition DecayFit.h:98
double Fp()
Definition DecayFit.h:107
DecayFitIntegrateSignals(DecayFitCorrections *corrections=nullptr)
Definition DecayFit.h:220
double rs()
Definition DecayFit.h:150
double r()
Definition DecayFit.h:131
std::string str()
Definition DecayFit.h:210
void normM_p2s(double *M, int Nchannels)
DecayFitCorrections * corrections
Definition DecayFit.h:86
double Bp
Total background signal parallel.
Definition DecayFit.h:95
double Bexpected
expected corresponding to the mean Bg signal
Definition DecayFit.h:104
double B
Total background.
Definition DecayFit.h:101
double Sp
Total signal parallel.
Definition DecayFit.h:89
void normM(double *M, int Nchannels)
Definition DecayFit.h:63
double penalty
Definition DecayFit.h:69
int firstcall
Definition DecayFit.h:68
int softbifl
Definition DecayFit.h:66
int p2s_twoIstar
Definition DecayFit.h:67
int fixedrho
Definition DecayFit.h:65
std::string str()
Definition DecayFit.h:71
Definition LvArrays.h:43
Definition LvArrays.h:66