// @(#)root/physics:$Id$
// Author: Adrian Bevan  2001

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * Copyright (C) 2001, Liverpool University.                             *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TFeldmanCousins
#define ROOT_TFeldmanCousins

////////////////////////////////////////////////////////////////////////////
// TFeldmanCousins
//
// class to calculate the CL upper limit using
// the Feldman-Cousins method as described in PRD V57 #7, p3873-3889
//
// The default confidence interval calvculated using this method is 90%
// This is set either by having a default the constructor, or using the
// appropriate fraction when instantiating an object of this class (e.g. 0.9)
//
// The simple extension to a gaussian resolution function bounded at zero
// has not been addressed as yet -> `time is of the essence' as they write
// on the wall of the maze in that classic game ...
//
//    VARIABLES THAT CAN BE ALTERED
//    -----------------------------
// => depending on your desired precision: The intial values of fMuMin,
// fMuMax, fMuStep and fNMax are those used in the PRD:
//   fMuMin = 0.0
//   fMuMax = 50.0
//   fMuStep= 0.005
// but there is total flexibility in changing this should you desire.
//
// Author: Adrian Bevan, Liverpool University
//
// Copyright Liverpool University 2001       bevan@slac.stanford.edu
///////////////////////////////////////////////////////////////////////////

#include "TObject.h"
#include "TString.h"

class TFeldmanCousins : public TObject {
protected:
   Double_t fCL;         // confidence level as a fraction [e.g. 90% = 0.9]
   Double_t fUpperLimit; // the calculated upper limit
   Double_t fLowerLimit; // the calculated lower limit
   Double_t fNobserved;  // input number of observed events
   Double_t fNbackground;// input number of background events
   Double_t fMuMin;      // minimum value of signal to use in calculating the tables
   Double_t fMuMax;      // maximum value of signal to use in calculating the tables
   Double_t fMuStep;     // the step in signal to use when generating tables
   Int_t    fNMuStep;    // = (int)(fMuStep)
   Int_t    fNMax;       // = (int)(fMuMax)
   Int_t    fQUICK;      // take a short cut to speed up the process of generating a
                        // lut.  This scans from Nobserved-Nbackground-fMuMin upwards
                        // assuming that UL > Nobserved-Nbackground.

   ////////////////////////////////////////////////
   // calculate the poissonian probability for   //
   // a mean of mu+B events with a variance of N //
   ////////////////////////////////////////////////
   Double_t Prob(Int_t N, Double_t mu, Double_t B);

   ////////////////////////////////////////////////
   // calculate the probability table and see if //
   // fNObserved is in the 100.0 * fCL %         //
   // interval                                   //
   ////////////////////////////////////////////////
   Int_t FindLimitsFromTable(Double_t mu);

public:
   TFeldmanCousins(Double_t newCL=0.9, TString options = "");
   virtual ~TFeldmanCousins();

   ////////////////////////////////////////////////
   // calculate the upper limit given Nobserved  //
   // and Nbackground events                     //
   // the variables fUpperLimit and fLowerLimit  //
   // are set before returning the upper limit   //
   ////////////////////////////////////////////////
   Double_t CalculateUpperLimit(Double_t Nobserved, Double_t Nbackground);
   Double_t CalculateLowerLimit(Double_t Nobserved, Double_t Nbackground);

   inline Double_t GetUpperLimit(void)  const { return fUpperLimit;  }
   inline Double_t GetLowerLimit(void)  const { return fLowerLimit;  }
   inline Double_t GetNobserved(void)   const { return fNobserved;   }
   inline Double_t GetNbackground(void) const { return fNbackground; }
   inline Double_t GetCL(void)          const { return fCL;          }

   inline Double_t GetMuMin(void)       const { return fMuMin;  }
   inline Double_t GetMuMax(void)       const { return fMuMax;  }
   inline Double_t GetMuStep(void)      const { return fMuStep; }
   inline Double_t GetNMax(void)        const { return fNMax;   }

   inline void     SetNobserved(Double_t NObs)         { fNobserved   = NObs;  }
   inline void     SetNbackground(Double_t Nbg)        { fNbackground = Nbg;   }
   inline void     SetCL(Double_t newCL)               { fCL          = newCL; }

   inline void     SetMuMin(Double_t  newMin    = 0.0)   { fMuMin = newMin;  }
   void            SetMuMax(Double_t  newMax    = 50.0);
   void            SetMuStep(Double_t newMuStep = 0.005);

