Jpp 20.0.0-rc.7
the software that should make you happy
Loading...
Searching...
No Matches
JASTRONOMY::JGen2 Struct Reference

Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiments. More...

#include <JGen2.hh>

Inheritance diagram for JASTRONOMY::JGen2:
std::vector< JPseudoExperiment > JASTRONOMY::JPseudoExperiment_t JASTRONOMY::JExperiment

Public Types

typedef JAspera::fit_type fit_type
 fit type
 

Public Member Functions

void configure (size_t N)
 Configure lookup tables.
 
double getSignal () const
 Get total signal.
 
double getBackground () const
 Get total background.
 
virtual void set (const double fS, const double fB=1.0) override
 Set scaling factors of signal and background strengths.
 
virtual JAsperagetAspera () override
 Get fit method.
 
virtual stats_type run (JAspera &out) const
 Generate pseudo experiment and transfer S/N values to fit method.
 
virtual stats_type run (JAspera &out, const size_t nb) const
 Generate background only pseudo experiment and transfer S/N values to fit method.
 
result_type operator() ()
 Generate pseudo experiment and fit signal strength.
 
result_type operator() (const size_t nb)
 Generate background only pseudo experiment and fit signal strength.
 
void operator() (std::vector< result_type > &storage)
 Run pseudo experiments using given storage.
 
template<class T , class JValue_t >
void operator() (JValue_t result_type::*pm, std::vector< T > &storage)
 Run pseudo experiments using given storage.
 
template<class T , class JValue_t >
void operator() (JValue_t JAspera::fit_type::*pm, std::vector< T > &storage)
 Run pseudo experiments using given storage.
 
double getSignalStrengthForUpperLimit (const JAspera &aspera, const double Q, const size_t numberOfTests, const double precision=1.0e-4)
 Get signal strength given result of experiment and probability of upper limit.
 

Static Public Member Functions

static double getSNR ()
 Get minimal signa-to-noise ratio.
 
static void setSNR (const double value)
 Set minimal signa-to-noise ratio.
 
static bool check (const double s, const double b)
 Check validity of signal and background.
 
static bool check (const TAxis *ha, const TAxis *hb)
 Check histogram bins.
 
static bool check (const TH1 &ha, const TH1 &hb)
 Check histogram bins.
 
static bool check (const TH2 &ha, const TH2 &hb)
 Check histogram bins.
 
static bool check (const TH3 &ha, const TH3 &hb)
 Check histogram bins.
 

Static Public Attributes

static constexpr double MINIMAL_SIGNAL_STRENGTH = 1.0e-10
 
static constexpr double MAXIMAL_SIGNAL_STRENGTH = 1.0e+10
 

Protected Member Functions

double getProbabilityForUpperLimit (const double ps, const double ts, const size_t nx) const
 Get probability for given pseudo experiment and signal strength to exceed minimal test statistic for upper limit.
 

Protected Attributes

JAspera fit
 fit
 

Static Private Member Functions

static double & get_snr ()
 Get minimal signa-to-noise ratio.
 

Detailed Description

Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiments.

Definition at line 25 of file JGen2.hh.

Member Typedef Documentation

◆ fit_type

Member Function Documentation

◆ configure()

void JASTRONOMY::JGen2::configure ( size_t N)
inline

Configure lookup tables.

Parameters
Nnumber of bins

Definition at line 34 of file JGen2.hh.

35 {
36 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
37 i.configure(N);
38 }
39 }

◆ getSignal()

double JASTRONOMY::JGen2::getSignal ( ) const
inline

Get total signal.

Returns
signal

Definition at line 47 of file JGen2.hh.

48 {
49 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getSignal(); } );
50 }

◆ getBackground()

double JASTRONOMY::JGen2::getBackground ( ) const
inline

Get total background.

Returns
background

Definition at line 58 of file JGen2.hh.

59 {
60 return std::accumulate(this->begin(), this->end(), 0.0, [](const double y, const JPseudoExperiment& px) { return y + px.getBackground(); } );
61 }

◆ set()

