Jpp 20.0.0-rc.9-22-g74b57fa79
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 * Add remnant signal and background.
31 */
32 void add()
33 {
34 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
35 i.add();
36 }
37 }
38
39 /**
40 * Configure lookup tables.
41 *
42 * \param N number of bins
43 */
44 void configure(size_t N)
45 {
46 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
47 i.configure(N);
48 }
49 }
50
51
52 /**
53 * Get total signal.
54 *
55 * \return signal
56 */
57 double getSignal() const
58 {
59 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getSignal(); } );
60 }
61
62
63 /**
64 * Get total background.
65 *
66 * \return background
67 */
68 double getBackground() const
69 {
70 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getBackground(); } );
71 }
72
73
74 /**
75 * Set scaling factors of signal and background strengths.
76 *
77 * \param fS signal strength
78 * \param fB background strength
79 */
80 virtual void set(const double fS, const double fB = 1.0) override
81 {
82 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
83 i.set(fS, fB);
84 }
85 }
86
87
88 /**
89 * Get fit method.
90 *
91 * \return fit
92 */
93 virtual JAspera& getAspera() override
94 {
95 return this->fit;
96 }
97
98
99 /**
100 * Generate pseudo experiment and transfer S/N values to fit method.
101 *
102 * \param out output
103 * \return result
104 */
105 virtual stats_type run(JAspera& out) const
106 {
107 stats_type ps = { 0, 0 };
108
109 for (const auto& px : static_cast<const std::vector<JPseudoExperiment>&>(*this)) {
110 ps += px.run(out);
111 }
112
113 return ps;
114 }
115
116
117 /**
118 * Generate background only pseudo experiment and transfer S/N values to fit method.
119 *
120 * \param out output
121 * \param nb number of background events
122 * \return result
123 */
124 virtual stats_type run(JAspera& out, const size_t nb) const
125 {
126 stats_type ps = { 0, 0 };
127
128 const double B = this->getBackground();
129
130 for (size_t i = 0; i != nb; ++i) {
131
132 const double X = gRandom->Uniform(0.0, B);
133
134 double x = 0.0;
135
136 for (const auto& px : static_cast<const std::vector<JPseudoExperiment>&>(*this)) {
137
138 x += px.getBackground();
139
140 if (x >= X) {
141
142 ps += px.run(out, 1);
143
144 break;
145 }
146 }
147 }
148
149 return ps;
150 }
151
152 protected:
153 JAspera fit; //!< fit
154 };
155}
156
157#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:93
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:124
virtual stats_type run(JAspera &out) const
Generate pseudo experiment and transfer S/N values to fit method.
Definition JGen2.hh:105
double getSignal() const
Get total signal.
Definition JGen2.hh:57
void add()
Add remnant signal and background.
Definition JGen2.hh:32
virtual void set(const double fS, const double fB=1.0) override
Set scaling factors of signal and background strengths.
Definition JGen2.hh:80
void configure(size_t N)
Configure lookup tables.
Definition JGen2.hh:44
JAspera fit
fit
Definition JGen2.hh:153
double getBackground() const
Get total background.
Definition JGen2.hh:68
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.