CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CommonTools/Statistics/interface/BinomialProbability.h

Go to the documentation of this file.
00001 #ifndef BinomialProbability_H
00002 #define BinomialProbability_H
00003 
00010 class BinomialProbability {
00011 public:
00012 
00013   BinomialProbability() : theHits(0), theTotal(0) {}
00014   
00015   BinomialProbability(int hits, int entries) : 
00016     theHits(hits), theTotal(entries) {}
00017 
00018   float value() const {
00019     return theTotal == 0 ? 0 :float(theHits) / float(theTotal);
00020   }
00021   
00022   float error() const {
00023     float p = value();
00024     return theTotal <= 1 ? 0 : sqrt( p*(1.f - p)/(theTotal-1));
00025   }
00026   
00027   int entries() const { return theTotal;}
00028   
00029   int hits() const { return theHits;}
00030   
00031   void hit() { theHits++; theTotal++;}
00032   
00033   void miss() { theTotal++;}
00034   
00035   void update( bool hit) {
00036     if ( hit) theHits++;
00037     theTotal++;
00038   }
00039 
00040 private:
00041   
00042   int theHits;
00043   int theTotal;
00044   
00045 };
00046 
00047 #endif