Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JGen2UpperLimit.cc File Reference

Test application for pseudo experiment generation and likelihood ratio evaluations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <vector>
#include <map>
#include <exception>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TRandom3.h"
#include "JAstronomy/JGen2.hh"
#include "JAstronomy/JGarage.hh"
#include "JAstronomy/JAstronomyToolkit.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JROOT/JRandom.hh"
#include "Jeep/JContainer.hh"
#include "Jeep/JParser.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Test application for pseudo experiment generation and likelihood ratio evaluations.

Author
mdejong

Definition in file JGen2UpperLimit.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 135 of file JGen2UpperLimit.cc.

136{
137 using namespace std;
138 using namespace JPP;
139
140 typedef JAbstractHistogram<double> histogram_type;
141
143 string outputFile;
144 size_t numberOfTests;
145 size_t M;
146 double SNR;
147 histogram_type X;
148 JRandom seed;
149 double precision;
150 int debug;
151
152 try {
153
154 JParser<> zap;
155
157
158 zap['E'] = make_field(setup,
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"
161 << "\twhere <type> can be:" << get_keys(nuisance_helper));
162 zap['o'] = make_field(outputFile, "output file with histograms") = "benchmark.root";
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;
168 zap['S'] = make_field(seed) = 0;
169 zap['d'] = make_field(debug) = 1;
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; // probability limit
183
184 JGen2 px;
185
186 for (const auto& i : setup) {
187
188 const TObject* pS = getObject(i.HS);
189 const TObject* pB = getObject(i.HB);
190 const TObject* ps = getObject(i.Hs);
191 const TObject* pb = getObject(i.Hb);
192
193 STATUS(printer("Signal for generation:", pS) << endl);
194 STATUS(printer("Background for generation:", pB) << endl);
195 STATUS(printer("Signal for evaluation:", ps) << endl);
196 STATUS(printer("Background for evaluation:", pb) << endl);
197
198 JPseudoExperiment pi(pS, pB, ps, pb);
199
200 pi.nuisance = i.nuisance;
201
202 px.push_back(pi);
203 }
204
205 if (M != 0) {
206 px.configure(M);
207 }
208
209 STATUS("Signal: " << FIXED(10,3) << px.getSignal() << endl);
210 STATUS("Background: " << FIXED(10,3) << px.getBackground() << endl);
211 STATUS("Number of tests: " << setw(10) << numberOfTests << endl);
212
213
214 TFile out(outputFile.c_str(), "recreate");
215
216 out << *gRandom;
217
218 TH1D h0("h0", NULL, X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
219 TH1D h1("h1", NULL, X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
220
221
222 // generate background only pseudo experiments and store fitted signals
223
224 px.set(0.0);
225
226 for (size_t i = 0; i != numberOfTests; ++i) {
227
228 JAspera aspera;
229
230 px.run(aspera);
231
232 h0.Fill(aspera(true).signal);
233 }
234
235
236 vector<double> mu_up;
237
238 for (size_t i = 0; i != numberOfTests; ++i) {
239
240 if ((i*10) < numberOfTests || (i*10)%numberOfTests == 0) {
241 STATUS(setw(6) << i << '\r'); DEBUG(endl);
242 }
243
244 JAspera aspera;
245
246 px.set(0.0);
247
248 px.run(aspera);
249
250 mu_up.push_back(px.getSignalStrengthForUpperLimit(aspera, Q, numberOfTests));
251 }
252 STATUS(endl);
253
254 for (const double x : mu_up) {
255 h1.Fill(x);
256 }
257
258 sort(mu_up.begin(), mu_up.end());
259
260 cout << "<mu> " << FIXED(7,3) << mu_up[mu_up.size() / 2] << endl;
261
262 out.Write();
263 out.Close();
264}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
Utility class to parse command line options.
Definition JParser.hh:1664
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
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).
Definition setup.py:1
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Auxiliary data structure to fit signal strength using likelihood ratio.
Definition JAspera.hh:24
Auxiliary data structure to fit signal strength using likelihood ratio for multiple pseudo experiment...
Definition JGen2.hh:28
virtual stats_type run(JAspera &out) const
Generate pseudo experiment and transfer S/N values to fit method.
Definition JGen2.hh:105
double getSignal() const
Get total signal.
Definition JGen2.hh:57
virtual void set(const double fS, const double fB=1.0) override
Set scaling factors of signal and background strengths.
Definition JGen2.hh:80
void configure(size_t N)
Configure lookup tables.
Definition JGen2.hh:44
double getBackground() const
Get total background.
Definition JGen2.hh:68
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.
Pseudo experiment using CDF for combined generation and likelihood evaluation.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:41
Template definition of random value generator.
Simple data structure for histogram binning.