Auxiliary data structure to fit signal strength using likelihood ratio.
More...
#include <JAspera.hh>
|
| void | put (const double s, const double b) |
| | Put signal and background to list of pre-computed N/S values.
|
| |
| void | put (const size_t n, const double s, const double b) |
| | Put signal and background to list of pre-computed N/S values.
|
| |
| double | getLikelihood (const double p) const |
| | Get likelihood for given signal strength.
|
| |
| double | getDerivative (const double p) const |
| | Get derivative of likelihood for given signal strength.
|
| |
| fit_type | operator() (const bool ns=false) const |
| | Fit signal strength.
|
| |
| double | getTestStatisticForUpperLimit (const double ps) const |
| | Get test statistic for given signal strength.
|
| |
| double | getSignal () const |
| | Get total signal strength.
|
| |
| void | setSignal (const double wS) |
| | Set signal strength.
|
| |
| void | addSignal (const double wS) |
| | Add signal strength.
|
| |
|
| static constexpr double | EPSILON = 1.0e-3 |
| | precision determination of signal strength
|
| |
|
| double | ws = 0.0 |
| | total signal strength
|
| |
Auxiliary data structure to fit signal strength using likelihood ratio.
Definition at line 22 of file JAspera.hh.
◆ put() [1/2]
| void JASTRONOMY::JAspera::put |
( |
const double | s, |
|
|
const double | b ) |
|
inline |
Put signal and background to list of pre-computed N/S values.
- Parameters
-
Definition at line 44 of file JAspera.hh.
46 {
47 push_back(b/s);
48
50 }
double ws
total signal strength
◆ put() [2/2]
| void JASTRONOMY::JAspera::put |
( |
const size_t | n, |
|
|
const double | s, |
|
|
const double | b ) |
|
inline |
Put signal and background to list of pre-computed N/S values.
- Parameters
-
| n | data |
| s | signal |
| b | background |
Definition at line 60 of file JAspera.hh.
63 {
64 for (
size_t i = 0; i !=
n; ++i) {
65 push_back(b/s);
66 }
67
69 }
◆ getLikelihood()
| double JASTRONOMY::JAspera::getLikelihood |
( |
const double | p | ) |
const |
|
inline |
Get likelihood for given signal strength.
- Parameters
-
- Returns
- likelihood
Definition at line 78 of file JAspera.hh.
◆ getDerivative()
| double JASTRONOMY::JAspera::getDerivative |
( |
const double | p | ) |
const |
|
inline |
Get derivative of likelihood for given signal strength.
- Parameters
-
- Returns
- derivative of likelihood
Definition at line 96 of file JAspera.hh.
◆ operator()()
| fit_type JASTRONOMY::JAspera::operator() |
( |
const bool | ns = false | ) |
const |
|
inline |
Fit signal strength.
- Parameters
-
| ns | allow for negative signal |
- Returns
- result
Definition at line 149 of file JAspera.hh.
150 {
152
153 if (this->empty()) {
154
155
156
157 return { 0.0, 0.0 };
158
159 } else if (this->size() == 1 ) {
160
161
162
163 const double x = 1.0/
ws - (*this)[0];
164
165 if (x > 0.0 || ns)
167 else
168 return { 0.0, 0.0 };
169 }
170
171 double x1 = 0.0;
172 double x2 = 0.0;
173
175 double f2 = 0.0;
176
177 if (f1 == 0.0) {
178
179 return { 0.0, 0.0 };
180
181 } else if (f1 > 0.0) {
182
183 x1 = 0.0;
184 x2 = (double) this->size() /
ws;
185
187
188 } else if (ns) {
189
190 x2 = 0.0;
191 x1 = -(*this)[0];
192
194 if (-x > x1) {
196 }
197 }
198
200
201 f2 = f1;
203
204 } else {
205
206 return { 0.0, 0.0 };
207 }
208
209#if defined(BISECTION)
210
211
212
214
215 const double x = 0.5 * (x1 + x2);
216
219 else
221 }
222
223 const double x = 0.5 * (x1 + x2);
224
226
227#elif defined(NEWTON_RAPHSON)
228
229
230
231 double dx = x2 - x1;
232 double x = 0.5 * (x1 + x2);
233
234 derivatives_type
y = getDerivatives(x);
235
236 struct {
237 double dx;
238 } old;
239
240 old.dx = dx;
241
242 for ( ; ; ) {
243
244 if ((
y.fp + (x2 - x)*
y.fpp)*(
y.fp + (x1 - x)*
y.fpp) > 0.0 || fabs(2.0*
y.fp) > fabs(old.dx*
y.fpp)) {
245
246 old.dx = dx;
247
248 dx = 0.5 * (x2 - x1);
250
251 } else {
252
253 old.dx = dx;
254
257 }
258
260 break;
261 }
262
263 y = getDerivatives(x);
264
267 else
269 }
270
272
273#else
274
275
276
278
279 const double xm = 0.5 * (x1 + x2);
281
282 const double s = sqrt(fm*fm - f1*f2);
283
284 if (s == 0.0) {
285 break;
286 }
287
288 const double xn = xm + (xm - x1) * fm/s;
290
291 if (fn == 0.0) {
293 }
294
295 if (signbit(fn) != signbit(fm)) {
296
297 x1 = xm;
298 f1 = fm;
299 x2 = xn;
300 f2 = fn;
301
302 } else {
303
304 if (signbit(fn)) {
305
306 x2 = xn;
307 f2 = fn;
308
309 } else {
310
311 x1 = xn;
312 f1 = fn;
313 }
314 }
315 }
316
317 const double x = 0.5 * (x1 + x2);
318
320#endif
321 }
double getLikelihood(const double p) const
Get likelihood for given signal strength.
static constexpr double EPSILON
precision determination of signal strength
double getDerivative(const double p) const
Get derivative of likelihood for given signal strength.
◆ getTestStatisticForUpperLimit()
| double JASTRONOMY::JAspera::getTestStatisticForUpperLimit |
( |
const double | ps | ) |
const |
|
inline |
Get test statistic for given signal strength.
See formula 16 in this reference.
- Parameters
-
- Returns
- test statistic
Definition at line 331 of file JAspera.hh.
332 {
333 const fit_type
result = (*this)(
true);
334
337 else if (
result.signal <= ps)
339 else
340 return 0.0;
341 }
◆ getSignal()
| double JASTRONOMY::JAspera::getSignal |
( |
| ) |
const |
|
inline |
Get total signal strength.
- Returns
- signal strength
Definition at line 349 of file JAspera.hh.
◆ setSignal()
| void JASTRONOMY::JAspera::setSignal |
( |
const double | wS | ) |
|
|
inline |
Set signal strength.
- Parameters
-
Definition at line 360 of file JAspera.hh.
◆ addSignal()
| void JASTRONOMY::JAspera::addSignal |
( |
const double | wS | ) |
|
|
inline |
Add signal strength.
- Parameters
-
Definition at line 371 of file JAspera.hh.
◆ EPSILON
| double JASTRONOMY::JAspera::EPSILON = 1.0e-3 |
|
staticconstexpr |
precision determination of signal strength
Definition at line 26 of file JAspera.hh.
◆ ws
| double JASTRONOMY::JAspera::ws = 0.0 |
|
protected |
The documentation for this struct was generated from the following file: