136{
139
141
144 size_t numberOfTests;
145 size_t M;
146 double SNR;
147 histogram_type X;
149 double precision;
151
152 try {
153
155
157
159 "douplets of signal and background histograms and doublets of signal and background nuisances, \n"
160 << "\teach of which defined by <file name>:<histogram name> and <type> (values), respectively, \n"
163 zap[
'n'] =
make_field(numberOfTests,
"number of tests");
164 zap[
'M'] =
make_field(M,
"lookup table for CDFs") = 0;
165 zap[
'R'] =
make_field(SNR,
"signal-to-noise ratio") = 0.0;
166 zap[
'x'] =
make_field(X,
"x-axis likelihood histogram") = histogram_type(100, -1.0e3, +1.0e3);
167 zap[
'p'] =
make_field(precision,
"precision") = 1.0e-4;
170
171 zap(argc, argv);
172 }
173 catch(const exception& error) {
174 FATAL(error.what() << endl);
175 }
176
177
178 seed.set(gRandom);
179
180 JExperiment::setSNR(SNR);
181
182 const double Q = 0.9;
183 const double MUMIN = 1.0e-10;
184 const double MUMAX = 1.0e+10;
185 const size_t N = numberOfTests * 5;
186
188
189 for (const auto& i : setup) {
190
195
196 STATUS(printer(
"Signal for generation:", pS) << endl);
197 STATUS(printer(
"Background for generation:", pB) << endl);
198 STATUS(printer(
"Signal for evaluation:", ps) << endl);
199 STATUS(printer(
"Background for evaluation:", pb) << endl);
200
202
203 pi.nuisance = i.nuisance;
204
205 px.push_back(pi);
206 }
207
208 if (M != 0) {
210 }
211
214 STATUS(
"Number of tests: " << setw(10) << numberOfTests << endl);
215
216
218
219 out << *gRandom;
220
221 TH1D h0("h0", NULL, X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
222 TH1D h1("h1", NULL, X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
223
224
225
226
228
229 const JPseudoExperiment::h0_type mu_0(px, numberOfTests);
230
231 for (const double x : mu_0) {
232 h0.Fill(x);
233 }
234
235
237
238 for (size_t i = 0; i != numberOfTests; ++i) {
239
240 if ((i*10) < numberOfTests || (i*10)%numberOfTests == 0) {
242 }
243
245
247
249
251
252 DEBUG(
"pseudo experiment " << setw(3) << aspera.size() <<
' ' <<
FIXED(12,5) <<
result.signal <<
' ' <<
FIXED(12,5) <<
result.likelihood << endl);
253
254 double mu = 0.0;
255
256 if (mu_0.getFractionBelow(
result.signal) > 1.0 - Q) {
257
258 double mumin = 1.0;
259 double mumax = 1.0;
260
261 {
262 for ( ; ; mumax *= 2.0) {
263
265
267
269
271
272 if (ps < 1.0 - Q || mumax > MUMAX) {
273 break;
274 }
275 }
276 }
277
278 if (mumax == 1.0) {
279
280 mumin = 0.5*mumax;
281
282 for ( ; ; mumin *= 0.5) {
283
285
287
289
291
292 if (ps > 1.0 - Q || mumin < MUMIN) {
293 break;
294 }
295 }
296
297 mumax = 2.0*mumin;
298
299 } else {
300
301 mumin = 0.5*mumax;
302 }
303
304 if (mumin < MUMIN)
305 mu = mumin;
306 else if (mumax > MUMAX)
307 mu = mumax;
308 else {
309
310 for ( ; ; ) {
311
312 mu = 0.5 * (mumin + mumax);
313
315
317
319
321
322 if (fabs(ps - (1.0 - Q)) <= precision) {
323 break;
324 }
325
326 if (ps >= 1.0 - Q)
327 mumin = mu;
328 else
329 mumax = mu;
330 }
331 }
332 }
333
334 mu_up.push_back(mu);
335 }
337
338 for (const double x : mu_up) {
339 h1.Fill(x);
340 }
341
342 sort(mu_up.begin(), mu_up.end());
343
344 cout <<
"<mu> " <<
FIXED(7,3) << mu_up[mu_up.size() / 2] << endl;
345
346 out.Write();
347 out.Close();
348}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Auxiliary data structure to fit signal strength using likelihood ratio.
double getTestStatisticForUpperLimit(const double ps) const
Get test statistic for given signal strength.
Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiment...
virtual stats_type run(JAspera &out) const
Generate pseudo experiment and transfer S/N values to fit method.
double getSignal() const
Get total signal.
virtual void set(const double fS, const double fB=1.0) override
Set scaling factors of signal and background strengths.
void configure(size_t N)
Configure lookup tables.
double getBackground() const
Get total background.
dictionary_type & getDictionary()
Get dictionary.
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 ...
Pseudo experiment using CDF for combined generation and likelihood evaluation.
struct JASTRONOMY::JPseudoExperiment::parameters_type nuisance
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Template definition of random value generator.
Auxiliary data structure for floating point format specification.