Jpp 20.0.0-rc.9-4-g539b3ce77
the software that should make you happy
Loading...
Searching...
No Matches
JRealExperiment.hh
Go to the documentation of this file.
1#ifndef __JASTRONOMY__JREALEXPERIMENT__
2#define __JASTRONOMY__JREALEXPERIMENT__
3
4#include <vector>
5
6#include "TObject.h"
7#include "TH1.h"
8#include "TH2.h"
9#include "TH3.h"
10
12#include "JAstronomy/JAspera.hh"
13
14
15/**
16 * \file
17 *
18 * Real experiment.
19 * \author mdejong
20 */
21namespace JASTRONOMY {}
22namespace JPP { using namespace JASTRONOMY; }
23
24namespace JASTRONOMY {
25
26 /**
27 * Real experiment using PDF of signal and background.
28 */
30 public JExperiment,
31 public JAspera
32 {
33 /**
34 * Default constructor.
35 */
38
39
40 /**
41 * Constructor.
42 *
43 * \param hd histogram with data
44 * \param hs histogram with PDF of signal
45 * \param hb histogram with PDF of background
46 */
47 template<class H_t>
48 JRealExperiment(const H_t& hd,
49 const H_t& hs,
50 const H_t& hb)
51 {
52 add(hd, hs, hb);
53 }
54
55
56 /**
57 * Add objects with data and PDFs of signal and background.
58 *
59 * \param pd pointer to object with data
60 * \param ps pointer to object with PDF of signal
61 * \param pb pointer to object with PDF of background
62 */
63 void add(const TObject* pd,
64 const TObject* ps,
65 const TObject* pb)
66 {
67 if (add<TH3>(pd, ps, pb)) { return; }
68 if (add<TH2>(pd, ps, pb)) { return; }
69 if (add<TH1>(pd, ps, pb)) { return; }
70 }
71
72
73 /**
74 * Add histograms with data and PDFs of signal and background.
75 *
76 * \param hd histogram with data
77 * \param hs histogram with PDF of signal
78 * \param hb histogram with PDF of background
79 */
80 void add(const TH1& hd,
81 const TH1& hs,
82 const TH1& hb)
83 {
84 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
85 add(hd.GetBinContent(ix),
86 hs.GetBinContent(ix),
87 hb.GetBinContent(ix));
88 }
89 }
90
91
92 /**
93 * Add histograms with data and PDFs of signal and background.
94 *
95 * \param hd histogram with data
96 * \param hs histogram with PDF of signal
97 * \param hb histogram with PDF of background
98 */
99 void add(const TH2& hd,
100 const TH2& hs,
101 const TH2& hb)
102 {
103 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
104 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
105 add(hd.GetBinContent(ix, iy),
106 hs.GetBinContent(ix, iy),
107 hb.GetBinContent(ix, iy));
108 }
109 }
110 }
111
112
113 /**
114 * Add histograms with data and PDFs of signal and background.
115 *
116 * \param hd histogram with data
117 * \param hs histogram with PDF of signal
118 * \param hb histogram with PDF of background
119 */
120 void add(const TH3& hd,
121 const TH3& hs,
122 const TH3& hb)
123 {
124 for (Int_t ix = 1; ix <= hs.GetXaxis()->GetNbins(); ++ix) {
125 for (Int_t iy = 1; iy <= hs.GetYaxis()->GetNbins(); ++iy) {
126 for (Int_t iz = 1; iz <= hs.GetZaxis()->GetNbins(); ++iz) {
127 add(hd.GetBinContent(ix, iy, iz),
128 hs.GetBinContent(ix, iy, iz),
129 hb.GetBinContent(ix, iy, iz));
130 }
131 }
132 }
133 }
134
135
136 /**
137 * Add data, signal and background.
138 *
139 * \param n data
140 * \param s signal
141 * \param b background
142 */
143 void add(const size_t n,
144 const double s,
145 const double b)
146 {
147 if (check(s, b)) {
148 put(n, s, b);
149 } else {
150 remnant.add(n, s, b);
151 }
152 }
153
154
155 /**
156 * Add remnant data, signal and background.
157 */
158 void add()
159 {
160 if (remnant.n != 0) {
161
163
164 remnant.reset();
165 }
166 }
167
168 protected:
169 /**
170 * Add objects with data and PDFs of signal and background.
171 *
172 * \param pd pointer to object with data
173 * \param ps pointer to object with PDF of signal
174 * \param pb pointer to object with PDF of background
175 * \return true if added; else false
176 */
177 template<class H_t>
178 bool add(const TObject* pd,
179 const TObject* ps,
180 const TObject* pb)
181 {
182 if (dynamic_cast<const H_t*>(pd) != NULL &&
183 dynamic_cast<const H_t*>(ps) != NULL &&
184 dynamic_cast<const H_t*>(pb) != NULL) {
185
186 const H_t& hd = dynamic_cast<const H_t&>(*pd);
187 const H_t& hs = dynamic_cast<const H_t&>(*ps);
188 const H_t& hb = dynamic_cast<const H_t&>(*pb);
189
190 if (check(hd, hs) && check(hs, hb)) {
191
192 add(hd, hs, hb);
193
194 return true;
195 }
196 }
197
198 return false;
199 }
200
201
203
204 void add(const size_t n, const double s, const double b)
205 {
206 this->n += n;
207 this->s += s;
208 this->b += b;
209 }
210
211 void reset()
212 {
213 this->n = 0;
214 this->s = 0.0;
215 this->b = 0.0;
216 }
217
218 size_t n = 0;
219 double s = 0.0;
220 double b = 0.0;
221
223 };
224}
225
226#endif
Per aspera ad astra.
Experiment.
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 put(const double s, const double b)
Put signal and background to list of pre-computed N/S values.
Definition JAspera.hh:44
Auxiliary base class for experiment.
static bool check(const double s, const double b)
Check validity of signal and background.
void add(const size_t n, const double s, const double b)
Real experiment using PDF of signal and background.
void add()
Add remnant data, signal and background.
void add(const TH2 &hd, const TH2 &hs, const TH2 &hb)
Add histograms with data and PDFs of signal and background.
void add(const TH1 &hd, const TH1 &hs, const TH1 &hb)
Add histograms with data and PDFs of signal and background.
void add(const TH3 &hd, const TH3 &hs, const TH3 &hb)
Add histograms with data and PDFs of signal and background.
struct JASTRONOMY::JRealExperiment::remnant_type remnant
JRealExperiment()
Default constructor.
void add(const TObject *pd, const TObject *ps, const TObject *pb)
Add objects with data and PDFs of signal and background.
JRealExperiment(const H_t &hd, const H_t &hs, const H_t &hb)
Constructor.
bool add(const TObject *pd, const TObject *ps, const TObject *pb)
Add objects with data and PDFs of signal and background.
void add(const size_t n, const double s, const double b)
Add data, signal and background.