Jpp 20.0.0-72-g597b30bc9
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 //we have slight overcoverage and can't reach requested CL precisely
295 if (( ps <= (1 - Q)) && (mu - mumin < precision) && (mumax - mu < precision)) return mu;
296
297 }
298 }
299 }
300
301 return 0.0;
302 }
303
304 protected:
305 /**
306 * Get probability for given pseudo experiment and signal strength to exceed minimal test statistic for upper limit.
307 *
308 * \param ps signal strength
309 * \param ts test statistic
310 * \param nx number of pseudo experiments
311 */
312 inline double getProbabilityForUpperLimit(const double ps,
313 const double ts,
314 const size_t nx) const
315 {
316 size_t ns = 0;
317
318 for (size_t i = 0; i != nx; ++i) {
319
320 JAspera aspera;
321
322 this->run(aspera);
323
324 if (ps <= std::numeric_limits<double>::min()) {
325
326 if (aspera().signal <= ps) {
327 ns += 1;
328 }
329
330 } else if (aspera.getTestStatisticForUpperLimit(ps) > ts) {
331 ns += 1;
332 }
333 }
334
335 return (double) ns / (double) nx;
336 }
337 };
338
339
340 /**
341 * Pseudo experiment using CDF for combined generation and likelihood evaluation.
342 */
345 {
346 using JPseudoExperiment_t::operator();
347
348 /**
349 * Default constructor.
350 */
353
354
355 /**
356 * Constructor.
357 *
358 * \param hs histogram with PDF of signal
359 * \param hb histogram with PDF of background
360 */
361 template<class H_t>
362 JPseudoExperiment(const H_t& hs,
363 const H_t& hb)
364 {
365 add(hs, hb);
366 }
367
368
369 /**
370 * Constructor.
371 *
372 * \param hS histogram with PDF for generation of signal
373 * \param hB histogram with PDF for generation of background
374 * \param hs histogram with PDF for evaluation of signal
375 * \param hb histogram with PDF for evaluation of background
376 */
377 template<class H_t>
378 JPseudoExperiment(const H_t& hS,
379 const H_t& hB,
380 const H_t& hs,
381 const H_t& hb)
382 {
383 add(hS, hB, hs, hb);
384 }
385
386
387 /**
388 * Add objects with PDFs of signal and background.
389 *
390 * \param ps pointer to object with PDF of signal
391 * \param pb pointer to object with PDF of background
392 */
393 void add(const TObject* ps,
394 const TObject* pb)
395 {
396 if (add<TH3>(ps, pb)) { return; }
397 if (add<TH2>(ps, pb)) { return; }
398 if (add<TH1>(ps, pb)) { return; }
399 }
400
401
402 /**
403 * Add objects with PDFs of signal and background.
404 *
405 * \param pS pointer to object with PDF for generation of signal
406 * \param pB pointer to object with PDF for generation of background
407 * \param ps pointer to object with PDF for evaluation of signal
408 * \param pb pointer to object with PDF for evaluation of background
409 */
410 void add(const TObject* pS,
411 const TObject* pB,
412 const TObject* ps,
413 const TObject* pb)
414 {
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; }
418 }
419
420
421 /**
422 * Add histograms with PDFs of signal and background.
423 *
424 * \param hs histogram with PDF of signal
425 * \param hb histogram with PDF of background
426 */
427 void add(const TH1& hs,
428 const TH1& hb)
429 {
430 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
431 add(hs.GetBinContent(ix),
432 hb.GetBinContent(ix));
433 }
434 }
435
436
437 /**
438 * Add histograms with PDFs of signal and background.
439 *
440 * \param hS histogram with PDF for generation of signal
441 * \param hB histogram with PDF for generation of background
442 * \param hs histogram with PDF for evaluation of signal
443 * \param hb histogram with PDF for evaluation of background
444 */
445 void add(const TH1& hS,
446 const TH1& hB,
447 const TH1& hs,
448 const TH1& hb)
449 {
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));
455 }
456 }
457
458
459 /**
460 * Add histograms with PDFs of signal and background.
461 *
462 * \param hs histogram with PDF of signal
463 * \param hb histogram with PDF of background
464 */
465 void add(const TH2& hs,
466 const TH2& hb)
467 {
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));
472 }
473 }
474 }
475
476
477 /**
478 * Add histograms with PDFs of signal and background.
479 *
480 * \param hS histogram with PDF for generation of signal
481 * \param hB histogram with PDF for generation of background
482 * \param hs histogram with PDF for evaluation of signal
483 * \param hb histogram with PDF for evaluation of background
484 */
485 void add(const TH2& hS,
486 const TH2& hB,
487 const TH2& hs,
488 const TH2& hb)
489 {
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));
496 }
497 }
498 }
499
500
501 /**
502 * Add histograms with PDFs of signal and background.
503 *
504 * \param hs histogram with PDF of signal
505 * \param hb histogram with PDF of background
506 */
507 void add(const TH3& hs,
508 const TH3& hb)
509 {
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));
515 }
516 }
517 }
518 }
519
520
521 /**
522 * Add histograms with PDFs of signal and background.
523 *
524 * \param hS histogram with PDF for generation of signal
525 * \param hB histogram with PDF for generation of background
526 * \param hs histogram with PDF for evaluation of signal
527 * \param hb histogram with PDF for evaluation of background
528 */
529 void add(const TH3& hS,
530 const TH3& hB,
531 const TH3& hs,
532 const TH3& hb)
533 {
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));
541 }
542 }
543 }
544 }
545
546
547 /**
548 * Add signal and background.
549 *
550 * \param s signal
551 * \param b background
552 */
553 void add(const double s,
554 const double b)
555 {
556 if (check(s, b)) {
557
558 cs.put(s);
559 cb.put(b);
560
561 aspera.put(s, b);
562
563 } else {
564
565 remnant.add(s, b, s, b);
566 }
567 }
568
569
570 /**
571 * Add signal and background.
572 *
573 * \param S signal for generation
574 * \param B background for generation
575 * \param s signal for evaluation
576 * \param b background for evaluation
577 */
578 void add(const double S,
579 const double B,
580 const double s,
581 const double b)
582 {
583 if (//check(S, B) &&
584 check(s, b)) {
585
586 cs.put(S);
587 cb.put(B);
588
589 aspera.put(s, b);
590
591 } else {
592
593 remnant.add(S, B, s, b);
594 }
595 }
596
597
598 /**
599 * Add remnant signal and background.
600 */
601 void add()
602 {
603 if (remnant.n != 0) {
604
606
607 remnant.reset();
608 }
609 }
610
611
612 /**
613 * Get total signal.
614 *
615 * \return signal
616 */
617 double getSignal() const
618 {
619 return cs.back() * this->fs;
620 }
621
622
623 /**
624 * Get total background.
625 *
626 * \return background
627 */
628 double getBackground() const
629 {
630 return cb.back() * this->fb;
631 }
632
633
634 /**
635 * Set scaling factors of signal and background strengths.
636 *
637 * \param fS signal strength
638 * \param fB background strength
639 */
640 virtual void set(const double fS, const double fB = 1.0) override
641 {
642 for (auto& i : aspera) {
643 i *= fB / this->fb;
644 }
645
646 this->fs = fS;
647 this->fb = fB;
648 }
649
650
651 /**
652 * Get fit method.
653 *
654 * \return fit
655 */
656 virtual JAspera& getAspera() override
657 {
658 return this->fit;
659 }
660
661
662 /**
663 * Generate pseudo experiment and transfer values to fit method.
664 *
665 * \param out output
666 * \return result
667 */
668 virtual stats_type run(JAspera& out) const
669 {
671
672 const size_t ns = gRandom->Poisson(getSignal() * nuisance.signal ->get()); // number of signal events
673 const size_t nb = gRandom->Poisson(getBackground() * nuisance.background->get()); // number of background events
674
675 for (size_t i = ns; i != 0; --i) { out.push_back(aspera[cs.get_index(gRandom->Rndm())]); } // store distributed signal events
676 for (size_t i = nb; i != 0; --i) { out.push_back(aspera[cb.get_index(gRandom->Rndm())]); } // store distributed background events
677
678 return { ns, nb };
679 }
680
681
682 /**
683 * Generate background only pseudo experiment and transfer S/N values to fit method.
684 *
685 * \param out output
686 * \param nb number of background events
687 * \return result
688 */
689 virtual stats_type run(JAspera& out, const size_t nb) const
690 {
692
693 for (size_t i = nb; i != 0; --i) { out.push_back(aspera[cb.get_index(gRandom->Rndm())]); } // store distributed background events
694
695 return { 0, nb };
696 }
697
698
699 /**
700 * Nuisance parameters.
701 */
703
704 /**
705 * Read parameters from input stream.
706 *
707 * \param in input stream
708 * \param parameters parameters
709 * \return input stream
710 */
711 friend inline std::istream& operator>>(std::istream& in, parameters_type& parameters)
712 {
713 return in >> parameters.signal
714 >> parameters.background;
715 }
716
717
718 /**
719 * Write parameters to output stream.
720 *
721 * \param out output stream
722 * \param parameters parameters
723 * \return output stream
724 */
725 friend inline std::ostream& operator<<(std::ostream& out, const parameters_type& parameters)
726 {
727 return out << parameters.signal << ' '
728 << parameters.background;
729 }
730
731 nuisance_type signal = std::make_shared<JNuisanceFixed>();
732 nuisance_type background = std::make_shared<JNuisanceFixed>();
733
735
736
737 /**
738 * Configure lookup tables.
739 *
740 * \param N number of bins
741 */
742 void configure(size_t N)
743 {
744 cs.configure(N);
745 cb.configure(N);
746 }
747
748 protected:
749 /**
750 * Add objects with PDF of signal and background.
751 *
752 * \param ps pointer to object with PDF of signal
753 * \param pb pointer to object with PDF of background
754 * \return true if added; else false
755 */
756 template<class H_t>
757 bool add(const TObject* ps,
758 const TObject* pb)
759 {
760 if (dynamic_cast<const H_t*>(ps) != NULL &&
761 dynamic_cast<const H_t*>(pb) != NULL) {
762
763 const H_t& hs = dynamic_cast<const H_t&>(*ps);
764 const H_t& hb = dynamic_cast<const H_t&>(*pb);
765
766 if (check(hs, hb)) {
767
768 add(hs, hb);
769
770 return true;
771 }
772 }
773
774 return false;
775 }
776
777
778 /**
779 * Add objects with PDF of signal and background.
780 *
781 * \param pS pointer to object with PDF for generation of signal
782 * \param pB pointer to object with PDF for generation of background
783 * \param ps pointer to object with PDF for evaluation of signal
784 * \param pb pointer to object with PDF for evaluation of background
785 * \return true if added; else false
786 */
787 template<class H_t>
788 bool add(const TObject* pS,
789 const TObject* pB,
790 const TObject* ps,
791 const TObject* pb)
792 {
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) {
797
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);
802
803 if (check(hS, hB) && check(hB, hs) && check(hs, hb)) {
804
805 add(hS, hB, hs, hb);
806
807 return true;
808 }
809 }
810
811 return false;
812 }
813
814
815 /**
816 * Auxiliary data structure for CDF.
817 */
818 struct cdf_type :
819 public std::vector<double>
820 {
821 /**
822 * Configure lookup table to substitute binary search.
823 *
824 * \param N number of bins
825 */
826 void configure(size_t N)
827 {
828 if (this->size() > 1) {
829
830 index.resize(N);
831
832 size_t p = 0;
833
834 for (size_t i = 0; i != N; ++i) {
835
836 const double x = this->back() * (double) i / (double) N;
837
838 while ((*this)[p+1] < x) {
839 ++p;
840 }
841
842 index[i] = p;
843 }
844 }
845 }
846
847 /**
848 * Get index corresponding to given random value.
849 *
850 * \param rv random value [0,1>
851 * \param option option to force use of binary search
852 * \return index
853 */
854 inline size_t get_index(const double rv, const bool option = false) const
855 {
856 const double value = this->back() * rv;
857
858 if (option || index.empty()) {
859
860 size_t first = 0;
861 size_t count = this->size();
862
863 for (size_t i, step; count != 0; ) {
864
865 step = count / 2;
866 i = first + step;
867
868 if ((*this)[i] < value) {
869 first = ++i;
870 count -= step + 1;
871 } else {
872 count = step;
873 }
874 }
875
876 return first;
877
878 } else {
879
880 size_t i = index[rv * index.size()];
881
882 while (i != this->size() && (*this)[i] < value) {
883 ++i;
884 }
885
886 return i;
887 }
888 }
889
890
891 /**
892 * Put given value.
893 *
894 * \param x value
895 */
896 void put(const double x)
897 {
898 if (this->empty())
899 this->push_back(x);
900 else
901 this->push_back(this->back() + x);
902 }
903
904 private:
905 std::vector<size_t> index; //!< lookup table
906 };
907
908
909 cdf_type cs; //!< CDF of signal
910 cdf_type cb; //!< CDF of background
911
912 JAspera aspera; //!< pre-computed N/S values
913
914 double fs = 1.0; //!< scaling factor signal strength
915 double fb = 1.0; //!< scaling factor background strength
916
917 JAspera fit; //!< fit
918
920
921 void add(const double S, const double B, const double s, const double b)
922 {
923 this->n += 1;
924 this->S += S;
925 this->B += B;
926 this->s += s;
927 this->b += b;
928 }
929
930 void reset()
931 {
932 this->n = 0;
933 this->S = 0.0;
934 this->B = 0.0;
935 this->s = 0.0;
936 this->b = 0.0;
937 }
938
939 size_t n = 0;
940 double S = 0.0;
941 double B = 0.0;
942 double s = 0.0;
943 double b = 0.0;
944
946 };
947}
948
949#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:269
double getSignal() const
Get total signal strength.
Definition JAspera.hh:247
void setSignal(const double wS)
Set signal strength.
Definition JAspera.hh:258
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:229
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.