RooHistError.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooHistError.h,v 1.14 2007/05/11 09:11:30 verkerke Exp $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 #ifndef ROO_HIST_ERROR
00017 #define ROO_HIST_ERROR
00018 
00019 #include "Rtypes.h"
00020 #include "RooNumber.h"
00021 #include "RooAbsFunc.h"
00022 #include <math.h>
00023 #include <iostream>
00024 using namespace std ;
00025 
00026 class RooHistError {
00027 public:
00028   static const RooHistError &instance();
00029   virtual ~RooHistError() {} ;
00030 
00031   Bool_t getPoissonInterval(Int_t n, Double_t &mu1, Double_t &mu2, Double_t nSigma= 1) const;
00032   Bool_t getBinomialIntervalAsym(Int_t n, Int_t m, Double_t &a1, Double_t &a2, Double_t nSigma= 1) const;
00033   Bool_t getBinomialIntervalEff(Int_t n, Int_t m, Double_t &a1, Double_t &a2, Double_t nSigma= 1) const;
00034   Bool_t getInterval(const RooAbsFunc *Qu, const RooAbsFunc *Ql, Double_t pointEstimate, Double_t stepSize,
00035                      Double_t &lo, Double_t &hi, Double_t nSigma) const;
00036   
00037   static RooAbsFunc *createPoissonSum(Int_t n) ;
00038   static RooAbsFunc *createBinomialSum(Int_t n, Int_t m, Bool_t eff) ;
00039 
00040 private:
00041 
00042 
00043   Bool_t getPoissonIntervalCalc(Int_t n, Double_t &mu1, Double_t &mu2, Double_t nSigma= 1) const;
00044   Double_t _poissonLoLUT[1000] ;
00045   Double_t _poissonHiLUT[1000] ;
00046 
00047   RooHistError();
00048   Double_t seek(const RooAbsFunc &f, Double_t startAt, Double_t step, Double_t value) const;
00049 
00050   // -----------------------------------------------------------
00051   // Define a 1-dim RooAbsFunc of mu that evaluates the sum:
00052   //
00053   //  Q(n|mu) = Sum_{k=0}^{n} P(k|mu)
00054   //
00055   // where P(n|mu) = exp(-mu) mu**n / n! is the Poisson PDF.
00056   // -----------------------------------------------------------
00057   class PoissonSum : public RooAbsFunc {
00058   public:
00059     inline PoissonSum(Int_t n) : RooAbsFunc(1), _n(n) { }
00060     inline Double_t operator()(const Double_t xvec[]) const {
00061       Double_t mu(xvec[0]),result(1),factorial(1);
00062       for(Int_t k= 1; k <= _n; k++) {
00063         factorial*= k;
00064         result+= pow(mu,k)/factorial;
00065       }
00066       return exp(-mu)*result;
00067     };
00068     inline Double_t getMinLimit(UInt_t /*index*/) const { return 0; }
00069     inline Double_t getMaxLimit(UInt_t /*index*/) const { return RooNumber::infinity() ; }
00070   private:
00071     Int_t _n;
00072   };
00073 
00074   // -----------------------------------------------------------
00075   // Define a 1-dim RooAbsFunc of a that evaluates the sum:
00076   //
00077   //  Q(n|n+m,a) = Sum_{k=0}^{n} B(k|n+m,a)
00078   //
00079   // where B(n|n+m,a) = (n+m)!/(n!m!) ((1+a)/2)**n ((1-a)/2)**m
00080   // is the Binomial PDF.
00081   // -----------------------------------------------------------
00082   class BinomialSumAsym : public RooAbsFunc {
00083   public:
00084     BinomialSumAsym(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) { 
00085     }
00086     inline Double_t operator()(const Double_t xvec[]) const 
00087       {
00088         Double_t p1(0.5*(1+xvec[0])),p2(1-p1),result(0),fact1(1),fact2(1);
00089         for(Int_t k= 0; k <= _n1; k++) {
00090           if(k > 0) { fact2*= k; fact1*= _N1-k+1; }
00091           result+= fact1/fact2*pow(p1,k)*pow(p2,_N1-k);
00092         }
00093         return result;
00094       };
00095 
00096     inline Double_t getMinLimit(UInt_t /*index*/) const { return -1; }
00097     inline Double_t getMaxLimit(UInt_t /*index*/) const { return +1; }
00098 
00099   private:
00100     Int_t _n1 ; // WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
00101     Int_t _N1 ;
00102   } ;
00103 
00104 
00105   // -----------------------------------------------------------
00106   // Define a 1-dim RooAbsFunc of a that evaluates the sum:
00107   //
00108   //  Q(n|n+m,a) = Sum_{k=0}^{n} B(k|n+m,a)
00109   //
00110   // where B(n|n+m,a) = (n+m)!/(n!m!) ((1+a)/2)**n ((1-a)/2)**m
00111   // is the Binomial PDF.
00112   // -----------------------------------------------------------
00113   class BinomialSumEff : public RooAbsFunc {
00114   public:
00115     BinomialSumEff(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) { 
00116     }
00117     inline Double_t operator()(const Double_t xvec[]) const 
00118       {
00119         Double_t p1(xvec[0]),p2(1-p1),result(0),fact1(1),fact2(1);
00120         for(Int_t k= 0; k <= _n1; k++) {
00121           if(k > 0) { fact2*= k; fact1*= _N1-k+1; }
00122           result+= fact1/fact2*pow(p1,k)*pow(p2,_N1-k);
00123         }
00124         return result;
00125       };
00126 
00127     inline Double_t getMinLimit(UInt_t /*index*/) const { return  0; }
00128     inline Double_t getMaxLimit(UInt_t /*index*/) const { return +1; }
00129 
00130   private:
00131     Int_t _n1 ; // WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
00132     Int_t _N1 ;
00133   } ;
00134 
00135   ClassDef(RooHistError,1) // Utility class for calculating histogram errors
00136 };
00137 
00138 #endif

Generated on Tue Jul 5 14:26:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1