virtual void JASTRONOMY::JGen2::set ( const double fS,
const double fB = 1.0 )
inlineoverridevirtual

Set scaling factors of signal and background strengths.

Parameters
fSsignal strength
fBbackground strength

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 70 of file JGen2.hh.

71 {
72 for (auto& i : static_cast<std::vector<JPseudoExperiment>&>(*this)) {
73 i.set(fS, fB);
74 }
75 }

◆ getAspera()

virtual JAspera & JASTRONOMY::JGen2::getAspera ( )
inlineoverridevirtual

Get fit method.

Returns
fit

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 83 of file JGen2.hh.

84 {
85 return this->fit;
86 }
JAspera fit
fit
Definition JGen2.hh:143

◆ run() [1/2]

virtual stats_type JASTRONOMY::JGen2::run ( JAspera & out) const
inlinevirtual

Generate pseudo experiment and transfer S/N values to fit method.

Parameters
outoutput
Returns
result

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 95 of file JGen2.hh.

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 }

◆ run() [2/2]

virtual stats_type JASTRONOMY::JGen2::run ( JAspera & out,
const size_t nb ) const
inlinevirtual

Generate background only pseudo experiment and transfer S/N values to fit method.

Parameters
outoutput
nbnumber of background events
Returns
result

Implements JASTRONOMY::JPseudoExperiment_t.

Definition at line 114 of file JGen2.hh.

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 }
double getBackground() const
Get total background.
Definition JGen2.hh:58

◆ operator()() [1/5]

result_type JASTRONOMY::JPseudoExperiment_t::operator() ( )
inlineinherited

Generate pseudo experiment and fit signal strength.

Returns
result

Definition at line 115 of file JPseudoExperiment.hh.

116 {
117 JAspera& aspera = getAspera();
118
119 // reset
120
121 aspera.clear();
122 aspera.setSignal(0.0);
123
124 return { run(aspera), aspera() };
125 }
virtual JAspera & getAspera()=0
Get fit method.
virtual stats_type run(JAspera &out) const =0
Generate pseudo experiment and transfer S/N values to fit method.

◆ operator()() [2/5]

result_type JASTRONOMY::JPseudoExperiment_t::operator() ( const size_t nb)
inlineinherited

Generate background only pseudo experiment and fit signal strength.

Parameters
nbnumber of background events
Returns
result

Definition at line 134 of file JPseudoExperiment.hh.

135 {
136 JAspera& aspera = getAspera();
137
138 // reset
139
140 aspera.clear();
141 aspera.setSignal(0.0);
142
143 return { run(aspera, nb), aspera() };
144 }

◆ operator()() [3/5]

void JASTRONOMY::JPseudoExperiment_t::operator() ( std::vector< result_type > & storage)
inlineinherited

Run pseudo experiments using given storage.

Parameters
storagestorage

Definition at line 152 of file JPseudoExperiment.hh.

153 {
154 for (auto& i : storage) {
155 i = (*this)();
156 }
157 }

◆ operator()() [4/5]

template<class T , class JValue_t >
void JASTRONOMY::JPseudoExperiment_t::operator() ( JValue_t result_type::* pm,
std::vector< T > & storage )
inlineinherited

Run pseudo experiments using given storage.

Parameters
pmpointer to data member of result
storagestorage

Definition at line 167 of file JPseudoExperiment.hh.

168 {
169 for (auto& i : storage) {
170 i = (*this)().*pm;
171 }
172 }

◆ operator()() [5/5]

template<class T , class JValue_t >
void JASTRONOMY::JPseudoExperiment_t::operator() ( JValue_t JAspera::fit_type::* pm,
std::vector< T > & storage )
inlineinherited

Run pseudo experiments using given storage.

Parameters
pmpointer to data member of result
storagestorage

Definition at line 182 of file JPseudoExperiment.hh.

183 {
184 (*this)(static_cast<JValue_t result_type::*>(pm), storage);
185 }

◆ getSignalStrengthForUpperLimit()