   ClassDef(TFeldmanCousins,1) //calculate the CL upper limit using the Feldman-Cousins method
};

#endif






 TFeldmanCousins.h:1
 TFeldmanCousins.h:2
 TFeldmanCousins.h:3
 TFeldmanCousins.h:4
 TFeldmanCousins.h:5
 TFeldmanCousins.h:6
 TFeldmanCousins.h:7
 TFeldmanCousins.h:8
 TFeldmanCousins.h:9
 TFeldmanCousins.h:10
 TFeldmanCousins.h:11
 TFeldmanCousins.h:12
 TFeldmanCousins.h:13
 TFeldmanCousins.h:14
 TFeldmanCousins.h:15
 TFeldmanCousins.h:16
 TFeldmanCousins.h:17
 TFeldmanCousins.h:18
 TFeldmanCousins.h:19
 TFeldmanCousins.h:20
 TFeldmanCousins.h:21
 TFeldmanCousins.h:22
 TFeldmanCousins.h:23
 TFeldmanCousins.h:24
 TFeldmanCousins.h:25
 TFeldmanCousins.h:26
 TFeldmanCousins.h:27
 TFeldmanCousins.h:28
 TFeldmanCousins.h:29
 TFeldmanCousins.h:30
 TFeldmanCousins.h:31
 TFeldmanCousins.h:32
 TFeldmanCousins.h:33
 TFeldmanCousins.h:34
 TFeldmanCousins.h:35
 TFeldmanCousins.h:36
 TFeldmanCousins.h:37
 TFeldmanCousins.h:38
 TFeldmanCousins.h:39
 TFeldmanCousins.h:40
 TFeldmanCousins.h:41
 TFeldmanCousins.h:42
 TFeldmanCousins.h:43
 TFeldmanCousins.h:44
 TFeldmanCousins.h:45
 TFeldmanCousins.h:46
 TFeldmanCousins.h:47
 TFeldmanCousins.h:48
 TFeldmanCousins.h:49
 TFeldmanCousins.h:50
 TFeldmanCousins.h:51
 TFeldmanCousins.h:52
 TFeldmanCousins.h:53
 TFeldmanCousins.h:54
 TFeldmanCousins.h:55
 TFeldmanCousins.h:56
 TFeldmanCousins.h:57
 TFeldmanCousins.h:58
 TFeldmanCousins.h:59
 TFeldmanCousins.h:60
 TFeldmanCousins.h:61
 TFeldmanCousins.h:62
 TFeldmanCousins.h:63
 TFeldmanCousins.h:64
 TFeldmanCousins.h:65
 TFeldmanCousins.h:66
 TFeldmanCousins.h:67
 TFeldmanCousins.h:68
 TFeldmanCousins.h:69
 TFeldmanCousins.h:70
 TFeldmanCousins.h:71
 TFeldmanCousins.h:72
 TFeldmanCousins.h:73
 TFeldmanCousins.h:74
 TFeldmanCousins.h:75
 TFeldmanCousins.h:76
 TFeldmanCousins.h:77
 TFeldmanCousins.h:78
 TFeldmanCousins.h:79
 TFeldmanCousins.h:80
 TFeldmanCousins.h:81
 TFeldmanCousins.h:82
 TFeldmanCousins.h:83
 TFeldmanCousins.h:84
 TFeldmanCousins.h:85
 TFeldmanCousins.h:86
 TFeldmanCousins.h:87
 TFeldmanCousins.h:88
 TFeldmanCousins.h:89
 TFeldmanCousins.h:90
 TFeldmanCousins.h:91
 TFeldmanCousins.h:92
 TFeldmanCousins.h:93
 TFeldmanCousins.h:94
 TFeldmanCousins.h:95
 TFeldmanCousins.h:96
 TFeldmanCousins.h:97
 TFeldmanCousins.h:98
 TFeldmanCousins.h:99
 TFeldmanCousins.h:100
 TFeldmanCousins.h:101
 TFeldmanCousins.h:102
 TFeldmanCousins.h:103
 TFeldmanCousins.h:104
 TFeldmanCousins.h:105
 TFeldmanCousins.h:106
 TFeldmanCousins.h:107
 TFeldmanCousins.h:108
 TFeldmanCousins.h:109
 TFeldmanCousins.h:110
 TFeldmanCousins.h:111
 TFeldmanCousins.h:112
 TFeldmanCousins.h:113
 TFeldmanCousins.h:114
 TFeldmanCousins.h:115
 TFeldmanCousins.h:116
 TFeldmanCousins.h:117