C++ API

class ap::ap_error

Public Static Functions

void make_assertion(bool bClause)
class bfgs

Public Functions

bfgs(TargetFP fun)
bfgs(TargetFP fun, int n)
~bfgs()
void setN(int n)
void seteps(double e)
void seteps()
void fix(int n)
void free(int n)
int minimize(double *x, void *p)

Public Members

int maxiter

Private Functions

void setdefaults()
void lbfgsminimize(const int&, const int&, ap::real_1d_array&, const double&, const double&, const double&, const int&, int&)
void lbfgslincomb(const int&, const double&, const ap::real_1d_array&, int, ap::real_1d_array&, int)
double lbfgsdotproduct(const int&, const ap::real_1d_array&, int, const ap::real_1d_array&, int)
void lbfgsmcsrch(const int&, ap::real_1d_array&, double&, ap::real_1d_array&, const ap::real_1d_array&, int, double&, const double&, const double&, const int&, int&, int&, ap::real_1d_array&, const double&, const double&, const double&)
void lbfgsmcstep(double&, double&, double&, double&, double&, double&, double&, const double&, const double&, bool&, const double&, const double&, int&)
void lbfgsnewiteration(const ap::real_1d_array&, double, const ap::real_1d_array&)
void fgrad1(ap::real_1d_array&, double&, ap::real_1d_array&)
void fgrad2(ap::real_1d_array&, double&, ap::real_1d_array&)
void fgrad4(ap::real_1d_array&, double&, ap::real_1d_array&)
void funcgrad(ap::real_1d_array &x, double &fval, ap::real_1d_array &g)

Private Members

int N
double eps
double sqrt_eps
TargetFP f
void *pcopy
double *xd
int *fixed
class ap::complex

Public Functions

complex()
complex(const double &_x)
complex(const double &_x, const double &_y)
complex(const complex &z)
complex &operator=(const double &v)
complex &operator+=(const double &v)
complex &operator-=(const double &v)
complex &operator*=(const double &v)
complex &operator/=(const double &v)
complex &operator=(const complex &z)
complex &operator+=(const complex &z)
complex &operator-=(const complex &z)
complex &operator*=(const complex &z)
complex &operator/=(const complex &z)

Public Members

double x
double y
template<class T>
class ap::const_raw_vector

Subclassed by ap::raw_vector< T >

Public Functions

const_raw_vector(const T *Data, int Length, int Step)
const T *GetData() const
int GetLength() const
int GetStep() const

Protected Attributes

T *pData
int iLength
int iStep
class Decay

Public Functions

std::vector<int> get_score_range()
void set_score_range(int min, int max)
bool get_is_valid() const
void set_convolution_method(int v)

The method used for convolution.

0 - fconv_per_cs_time_axis 1 - fconv_cs_time_axis 2 - fconv_per 3 - fconv 4 - fconv with AVX optimization 5 - fconv_per with AVX optimization

int get_convolution_method()
void set_abs_lifetime_spectrum(bool v)
bool get_abs_lifetime_spectrum() const
void set_weights_by_data(std::vector<double> data)
void set_data(double *input, int n_input)
void get_data(double **output_view, int *n_output)
void set_use_amplitude_threshold(bool v)
bool get_use_amplitude_threshold() const
void set_amplitude_threshold(double v)
double get_amplitude_threshold() const
void set_number_of_photons(double v)
double get_number_of_photons()
void set_excitation_period(double v)
double get_excitation_period() const
void set_irf_shift_channels(double v)
double get_irf_shift_channels() const
void set_scatter_fraction(double v)
double get_scatter_fraction() const
void set_constant_offset(double v)
double get_constant_offset() const
void set_convolution_start(int v)
int get_convolution_start() const
void set_convolution_stop(int v)
int get_convolution_stop() const
void set_convolution_range(std::vector<int> v)
std::vector<int> get_convolution_range() const
void set_use_pile_up_correction(bool v)
bool get_use_pile_up_correction() const
void set_irf(double *input, int n_input)
void get_irf(double **output_view, int *n_output)
void set_linearization(double *input, int n_input)
void get_linearization(double **output_view, int *n_output)
bool get_use_linearization() const
void set_use_linearization(bool v)
void get_corrected_irf(double **output_view, int *n_output)
void get_model(double **output_view, int *n_output)
void set_lifetime_spectrum(double *input, int n_input = -1)
void get_lifetime_spectrum(double **output_view, int *n_output)
void set_data_weights(double *input, int n_input)
void get_data_weights(double **output_view, int *n_output)
void set_time_axis(double *input, int n_input)
void get_time_axis(double **output_view, int *n_output)
void set_irf_background_counts(double irf_background_counts)
double get_irf_background_counts() const
void set_instrument_dead_time(double instrument_dead_time)
double get_instrument_dead_time() const
void set_acquisition_time(double acquisition_time)
double get_acquisition_time() const
void set_use_corrected_irf_as_scatter(bool v)
bool get_use_corrected_irf_as_scatter() const
void set_scale_model_to_data(bool v)
bool get_scale_model_to_data() const
void set_tttr_data(std::shared_ptr<TTTR> tttr_data, int tttr_micro_time_coarsening)
void set_tttr_irf(std::shared_ptr<TTTR> tttr_irf, int tttr_micro_time_coarsening)
Decay(std::vector<double> data = std::vector<double>(), std::vector<double> time_axis = std::vector<double>(), std::vector<double> irf_histogram = std::vector<double>(), double constant_offset = 0.0, double irf_background_counts = 0.0, double scatter_fraction = 0.0, double irf_shift_channels = 0.0, std::vector<double> lifetime_spectrum = std::vector<double>(), std::vector<int> convolution_range = std::vector<int>({0, -1}), std::vector<int> score_range = std::vector<int>({0, -1}), double excitation_period = 100.0, bool scale_model_to_data = true, double number_of_photons = 1, std::vector<double> linearization = std::vector<double>(), bool use_linearization = false, bool use_pile_up_correction = false, bool use_corrected_irf_as_scatter = false, bool use_amplitude_threshold = false, double amplitude_threshold = 1e-9, double acquisition_time = 1e6, double instrument_dead_time = 1e-9, int convolution_method = 0, std::vector<double> data_weights = std::vector<double>(), std::shared_ptr<TTTR> tttr_data = nullptr, std::shared_ptr<TTTR> tttr_irf = nullptr, int tttr_micro_time_coarsening = 1)

Parameters
  • tttr_data: pointer to TTTR object that is used to construct a decay histogram

  • tttr_micro_time_coarsening: an (optional) integer by which the micro times are divided to coarsen the time axis (default is 1)

  • data: the data to which the decay is fitted

  • time_axis: the time axis that belongs to the data

  • data_weights: the weights of the data points. If the weights are not provided (nullptr / None) the weights are computed assuming Poisson noise.

  • irf_histogram: The instrument response function (IRF) that is used for convolution. If no IRF is provided

  • convolution_start: The start index in the IRF used for convolution. Points in the IRF before the start index are not used for convolution.

  • convolution_stop: The stop index in the IRF used for convolution. Points beyond the stop index are not convolved.

  • use_amplitude_threshold: If this is set to true (default value is true) the values that are smaller then a specified threshold are omitted

  • amplitude_threshold: The amplitude threshold that is used if the parameter use_amplitude_threshold is set to true (the default value is 1e10)

  • use_pile_up_correction: If this is set to true (the default value is false) the convolved model function is ‘piled up’ to match pile up artifacts in the data.

  • excitation_period: the repetition period, .i.e, the time between subsequent excitation pulses.