double JASTRONOMY::JPseudoExperiment_t::getSignalStrengthForUpperLimit ( const JAspera & aspera,
const double Q,
const size_t numberOfTests,
const double precision = 1.0e-4 )
inlineinherited

Get signal strength given result of experiment and probability of upper limit.

Parameters
asperaresult of experiment
Qprobability
numberOfTestsnumber of tests
precisionprecision
Returns
signal strength

Definition at line 201 of file JPseudoExperiment.hh.

205 {
206 using namespace std;
207
208 const JAspera::fit_type result = aspera(true);
209
210 size_t n = 0;
211
212 this->set(0.0);
213
214 for (size_t i = 0; i != numberOfTests; ++i) {
215
216 JAspera aspera;
217
218 this->run(aspera);
219
220 if (aspera(true).signal < result.signal) {
221 n += 1;
222 }
223 }
224
225 if (n > (1.0 - Q) * numberOfTests) {
226
227 double mumin = 1.0;
228 double mumax = 1.0;
229
230 {
231 for ( ; ; mumax *= 2.0) {
232
233 const double ts = aspera.getTestStatisticForUpperLimit(mumax);
234
235 this->set(mumax);
236
237 const double ps = this->getProbabilityForUpperLimit(mumax, ts, numberOfTests);
238
239 if (ps < 1.0 - Q || mumax > MAXIMAL_SIGNAL_STRENGTH) {
240 break;
241 }
242 }
243 }
244
245 if (mumax == 1.0) {
246
247 mumin = 0.5*mumax;
248
249 for ( ; ; mumin *= 0.5) {
250
251 const double ts = aspera.getTestStatisticForUpperLimit(mumin);
252
253 this->set(mumin);
254
255 const double ps = this->getProbabilityForUpperLimit(mumin, ts, numberOfTests);
256
257 if (ps > 1.0 - Q || mumin < MINIMAL_SIGNAL_STRENGTH) {
258 break;
259 }
260 }
261
262 mumax = 2.0*mumin;
263
264 } else {
265
266 mumin = 0.5*mumax;
267 }
268
269 if (mumin < MINIMAL_SIGNAL_STRENGTH)
270 return mumin;
271 else if (mumax > MAXIMAL_SIGNAL_STRENGTH)
272 return mumax;
273 else {
274
275 for ( ; ; ) { // binary search
276
277 const double mu = 0.5 * (mumin + mumax);
278
279 const double ts = aspera.getTestStatisticForUpperLimit(mu);
280
281 this->set(mu);
282
283 const double ps = this->getProbabilityForUpperLimit(mu, ts, numberOfTests);
284
285 if (fabs(ps - (1.0 - Q)) <= precision) {
286 return mu;
287 }
288
289 if (ps >= 1.0 - Q)
290 mumin = mu;
291 else
292 mumax = mu;
293 }
294 }
295 }
296
297 return 0.0;
298 }
const int n
Definition JPolint.hh:791
static constexpr double MINIMAL_SIGNAL_STRENGTH
double getProbabilityForUpperLimit(const double ps, const double ts, const size_t nx) const
Get probability for given pseudo experiment and signal strength to exceed minimal test statistic for ...
virtual void set(const double fS, const double fB=1.0)=0
Set scaling factors of signal and background strengths.
static constexpr double MAXIMAL_SIGNAL_STRENGTH

◆ getProbabilityForUpperLimit()

double JASTRONOMY::JPseudoExperiment_t::getProbabilityForUpperLimit ( const double ps,
const double ts,
const size_t nx ) const
inlineprotectedinherited

Get probability for given pseudo experiment and signal strength to exceed minimal test statistic for upper limit.

Parameters
pssignal strength
tstest statistic
nxnumber of pseudo experiments

Definition at line 308 of file JPseudoExperiment.hh.

311 {
312 size_t ns = 0;
313
314 for (size_t i = 0; i != nx; ++i) {
315
316 JAspera aspera;
317
318 this->run(aspera);
319
320 if (ps <= std::numeric_limits<double>::min()) {
321
322 if (aspera().signal <= ps) {
323 ns += 1;
324 }
325
326 } else if (aspera.getTestStatisticForUpperLimit(ps) > ts) {
327 ns += 1;
328 }
329 }
330
331 return (double) ns / (double) nx;
332 }

