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) {
295 if (( ps <= (1 - Q)) && (mu - mumin < precision) && (mumax - mu < precision))
return mu;
314 const size_t nx)
const
318 for (
size_t i = 0; i != nx; ++i) {
324 if (ps <= std::numeric_limits<double>::min()) {
326 if (aspera().signal <= ps) {
335 return (
double) ns / (double) nx;
346 using JPseudoExperiment_t::operator();
415 if (
add<TH3>(pS, pB, ps, pb)) {
return; }
416 if (
add<TH2>(pS, pB, ps, pb)) {
return; }
417 if (
add<TH1>(pS, pB, ps, pb)) {
return; }
430 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
431 add(hs.GetBinContent(ix),
432 hb.GetBinContent(ix));
450 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
451 add(hS.GetBinContent(ix),
452 hB.GetBinContent(ix),
453 hs.GetBinContent(ix),
454 hb.GetBinContent(ix));
468 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
469 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
470 add(hs.GetBinContent(ix, iy),
471 hb.GetBinContent(ix, iy));
490 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
491 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
492 add(hS.GetBinContent(ix, iy),
493 hB.GetBinContent(ix, iy),
494 hs.GetBinContent(ix, iy),
495 hb.GetBinContent(ix, iy));
510 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
511 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
512 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
513 add(hs.GetBinContent(ix, iy, iz),
514 hb.GetBinContent(ix, iy, iz));
534 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
535 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
536 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
537 add(hS.GetBinContent(ix, iy, iz),
538 hB.GetBinContent(ix, iy, iz),
539 hs.GetBinContent(ix, iy, iz),
540 hb.GetBinContent(ix, iy, iz));
619 return cs.back() * this->
fs;
630 return cb.back() * this->
fb;
640 virtual void set(
const double fS,
const double fB = 1.0)
override
675 for (
size_t i = ns; i != 0; --i) { out.push_back(
aspera[
cs.
get_index(gRandom->Rndm())]); }
676 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
693 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
713 return in >> parameters.
signal
727 return out << parameters.
signal <<
' '
760 if (
dynamic_cast<const H_t*
>(ps) != NULL &&
761 dynamic_cast<const H_t*
>(pb) != NULL) {
763 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
764 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
793 if (
dynamic_cast<const H_t*
>(pS) != NULL &&
794 dynamic_cast<const H_t*
>(pB) != NULL &&
795 dynamic_cast<const H_t*
>(ps) != NULL &&
796 dynamic_cast<const H_t*
>(pb) != NULL) {
798 const H_t& hS =
dynamic_cast<const H_t&
>(*pS);
799 const H_t& hB =
dynamic_cast<const H_t&
>(*pB);
800 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
801 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
828 if (this->size() > 1) {
834 for (
size_t i = 0; i != N; ++i) {
836 const double x = this->back() * (double) i / (
double) N;
838 while ((*
this)[p+1] < x) {
854 inline size_t get_index(
const double rv,
const bool option =
false)
const
856 const double value = this->back() * rv;
858 if (option ||
index.empty()) {
861 size_t count = this->size();
863 for (
size_t i, step; count != 0; ) {
868 if ((*
this)[i] < value) {
882 while (i != this->size() && (*
this)[i] < value) {
901 this->push_back(this->back() + x);
921 void add(
const double S,
const double B,
const double s,
const double b)
std::shared_ptr< JNuisance > nuisance_type
Type definition of generic nuisance.
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.
void add(const double S, const double B, const double s, const double b)
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.
void add()
Add remnant signal and background.
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.
struct JASTRONOMY::JPseudoExperiment::remnant_type remnant
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.