CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/PhysicsTools/RooStatsCms/interface/BinomialInterval.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_RooStatsCms_BinomialInterval_h
00002 #define PhysicsTools_RooStatsCms_BinomialInterval_h
00003 /* \class BinomialInterval
00004  *
00005  * \author Jordan Tucker
00006  * integration in CMSSW: Luca Lista
00007  *
00008  */
00009 
00010 
00011 #if (defined (STANDALONE) or defined (__CINT__) )
00012 #include "TNamed.h"
00013 #endif
00014 
00015 // A class to implement the calculation of intervals for the binomial
00016 // parameter rho. The bulk of the work is done by derived classes that
00017 // implement calculate() appropriately.
00018 class BinomialInterval 
00019 #if (defined (STANDALONE) or defined (__CINT__) )
00020 : public TNamed
00021 #endif
00022 {
00023 public:
00024   // For central intervals, an enum to indicate whether the interval
00025   // should put all of alpha at the lower or upper end, or equally
00026   // divide it.
00027   enum tail_type { equal_tailed, lower_tailed, upper_tailed };
00028 
00029   // Set alpha, type, and the cached values of kappa (the normal
00030   // quantile).
00031   void init(const double alpha, const tail_type t=equal_tailed);
00032 
00033   // Methods which derived classes must implement.
00034 
00035   // Calculate the interval given a number of successes and a number
00036   // of trials. (Successes/trials are doubles to having to cast to
00037   // double later anyway.)
00038   virtual void calculate(const double successes, const double trials) = 0;
00039 
00040   // Return a pretty name for the interval (e.g. "Feldman-Cousins").
00041   virtual const char* name() const = 0;
00042 
00043   // A simple test (depending on the tail type) whether a certain
00044   // value of the binomial parameter rho is in the interval or not.
00045   bool contains(double rho);
00046   
00047   // Calculate and return the coverage probability given the true
00048   // binomial parameter rho and the number of trials.
00049   double coverage_prob(const double rho, const int trials);
00050 
00051   // Convenience methods to scan the parameter space. In each, the
00052   // pointers must point to already-allocated arrays of double, with
00053   // the number of doubles depending on the method. (double is used
00054   // even for parameters that are naturally int for compatibility with
00055   // TGraph/etc.)
00056 
00057   // Given ntot trials, scan rho in [0,1] with nrho points (so the
00058   // arrays must be allocated double[nrho]).
00059   void scan_rho(const int ntot, const int nrho, double* rho, double* prob);
00060 
00061   // Given the true value of rho, scan over from ntot_min to ntot_max
00062   // trials (so the arrays must be allocated double[ntot_max -
00063   // ntot_min + 1]).
00064   void scan_ntot(const double rho, const int ntot_min, const int ntot_max, double* ntot, double* prob);
00065 
00066   // Construct nrho acceptance sets in rho = [0,1] given ntot trials
00067   // and put the results in x_l and x_r. The arrays must be allocated
00068   // as double[nrho].
00069   virtual bool neyman(const int ntot, const int nrho, double* rho, double* x_l, double* x_r) { return false; } 
00070 
00071   // Dump a table of intervals from trials_min to trials_max, with
00072   // successes = 0 to trials for each. The table is produced in a file
00073   // in the current directory, given the name of the interval.
00074   void dump(const int trials_min, const int trials_max);
00075 
00076   // Simple accessors.
00077   double alpha() const { return alpha_; }
00078   double lower() const { return lower_; }
00079   double upper() const { return upper_; }
00080   double length() const { return upper_ - lower_; }
00081 
00082 protected:
00083   double    alpha_;
00084   tail_type type_;
00085   double    alpha_min_;
00086   double    kappa_;
00087   double    kappa2_;
00088 
00089   double lower_;
00090   double upper_;
00091 
00092   void set(double l, double u) { lower_ = l; upper_ = u; }
00093 
00094 #if (defined (STANDALONE) or defined (__CINT__) )
00095 ClassDef(BinomialInterval,1)
00096 #endif
00097 };
00098 
00099 #endif
00100