29 double inf = numeric_limits<double>::infinity();
32 int main(
int argc,
char *argv[]){
34 cerr <<
"Must supply 8 rates as arguments: bkg A, bkg B, bkg C, bkg D, sig A, sig B, sig C, sig D" << endl;
42 double bkg_a = atof(argv[1]);
43 double bkg_b = atof(argv[2]);
44 double bkg_c = atof(argv[3]);
45 double bkg_d = atof(argv[4]);
49 bkg_a, bkg_b, bkg_c, bkg_d);
52 double sig_a = atof(argv[5]);
53 double sig_b = atof(argv[6]);
54 double sig_c = atof(argv[7]);
55 double sig_d = atof(argv[8]);
58 double tot_a = bkg_a + sig_a;
59 double tot_b = bkg_b + sig_b;
60 double tot_c = bkg_c + sig_c;
61 double tot_d = bkg_d + sig_d;
64 double pred_a, pred_b, pred_c, pred_d;
66 pred_a, pred_b, pred_c, pred_d);
69 PrintRates(cout,
"Background", bkg_a, bkg_b, bkg_c, bkg_d);
70 PrintRates(cout,
" Signal", sig_a, sig_b, sig_c, sig_d);
71 PrintRates(cout,
" Total", tot_a, tot_b, tot_c, tot_d);
72 PrintRates(cout,
" ABCD", pred_a, pred_b, pred_c, pred_d);
77 cout <<
"Z-score: " << setprecision(6) << z << endl;
94 for(
int i = 1; i < argc - 1; ++i){
95 oss << argv[i] <<
"_";
104 double pred_a, pred_b, pred_c, pred_d;
106 pred_a, pred_b, pred_c, pred_d);
119 double q = 2.*(alt_ll-null_ll);
120 return q >= 0. ? q : 0.;
124 return erfc(sqrt(0.5*q));
136 return erfc(z/sqrt(2.));
140 double cp = 1.-0.5*p;
141 return cp <= 0. ? -
inf 143 : TMath::NormQuantile(cp);
151 vector<double> out(sb_qs.size());
152 for(
size_t i = 0; i < out.size(); ++i){
159 vector<double> out(sb_qs.size());
160 for(
size_t i = 0; i < out.size(); ++i){
161 out.at(i) =
QToZ(sb_qs.at(i));
167 return static_cast<double>(distance(
lower_bound(qs.begin(), qs.end(), q), qs.end()))/qs.size();
171 vector<double> out(n);
172 poisson_distribution<unsigned> pa(a), pb(b), pc(c), pd(d);
173 for(
size_t i = 0; i < n; ++i){
175 b > 0. ? pb(prng) : 0.,
176 c > 0. ? pc(prng) : 0.,
177 d > 0. ? pd(prng) : 0.);
179 sort(out.begin(), out.end());
184 double &a_out,
double &b_out,
double &c_out,
double &d_out){
185 double total = a_in + b_in + c_in + d_in;
186 a_out = total ? (a_in+b_in)*(a_in+c_in)/total : 0.;
187 b_out = total ? (a_in+b_in)*(b_in+d_in)/total : 0.;
188 c_out = total ? (a_in+c_in)*(c_in+d_in)/total : 0.;
189 d_out = total ? (b_in+d_in)*(c_in+d_in)/total : 0.;
193 return (pred > 0.) ? (obs*log(pred) - pred) : (obs > 0. ? -
inf : 0.);
197 double a,
double b,
double c,
double d){
198 out << fixed << showpoint << setprecision(2);
201 <<
' ' << setw(8) << a
202 <<
' ' << setw(8) << b
203 <<
' ' << setw(8) << c
204 <<
' ' << setw(8) << d
209 array<int, mt19937::state_size> vals;
211 generate(vals.begin(), vals.end(), ref(rd));
212 seed_seq ss(vals.begin(), vals.end());
217 const vector<double> &b_qs,
218 const vector<double> &sb_qs){
219 TH1D hb(
"hb", (params+
";-2*ln(L_{null}/L_{alt});PDF").c_str(), 100, 0., 30.);
220 hb.SetLineColor(kGreen+2);
224 TH1D hsb(
"hsb", (params+
";-2*ln(L_{null}/L_{alt});PDF").c_str(), 100, 0., 30.);
225 hsb.SetLineColor(kRed+2);
230 for(
const double &q: b_qs) hb.Fill(q);
231 for(
const double &q: sb_qs) hsb.Fill(q);
236 TF1 pdf(
"pdf",
"ROOT::Math::chisquared_pdf(x,1.)", 0., 30.);
237 pdf.SetTitle((params+
";-2*ln(L_{null}/L_{alt});PDF").c_str());
239 pdf.SetLineColor(kBlack);
243 pdf.SetMinimum(1
e-8);
245 TLegend l(0.1, 0.1, 0.4, 0.4);
246 l.AddEntry(&hsb,
"S+B",
"le");
247 l.AddEntry(&hb,
"B-only",
"le");
248 l.AddEntry(&pdf,
"#chi^{2}(1)",
"l");
256 c.Print((
"q_"+params+
".pdf").c_str());
260 const vector<double> &b_qs,
261 const vector<double> &sb_qs,
263 TH1D htoy(
"htoy", (params+
";Significance;PDF").c_str(), 100, 0., 10.);
264 htoy.SetLineColor(kRed+2);
265 htoy.SetLineStyle(1);
266 htoy.SetLineWidth(4);
267 htoy.SetStats(
false);
268 TH1D hasympt(
"hasympt", (params+
";Significance;PDF").c_str(), 100, 0., 10.);
269 hasympt.SetLineColor(kBlack);
270 hasympt.SetLineStyle(2);
271 hasympt.SetLineWidth(4);
272 hasympt.SetStats(
false);
273 TH1D hnull(
"hnull", (params+
";Significance;PDF").c_str(), 100, 0., 10.);
274 hnull.SetLineColor(kGreen+2);
275 hnull.SetLineStyle(1);
276 hnull.SetLineWidth(4);
277 hnull.SetStats(
false);
278 TF1 pdf(
"pdf",
"2*TMath::Gaus(x,0,1,1)", 0., 10.);
280 pdf.SetTitle((params+
";Significance;PDF").c_str());
281 pdf.SetLineColor(kBlack);
287 for(
const double &zi: toy_zs) htoy.Fill(zi);
288 for(
const double &q: sb_qs) hasympt.Fill(
QToZ(q));
289 for(
const double &q: b_qs) hnull.Fill(
QToZ(q));
298 TLine line(z, 0., z, 1.);
299 line.SetLineColor(kRed+2);
300 line.SetLineStyle(3);
301 line.SetLineWidth(2);
303 TLegend
leg(0.6, 0.6, 0.9, 0.9);
304 leg.AddEntry(&htoy,
"S+B (toys)",
"l");
305 leg.AddEntry(&hnull,
"B-only (toys)",
"l");
306 leg.AddEntry(&hasympt,
"S+B (asympt)",
"l");
307 leg.AddEntry(&pdf,
"B-only (asympt)",
"l");
311 hasympt.Draw(
"hist same");
312 hnull.Draw(
"hist same");
313 htoy.Draw(
"hist same");
315 if(z >= 0.) line.Draw(
"same");
316 c.Print((
"z_"+params+
".pdf").c_str());
320 int nbins = h.GetNbinsX();
321 double entries = h.GetEntries();
323 h.SetBinContent(1, h.GetBinContent(0)+h.GetBinContent(1));
324 h.SetBinError(1, hypot(h.GetBinError(0), h.GetBinError(1)));
325 h.SetBinContent(nbins, h.GetBinContent(nbins)+h.GetBinContent(nbins+1));
326 h.SetBinError(nbins, hypot(h.GetBinError(nbins), h.GetBinError(nbins+1)));
328 h.SetBinContent(0, 0.);
329 h.SetBinError(0, 0.);
330 h.SetBinContent(nbins+1, 0.);
331 h.SetBinError(nbins+1, 0.);
333 h.Scale(1./h.Integral(
"width"));
334 h.SetEntries(entries);
338 return h.GetBinContent(h.GetMaximumBin());
double RealMax(const TH1D &h)
vector< double > GetSignificances(const vector< double > &b_qs, const vector< double > &sb_qs)
double FindFraction(const vector< double > &qs, double q)
double GetTestStatistic(double a, double b, double c, double d)
int main(int argc, char *argv[])
double BinLogLikelihood(double obs, double pred)
void PrintRates(ostream &out, const string &name, double a, double b, double c, double d)
void InitializePRNG(mt19937 &prng)
void PlotZDistributions(const string ¶ms, const vector< double > &b_qs, const vector< double > &sb_qs, double z)
string GetParamString(int argc, char *argv[])
void GetPredictions(double a_in, double b_in, double c_in, double d_in, double &a_out, double &b_out, double &c_out, double &d_out)
void NormalizeWithOverflow(TH1D &h)
void PlotQDistributions(const string ¶ms, const vector< double > &b_qs, const vector< double > &sb_qs)
vector< double > SampleTestStatistic(mt19937 &prng, size_t n, double a, double b, double c, double d)