1#ifndef __JASTRONOMY__JPSEUDOEXPERIMENT__
2#define __JASTRONOMY__JPSEUDOEXPERIMENT__
80 virtual void set(
const double fS,
const double fB = 1.0) = 0;
124 return {
run(aspera), aspera() };
143 return {
run(aspera, nb), aspera() };
154 for (
auto& i : storage) {
166 template<
class T,
class JValue_t>
169 for (
auto& i : storage) {
181 template<
class T,
class JValue_t>
184 (*this)(
static_cast<JValue_t
result_type::*
>(pm), storage);
203 const size_t numberOfTests,
204 const double precision = 1.0e-4)
214 for (
size_t i = 0; i != numberOfTests; ++i) {
220 if (aspera(
true).signal < result.signal) {
225 if (n > (1.0 - Q) * numberOfTests) {
231 for ( ; ; mumax *= 2.0) {
249 for ( ; ; mumin *= 0.5) {
277 const double mu = 0.5 * (mumin + mumax);
285 if (fabs(ps - (1.0 - Q)) <= precision) {
310 const size_t nx)
const
314 for (
size_t i = 0; i != nx; ++i) {
320 if (ps <= std::numeric_limits<double>::min()) {
322 if (aspera().signal <= ps) {
331 return (
double) ns / (double) nx;
342 using JPseudoExperiment_t::operator();
411 if (
add<TH3>(pS, pB, ps, pb)) {
return; }
412 if (
add<TH2>(pS, pB, ps, pb)) {
return; }
413 if (
add<TH1>(pS, pB, ps, pb)) {
return; }
426 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
427 add(hs.GetBinContent(ix),
428 hb.GetBinContent(ix));
446 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
447 add(hS.GetBinContent(ix),
448 hB.GetBinContent(ix),
449 hs.GetBinContent(ix),
450 hb.GetBinContent(ix));
464 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
465 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
466 add(hs.GetBinContent(ix, iy),
467 hb.GetBinContent(ix, iy));
486 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
487 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
488 add(hS.GetBinContent(ix, iy),
489 hB.GetBinContent(ix, iy),
490 hs.GetBinContent(ix, iy),
491 hb.GetBinContent(ix, iy));
506 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
507 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
508 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
509 add(hs.GetBinContent(ix, iy, iz),
510 hb.GetBinContent(ix, iy, iz));
530 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
531 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
532 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
533 add(hS.GetBinContent(ix, iy, iz),
534 hB.GetBinContent(ix, iy, iz),
535 hs.GetBinContent(ix, iy, iz),
536 hb.GetBinContent(ix, iy, iz));
593 return cs.back() * this->
fs;
604 return cb.back() * this->
fb;
614 virtual void set(
const double fS,
const double fB = 1.0)
override
649 for (
size_t i = ns; i != 0; --i) { out.push_back(
aspera[
cs.
get_index(gRandom->Rndm())]); }
650 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
667 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
687 return in >> parameters.
signal
701 return out << parameters.
signal <<
' '
734 if (
dynamic_cast<const H_t*
>(ps) != NULL &&
735 dynamic_cast<const H_t*
>(pb) != NULL) {
737 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
738 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
767 if (
dynamic_cast<const H_t*
>(pS) != NULL &&
768 dynamic_cast<const H_t*
>(pB) != NULL &&
769 dynamic_cast<const H_t*
>(ps) != NULL &&
770 dynamic_cast<const H_t*
>(pb) != NULL) {
772 const H_t& hS =
dynamic_cast<const H_t&
>(*pS);
773 const H_t& hB =
dynamic_cast<const H_t&
>(*pB);
774 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
775 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
802 if (this->size() > 1) {
808 for (
size_t i = 0; i != N; ++i) {
810 const double x = this->back() * (double) i / (
double) N;
812 while ((*
this)[p+1] < x) {
828 inline size_t get_index(
const double rv,
const bool option =
false)
const
830 const double value = this->back() * rv;
832 if (option ||
index.empty()) {
835 size_t count = this->size();
837 for (
size_t i, step; count != 0; ) {
842 if ((*
this)[i] < value) {
856 while (i != this->size() && (*
this)[i] < value) {
875 this->push_back(this->back() + x);
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure to fit signal strength using likelihood ratio.
void addSignal(const double wS)
Add signal strength.
double getSignal() const
Get total signal strength.
void setSignal(const double wS)
Set signal strength.
void put(const double s, const double b)
Put signal and background to list of pre-computed N/S values.
double getTestStatisticForUpperLimit(const double ps) const
Get test statistic for given signal strength.
Auxiliary base class for experiment.
static bool check(const double s, const double b)
Check validity of signal and background.
Auxiliary data structure for CDF.
void put(const double x)
Put given value.
std::vector< size_t > index
lookup table
size_t get_index(const double rv, const bool option=false) const
Get index corresponding to given random value.
void configure(size_t N)
Configure lookup table to substitute binary search.
friend std::ostream & operator<<(std::ostream &out, const parameters_type ¶meters)
Write parameters to output stream.
friend std::istream & operator>>(std::istream &in, parameters_type ¶meters)
Read parameters from input stream.
Combined result of pseudo experiment and fit.
Statistics of pseudo experiment.
size_t ns
number of generated signal events
size_t nb
number of generated background events
stats_type & operator+=(const stats_type &px)
Addition operator.
Auxiliary interface for pseudo experiment.
result_type operator()()
Generate pseudo experiment and fit signal strength.
virtual JAspera & getAspera()=0
Get fit method.
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.
result_type operator()(const size_t nb)
Generate background only pseudo experiment and fit signal strength.
void operator()(JValue_t result_type::*pm, std::vector< T > &storage)
Run pseudo experiments using given storage.
static constexpr double MINIMAL_SIGNAL_STRENGTH
virtual stats_type run(JAspera &out, const size_t nb) const =0
Generate background only pseudo experiment and transfer S/N values to fit method.
void operator()(std::vector< result_type > &storage)
Run pseudo experiments using given storage.
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
virtual stats_type run(JAspera &out) const =0
Generate pseudo experiment and transfer S/N values to fit method.
JAspera::fit_type fit_type
fit type
Pseudo experiment using CDF for combined generation and likelihood evaluation.
void add(const TObject *ps, const TObject *pb)
Add objects with PDFs of signal and background.
struct JASTRONOMY::JPseudoExperiment::parameters_type nuisance
virtual stats_type run(JAspera &out, const size_t nb) const
Generate background only pseudo experiment and transfer S/N values to fit method.
cdf_type cs
CDF of signal.
virtual stats_type run(JAspera &out) const
Generate pseudo experiment and transfer values to fit method.
void add(const TH3 &hS, const TH3 &hB, const TH3 &hs, const TH3 &hb)
Add histograms with PDFs of signal and background.
void add(const TH1 &hS, const TH1 &hB, const TH1 &hs, const TH1 &hb)
Add histograms with PDFs of signal and background.
bool add(const TObject *ps, const TObject *pb)
Add objects with PDF of signal and background.
virtual JAspera & getAspera() override
Get fit method.
bool add(const TObject *pS, const TObject *pB, const TObject *ps, const TObject *pb)
Add objects with PDF of signal and background.
double getSignal() const
Get total signal.
void add(const TH2 &hS, const TH2 &hB, const TH2 &hs, const TH2 &hb)
Add histograms with PDFs of signal and background.
void add(const TH3 &hs, const TH3 &hb)
Add histograms with PDFs of signal and background.
JPseudoExperiment(const H_t &hS, const H_t &hB, const H_t &hs, const H_t &hb)
Constructor.
virtual void set(const double fS, const double fB=1.0) override
Set scaling factors of signal and background strengths.
double fb
scaling factor background strength
cdf_type cb
CDF of background.
void add(const double S, const double B, const double s, const double b)
Add signal and background.
void add(const TH2 &hs, const TH2 &hb)
Add histograms with PDFs of signal and background.
JPseudoExperiment(const H_t &hs, const H_t &hb)
Constructor.
JAspera aspera
pre-computed N/S values
double getBackground() const
Get total background.
void add(const TObject *pS, const TObject *pB, const TObject *ps, const TObject *pb)
Add objects with PDFs of signal and background.
void add(const TH1 &hs, const TH1 &hb)
Add histograms with PDFs of signal and background.
double fs
scaling factor signal strength
void configure(size_t N)
Configure lookup tables.
void add(const double s, const double b)
Add signal and background.
JPseudoExperiment()
Default constructor.