tttrlib
A library for time-tagged time resolved data
Loading...
Searching...
No Matches
DecayStatistics.h
Go to the documentation of this file.
1#ifndef TTTRLIB_DECAYSTATISTICS_H
2#define TTTRLIB_DECAYSTATISTICS_H
3
4
5#include <cmath>
6#include <vector>
7#include <numeric>
8#include <algorithm>
9#include <iostream>
10#include <cstring> /* strcmp */
11
12
16void init_fact();
17
26double loggammaf(double t);
27
35double wcm(int C, double m);
36
55double wcm_p2s(int C, double mp, double ms);
56
66double Wcm_p2s(int* C, double* M, int Nchannels);
67
85double twoIstar_p2s(int* C, double* M, int Nchannels);
86
100double twoIstar(int* C, double* M, int Nchannels);
101
111double Wcm(int* C, double* M, int Nchannels);
112
113
114namespace statistics{
115
116 inline double neyman(double* data, double *model, int start, int stop){
117 double chi2 = 0.0;
118 for(int i = start; i < stop; i++){
119 double mu = model[i];
120 double m = std::max(1., data[i]);
121 chi2 += (mu - m) * (mu - m) / m;
122 }
123 return chi2;
124 }
125
126 inline double poisson(double* data, double *model, int start, int stop){
127 double chi2 = 0.0;
128 for(int i = start; i < stop; i++){
129 double mu = model[i];
130 double m = data[i];
131 chi2 += 2 * std::abs(mu);
132 chi2 -= 2 * m * (1 + log(std::max(1.0, mu) / std::max(1.0, m)));
133 }
134 return chi2;
135 }
136
137 inline double pearson(double* data, double *model, int start, int stop){
138 double chi2 = 0.0;
139 for(int i = start; i < stop; i++){
140 double m = model[i];
141 double d = data[i];
142 if (m > 0) {
143 chi2 += (m-d) / m;
144 }
145 }
146 return chi2;
147 }
148
149 inline double gauss(double* data, double *model, int start, int stop){
150 double chi2 = 0.0;
151 for(int i = start; i < stop; i++){
152 double mu = model[i];
153 double m = data[i];
154 double mu_p = std::sqrt(.25 + m * m) - 0.5;
155 if(mu_p <= 1.e-12) continue;
156 chi2 += (mu - m) * (mu - m) / mu + std::log(mu/mu_p) - (mu_p - m) * (mu_p - m) / mu_p;
157 }
158 return chi2;
159 }
160
161 inline double cnp(double* data, double *model, int start, int stop){
162 double chi2 = 0.0;
163 for(int i = start; i < stop; i++){
164 double m = data[i];
165 double mu = model[i];
166 if(m <= 1e-12) continue;
167 chi2 += (mu - m) * (mu - m) / (3. / (1./m + 2./mu));
168 }
169 return chi2;
170 }
171
173 inline double sswr(double* data, double *model, double *data_noise, int start, int stop){
174 double chi2 = 0.0;
175 for(int i=start;i<stop;i++){
176 double d = (data[i] - model[i]) / data_noise[i];
177 chi2 += d * d;
178 }
179 return chi2;
180 }
181
196 std::vector<double> &data,
197 std::vector<double> &model,
198 std::vector<double> &weights,
199 int x_min = -1,
200 int x_max = -1,
201 const char* type = "neyman"
202 );
203
204}
205
206#endif //TTTRLIB_DECAYSTATISTICS_H
void init_fact()
double loggammaf(double t)
double Wcm_p2s(int *C, double *M, int Nchannels)
double Wcm(int *C, double *M, int Nchannels)
double wcm_p2s(int C, double mp, double ms)
double twoIstar_p2s(int *C, double *M, int Nchannels)
double wcm(int C, double m)
double twoIstar(int *C, double *M, int Nchannels)
Definition DecayStatistics.h:114
double chi2_counting(std::vector< double > &data, std::vector< double > &model, std::vector< double > &weights, int x_min=-1, int x_max=-1, const char *type="neyman")
Computes different chi2 measures for counting data.
double neyman(double *data, double *model, int start, int stop)
Definition DecayStatistics.h:116
double pearson(double *data, double *model, int start, int stop)
Definition DecayStatistics.h:137
double sswr(double *data, double *model, double *data_noise, int start, int stop)
Sum of squared weighted residuals.
Definition DecayStatistics.h:173
double cnp(double *data, double *model, int start, int stop)
Definition DecayStatistics.h:161
double gauss(double *data, double *model, int start, int stop)
Definition DecayStatistics.h:149
double poisson(double *data, double *model, int start, int stop)
Definition DecayStatistics.h:126