void get_weighted_residuals(double **output_view, int *n_output)
void evaluate()
double get_mean_lifetime()

Return

mean lifetime compute by the methods of momements (first moment)

double get_score(int x_min = -1, int x_max = -1, const char *score_type = "poisson")

Computes the chi2 for the model and the data

The “normal” chi2 is the sum of the squared weighted deviations between the data and the model.

Return

the chi2 value

Parameters
  • x_min: minimum index number of data / model used to compute the chi2

  • x_max: maximum index number of data / model used to compute the chi2

  • score_type: is either neyman or poisson for large count and low count data, respectively, pearson, gauss, cnp

void set(std::vector<double> data = std::vector<double>(), std::vector<double> time_axis = std::vector<double>(), std::vector<double> irf_histogram = std::vector<double>(), double constant_offset = 0.0, double irf_background_counts = 0.0, double scatter_fraction = 0.0, double irf_shift_channels = 0.0, std::vector<double> lifetime_spectrum = std::vector<double>(), std::vector<int> convolution_range = std::vector<int>({0, -1}), std::vector<int> score_range = std::vector<int>({0, -1}), double excitation_period = 100.0, bool scale_model_to_data = true, double number_of_photons = 1, std::vector<double> linearization = std::vector<double>(), bool use_linearization = false, bool use_pile_up_correction = false, bool use_corrected_irf_as_scatter = false, bool use_amplitude_threshold = false, double amplitude_threshold = 1e-9, double acquisition_time = 1e9, double instrument_dead_time = 1e-9, int convolution_method = 0, std::vector<double> data_weights = std::vector<double>(), std::shared_ptr<TTTR> tttr_data = nullptr, std::shared_ptr<TTTR> tttr_irf = nullptr, int tttr_micro_time_coarsening = 1, bool force_fill_irf = false, bool force_time_axis = false)

Update parameters

Public Static Functions

int compute_decay(double *model_function, int n_model_function, double *data, int n_data, double *squared_data_weights, int n_squared_data_weights, double *time_axis, int n_time_axis, double *irf_histogram, int n_irf_histogram, double *lifetime_spectrum, int n_lifetime_spectrum, double *scatter = nullptr, int n_scatter = -1, int convolution_start = 0, int convolution_stop = -1, double scatter_fraction = 0.0, double excitation_period = 1000.0, double constant_offset = 0.0, double number_of_photons = 1, bool use_amplitude_threshold = false, double amplitude_threshold = 1e10, bool use_pile_up_correction = false, double instrument_dead_time = 120.0, double acquisition_time = 1e9, bool add_corrected_irf_as_scatter = false, bool scale_model_to_data = false, int convolution_method = 0, bool take_abs_of_lifetime_spectrum = false, bool use_linearization = false, double *linearization = nullptr, int n_linearization = -1)

Computes a fluorescence decay for a lifetime spectrum.

The lifetime spectrum is a interleaved array of amplitudes and fluorescence lifetimes. The fluorescence decay for the lifetime spectrum is computed. The computed decay is convolved with a instrument response function (IRF). Before convolution the IRF is corrected for a constant offset. The convolution considers periodic excitation. The IRF is shifted by a specified value of micro time channels. After convolution a constant fraction of scattered light is added to the computed decay and the decay is scaled to the number of photons in an experimental fluorescence decay. Finally, a constant background is added. Optionally, pile-up is added to the computed fluorescence decay. Before the fluorescence decay is computed an amplitude threshold can be applied to the fluorescence lifetime spectrum to discriminate fluorescence lifetimes with small amplitudes.

Parameters
  • model_function[out]: The output array that will contain the computed fluorescence decay

  • n_model_function[out]: The number of points in the model function

  • data[in]: The data for which the model function is computed. The data will be used to scaled the computed decay.

  • n_data[in]: The number of data points

  • squared_data_weights[in]: The squared weights of the data points. The data weights are used to scale the model function to the data (usually the data weights is Poissonian)

  • n_data_weights[in]: The number of weights

  • time_axis[in]: The time axiss for which the fluorescence decay is computed for

  • n_time_axis[in]: The number of points in the time axis

  • irf_histogram[in]: The instrument response function used for convolution

  • n_irf_histogram[in]: The number of points in the instrument response function

  • lifetime_spectrum[in]: The lifetime spectrum. A lifetime specturm is an interleaved array of amplitudes and fluorescence lifetimes, .e.g, (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • n_lifetime_spectrum[in]: The number of points in the fluorescence lifetime spectrum

  • convolution_start[in]: The start of the convolution

  • convolution_stop[in]: The stop of the convoution. The decay will be computed in the range [start, stop]

  • irf_background_counts[in]: The background counts of the instrument response function. This number will be subtracted from the IRF before convolution.

  • irf_shift_channels[in]: The number of micro time channels the IRF will be shifted before the fluorescence lifetimes are convoluted with the IRF.

  • scatter_fraction[in]: The fraction (integrated fraction), i.e., the area the scattered light will have in the computed decay.

  • excitation_period[in]: The excitation period (in units of the fluorescence lifetime, usually nanoseconds) that was used to excite the sample

  • constant_offset: A constant offset that is added to the fluorescence decay.

  • number_of_photons[in]: the area to which the model fluorescence decay is scaled to. If this value is negative (default value is -1) the model fluorescence decay is scaled to the data in the range defined by the parameters start, stop

  • use_amplitude_threshold[in]: if set to true (default is false) a threshold will be applied. If this parameter is set to true, fluorescence lifetimes with a amplitude that is smaller than a threshold will be not considered.

  • amplitude_threshold: The threshold that is used to discriminate fluorescence lifetimes that are smaller.

  • use_pile_up_correction: if set to true (default is false) pile up will be added to the model function.

  • instrument_dead_time: the dead time of the instrument (used for pile up (in units of the lifetime, usually nano seconds)

  • acquisition_time: the total time the acquisition of the decay in seconds.

  • add_corrected_irf_as_scatter: if set to true (default is false) the background corrected irf will be added as scatter to the decay. If this is false the irf prior to a background and shift corrected irf is added as a scatter fraction.

  • scale_model_to_data: if set to true (default is true) the model is either scaled to the area s provided by total_area (if total_area is larger then zero) or to the total number of experimental counts.

std::vector<double> shift_array(double *input, int n_input, double shift, bool set_outside = true, double outside_value = 0.0)

Shift an input array by a floating number.

Parameters
  • input[in]: the input array

  • n_input[in]: length of the input array

  • output: output array

  • n_output: length of the output array

  • shift[in]: the shift of the output

void add_curve(double **output_view, int *n_output, double *curve1, int n_curve1, double *curve2, int n_curve2, double areal_fraction_curve2, int start = 0, int stop = -1)

Computes the sum of two arrays considering their respective areal fraction.

A weighted sum of two curves is computed. The weighted sum is computed by the area of the first curve and the areal fraction of the second curve. The area of the computed curve equals to the area of the first input curve while the areal fraction of the second input curve will be equal to the specified value in the range specified by the input parameters. modifies curve1 inplace

Parameters
  • output: the computed output curve (array)

  • n_output: the number of points in the output

  • curve1[inout]: the first input curve / array

  • n_curve1[inout]: number of points in the first array

  • curve2[in]: second curve / array

  • n_curve2[in]: number of points in the second array

  • areal_fraction_curve2[in]: areal fraction of the second curve in the output array

  • start[in]: start index used for the area calculation

  • stop[in]: stop index used for the area calculation

double compute_score(double *data, int n_data, double *time_axis = nullptr, int n_time_axis = -1, double *irf_histogram = nullptr, int n_irf_histogram = -1, double constant_offset = 0.0, double irf_background_counts = 0.0, double scatter_fraction = 0.0, double irf_shift_channels = 0.0, double *lifetime_spectrum = nullptr, int n_lifetime_spectrum = -1, std::vector<int> convolution_range = std::vector<int>({0, -1}), std::vector<int> score_range = std::vector<int>({0, -1}), double excitation_period = 100.0, bool scale_model_to_data = true, double number_of_photons = 1, double *linearization = nullptr, int n_linearization = -1, bool use_linearization = false, bool use_pile_up_correction = false, bool use_corrected_irf_as_scatter = false, bool use_amplitude_threshold = false, double amplitude_threshold = 1e10, double acquisition_time = 1e9, double instrument_dead_time = 1e-9, int convolution_method = 0, double *data_weights = nullptr, int n_data_weights = -1, const char *score_type = "poisson", bool take_abs_of_lifetime_spectrum = true)
double compute_mean_lifetime(std::vector<double> irf_histogram, std::vector<double> decay_histogram, double micro_time_resolution)

Compute a mean lifetime by the moments of the decay and the instrument response function.

The computed lifetime is the first lifetime determined by the method of moments (Irvin Isenberg, 1973, Biophysical journal).

Return

Parameters
  • irf_histogram:

  • decay_histogram:

  • micro_time_resolution:

Protected Static Functions

void scale_model(bool scale_model_to_data, double number_of_photons, int convolution_start, int convolution_stop, double constant_background, double *model, double *data, double *squared_data_weights)

Private Functions

void set_is_valid(bool v)

Used to set if the decay is ‘valid’. A decay is invalid if the computed model, wres, etc. does not correspond to the input parameters. It should not be decided by outside if the decay is valid.

Private Members

bool _irf_is_corrected = true

Used to keep track of irf shifts and background if false get_corrected_irf will recompute the irf

std::vector<double> _linearization_table

The model function is multiplied by this vector is _use_linearization is true.

bool _use_linearization = false

If set to true multiply the linearization to the model function.

bool _scale_model_to_data

If set to true scales the model to the data (default false)

bool _use_corrected_irf_as_scatter

If set to true uses the background corrected IRF as scatter.

double _acquisition_time

Acquisition time of the experiment in seconds.

double _instrument_dead_time

Dead time of the instrument in units of the lifetime (usually nanoseconds)

std::vector<double> _weighted_residuals = std::vector<double>()

Stores the weighted residuals.

double _number_of_photons = -1

Proportional to the area of the model. If negative, the area is scaled to the data.

double _constant_offset = 0.0

The constant offset in the model.

double _scatter_fraction = 0.0

The fraction of the irf (scattered light) in the model decay.

double _irf_shift_channels = 0.0

The time shift of the irf.

double _irf_background_counts = 0.0

Background counts of irf. This number is sutracted from the counts in each channel before convolution.

double _excitation_period = 100.

The repetiotion period (usually in nano seconds)

std::vector<double> _corrected_irf = std::vector<double>()

The background corrected instrument response function.

std::vector<double> _irf = std::vector<double>()

The instrument response function.

std::vector<double> _data = std::vector<double>()

The experimental data (used for scaling)

std::vector<double> _weights = std::vector<double>()

The weights of the experimental data (used for weighted residuals)

std::vector<double> _sq_weights = std::vector<double>()

The squared weights of the experimental data (used for scaling)

std::vector<double> _time_axis = std::vector<double>()

The time axis of the data (used in convolution)

std::vector<double> _model_function = std::vector<double>()

The used to store the model function.

std::vector<double> _lifetime_spectrum = std::vector<double>()

The lifetime spectrum.

bool _is_valid = false

Set to valid if the output decay matched the input.

bool _use_pile_up_correction = false

If set to true will add pile up to the model function.

int _convolution_start = 0

Convolution range.

int _convolution_stop = -1
double _amplitude_threshold = 1e10

Amplitude threshold used to discriminate low populated lifetimes.

bool _use_amplitude_threshold = false

If set to true discriminates low populated lifetimes in convolution.

bool _abs_lifetime_spectrum = true

If set to true take abs values of lifetime spectrum.

int _score_range_min = -1

The range on which the scoring function is evaluated.

int _score_range_max = -1
int _convolution_method = 0

The method used for convolution.

struct LVDoubleArray

Public Functions

~LVDoubleArray()

Public Members

int length
double *data
struct LVI32Array
#include <lvarrays.h>

Structures and functions used for LabView interface.

fit2x was originally developed as a C backend for LabView software. Therefore, the interface with fit2x uses structures that can be accessed by Labview. In order to make an interfacing with Python and other languages possible there is a this files defines a set of functions that facilitate the creation of the LabView structures.

Public Functions

~LVI32Array()

Public Members

int length
int *data
struct MParam

Public Functions

~MParam()

Public Members

LVI32Array **expdata
LVDoubleArray **irf
LVDoubleArray **bg
double dt
LVDoubleArray **corrections
LVDoubleArray **M
class phasor

Public Static Functions

std::vector<double> compute_phasor(unsigned short *micro_times, std::vector<int> &idxs, double frequency, int minimum_number_of_photons = 1, double g_irf = 1.0, double s_irf = 0.0)

Compute the phasor (g,s) for a selection of micro times

This function computes the phasor (g,s) for a set of micro times that are selected out of an vector. The microtimes are selected by a second vector. The second vector speciefies which indices of the microtime vector are used to compute the phasor.

Return

vector of length 2: first element g-value, second element s-value

Parameters
  • micro_times: vector of micro times

  • idxs: vector of selected indices

  • minimum_number_of_photons:

  • frequency: the frequency of the phasor

  • g_irf: g-value of instrument response phasor

  • s_irf: s-value of instrument response phasor

std::vector<double> compute_phasor_all(unsigned short *microtimes, int n_microtimes, double frequency)

Compute the phasor (g,s) for a all passed micro times

Return

vector of length 2: first element g-value, second element s-value

Parameters
  • micro_times: vector of micro times

  • n_microtimes: number of elements in the micro time array

  • frequency: the frequency of the phasor

double g(double g_irf, double s_irf, double g_exp, double s_exp)

https://journals.plos.org/plosone/article/file?type=supplementary&id=info:doi/10.1371/journal.pone.0194578.s001

Return

Parameters
  • g_irf: g-value of instrument response phasor

  • s_irf: s-value of instrument response phasor

  • g_exp:

  • s_exp:

double s(double g_irf, double s_irf, double g_exp, double s_exp)

https://journals.plos.org/plosone/article/file?type=supplementary&id=info:doi/10.1371/journal.pone.0194578.s001

Return

Parameters
  • g_irf:

  • s_irf:

  • g_exp:

  • s_exp:

void get_phasor_image(float **output, int *dim1, int *dim2, int *dim3, int *dim4, std::shared_ptr<CLSMImage> image, TTTR *tttr_irf = nullptr, double frequency = -1, int minimum_number_of_photons = 30, bool stack_frames = false)
template<class T>
class ap::raw_vector : public ap::const_raw_vector<T>

Public Functions

raw_vector(T *Data, int Length, int Step)
T *GetData()
template<class T>
class ap::template_1d_array

Public Functions

template_1d_array()
~template_1d_array()
template_1d_array(const template_1d_array &rhs)
const template_1d_array &operator=(const template_1d_array &rhs)
const T &operator()(int i) const
T &operator()(int i)
void setbounds(int iLow, int iHigh)
void setcontent(int iLow, int iHigh, const T *pContent)
T *getcontent()
const T *getcontent() const
int getlowbound(int iBoundNum = 0) const
int gethighbound(int iBoundNum = 0) const
raw_vector<T> getvector(int iStart, int iEnd)
const_raw_vector<T> getvector(int iStart, int iEnd) const

Private Functions

bool wrongIdx(int i) const

Private Members

T *m_Vec
long m_iVecSize
long m_iLow
long m_iHigh
template<class T>
class ap::template_2d_array

Public Functions

template_2d_array()
~template_2d_array()
template_2d_array(const template_2d_array &rhs)
const template_2d_array &operator=(const template_2d_array &rhs)
const T &operator()(int i1, int i2) const
T &operator()(int i1, int i2)
void setbounds(int iLow1, int iHigh1, int iLow2, int iHigh2)
void setcontent(int iLow1, int iHigh1, int iLow2, int iHigh2, const T *pContent)
T *getcontent()
const T *getcontent() const
int getlowbound(int iBoundNum) const
int gethighbound(int iBoundNum) const
raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd)
raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd)
const_raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd) const
const_raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd) const

Private Functions

bool wrongRow(int i) const
bool wrongColumn(int j) const

Private Members

T *m_Vec
long m_iVecSize
long m_iLow1
long m_iLow2
long m_iHigh1
long m_iHigh2
long m_iConstOffset
long m_iLinearMember
namespace ap

Typedefs

typedef template_1d_array<int> integer_1d_array
typedef template_1d_array<double> real_1d_array
typedef template_1d_array<complex> complex_1d_array
typedef template_1d_array<bool> boolean_1d_array
typedef template_2d_array<int> integer_2d_array
typedef template_2d_array<double> real_2d_array
typedef template_2d_array<complex> complex_2d_array
typedef template_2d_array<bool> boolean_2d_array

Functions

const complex operator/(const complex &lhs, const complex &rhs)
const bool operator==(const complex &lhs, const complex &rhs)
const bool operator!=(const complex &lhs, const complex &rhs)
const complex operator+(const complex &lhs)
const complex operator-(const complex &lhs)
const complex operator+(const complex &lhs, const complex &rhs)
const complex operator+(const complex &lhs, const double &rhs)
const complex operator+(const double &lhs, const complex &rhs)
const complex operator-(const complex &lhs, const complex &rhs)
const complex operator-(const complex &lhs, const double &rhs)
const complex operator-(const double &lhs, const complex &rhs)
const complex operator*(const complex &lhs, const complex &rhs)
const complex operator*(const complex &lhs, const double &rhs)
const complex operator*(const double &lhs, const complex &rhs)
const complex operator/(const double &lhs, const complex &rhs)
const complex operator/(const complex &lhs, const double &rhs)
const double abscomplex(const complex &z)
const complex conj(const complex &z)
const complex csqr(const complex &z)
template<class T>
T vdotproduct(const_raw_vector<T> v1, const_raw_vector<T> v2)
template<class T>
void vmove(raw_vector<T> vdst, const_raw_vector<T> vsrc)
template<class T>
void vmoveneg(raw_vector<T> vdst, const_raw_vector<T> vsrc)
template<class T, class T2>
void vmove(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
template<class T>
void vadd(raw_vector<T> vdst, const_raw_vector<T> vsrc)
template<class T, class T2>
void vadd(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
template<class T>
void vsub(raw_vector<T> vdst, const_raw_vector<T> vsrc)
template<class T, class T2>
void vsub(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
template<class T, class T2>
void vmul(raw_vector<T> vdst, T2 alpha)
int sign(double x)
double randomreal()
int randominteger(int maxv)
int round(double x)
int trunc(double x)
int ifloor(double x)
int iceil(double x)
double pi()
double sqr(double x)
int maxint(int m1, int m2)
int minint(int m1, int m2)
double maxreal(double m1, double m2)
double minreal(double m1, double m2)

Variables

const double machineepsilon
const double maxrealnumber
const double minrealnumber
namespace statistics

Functions

double chi2_counting(std::vector<double> &data, std::vector<double> &model, int x_min = -1, int x_max = -1, const char *type = "neyman")

Different chi2 measures for counting data:

https://arxiv.org/pdf/1903.07185.pdf

Return

Parameters
  • data:

  • model:

  • x_min:

  • x_max:

  • type:

file ap.h
#include <stdlib.h>#include <math.h>

Defines

AP_ASSERT
file decay.h
#include <cmath>#include <iostream>#include <vector>#include <cstdlib>#include <numeric>#include <algorithm>#include <cstring>#include <memory>#include “omp.h”#include “tttrlib/tttr.h”#include “fsconv.h”#include “statistics.h”
file fit23.h
#include <iostream>#include <cmath>#include “fsconv.h”#include “lvarrays.h”

Functions

int modelf23(double *param, double *irf, double *bg, int Nchannels, double dt, double *corrections, double *mfunction)

Single exponential model function with single rotational correlation time, with scatter contribution (BIFL scatter model)

This function computes the fluorescence decay in the parallel and perpendicular detection channel for a single exponential decay with a fluorescence lifetime tau, a single rotational correlation time rho, and separate instrument response functions for the parallel and perpendicular detection channels. The model considers the faction of scattered light in the two detection channels by the parameter gamma. The scattered light contribution is handled by patterns for the light in the parallel and perpendicular detection channel.

The instrument response function, the background, and the computed model function are in the Jordi format, i.e., one-dimensional arrays of the parallel and perpendicular detection channel.

Return

integer (not used, 0 by default)

Parameters
  • [in] param: array containing the model parameters [0] tau, [1] gamma, [2] r0, [3] rho

  • [in] irf: instrument response function in Jordi format (parallel, perpendicular)

  • bg[in]: background pattern in Jordi format (parallel, perpendicular)

  • Nchannels[in]: number of channels (half the length of the Jordi arrays)

  • dt[in]: time difference between two consecutive counting channels

  • corrections[in]: [0] excitation period, [1] g factor, [2] l1, [3] l2, [4] convolution stop channel number

  • mfunction[out]: output array of the computed decay in Jordi format. The output array has to have twice the number of channels. It needs to be allocated by beforehand.

double targetf23(double *x, void *pv)

Target function (to minimize) for fit23.

Computes the model function 23 and returns a score that quantifies the discrepancy between the data and the model.

Return

a normalized chi2

Parameters
  • x[inout]: a vector of length that that contains the starting parameters for the optimization and is used to return the optimized parameters. [0] fluorescence lifetime - tau (in) [1] fraction of scattered light - gamma (in) [2] fundamental anisotropy - r0 (in) [3] rotational correlation time - rho (in) [4] if negative reduce contribution of background photons from scoring function - Soft BIFL scatter fit? (flag) (in) [5] specifies type of score that is returned - 2I*: P+2S? (flag), this parameter only affects the returned score and does not influence the fitting (in) [6] background corrected anisotropy - r Scatter (out) [7] anisotropy without background correction - r Experimental (out)

  • pv[in]: a pointer to a MParam structure that contains the data and a set of corrections.

double fit23(double *x, short *fixed, MParam *p)

Function that optimizes parameters of model23 to data.

Return

Parameters
  • x[inout]: a vector of length that that contains the starting parameters for the optimization and is used to return the optimized parameters. [0] fluorescence lifetime - tau (in,out) [1] fraction of scattered light - gamma (in,out) [2] fundamental anisotropy - r0 () [3] rotational correlation time - rho (in,out) [4] if negative reduce contribution of background photons from scoring function - Soft BIFL scatter fit? (flag) (in) [5] specifies type of score that is returned - 2I*: P+2S? (flag), this parameter only affects the returned score and does not influence the fitting (in) [6] background corrected anisotropy - r Scatter (out) [7] anisotropy without background correction - r Experimental (out)

  • fixed: an array at least of length 4 for the parameters tau, gamma, r0, and rho that specifies if a parameter is optimized. If a value is set to 1, the parameter is optimized.

  • p: an instance of MParam that contains all relevant information, i.e., experimental data, the instrument response function, the needed corrections ( g-factor, l1, l2)

void correct_input23(double *x, double *xm, LVDoubleArray *corrections, int return_r)

Correct input parameters and compute anisotropy

This function corrects the input parameters for fit23 and takes care of unreasonable values. The fluorescence lifetime is constraint to positive values, gamma (the fraction of scattered light) is constraint to values between 0.0 and 0.999, the rotational correlation time rho is (if the global variable fixedrho is set to true) to the value that corresponds to the Perrin equation (for the computed, experimental anisotropy). Moreover, this function computes the anisotropy based on the corrected (g-factor, l1, l2, background) intensities, if the variable return_r is set to true.

Parameters
  • x[inout]: array of length 8 that contains parameters x[0] fluorescence lifetime - tau; x[1] fraction of scattered light - gamma; x[2] fundamental anisotropy - r0 x[3] rotational time - rho; x[4] softbifl - flag specifying the type of bifl fit (not used here) x[5] p2s_twoIstar - flag specifying the type of chi2 calculation (not used here) x[6] background corrected anisotropy x[7] anisotropy without background correction

  • xm[inout]: array that will contain the corrected parameters

  • corrections[in]:

  • return_r[in]: if set to true (positive) computes the anisotropy and returns the scatter corrected and the signal (no scatter correction) anisotropy and writes the values to the input/output vector x.

file fit24.h

Functions

int modelf24(double *param, double *irf, double *bg, int Nchannels, double dt, double *corrections, double *mfunction)

Bi-exponential model function.

Bi-exponential model function with two fluorescence lifetimes tau1, tau2 and amplitude of the second lifetime A2, fraction scattered light gamma, and a constant offset. A2 (A1 + A2 = 1)

The model function does not describe anisotropy. The decays passed as a Jordi format are treated identical in first and the second channel of the stacked arrays.

mfunction[i] * (1. - gamma) / sum_m + bg[i] * gamma / sum_s + offset

Return

Parameters
  • [in] param: array containing the parameters of the model [0] tau1, [1] gamma, [2] tau2, [3] A2, [4] offset

  • [in] irf: instrument response function in Jordi format

  • bg[in]: background pattern in Jordi format

  • Nchannels[in]: number of channels (half the length of the Jordi arrays)

  • dt[in]: time difference between two consecutive counting channels

  • corrections[in]: [0] excitation period, [1] unused, [2] unused, [3] unused, [4] convolution stop channel.

  • mfunction[out]: output array of the computed decay in Jordi format. The output array has to have twice the number of channels. It needs to be allocated by beforehand.

double targetf24(double *x, void *pv)

Target function (to minimize) for fit23.

Return

a normalized chi2

Parameters
  • [in] x: array containing the parameters of the model [0] tau1, [1] gamma, [2] tau2, [3] A2, [4] offset

  • pv[in]: a pointer to a MParam structure that contains the data and a set of corrections.

double fit24(double *x, short *fixed, MParam *p)

Fit a bi-exponential decay model

This function fits a bi-exponential decay model to two decays that are stacked using global parameters for the lifetimes and amplitudes.

Bi-exponential model function with two fluorescence lifetimes tau1, tau2 and amplitude of the second lifetime A2, fraction scattered light gamma, and a constant offset. A2 (A1 + A2 = 1)

The model function does not describe anisotropy. The decays passed as a Jordi format are treated identical in first and the second channel of the stacked arrays.

The anisotropy is computed assuming that the first and the second part of the Jordi input arrays are for parallel and perpendicular using the correction array of the attribute p of the type MParam.

Return

Quality parameter 2I*

Parameters
  • [inout] x: array containing the parameters of the model [0] tau1, [1] gamma, [2] tau2, [3] A2, [4] offset, [5] BIFL scatter fit? (flag) - if smaller than 0 uses soft bifl scatter fit (seems to be unused) [6] r Scatter (output only), [7] r Experimental (output only)

  • fixed: an array at least of length 5 for the parameters [0] tau1, [1] gamma, [2] tau2, [3] A2, [4] offset. If a value is not set to fixed the parameter is optimized.

  • p: an instance of MParam that contains relevant information. Here, experimental data, the instrument response function, and the background decay are used.

void correct_input24(double *x, double *xm, LVDoubleArray *corrections, int return_r)

Correct input parameters and compute anisotropy for fit24.

limits (0.001 < A2 < 0.999), (0.001 < gamma < 0.999), (tau1 > 0), (tau2 > 0), background > 0 (called offset in other places)

Return

Parameters
  • x[inout]: [0] tau1, [1] gamma [2] tau2, [3] A2, [4] background, [5] BIFL scatter fit? (flag, not used), [6] anisotropy r (scatter corrected, output), [7] anisotropy (no scatter correction, output)

  • xm[out]: array for corrected parameters (amplied range)

  • corrections: [1] g factor, [2] l1, [3] l3

  • return_r: if true computes the anisotropy.

file fit25.h

Functions

void correct_input25(double *x, double *xm, LVDoubleArray *corrections, int return_r)

adjust parameters for fit25 and compute anisotropy

Makes sure that (0 < gamma < 0.999) and (0<rho).

Return

Parameters
  • x:

  • xm:

  • corrections:

  • return_r:

double targetf25(double *x, void *pv)

Function used to compute the target value in fit 25

This is misleadingly named target25. Fit25 selects out of a set of 4 lifetimes the lifetime that describes best the data.

Return

Parameters
  • x:

  • pv:

double fit25(double *x, short *fixed, MParam *p)

Selects the lifetime out of a set of 4 fixed lifetimes that best describes the data.

This function selects out of a set of 4 lifetimes tau the lifetime that fits best the data and returns the lifetime through the parameter x[0].

If softBIFL flag is set to (x[6] < 0) and fixed[4] is zero gamma is optimized for each lifetime tau and the best gamma is returned by x[4]. The gamma is fitted with fit23.

Return

Parameters
  • [inout] x: array containing the parameters [0] tau1 output for best tau (always fixed), [1] tau2 (always fixed), [2] tau3 (always fixed), [3] tau4 (always fixed), [4] gamma (input, output), [5] fundamental anisotropy r0, [6] BIFL scatter fit? (flag), [7] r Scatter (output only), [8] r Experimental (output only)

  • fixed: array that is of least of length 5. Only the element fixed[4] is used. If fixed[4] is zero gamma is optimized for each lifetime.

  • p: an instance of MParam that contains all relevant information, i.e., experimental data, the instrument response function, the needed corrections for the anisotropy (g-factor, l1, l2)

file fit26.h

Functions

void correct_input26(double *x, double *xm)

Correct input for fit 26

Constrains the fraction x1 of the first pattern to (0 < x1 < 1).

Parameters
  • x[in]: x[0] fraction of first pattern

  • xm[out]: xm[0] corrected fraction of first pattern

double targetf26(double *x, void *pv)
double fit26(double *x, short *fixed, MParam *p)

Pattern-fit

Fits the fraction of a mixture of two patterns

The two patterns are set by the attributes irf and bg of the MParam structure.

Return

Parameters
  • x: [0] fraction of pattern 1

  • fixed: not used

  • p: an instance of MParam that contains the patterns. The fist pattern is contained in the instrument response function array, the second in the background, array, the experimental data is in the array expdata.

file fits2x.h
#include <iostream>#include <cmath>#include <algorithm>#include “i_lbfgs.h”#include “lvarrays.h”#include “fsconv.h”#include “statistics.h”#include “fit23.h”#include “fit24.h”#include “fit25.h”#include “fit26.h”

Defines

FIT2X_VERSION

Functions

void compute_signal_and_background(MParam *p)

Computes the total number of photons in the parallel and perpendicular detection channel for the background and the measured signal. The computed number of photons are stored in the static variables Sp, Ss, Bp, Bs.

Parameters
  • p[in]: a pointer to a MParam object

void normM(double *M, int Nchannels)

Normalizes the number of photons in the entire model function to the number of experimental photons.

Here, the Number of experimental photons is Sp + Ss (signal in parallel and perpendicular). Sp and Ss are global variables that can be computed by compute_signal_and_background.

Parameters
  • M[inout]: array containing the model function in Jordi format

  • Nchannels[in]: number of channels in the experiment(half length of M array)

void normM(double *M, double s, int Nchannels)

Normalizes a model function (that is already normalized to a unit area) to the total number of photons in parallel and perpendicular,

Parameters
  • M[inout]: array containing the model function in Jordi format

  • s[in]: a scaling factor by which the model function is divided.

  • Nchannels[in]: the number of channels in the model function (half length of M array)

void normM_p2s(double *M, int Nchannels)

Normalizes the number of photons in the model function for Ss and Sp individually to the number of experimental photons in Ss and Sp.

Here, the number of experimental photons are global variables that can be computed by compute_signal_and_background.

Parameters
  • M: array[in,out] containing the model function in Jordi format

  • Nchannels[in]: number of channels in the experiment (half length of M array)

file fsconv.h
#include <cmath>#include <numeric>#include <vector>#include “omp.h”

Functions

void rescale(double *fit, double *decay, double *scale, int start, int stop)

Convolution, scaling, and lamp shift routines.

Scale model function to the data (old version)

This function rescales the model function (fit) to the data by the number of photons between a start and a stop micro time counting channel. The number of photons between start and stop are counted and the model function is scaled to match the data by area.

This rescaling function does not consider the noise in the data when rescaling the model.

Parameters
  • fit[inout]: model function that is scaled (modified in-place)

  • decay[in]: the experimental data to which the model function is scaled

  • scale[out]: the scaling parameter (the factor) by which the model function is multiplied.

  • start[in]: The start micro time channel

  • stop[in]: The stop micro time channel

void rescale_w(double *fit, double *decay, double *w_sq, double *scale, int start, int stop)

Scale model function to the data (with weights)

This function rescales the model function (fit) to the data by the number of photons between a start and a stop micro time counting channel. The number of photons between start and stop are counted and the model function is scaled to match the data by area considering the noise of the data.

The scaling factor is computed by:

scale = sum(fit*decay/w^2)/sum(fit^2/w^2)

Parameters
  • fit[inout]: model function that is scaled (modified in-place)

  • decay[in]: the experimental data to which the model function is scaled

  • w_sq[in]: squared weights of the data.

  • scale[out]: the scaling parameter (the factor) by which the model function is multiplied.

  • start[in]: The start micro time channel

  • stop[in]: The stop micro time channel

void rescale_w_bg(double *fit, double *decay, double *w_sq, double bg, double *scale, int start, int stop)

Scale model function to the data (with weights and background)

This function scales the model function (fit) to the data by the number of photons between a start and a stop micro time counting channel. The number of photons between start and stop are counted and the model function is scaled to match the data by area considering the noise of the data and a constant offset of the data.

scale = sum(fit*(decay-bg)/w^2)/sum(fit^2/w^2)

Parameters
  • fit[inout]: model function that is scaled (modified in-place)

  • decay[in]: the experimental data to which the model function is scaled

  • w_sq[in]: squared weights of the data.

  • bg[in]: constant background of the data

  • scale[out]: the scaling parameter (the factor) by which the model function is multiplied.

  • start[in]: The start micro time channel

  • stop[in]: The stop micro time channel

void fconv(double *fit, double *x, double *lamp, int numexp, int start, int stop, double dt = 0.05)

Convolve lifetime spectrum with instrument response (fast convolution, low repetition rate)

This function computes the convolution of a lifetime spectrum (a set of lifetimes with corresponding amplitudes) with a instrument response function (irf). This function does not consider periodic excitation and is suited for experiments at low repetition rate.

Parameters
  • fit[out]: model function. The convoluted decay is written to this array

  • x[in]: lifetime spectrum (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • lamp[in]: instrument response function

  • numexp[in]: number of fluorescence lifetimes

  • start[in]: start micro time index for convolution (not used)

  • stop[in]: stop micro time index for convolution.

  • dt[in]: time difference between two micro time channels

void fconv_avx(double *fit, double *x, double *lamp, int numexp, int start, int stop, double dt = 0.05)

Convolve lifetime spectrum with instrument response (fast convolution, AVX optimized for large lifetime spectra)

This function is a modification of fconv for large lifetime spectra. The lifetime spectrum is processed by AVX intrinsics. Four lifetimes are convolved at once. Spectra with lifetimes that are not multiple of four are zero padded.

Parameters
  • fit:

  • x:

  • lamp:

  • numexp:

  • start:

  • stop:

  • n_points:

  • dt:

void fconv_per(double *fit, double *x, double *lamp, int numexp, int start, int stop, int n_points, double period, double dt = 0.05)

Convolve lifetime spectrum with instrument response (fast convolution, high repetition rate)

This function computes the convolution of a lifetime spectrum (a set of lifetimes with corresponding amplitudes) with a instrument response function (irf). This function does consider periodic excitation and is suited for experiments at high repetition rate.

Parameters
  • fit[out]: model function. The convoluted decay is written to this array

  • x[in]: lifetime spectrum (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • lamp[in]: instrument response function

  • numexp[in]: number of fluorescence lifetimes

  • start[in]: start micro time index for convolution (not used)

  • stop[in]: stop micro time index for convolution.

  • n_points: number of points in the model function.

  • period: excitation period in units of the fluorescence lifetimes (typically nanoseconds)

  • dt[in]: time difference between two micro time channels

void fconv_per_avx(double *fit, double *x, double *lamp, int numexp, int start, int stop, int n_points, double period, double dt = 0.05)

Convolve lifetime spectrum with instrument response (fast convolution, high repetition rate), AVX optimized version.

This function computes the convolution of a lifetime spectrum (a set of lifetimes with corresponding amplitudes) with a instrument response function (irf). This function does consider periodic excitation and is suited for experiments at high repetition rate.

Parameters
  • fit[out]: model function. The convoluted decay is written to this array

  • x[in]: lifetime spectrum (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • lamp[in]: instrument response function

  • numexp[in]: number of fluorescence lifetimes

  • start[in]: start micro time index for convolution (not used)

  • stop[in]: stop micro time index for convolution.

  • n_points: number of points in the model function.

  • period: excitation period in units of the fluorescence lifetimes (typically nanoseconds)

  • dt[in]: time difference between two micro time channels

void fconv_per_cs(double *fit, double *x, double *lamp, int numexp, int stop, int n_points, double period, int conv_stop, double dt)

Convolve lifetime spectrum - fast convolution, high repetition rate, with convolution stop.

fast convolution, high repetition rate, with convolution stop for Paris

Parameters
  • fit[out]: model function. The convoluted decay is written to this array

  • x[in]: lifetime spectrum (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • lamp[in]: instrument response function

  • numexp[in]: number of fluorescence lifetimes

  • stop[in]: stop micro time index for convolution.

  • n_points: number of points in the model function.

  • period: excitation period in units of the fluorescence lifetimes (typically nanoseconds)

  • conv_stop: convolution stop micro channel number

  • dt[in]: time difference between two micro time channels

void fconv_ref(double *fit, double *x, double *lamp, int numexp, int start, int stop, double tauref, double dt = 0.05)

Convolve lifetime spectrum - fast convolution with reference compound decay.

This function convolves a set of fluorescence lifetimes and with associated amplitudes with an instrument response function. The provided amplitudes are scaled prior to the convolution by area using a reference fluorescence lifetime. The amplitudes are computed by

amplitude_corrected = a * ( 1 /tauref - 1 / tau)

where a and tau are provided amplitudes.

Parameters
  • fit[out]: model function. The convoluted decay is written to this array

  • x[in]: lifetime spectrum (amplitude1, lifetime1, amplitude2, lifetime2, …)

  • lamp[in]: instrument response function

  • numexp[in]: number of fluorescence lifetimes

  • start[in]: start micro time index for convolution (not used)

  • stop[in]: stop micro time index for convolution.

  • tauref: a reference lifetime used to rescale the amplitudes of the fluorescence lifetime spectrum

  • dt[in]: time difference between two micro time channels

void sconv(double *fit, double *p, double *lamp, int start, int stop)

Convolve fluorescence decay curve with irf - slow convolution.

This function computes a convolved model function for a fluorescence decay curve.

Parameters
  • fit: convolved model function

  • p: model function before convolution - fluorescence decay curve

  • lamp: instrument response function

  • start: start index of the convolution

  • stop: stop index of the convolution

void shift_lamp(double *lampsh, double *lamp, double ts, int n_points, double out_value = 0.0)

shift instrumnet response function

Parameters
  • lampsh:

  • lamp:

  • ts:

  • n_points:

  • out_value: the value of the shifted response function outside of the valid indices

void add_pile_up_to_model(double *model, int n_model, double *data, int n_data, double repetition_rate, double instrument_dead_time, double measurement_time, const char *pile_up_model = "coates")

Add a pile-up distortion to the model function.

This function adds a pile up distortion to a model fluorescence decay. The model used to compute the pile-up distortion follows the description of Coates (1968, eq. 2 and eq. 4)

Reference: Coates, P.: The correction for photonpile-up in the measurement of radiative lifetimes. J. Phys. E: Sci. Instrum. 1(8), 878–879 (1968)

Parameters
  • model[inout]: The array containing the model function

  • n_model[in]: Number of elements in the model array

  • data[in]: The array containing the experimental decay

  • n_data[in]: number of elements in experimental decay

  • repetition_rate[in]: The repetition-rate (excitation rate) in MHz

  • instrument_dead_time[in]: The overall dead-time of the detection system in nanoseconds

  • measurement_time[in]: The measurement time in seconds

  • pile_up_model[in]: The model used to compute the pile up distortion. (default “coates”)

void discriminate_small_amplitudes(double *lifetime_spectrum, int n_lifetime_spectrum, double amplitude_threshold)

Threshold the amplitudes

Amplitudes with absolute values smaller than the specified threshold are set to zero.

Parameters
  • lifetime_spectrum: interleaved lifetime spectrum (amplitude, lifetime)

  • n_lifetime_spectrum: number of elements in lifetime spectrum

  • amplitude_threshold:

void fconv_per_cs_time_axis(double *model, int n_model, double *time_axis, int n_time_axis, double *instrument_response_function, int n_instrument_response_function, double *lifetime_spectrum, int n_lifetime_spectrum, int convolution_start = 0, int convolution_stop = -1, double period = 100.0)

Compute the fluorescence decay for a lifetime spectrum and a instrument response function considering periodic excitation.

Fills the pre-allocated output array output_decay with a fluorescence intensity decay defined by a set of fluorescence lifetimes defined by the parameter lifetime_spectrum. The fluorescence decay will be convolved (non-periodically) with an instrumental response function that is defined by instrument_response_function.

This function calculates a fluorescence intensity model_decay that is convolved with an instrument response function (IRF). The fluorescence intensity model_decay is specified by its fluorescence lifetime spectrum, i.e., an interleaved array containing fluorescence lifetimes with corresponding amplitudes.

This convolution only works with evenly linear spaced time axes.

Parameters
  • inplace_output[inout]: Inplace output array that is filled with the values of the computed fluorescence intensity decay model

  • n_output[in]: Number of elements in the output array

  • time_axis[in]: the time-axis of the model_decay

  • n_time_axis[in]: length of the time axis

  • irf[in]: the instrument response function array

  • n_irf[in]: length of the instrument response function array

  • lifetime_spectrum[in]: Interleaved array of amplitudes and fluorescence lifetimes of the form (amplitude, lifetime, amplitude, lifetime, …)

  • n_lifetime_spectrum[in]: number of elements in the lifetime spectrum

  • convolution_start[in]: Start channel of convolution (position in array of IRF)

  • convolution_stop[in]: convolution stop channel (the index on the time-axis)

  • period: Period of repetition in units of the lifetime (usually, nano-seconds)

void fconv_cs_time_axis(double *inplace_output, int n_output, double *time_axis, int n_time_axis, double *instrument_response_function, int n_instrument_response_function, double *lifetime_spectrum, int n_lifetime_spectrum, int convolution_start = 0, int convolution_stop = -1)

Compute the fluorescence decay for a lifetime spectrum and a instrument response function.

Fills the pre-allocated output array output_decay with a fluorescence intensity decay defined by a set of fluorescence lifetimes defined by the parameter lifetime_spectrum. The fluorescence decay will be convolved (non-periodically) with an instrumental response function that is defined by instrument_response_function.

This function calculates a fluorescence intensity model_decay that is convolved with an instrument response function (IRF). The fluorescence intensity model_decay is specified by its fluorescence lifetime spectrum, i.e., an interleaved array containing fluorescence lifetimes with corresponding amplitudes.

This convolution works also with uneven spaced time axes.

Parameters
  • inplace_output[inout]: Inplace output array that is filled with the values of the computed fluorescence intensity decay model

  • n_output[in]: Number of elements in the output array

  • time_axis[in]: the time-axis of the model_decay

  • n_time_axis[in]: length of the time axis

  • irf[in]: the instrument response function array

  • n_irf[in]: length of the instrument response function array

  • lifetime_spectrum[in]: Interleaved array of amplitudes and fluorescence lifetimes of the form (amplitude, lifetime, amplitude, lifetime, …)

  • n_lifetime_spectrum[in]: number of elements in the lifetime spectrum

  • convolution_start[in]: Start channel of convolution (position in array of IRF)

  • convolution_stop[in]: convolution stop channel (the index on the time-axis)

  • use_amplitude_threshold[in]: If this value is True (default False) fluorescence lifetimes in the lifetime spectrum which have an amplitude with an absolute value of that is smaller than amplitude_threshold are not omitted in the convolution.

  • amplitude_threshold[in]: Threshold value for the amplitudes

file i_lbfgs.h
#include “ap.h”#include “lbfgs.h”#include <cmath>#include <iostream>

Typedefs

typedef double (*TargetFP)(double*, void*)

Functions

int fjac1(void (*)(double*, double*), double*, int, int, double, double*, )
int fgrad1(void (*)(double*, double&), double*, int, double, double*, )
int fjac2(void (*)(double*, double*), double*, int, int, double, double*, )
int fgrad2(void (*)(double*, double&), double*, int, double, double*, )
int fjac4(void (*)(double*, double*), double*, int, int, double, double*, )
int fgrad4(void (*)(double*, double&), double*, int, double, double*, )
file lbfgs.h
#include “ap.h”

Functions

void funcgrad(ap::real_1d_array, double&, ap::real_1d_array&)
void lbfgsminimize(const int &n, const int &m, ap::real_1d_array &x, const double &epsg, const double &epsf, const double &epsx, const int &maxits, int &info)
file lvarrays.h
#include <iostream>#include <cmath>#include <algorithm>#include <vector>

Typedefs

typedef struct LVI32Array LVI32Array

Structures and functions used for LabView interface.

fit2x was originally developed as a C backend for LabView software. Therefore, the interface with fit2x uses structures that can be accessed by Labview. In order to make an interfacing with Python and other languages possible there is a this files defines a set of functions that facilitate the creation of the LabView structures.

typedef struct LVDoubleArray LVDoubleArray
typedef struct MParam MParam

Functions

LVI32Array *CreateLVI32Array(size_t len)

Return

Parameters
  • len:

LVDoubleArray *CreateLVDoubleArray(size_t len)

Return

Parameters
  • len:

MParam *CreateMParam(double dt = 1.0, std::vector<double> corrections = std::vector<double>(), std::vector<double> irf = std::vector<double>(), std::vector<double> background = std::vector<double>(), std::vector<int> data = std::vector<int>())
file phasor.h
#include <vector>#include <cmath>#include <algorithm>#include “tttrlib/tttr.h”#include “tttrlib/image.h”
file statistics.h
#include <cmath>#include <vector>#include <numeric>#include <algorithm>#include <iostream>#include <cstring>#include “omp.h”

Functions

void init_fact()

Initialize an array containing pre-computed logratithms

double loggammaf(double t)

Approximation of log(gamma function). See wikipedia

https://en.wikipedia.org/wiki/Gamma_function#The_log-gamma_function

Return

approximation of the logarithm of the gamma function

Parameters
  • t: input of the gamma function

double wcm(int C, double m)

log-likelihood w(C|m) for Cp + 2Cs

Return

log-likelihood w(C|m) for Cp + 2Cs

Parameters
  • C: number of counts in channel

  • m: model function

double wcm_p2s(int C, double mp, double ms)

Compute the -log-likelihood for Cp + 2Cs of a single micro time channel.

Compute score of model counts in a parallel and perpendicular detection channel and the experimental counts for a micro time channel.

This function computes a score for the experimental counts (C) in a channel where the experimental counts were computed by the sum of the counts in the parallel (P) and the perpendicular (S) channel by the equation C = P + 2 S.

This function considers that the number of counts C = P + 2S is not Poissonian. The score relates to a maximum likelihood function.

Return

Parameters
  • C: number of experimental counts (P + 2 S) in a micro time channel

  • mp: number of counts of the model in parallel detection channel

  • ms: number of counts of the model in the perpendicular detection channel

double Wcm_p2s(int *C, double *M, int Nchannels)

Compute the overall -log-likelihood for Cp + 2Cs for all micro time channels

Return

-log-likelihood for Cp + 2Cs for all micro time channels

Parameters
  • C: array of experimental counts in Jordi format

  • M: array model function in Jordi format

  • Nchannels: number of micro time channels in parallel and perpendicular (half the number of elements in C and M).

double twoIstar_p2s(int *C, double *M, int Nchannels)

Compute overall 2I* for Cp + 2Cs

This function computes the overall 2I* for the model function Cp + 2Cs that is computed by parallel signal (Cp) and the perpendicular signal (Cs). For the definition of function 2I* see “An Experimental Comparison of the Maximum Likelihood Estimation and Nonlinear Least-Squares Fluorescence Lifetime Analysis of Single Molecules, Michael Maus, Mircea Cotlet, Johan Hofkens, Thomas Gensch, Frans C. De Schryver, J. Schaffer, and C. A. M. Seidel, Anal. Chem. 2001, 73, 9, 2078–2086”.

Return

2I* for Cp + 2Cs

Parameters
  • C: array of experimental counts in Jordi format

  • M: array model function in Jordi format

  • Nchannels: number of micro time channels in parallel and perpendicular (half the number of elements in C and M).

double twoIstar(int *C, double *M, int Nchannels)

Compute overall 2I* for Cp & Cs

This function computes 2I* for Cp and Cs. Cp and Cs are the model signals in the parallel and perpendicular channel. Contrary to twoIstar_p2s the overall 2I* is the sum of 2I* for Cp and Cs.

Return

2I* for Cp & Cs

Parameters
  • C: array of experimental counts in Jordi format

  • M: array model function in Jordi format

  • Nchannels: number of micro time channels in parallel and perpendicular (half the number of elements in C and M).

double Wcm(int *C, double *M, int Nchannels)

Compute overall -log-likelihood for Cp & Cs

Return

-log-likelihood for Cp & Cs

Parameters
  • C: array of experimental counts in Jordi format

  • M: array model function in Jordi format

  • Nchannels: number of micro time channels in parallel and perpendicular (half the number of elements in C and M).

dir /home/docs/checkouts/readthedocs.org/user_builds/fit2x/checkouts/development/include