◆ getSNR()

static double JASTRONOMY::JExperiment::getSNR ( )
inlinestaticinherited

Get minimal signa-to-noise ratio.

Returns
signa-to-noise ratio.

Definition at line 32 of file JExperiment.hh.

33 {
34 return get_snr();
35 }
static double & get_snr()
Get minimal signa-to-noise ratio.

◆ setSNR()

static void JASTRONOMY::JExperiment::setSNR ( const double value)
inlinestaticinherited

Set minimal signa-to-noise ratio.

Parameters
valuesigna-to-noise ratio.

Definition at line 43 of file JExperiment.hh.

44 {
45 get_snr() = value;
46 }

◆ check() [1/5]

static bool JASTRONOMY::JExperiment::check ( const double s,
const double b )
inlinestaticinherited

Check validity of signal and background.

Parameters
ssignal
bbackground
Returns
true if signal and backgroud are valid; else false

Definition at line 56 of file JExperiment.hh.

57 {
58 return (s > 0.0 && b > 0.0 && s/b >= getSNR());
59 }
static double getSNR()
Get minimal signa-to-noise ratio.

◆ check() [2/5]

static bool JASTRONOMY::JExperiment::check ( const TAxis * ha,
const TAxis * hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram axis
hbhistogram axis
Returns
true if same binning; else false

Definition at line 69 of file JExperiment.hh.

70 {
71 return (ha->GetNbins() == hb->GetNbins() &&
72 ha->GetXmin() == hb->GetXmin() &&
73 ha->GetXmax() == hb->GetXmax());
74 }

◆ check() [3/5]

static bool JASTRONOMY::JExperiment::check ( const TH1 & ha,
const TH1 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 83 of file JExperiment.hh.

84 {
85 return check(ha.GetXaxis(), hb.GetXaxis());
86 }
static bool check(const double s, const double b)
Check validity of signal and background.

◆ check() [4/5]

static bool JASTRONOMY::JExperiment::check ( const TH2 & ha,
const TH2 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 96 of file JExperiment.hh.

97 {
98 return (check(ha.GetXaxis(), hb.GetXaxis()) &&
99 check(ha.GetYaxis(), hb.GetYaxis()));
100 }

◆ check() [5/5]

static bool JASTRONOMY::JExperiment::check ( const TH3 & ha,
const TH3 & hb )
inlinestaticinherited

Check histogram bins.

Parameters
hahistogram
hbhistogram
Returns
true if same binning; else false

Definition at line 110 of file JExperiment.hh.

111 {
112 return (check(ha.GetXaxis(), hb.GetXaxis()) &&
113 check(ha.GetYaxis(), hb.GetYaxis()) &&
114 check(ha.GetZaxis(), hb.GetZaxis()));
115 }

◆ get_snr()

static double & JASTRONOMY::JExperiment::get_snr ( )
inlinestaticprivateinherited

Get minimal signa-to-noise ratio.

Returns
signa-to-noise ratio.

Definition at line 123 of file JExperiment.hh.

124 {
125 static double value = 0.0;
126
127 return value;
128 }

Member Data Documentation

◆ fit

JAspera JASTRONOMY::JGen2::fit
protected

fit

Definition at line 143 of file JGen2.hh.

◆ MINIMAL_SIGNAL_STRENGTH

double JASTRONOMY::JPseudoExperiment_t::MINIMAL_SIGNAL_STRENGTH = 1.0e-10
staticconstexprinherited

Definition at line 188 of file JPseudoExperiment.hh.

◆ MAXIMAL_SIGNAL_STRENGTH

double JASTRONOMY::JPseudoExperiment_t::MAXIMAL_SIGNAL_STRENGTH = 1.0e+10
staticconstexprinherited

Definition at line 189 of file JPseudoExperiment.hh.


The documentation for this struct was generated from the following file: