CMS 3D CMS Logo

BinomialInterval.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_RooStatsCms_BinomialInterval_h
2 #define PhysicsTools_RooStatsCms_BinomialInterval_h
3 /* \class BinomialInterval
4  *
5  * \author Jordan Tucker
6  * integration in CMSSW: Luca Lista
7  *
8  */
9 
10 
11 #if (defined (STANDALONE) or defined (__CINT__) )
12 #include "TNamed.h"
13 #endif
14 
15 // A class to implement the calculation of intervals for the binomial
16 // parameter rho. The bulk of the work is done by derived classes that
17 // implement calculate() appropriately.
19 #if (defined (STANDALONE) or defined (__CINT__) )
20 : public TNamed
21 #endif
22 {
23 public:
24  // For central intervals, an enum to indicate whether the interval
25  // should put all of alpha at the lower or upper end, or equally
26  // divide it.
28 
29  // Set alpha, type, and the cached values of kappa (the normal
30  // quantile).
31  void init(const double alpha, const tail_type t=equal_tailed);
32 
33  virtual ~BinomialInterval() = default;
34  // Methods which derived classes must implement.
35 
36  // Calculate the interval given a number of successes and a number
37  // of trials. (Successes/trials are doubles to having to cast to
38  // double later anyway.)
39  virtual void calculate(const double successes, const double trials) = 0;
40 
41  // Return a pretty name for the interval (e.g. "Feldman-Cousins").
42  virtual const char* name() const = 0;
43 
44  // A simple test (depending on the tail type) whether a certain
45  // value of the binomial parameter rho is in the interval or not.
46  bool contains(double rho);
47 
48  // Calculate and return the coverage probability given the true
49  // binomial parameter rho and the number of trials.
50  double coverage_prob(const double rho, const int trials);
51 
52  // Convenience methods to scan the parameter space. In each, the
53  // pointers must point to already-allocated arrays of double, with
54  // the number of doubles depending on the method. (double is used
55  // even for parameters that are naturally int for compatibility with
56  // TGraph/etc.)
57 
58  // Given ntot trials, scan rho in [0,1] with nrho points (so the
59  // arrays must be allocated double[nrho]).
60  void scan_rho(const int ntot, const int nrho, double* rho, double* prob);
61 
62  // Given the true value of rho, scan over from ntot_min to ntot_max
63  // trials (so the arrays must be allocated double[ntot_max -
64  // ntot_min + 1]).
65  void scan_ntot(const double rho, const int ntot_min, const int ntot_max, double* ntot, double* prob);
66 
67  // Construct nrho acceptance sets in rho = [0,1] given ntot trials
68  // and put the results in x_l and x_r. The arrays must be allocated
69  // as double[nrho].
70  virtual bool neyman(const int ntot, const int nrho, double* rho, double* x_l, double* x_r) { return false; }
71 
72  // Dump a table of intervals from trials_min to trials_max, with
73  // successes = 0 to trials for each. The table is produced in a file
74  // in the current directory, given the name of the interval.
75  void dump(const int trials_min, const int trials_max);
76 
77  // Simple accessors.
78  double alpha() const { return alpha_; }
79  double lower() const { return lower_; }
80  double upper() const { return upper_; }
81  double length() const { return upper_ - lower_; }
82 
83 protected:
84  double alpha_;
86  double alpha_min_;
87  double kappa_;
88  double kappa2_;
89 
90  double lower_;
91  double upper_;
92 
93  void set(double l, double u) { lower_ = l; upper_ = u; }
94 
95 #if (defined (STANDALONE) or defined (__CINT__) )
96 ClassDef(BinomialInterval,1)
97 #endif
98 };
99 
100 #endif
101 
virtual const char * name() const =0
virtual bool neyman(const int ntot, const int nrho, double *rho, double *x_l, double *x_r)
double upper() const
virtual void calculate(const double successes, const double trials)=0
double alpha() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void init(const double alpha, const tail_type t=equal_tailed)
void scan_rho(const int ntot, const int nrho, double *rho, double *prob)
virtual ~BinomialInterval()=default
double lower() const
double coverage_prob(const double rho, const int trials)
double length() const
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)