CMS 3D CMS Logo

BinomialInterval.cc
Go to the documentation of this file.
1 #include <string>
2 #include <cstdio>
3 #include "Math/PdfFuncMathCore.h"
4 #include "Math/QuantFuncMathCore.h"
5 
6 #if (defined (STANDALONE) or defined (__CINT__) )
7 #include "BinomialInterval.h"
8 
10 #else
12 #endif
13 
14 void BinomialInterval::init(const double alpha, const tail_type type) {
15  alpha_ = alpha;
16  type_ = type;
18  kappa_ = ROOT::Math::normal_quantile(1 - alpha/2, 1);
20 }
21 
23  if (type_ == upper_tailed)
24  return p <= upper_;
25  else if (type_ == lower_tailed)
26  return p >= lower_;
27  else //if (type_ == equal_tailed)
28  return p >= lower_ && p <= upper_;
29 }
30 
31 double BinomialInterval::coverage_prob(const double p, const int trials) {
32  double prob = 0;
33 
34  for (int X = 0; X <= trials; ++X) {
35  calculate(X, trials);
36 
37  if (contains(p))
38  prob += ROOT::Math::binomial_pdf(X, p, trials);
39  }
40 
41  return prob;
42 }
43 
44 void BinomialInterval::scan_rho(const int ntot, const int nrho, double* rho, double* prob) {
45  for (int i = 0; i < nrho; ++i) {
46  rho[i] = double(i)/nrho;
47  prob[i] = coverage_prob(rho[i], ntot);
48  }
49 }
50 
51 void BinomialInterval::scan_ntot(const double rho, const int ntot_min, const int ntot_max,
52  double* ntot, double* prob) {
53  for (int i = 0; i < ntot_max - ntot_min + 1; ++i) {
54  int nt = i + ntot_min;
55  ntot[i] = nt;
56  prob[i] = coverage_prob(rho, nt);
57  }
58 }
59 
60 void BinomialInterval::dump(const int trials_min, const int trials_max) {
61  const std::string fn = std::string("table.") + name() + std::string(".txt");
62  FILE* fdump = fopen(fn.c_str(), "wt");
63 
64  for (int n = trials_min; n <= trials_max; ++n) {
65  for (int X = 0; X <= n; X++) {
66  calculate(X, n);
67  fprintf(fdump, "%i %i %f %f\n", X, n, lower_, upper_);
68  }
69  fprintf(fdump, "\n");
70  }
71 
72  fclose(fdump);
73 }
type
Definition: HCALResponse.h:21
float alpha
Definition: AMPTWrapper.h:95
virtual const char * name() const =0
virtual void calculate(const double successes, const double trials)=0
double alpha() const
#define X(str)
Definition: MuonsGrabber.cc:48
void init(const double alpha, const tail_type t=equal_tailed)
void scan_rho(const int ntot, const int nrho, double *rho, double *prob)
int nt
Definition: AMPTWrapper.h:32
double coverage_prob(const double rho, const int trials)
ClassImp(BinomialInterval)
bool contains(double rho)
void scan_ntot(const double rho, const int ntot_min, const int ntot_max, double *ntot, double *prob)
void dump(const int trials_min, const int trials_max)