ConfidenceBelt.cxx

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: ConfidenceBelt.cxx 37290 2010-12-05 13:59:45Z moneta $
00002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
00003 /*************************************************************************
00004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 /*****************************************************************************
00012  * Project: RooStats
00013  * Package: RooFit/RooStats  
00014  * @(#)root/roofit/roostats:$Id: ConfidenceBelt.cxx 37290 2010-12-05 13:59:45Z moneta $
00015  * Original Author: Kyle Cranmer
00016  *   Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
00017  *
00018  *****************************************************************************/
00019 
00020 
00021 
00022 //_________________________________________________________
00023 //
00024 // BEGIN_HTML
00025 // ConfidenceBelt is a concrete implementation of the ConfInterval interface.  
00026 // It implements simple general purpose interval of arbitrary dimensions and shape.
00027 // It does not assume the interval is connected.
00028 // It uses either a RooDataSet (eg. a list of parameter points in the interval) or
00029 // a RooDataHist (eg. a Histogram-like object for small regions of the parameter space) to
00030 // store the interval.  
00031 // END_HTML
00032 //
00033 //
00034 
00035 #ifndef RooStats_ConfidenceBelt
00036 #include "RooStats/ConfidenceBelt.h"
00037 #endif
00038 
00039 #include "RooDataSet.h"
00040 #include "RooDataHist.h"
00041 
00042 #include "RooStats/RooStatsUtils.h"
00043 
00044 ClassImp(RooStats::ConfidenceBelt) ;
00045 
00046 using namespace RooStats;
00047 
00048 //____________________________________________________________________
00049 ConfidenceBelt::ConfidenceBelt() : 
00050    TNamed(), fParameterPoints(0)
00051 {
00052    // Default constructor
00053 }
00054 
00055 //____________________________________________________________________
00056 ConfidenceBelt::ConfidenceBelt(const char* name) :
00057   TNamed(name,name), fParameterPoints(0)
00058 {
00059    // Alternate constructor
00060 }
00061 
00062 //____________________________________________________________________
00063 ConfidenceBelt::ConfidenceBelt(const char* name, const char* title) :
00064    TNamed(name,title), fParameterPoints(0)
00065 {
00066    // Alternate constructor
00067 }
00068 
00069 //____________________________________________________________________
00070 ConfidenceBelt::ConfidenceBelt(const char* name, RooAbsData& data) :
00071   TNamed(name,name), fParameterPoints((RooAbsData*)data.Clone("PointsToTestForBelt"))
00072 {
00073    // Alternate constructor
00074 }
00075 
00076 //____________________________________________________________________
00077 ConfidenceBelt::ConfidenceBelt(const char* name, const char* title, RooAbsData& data) :
00078    TNamed(name,title), fParameterPoints((RooAbsData*)data.Clone("PointsToTestForBelt"))
00079 {
00080    // Alternate constructor
00081 }
00082 
00083 
00084 
00085 //____________________________________________________________________
00086 ConfidenceBelt::~ConfidenceBelt()
00087 {
00088    // Destructor
00089 
00090 }
00091 
00092 
00093 //____________________________________________________________________
00094 Double_t ConfidenceBelt::GetAcceptanceRegionMin(RooArgSet& parameterPoint, Double_t cl, Double_t leftside) {
00095 
00096   if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
00097   return GetAcceptanceRegion(parameterPoint, cl,leftside)->GetLowerLimit();
00098 }
00099 
00100 //____________________________________________________________________
00101 Double_t ConfidenceBelt::GetAcceptanceRegionMax(RooArgSet& parameterPoint, Double_t cl, Double_t leftside) {
00102   if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
00103   return GetAcceptanceRegion(parameterPoint, cl,leftside)->GetUpperLimit();
00104 }
00105 
00106 //____________________________________________________________________
00107 vector<Double_t> ConfidenceBelt::ConfidenceLevels() const {
00108   vector<Double_t> levels;
00109   return levels;
00110 }
00111 
00112 //____________________________________________________________________
00113 void ConfidenceBelt::AddAcceptanceRegion(RooArgSet& parameterPoint, Int_t dsIndex,
00114                                          Double_t lower, Double_t upper,
00115                                          Double_t cl, Double_t leftside){
00116   
00117   if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
00118 
00119   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPoints );
00120   RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );  
00121 
00122   //  cout << "add: " << tree << " " << hist << endl;
00123 
00124   if( !this->CheckParameters(parameterPoint) )
00125     std::cout << "problem with parameters" << std::endl;
00126 
00127   Int_t luIndex = fSamplingSummaryLookup.GetLookupIndex(cl, leftside);
00128   //  cout << "lookup index = " << luIndex << endl;
00129   if(luIndex <0 ) {
00130     fSamplingSummaryLookup.Add(cl,leftside);
00131     luIndex = fSamplingSummaryLookup.GetLookupIndex(cl, leftside);
00132     cout << "lookup index = " << luIndex << endl;
00133   }
00134   AcceptanceRegion* thisRegion = new AcceptanceRegion(luIndex, lower, upper);
00135   
00136   if( hist ) {
00137     // need a way to get index for given point
00138     // Can do this by setting hist's internal parameters to desired values
00139     // need a better way
00140     //    RooStats::SetParameters(&parameterPoint, const_cast<RooArgSet*>(hist->get())); 
00141     //    int index = hist->calcTreeIndex(); // get index
00142     int index = hist->getIndex(parameterPoint); // get index
00143     //    cout << "hist index = " << index << endl;
00144 
00145     // allocate memory if necessary.  numEntries is overkill?
00146     if((Int_t)fSamplingSummaries.size() <= index) {
00147       fSamplingSummaries.reserve( hist->numEntries() ); 
00148       fSamplingSummaries.resize( hist->numEntries() ); 
00149     }
00150 
00151     // set the region for this point (check for duplicate?)
00152     fSamplingSummaries.at(index) = *thisRegion;
00153   }
00154   else if( tree ){
00155     //    int index = tree->getIndex(parameterPoint); 
00156     int index = dsIndex;
00157     //    cout << "tree index = " << index << endl;
00158 
00159     // allocate memory if necessary.  numEntries is overkill?
00160     if((Int_t)fSamplingSummaries.size() <= index){
00161       fSamplingSummaries.reserve( tree->numEntries()  ); 
00162       fSamplingSummaries.resize( tree->numEntries() ); 
00163     }
00164 
00165     // set the region for this point (check for duplicate?)
00166     fSamplingSummaries.at( index ) = *thisRegion;
00167   }
00168 }
00169 
00170 //____________________________________________________________________
00171 void ConfidenceBelt::AddAcceptanceRegion(RooArgSet& parameterPoint, AcceptanceRegion region, 
00172                                          Double_t cl, Double_t leftside){
00173   
00174   if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
00175 
00176   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPoints );
00177   RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );
00178 
00179   if( !this->CheckParameters(parameterPoint) )
00180     std::cout << "problem with parameters" << std::endl;
00181   
00182   
00183   if( hist ) {
00184     // need a way to get index for given point
00185     // Can do this by setting hist's internal parameters to desired values
00186     // need a better way
00187     //    RooStats::SetParameters(&parameterPoint, const_cast<RooArgSet*>(hist->get())); 
00188     //    int index = hist->calcTreeIndex(); // get index
00189     int index = hist->getIndex(parameterPoint); // get index
00190 
00191     // allocate memory if necessary.  numEntries is overkill?
00192     if((Int_t)fSamplingSummaries.size() < index) fSamplingSummaries.reserve( hist->numEntries() ); 
00193 
00194     // set the region for this point (check for duplicate?)
00195     fSamplingSummaries.at(index) = region;
00196   }
00197   else if( tree ){
00198     tree->add( parameterPoint ); // assume it's unique for now
00199     int index = tree->numEntries() - 1; //check that last point added has index nEntries -1
00200     // allocate memory if necessary.  numEntries is overkill?
00201     if((Int_t)fSamplingSummaries.size() < index) fSamplingSummaries.reserve( tree->numEntries()  ); 
00202 
00203     // set the region for this point (check for duplicate?)
00204     fSamplingSummaries.at( index ) = region;
00205   }
00206 }
00207 
00208 //____________________________________________________________________
00209 AcceptanceRegion* ConfidenceBelt::GetAcceptanceRegion(RooArgSet &parameterPoint, Double_t cl, Double_t leftside) 
00210 {  
00211    // Method to determine if a parameter point is in the interval
00212 
00213   if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
00214 
00215   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPoints );
00216   RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );
00217   
00218   if( !this->CheckParameters(parameterPoint) ){
00219     std::cout << "problem with parameters" << std::endl;
00220     return 0; 
00221   }
00222   
00223   if( hist ) {
00224     // need a way to get index for given point
00225     // Can do this by setting hist's internal parameters to desired values
00226     // need a better way
00227     //    RooStats::SetParameters(&parameterPoint, const_cast<RooArgSet*>(hist->get())); 
00228     //    Int_t index = hist->calcTreeIndex(); // get index
00229     int index = hist->getIndex(parameterPoint); // get index
00230     return &(fSamplingSummaries.at(index).GetAcceptanceRegion());
00231   }
00232   else if( tree ){
00233     // need a way to get index for given point
00234     //    RooStats::SetParameters(&parameterPoint, tree->get()); // set tree's parameters to desired values
00235     Int_t index = 0; //need something like tree->calcTreeIndex(); 
00236     const RooArgSet* thisPoint = 0;
00237     for(index=0; index<tree->numEntries(); ++index){
00238       thisPoint = tree->get(index); 
00239       bool samePoint = true;
00240       TIter it = parameterPoint.createIterator();
00241       RooRealVar *myarg; 
00242       while ( samePoint && (myarg = (RooRealVar *)it.Next())) { 
00243         if(myarg->getVal() != thisPoint->getRealValue(myarg->GetName()))
00244           samePoint = false;
00245       }
00246       if(samePoint) 
00247         break;
00248     }
00249 
00250     return &(fSamplingSummaries.at(index).GetAcceptanceRegion());
00251   }
00252   else {
00253       std::cout << "dataset is not initialized properly" << std::endl;
00254   }
00255 
00256   return 0;
00257   
00258 }
00259 
00260 //____________________________________________________________________
00261 RooArgSet* ConfidenceBelt::GetParameters() const
00262 {  
00263    // returns list of parameters
00264    return new RooArgSet(*(fParameterPoints->get()));
00265 }
00266 
00267 //____________________________________________________________________
00268 Bool_t ConfidenceBelt::CheckParameters(RooArgSet &parameterPoint) const
00269 {  
00270 
00271    if (parameterPoint.getSize() != fParameterPoints->get()->getSize() ) {
00272       std::cout << "size is wrong, parameters don't match" << std::endl;
00273       return false;
00274    }
00275    if ( ! parameterPoint.equals( *(fParameterPoints->get() ) ) ) {
00276       std::cout << "size is ok, but parameters don't match" << std::endl;
00277       return false;
00278    }
00279    return true;
00280 }

Generated on Tue Jul 5 15:07:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1