Jpp 20.0.0-rc.6
the software that should make you happy
Loading...
Searching...
No Matches
JAstronomyToolkit.hh
Go to the documentation of this file.
1#ifndef __JASTRONOMY__JASTRONOMYTOOLKIT__
2#define __JASTRONOMY__JASTRONOMYTOOLKIT__
3
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JASTRONOMY {}
13namespace JPP { using namespace JASTRONOMY; }
14
15namespace JASTRONOMY {
16
17
18 /**
19 * Auxiliary data structure for discovery calculations.
20 */
21 template<class T, const size_t factor>
22 struct JDiscovery :
23 public JGarage<T, factor>
24 {
25 using JGarage<T, factor>::getProbability;
26
27 /**
28 * Constructor.
29 *
30 * \param px pseudo experiment
31 */
35
36
37 /**
38 * Get signal strength for which given likelihood is exceeded with given probability.
39 *
40 * \param Q likelihood
41 * \param P probability [0,1>
42 * \param numberOfTests number of tests
43 * \param precision precision of signal strength
44 * \return signal strength
45 */
46 inline double operator()(const double Q,
47 const double P,
48 const size_t numberOfTests,
49 const double precision = 1.0e-3)
50 {
51 double xmin = 1.0;
52 double xmax = 2.0;
53
54 while (getProbability(xmin, Q, numberOfTests) > P) { // set lower limit
55 xmax = xmin;
56 xmin *= 0.5;
57 }
58
59 while (getProbability(xmax, Q, numberOfTests) < P) { // set upper limit
60 xmin = xmax;
61 xmax *= 2.0;
62 }
63
64 while (xmax - xmin > precision) { // bisection
65
66 const double x = 0.5 * (xmin + xmax);
67
68 if (getProbability(x, Q, numberOfTests) < P)
69 xmin = x;
70 else
71 xmax = x;
72 }
73
74 return 0.5 * (xmin + xmax);
75 }
76
77 protected:
78 /**
79 * Run pseudo experiments to get probability corresponding to given minimal likelihood.
80 *
81 * \param fS signal strength
82 * \param Q likelihood
83 * \param numberOfTests number of tests
84 * \return probability
85 */
86 inline double getProbability(const double fS,
87 const double Q,
88 const size_t numberOfTests)
89 {
90 px.set(fS);
91
92 this->clear();
93
94 for (size_t i = 0; i != numberOfTests; ++i) {
95 this->put(px().likelihood);
96 }
97
98 return this->getProbability(Q);
99 }
100
102 };
103
104
105 /**
106 * Run pseudo experiments to determine signal strength for which given likelihood is exceeded with given probability.
107 *
108 * \param px pseudo experiment
109 * \param Q likelihood
110 * \param P probability [0,1>
111 * \param numberOfTests number of tests
112 * \param precision precision of signal strength
113 * \return signal strength
114 */
115 template<class T, const size_t factor>
117 const double Q,
118 const double P,
119 const size_t numberOfTests,
120 const double precision = 1.0e-3)
121 {
123
124 return discovery(Q, P, numberOfTests, precision);
125 }
126}
127
128#endif
Pseudo experiment.
double discovery(JPseudoExperiment_t &px, const double Q, const double P, const size_t numberOfTests, const double precision=1.0e-3)
Run pseudo experiments to determine signal strength for which given likelihood is exceeded with given...
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for discovery calculations.
double operator()(const double Q, const double P, const size_t numberOfTests, const double precision=1.0e-3)
Get signal strength for which given likelihood is exceeded with given probability.
JPseudoExperiment_t & px
JDiscovery(JPseudoExperiment_t &px)
Constructor.
double getProbability(const double fS, const double Q, const size_t numberOfTests)
Run pseudo experiments to get probability corresponding to given minimal likelihood.
Auxiliary container for statistical analysis of a large number of positive (or zero) values.
Definition JGarage.hh:30
void put(const T value)
Definition JGarage.hh:105
Auxiliary interface for pseudo experiment.
virtual void set(const double fS, const double fB=1.0)=0
Set scaling factors of signal and background strengths.