Jpp 20.0.0-rc.6
the software that should make you happy
Loading...
Searching...
No Matches
JGen2.hh
Go to the documentation of this file.
1#ifndef __JASTRONOMY__JGEN2__
2#define __JASTRONOMY__JGEN2__
3
4#include <vector>
5#include <numeric>
6
9
10
11/**
12 * \file
13 *
14 * Set of pseudo experments.
15 * \author mdejong
16 */
17namespace JASTRONOMY {}
18namespace JPP { using namespace JASTRONOMY; }
19
20namespace JASTRONOMY {
21
22 /**
23 * Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiments.
24 */
25 struct JGen2 :
26 public std::vector<JPseudoExperiment>,
28 {
29 /**
30 * Configure lookup tables.
31 *
32 * \param N number of bins
33 */
34 void configure(size_t N)
35 {
36 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
37 i.configure(N);
38 }
39 }
40
41
42 /**
43 * Get total signal.
44 *
45 * \return signal
46 */
47 double getSignal() const
48 {
49 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getSignal(); } );
50 }
51
52
53 /**
54 * Get total background.
55 *
56 * \return background
57 */
58 double getBackground() const
59 {
60 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getBackground(); } );
61 }
62
63
64 /**
65 * Set scaling factors of signal and background strengths.
66 *
67 * \param fS signal strength
68 * \param fB background strength
69 */
70 virtual void set(const double fS, const double fB = 1.0) override
71 {
72 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
73 i.set(fS, fB);
74 }
75 }
76
77
78 /**
79 * Get fit method.
80 *
81 * \return fit
82 */
83 virtual JAspera& getAspera() override
84 {
85 return this->fit;
86 }
87
88
89 /**
90 * Generate pseudo experiment and transfer S/N values to fit method.
91 *
92 * \param out output
93 * \return result
94 */
95 virtual stats_type run(JAspera& out) const
96 {
97 stats_type ps = { 0, 0 };
98
99 for (const auto& px : static_cast<const std::vector<JPseudoExperiment>&>(*this)) {
100 ps += px.run(out);
101 }
102
103 return ps;
104 }
105
106
107 /**
108 * Generate background only pseudo experiment and transfer S/N values to fit method.
109 *
110 * \param out output
111 * \param nb number of background events
112 * \return result
113 */
114 virtual stats_type run(JAspera& out, const size_t nb) const
115 {
116 stats_type ps = { 0, 0 };
117
118 const double B = this->getBackground();
119
120 for (size_t i = 0; i != nb; ++i) {
121
122 const double X = gRandom->Uniform(0.0, B);
123
124 double x = 0.0;
125
126 for (const auto& px : static_cast<const std::vector<JPseudoExperiment>&>(*this)) {
127
128 x += px.getBackground();
129
130 if (x >= X) {
131
132 ps += px.run(out, 1);
133
134 break;
135 }
136 }
137 }
138
139 return ps;
140 }
141
142 protected:
143 JAspera fit; //!< fit
144 };
145}
146
147#endif
Per aspera ad astra.
Pseudo experiment.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure to fit signal strength using likelihood ratio.
Definition JAspera.hh:24
Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiment...
Definition JGen2.hh:28
virtual JAspera & getAspera() override
Get fit method.
Definition JGen2.hh:83
virtual stats_type run(JAspera &out, const size_t nb) const
Generate background only pseudo experiment and transfer S/N values to fit method.
Definition JGen2.hh:114
virtual stats_type run(JAspera &out) const
Generate pseudo experiment and transfer S/N values to fit method.
Definition JGen2.hh:95
double getSignal() const
Get total signal.
Definition JGen2.hh:47
virtual void set(const double fS, const double fB=1.0) override
Set scaling factors of signal and background strengths.
Definition JGen2.hh:70
void configure(size_t N)
Configure lookup tables.
Definition JGen2.hh:34
JAspera fit
fit
Definition JGen2.hh:143
double getBackground() const
Get total background.
Definition JGen2.hh:58
Auxiliary interface for pseudo experiment.
Pseudo experiment using CDF for combined generation and likelihood evaluation.
double getSignal() const
Get total signal.
double getBackground() const
Get total background.