1#ifndef __JASTRONOMY__JPSEUDOEXPERIMENT__
2#define __JASTRONOMY__JPSEUDOEXPERIMENT__
85 for (
size_t i = 0; i != nx; ++i) {
91 this->push_back(aspera(
true).signal);
94 sort(this->begin(), this->end());
108 return (
double)
distance(this->begin(), lower_bound(this->begin(), this->end(), ps)) / (double) this->size();
119 virtual void set(
const double fS,
const double fB = 1.0) = 0;
163 return {
run(aspera), aspera() };
182 return {
run(aspera, nb), aspera() };
193 for (
auto& i : storage) {
205 template<
class T,
class JValue_t>
208 for (
auto& i : storage) {
220 template<
class T,
class JValue_t>
223 (*this)(
static_cast<JValue_t
result_type::*
>(pm), storage);
236 const size_t nx)
const
240 for (
size_t i = 0; i != nx; ++i) {
246 if (ps <= std::numeric_limits<double>::min()) {
248 if (aspera().signal <= ps) {
257 return (
double) ns / (double) nx;
268 using JPseudoExperiment_t::operator();
337 if (
add<TH3>(pS, pB, ps, pb)) {
return; }
338 if (
add<TH2>(pS, pB, ps, pb)) {
return; }
339 if (
add<TH1>(pS, pB, ps, pb)) {
return; }
352 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
353 add(hs.GetBinContent(ix),
354 hb.GetBinContent(ix));
372 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
373 add(hS.GetBinContent(ix),
374 hB.GetBinContent(ix),
375 hs.GetBinContent(ix),
376 hb.GetBinContent(ix));
390 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
391 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
392 add(hs.GetBinContent(ix, iy),
393 hb.GetBinContent(ix, iy));
412 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
413 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
414 add(hS.GetBinContent(ix, iy),
415 hB.GetBinContent(ix, iy),
416 hs.GetBinContent(ix, iy),
417 hb.GetBinContent(ix, iy));
432 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
433 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
434 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
435 add(hs.GetBinContent(ix, iy, iz),
436 hb.GetBinContent(ix, iy, iz));
456 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
457 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
458 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
459 add(hS.GetBinContent(ix, iy, iz),
460 hB.GetBinContent(ix, iy, iz),
461 hs.GetBinContent(ix, iy, iz),
462 hb.GetBinContent(ix, iy, iz));
519 return cs.back() * this->
fs;
530 return cb.back() * this->
fb;
540 virtual void set(
const double fS,
const double fB = 1.0)
override
575 for (
size_t i = ns; i != 0; --i) { out.push_back(
aspera[
cs.
get_index(gRandom->Rndm())]); }
576 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
593 for (
size_t i = nb; i != 0; --i) { out.push_back(
aspera[
cb.
get_index(gRandom->Rndm())]); }
613 return in >> parameters.
signal
627 return out << parameters.
signal <<
' '
660 if (
dynamic_cast<const H_t*
>(ps) != NULL &&
661 dynamic_cast<const H_t*
>(pb) != NULL) {
663 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
664 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
693 if (
dynamic_cast<const H_t*
>(pS) != NULL &&
694 dynamic_cast<const H_t*
>(pB) != NULL &&
695 dynamic_cast<const H_t*
>(ps) != NULL &&
696 dynamic_cast<const H_t*
>(pb) != NULL) {
698 const H_t& hS =
dynamic_cast<const H_t&
>(*pS);
699 const H_t& hB =
dynamic_cast<const H_t&
>(*pB);
700 const H_t& hs =
dynamic_cast<const H_t&
>(*ps);
701 const H_t& hb =
dynamic_cast<const H_t&
>(*pb);
728 if (this->size() > 1) {
734 for (
size_t i = 0; i != N; ++i) {
736 const double x = this->back() * (double) i / (
double) N;
738 while ((*
this)[p+1] < x) {
754 inline size_t get_index(
const double rv,
const bool option =
false)
const
756 const double value = this->back() * rv;
758 if (option ||
index.empty()) {
761 size_t count = this->size();
763 for (
size_t i, step; count != 0; ) {
768 if ((*
this)[i] < value) {
782 while (i != this->size() && (*
this)[i] < value) {
801 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
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.
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.
Auxiliary data structure for upper limit evaluations of background only pseudo experiments.
h0_type(const JPseudoExperiment_t &px, const size_t nx)
Constructor.
double getFractionBelow(const double ps) const
Get fraction below given upper limit of signal strength.
Result of combined 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)
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.
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.
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.
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.