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