Jpp 20.0.0-rc.9
the software that should make you happy
Loading...
Searching...
No Matches
JPseudoExperiment.hh
Go to the documentation of this file.
1#ifndef __JASTRONOMY__JPSEUDOEXPERIMENT__
2#define __JASTRONOMY__JPSEUDOEXPERIMENT__
3
4#include <istream>
5#include <ostream>
6#include <vector>
7#include <algorithm>
8#include <limits>
9
10#include "TObject.h"
11#include "TH1.h"
12#include "TH2.h"
13#include "TH3.h"
14#include "TRandom3.h"
15
17#include "JAstronomy/JAspera.hh"
19
20
21/**
22 * \file
23 *
24 * Pseudo experiment.
25 * \author mdejong
26 */
27namespace JASTRONOMY {}
28namespace JPP { using namespace JASTRONOMY; }
29
30namespace JASTRONOMY {
31
32
33 /**
34 * Auxiliary interface for pseudo experiment.
35 */
37 public JExperiment
38 {
39 /**
40 * Statistics of pseudo experiment.
41 */
42 struct stats_type {
43 /**
44 * Addition operator.
45 *
46 * \param px statistics of pseudo experiment
47 * \return this statistics
48 */
50 {
51 this->ns += px.ns;
52 this->nb += px.nb;
53
54 return *this;
55 }
56
57 size_t ns = 0; //!< number of generated signal events
58 size_t nb = 0; //!< number of generated background events
59 };
60
61
62 typedef JAspera::fit_type fit_type; //!< fit type
63
64
65 /**
66 * Combined result of pseudo experiment and fit.
67 */
68 struct result_type :
69 public stats_type,
70 public fit_type
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) = 0;
81
82
83 /**
84 * Get fit method.
85 *
86 * \return fit
87 */
88 virtual JAspera& getAspera() = 0;
89
90
91 /**
92 * Generate pseudo experiment and transfer S/N values to fit method.
93 *
94 * \param out output
95 * \return result
96 */
97 virtual stats_type run(JAspera& out) const = 0;
98
99
100 /**
101 * Generate background only pseudo experiment and transfer S/N values to fit method.
102 *
103 * \param out output
104 * \param nb number of background events
105 * \return result
106 */
107 virtual stats_type run(JAspera& out, const size_t nb) const = 0;
108
109
110 /**
111 * Generate pseudo experiment and fit signal strength.
112 *
113 * \return result
114 */
116 {
117 JAspera& aspera = getAspera();
118
119 // reset
120
121 aspera.clear();
122 aspera.setSignal(0.0);
123
124 return { run(aspera), aspera() };
125 }
126
127
128 /**
129 * Generate background only pseudo experiment and fit signal strength.
130 *
131 * \param nb number of background events
132 * \return result
133 */
134 inline result_type operator()(const size_t nb)
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 }
145
146
147 /**
148 * Run pseudo experiments using given storage.
149 *
150 * \param storage storage
151 */
153 {
154 for (auto& i : storage) {
155 i = (*this)();
156 }
157 }
158
159
160 /**
161 * Run pseudo experiments using given storage.
162 *
163 * \param pm pointer to data member of result
164 * \param storage storage
165 */
166 template<class T, class JValue_t>
167 inline void operator()(JValue_t result_type::*pm, std::vector<T>& storage)
168 {
169 for (auto& i : storage) {
170 i = (*this)().*pm;
171 }
172 }
173
174
175 /**
176 * Run pseudo experiments using given storage.
177 *
178 * \param pm pointer to data member of result
179 * \param storage storage
180 */
181 template<class T, class JValue_t>
182 inline void operator()(JValue_t JAspera::fit_type::*pm, std::vector<T>& storage)
183 {
184 (*this)(static_cast<JValue_t result_type::*>(pm), storage);
185 }
186
187
188 static constexpr double MINIMAL_SIGNAL_STRENGTH = 1.0e-10; // minimal signal strength for upper limit
189 static constexpr double MAXIMAL_SIGNAL_STRENGTH = 1.0e+10; // maximal signal strength for upper limit
190
191
192 /**
193 * Get signal strength given result of experiment and probability of upper limit.
194 *
195 * \param aspera result of experiment
196 * \param Q probability
197 * \param numberOfTests number of tests
198 * \param precision precision
199 * \return signal strength
200 */
202 const double Q,
203 const size_t numberOfTests,
204 const double precision = 1.0e-4)
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 }
299
300 protected:
301 /**
302 * Get probability for given pseudo experiment and signal strength to exceed minimal test statistic for upper limit.
303 *
304 * \param ps signal strength
305 * \param ts test statistic
306 * \param nx number of pseudo experiments
307 */
308 inline double getProbabilityForUpperLimit(const double ps,
309 const double ts,
310 const size_t nx) const
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 }
333 };
334
335
336 /**
337 * Pseudo experiment using CDF for combined generation and likelihood evaluation.
338 */
341 {
342 using JPseudoExperiment_t::operator();
343
344 /**
345 * Default constructor.
346 */
349
350
351 /**
352 * Constructor.
353 *
354 * \param hs histogram with PDF of signal
355 * \param hb histogram with PDF of background
356 */
357 template<class H_t>
358 JPseudoExperiment(const H_t& hs,
359 const H_t& hb)
360 {
361 add(hs, hb);
362 }
363
364
365 /**
366 * Constructor.
367 *
368 * \param hS histogram with PDF for generation of signal
369 * \param hB histogram with PDF for generation of background
370 * \param hs histogram with PDF for evaluation of signal
371 * \param hb histogram with PDF for evaluation of background
372 */
373 template<class H_t>
374 JPseudoExperiment(const H_t& hS,
375 const H_t& hB,
376 const H_t& hs,
377 const H_t& hb)
378 {
379 add(hS, hB, hs, hb);
380 }
381
382
383 /**
384 * Add objects with PDFs of signal and background.
385 *
386 * \param ps pointer to object with PDF of signal
387 * \param pb pointer to object with PDF of background
388 */
389 void add(const TObject* ps,
390 const TObject* pb)
391 {
392 if (add<TH3>(ps, pb)) { return; }
393 if (add<TH2>(ps, pb)) { return; }
394 if (add<TH1>(ps, pb)) { return; }
395 }
396
397
398 /**
399 * Add objects with PDFs of signal and background.
400 *
401 * \param pS pointer to object with PDF for generation of signal
402 * \param pB pointer to object with PDF for generation of background
403 * \param ps pointer to object with PDF for evaluation of signal
404 * \param pb pointer to object with PDF for evaluation of background
405 */
406 void add(const TObject* pS,
407 const TObject* pB,
408 const TObject* ps,
409 const TObject* pb)
410 {
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; }
414 }
415
416
417 /**
418 * Add histograms with PDFs of signal and background.
419 *
420 * \param hs histogram with PDF of signal
421 * \param hb histogram with PDF of background
422 */
423 void add(const TH1& hs,
424 const TH1& hb)
425 {
426 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
427 add(hs.GetBinContent(ix),
428 hb.GetBinContent(ix));
429 }
430 }
431
432
433 /**
434 * Add histograms with PDFs of signal and background.
435 *
436 * \param hS histogram with PDF for generation of signal
437 * \param hB histogram with PDF for generation of background
438 * \param hs histogram with PDF for evaluation of signal
439 * \param hb histogram with PDF for evaluation of background
440 */
441 void add(const TH1& hS,
442 const TH1& hB,
443 const TH1& hs,
444 const TH1& hb)
445 {
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));
451 }
452 }
453
454
455 /**
456 * Add histograms with PDFs of signal and background.
457 *
458 * \param hs histogram with PDF of signal
459 * \param hb histogram with PDF of background
460 */
461 void add(const TH2& hs,
462 const TH2& hb)
463 {
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));
468 }
469 }
470 }
471
472
473 /**
474 * Add histograms with PDFs of signal and background.
475 *
476 * \param hS histogram with PDF for generation of signal
477 * \param hB histogram with PDF for generation of background
478 * \param hs histogram with PDF for evaluation of signal
479 * \param hb histogram with PDF for evaluation of background
480 */
481 void add(const TH2& hS,
482 const TH2& hB,
483 const TH2& hs,
484 const TH2& hb)
485 {
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));
492 }
493 }
494 }
495
496
497 /**
498 * Add histograms with PDFs of signal and background.
499 *
500 * \param hs histogram with PDF of signal
501 * \param hb histogram with PDF of background
502 */
503 void add(const TH3& hs,
504 const TH3& hb)
505 {
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));
511 }
512 }
513 }
514 }
515
516
517 /**
518 * Add histograms with PDFs of signal and background.
519 *
520 * \param hS histogram with PDF for generation of signal
521 * \param hB histogram with PDF for generation of background
522 * \param hs histogram with PDF for evaluation of signal
523 * \param hb histogram with PDF for evaluation of background
524 */
525 void add(const TH3& hS,
526 const TH3& hB,
527 const TH3& hs,
528 const TH3& hb)
529 {
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));
537 }
538 }
539 }
540 }
541
542
543 /**
544 * Add signal and background.
545 *
546 * \param s signal
547 * \param b background
548 */
549 void add(const double s,
550 const double b)
551 {
552 if (check(s, b)) {
553
554 cs.put(s);
555 cb.put(b);
556
557 aspera.put(s, b);
558
559 } else {
560
561 remnant.add(s, b, s, b);
562 }
563 }
564
565
566 /**
567 * Add signal and background.
568 *
569 * \param S signal for generation
570 * \param B background for generation
571 * \param s signal for evaluation
572 * \param b background for evaluation
573 */
574 void add(const double S,
575 const double B,
576 const double s,
577 const double b)
578 {
579 if (//check(S, B) &&
580 check(s, b)) {
581
582 cs.put(S);
583 cb.put(B);
584
585 aspera.put(s, b);
586
587 } else {
588
589 remnant.add(S, B, s, b);
590 }
591 }
592
593
594 /**
595 * Add remnant signal and background.
596 */
597 void add()
598 {
599 if (remnant.n != 0) {
600
602
603 remnant.reset();
604 }
605 }
606
607
608 /**
609 * Get total signal.
610 *
611 * \return signal
612 */
613 double getSignal() const
614 {
615 return cs.back() * this->fs;
616 }
617
618
619 /**
620 * Get total background.
621 *
622 * \return background
623 */
624 double getBackground() const
625 {
626 return cb.back() * this->fb;
627 }
628
629
630 /**
631 * Set scaling factors of signal and background strengths.
632 *
633 * \param fS signal strength
634 * \param fB background strength
635 */
636 virtual void set(const double fS, const double fB = 1.0) override
637 {
638 for (auto& i : aspera) {
639 i *= fB / this->fb;
640 }
641
642 this->fs = fS;
643 this->fb = fB;
644 }
645
646
647 /**
648 * Get fit method.
649 *
650 * \return fit
651 */
652 virtual JAspera& getAspera() override
653 {
654 return this->fit;
655 }
656
657
658 /**
659 * Generate pseudo experiment and transfer values to fit method.
660 *
661 * \param out output
662 * \return result
663 */
664 virtual stats_type run(JAspera& out) const
665 {
667
668 const size_t ns = gRandom->Poisson(getSignal() * nuisance.signal ->get()); // number of signal events
669 const size_t nb = gRandom->Poisson(getBackground() * nuisance.background->get()); // number of background events
670
671 for (size_t i = ns; i != 0; --i) { out.push_back(aspera[cs.get_index(gRandom->Rndm())]); } // store distributed signal events
672 for (size_t i = nb; i != 0; --i) { out.push_back(aspera[cb.get_index(gRandom->Rndm())]); } // store distributed background events
673
674 return { ns, nb };
675 }
676
677
678 /**
679 * Generate background only pseudo experiment and transfer S/N values to fit method.
680 *
681 * \param out output
682 * \param nb number of background events
683 * \return result
684 */
685 virtual stats_type run(JAspera& out, const size_t nb) const
686 {
688
689 for (size_t i = nb; i != 0; --i) { out.push_back(aspera[cb.get_index(gRandom->Rndm())]); } // store distributed background events
690
691 return { 0, nb };
692 }
693
694
695 /**
696 * Nuisance parameters.
697 */
699
700 /**
701 * Read parameters from input stream.
702 *
703 * \param in input stream
704 * \param parameters parameters
705 * \return input stream
706 */
707 friend inline std::istream& operator>>(std::istream& in, parameters_type& parameters)
708 {
709 return in >> parameters.signal
710 >> parameters.background;
711 }
712
713
714 /**
715 * Write parameters to output stream.
716 *
717 * \param out output stream
718 * \param parameters parameters
719 * \return output stream
720 */
721 friend inline std::ostream& operator<<(std::ostream& out, const parameters_type& parameters)
722 {
723 return out << parameters.signal << ' '
724 << parameters.background;
725 }
726
729
731
732
733 /**
734 * Configure lookup tables.
735 *
736 * \param N number of bins
737 */
738 void configure(size_t N)
739 {
740 cs.configure(N);
741 cb.configure(N);
742 }
743
744 protected:
745 /**
746 * Add objects with PDF of signal and background.
747 *
748 * \param ps pointer to object with PDF of signal
749 * \param pb pointer to object with PDF of background
750 * \return true if added; else false
751 */
752 template<class H_t>
753 bool add(const TObject* ps,
754 const TObject* pb)
755 {
756 if (dynamic_cast<const H_t*>(ps) != NULL &&
757 dynamic_cast<const H_t*>(pb) != NULL) {
758
759 const H_t& hs = dynamic_cast<const H_t&>(*ps);
760 const H_t& hb = dynamic_cast<const H_t&>(*pb);
761
762 if (check(hs, hb)) {
763
764 add(hs, hb);
765
766 return true;
767 }
768 }
769
770 return false;
771 }
772
773
774 /**
775 * Add objects with PDF of signal and background.
776 *
777 * \param pS pointer to object with PDF for generation of signal
778 * \param pB pointer to object with PDF for generation of background
779 * \param ps pointer to object with PDF for evaluation of signal
780 * \param pb pointer to object with PDF for evaluation of background
781 * \return true if added; else false
782 */
783 template<class H_t>
784 bool add(const TObject* pS,
785 const TObject* pB,
786 const TObject* ps,
787 const TObject* pb)
788 {
789 if (dynamic_cast<const H_t*>(pS) != NULL &&
790 dynamic_cast<const H_t*>(pB) != NULL &&
791 dynamic_cast<const H_t*>(ps) != NULL &&
792 dynamic_cast<const H_t*>(pb) != NULL) {
793
794 const H_t& hS = dynamic_cast<const H_t&>(*pS);
795 const H_t& hB = dynamic_cast<const H_t&>(*pB);
796 const H_t& hs = dynamic_cast<const H_t&>(*ps);
797 const H_t& hb = dynamic_cast<const H_t&>(*pb);
798
799 if (check(hS, hB) && check(hB, hs) && check(hs, hb)) {
800
801 add(hS, hB, hs, hb);
802
803 return true;
804 }
805 }
806
807 return false;
808 }
809
810
811 /**
812 * Auxiliary data structure for CDF.
813 */
814 struct cdf_type :
815 public std::vector<double>
816 {
817 /**
818 * Configure lookup table to substitute binary search.
819 *
820 * \param N number of bins
821 */
822 void configure(size_t N)
823 {
824 if (this->size() > 1) {
825
826 index.resize(N);
827
828 size_t p = 0;
829
830 for (size_t i = 0; i != N; ++i) {
831
832 const double x = this->back() * (double) i / (double) N;
833
834 while ((*this)[p+1] < x) {
835 ++p;
836 }
837
838 index[i] = p;
839 }
840 }
841 }
842
843 /**
844 * Get index corresponding to given random value.
845 *
846 * \param rv random value [0,1>
847 * \param option option to force use of binary search
848 * \return index
849 */
850 inline size_t get_index(const double rv, const bool option = false) const
851 {
852 const double value = this->back() * rv;
853
854 if (option || index.empty()) {
855
856 size_t first = 0;
857 size_t count = this->size();
858
859 for (size_t i, step; count != 0; ) {
860
861 step = count / 2;
862 i = first + step;
863
864 if ((*this)[i] < value) {
865 first = ++i;
866 count -= step + 1;
867 } else {
868 count = step;
869 }
870 }
871
872 return first;
873
874 } else {
875
876 size_t i = index[rv * index.size()];
877
878 while (i != this->size() && (*this)[i] < value) {
879 ++i;
880 }
881
882 return i;
883 }
884 }
885
886
887 /**
888 * Put given value.
889 *
890 * \param x value
891 */
892 void put(const double x)
893 {
894 if (this->empty())
895 this->push_back(x);
896 else
897 this->push_back(this->back() + x);
898 }
899
900 private:
901 std::vector<size_t> index; //!< lookup table
902 };
903
904
905 cdf_type cs; //!< CDF of signal
906 cdf_type cb; //!< CDF of background
907
908 JAspera aspera; //!< pre-computed N/S values
909
910 double fs = 1.0; //!< scaling factor signal strength
911 double fb = 1.0; //!< scaling factor background strength
912
913 JAspera fit; //!< fit
914
916
917 void add(const double S, const double B, const double s, const double b)
918 {
919 this->n += 1;
920 this->S += S;
921 this->B += B;
922 this->s += s;
923 this->b += b;
924 }
925
926 void reset()
927 {
928 this->n = 0;
929 this->S = 0.0;
930 this->B = 0.0;
931 this->s = 0.0;
932 this->b = 0.0;
933 }
934
935 size_t n = 0;
936 double S = 0.0;
937 double B = 0.0;
938 double s = 0.0;
939 double b = 0.0;
940
942 };
943}
944
945#endif
Per aspera ad astra.
Experiment.
Nuisance parameter.
std::shared_ptr< JNuisance > nuisance_type
Type definition of generic nuisance.
Definition JNuisance.hh:347
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
void addSignal(const double wS)
Add signal strength.
Definition JAspera.hh:258
double getSignal() const
Get total signal strength.
Definition JAspera.hh:236
void setSignal(const double wS)
Set signal strength.
Definition JAspera.hh:247
void put(const double s, const double b)
Put signal and background to list of pre-computed N/S values.
Definition JAspera.hh:44
double getTestStatisticForUpperLimit(const double ps) const
Get test statistic for given signal strength.
Definition JAspera.hh:218
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 &parameters)
Write parameters to output stream.
friend std::istream & operator>>(std::istream &in, parameters_type &parameters)
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.
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.
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.