PointSetInterval.cxx

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: PointSetInterval.cxx 35821 2010-09-28 08:18:13Z 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: PointSetInterval.cxx 35821 2010-09-28 08:18:13Z 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 // PointSetInterval 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_PointSetInterval
00036 #include "RooStats/PointSetInterval.h"
00037 #endif
00038 
00039 #include "RooRealVar.h"
00040 #include "RooDataSet.h"
00041 #include "RooDataHist.h"
00042 
00043 ClassImp(RooStats::PointSetInterval) ;
00044 
00045 using namespace RooStats;
00046 
00047 
00048 //____________________________________________________________________
00049 PointSetInterval::PointSetInterval(const char* name) :
00050    ConfInterval(name), fConfidenceLevel(0.95), fParameterPointsInInterval(0)
00051 {
00052    // Default constructor
00053 }
00054 
00055 //____________________________________________________________________
00056 PointSetInterval::PointSetInterval(const char* name, RooAbsData& data) :
00057    ConfInterval(name), fConfidenceLevel(0.95), fParameterPointsInInterval(&data)
00058 {
00059    // Alternate constructor passing the dataset 
00060 }
00061 
00062 
00063 
00064 //____________________________________________________________________
00065 PointSetInterval::~PointSetInterval()
00066 {
00067    // Destructor
00068 
00069 }
00070 
00071 
00072 //____________________________________________________________________
00073 Bool_t PointSetInterval::IsInInterval(const RooArgSet &parameterPoint) const
00074 {  
00075    // Method to determine if a parameter point is in the interval
00076 
00077   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPointsInInterval );
00078   RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPointsInInterval );
00079   
00080   if( !this->CheckParameters(parameterPoint) ){
00081     //    std::cout << "problem with parameters" << std::endl;
00082     return false; 
00083   }
00084   
00085   if( hist ) {
00086     if ( hist->weight( parameterPoint , 0 ) > 0 ) // positive value indicates point is in interval
00087       return true; 
00088     else
00089       return false;
00090   }
00091   else if( tree ){
00092     const RooArgSet* thisPoint = 0;
00093     // need to check if the parameter point is the same as any point in tree. 
00094     for(Int_t i = 0; i<tree->numEntries(); ++i){
00095       // This method is not complete
00096       thisPoint = tree->get(i); 
00097       bool samePoint = true;
00098       TIter it = parameterPoint.createIterator();
00099       RooRealVar *myarg; 
00100       while ( samePoint && (myarg = (RooRealVar *)it.Next())) { 
00101         if(myarg->getVal() != thisPoint->getRealValue(myarg->GetName()))
00102           samePoint = false;
00103       }
00104       if(samePoint) 
00105         return true;
00106 
00107       //      delete thisPoint;
00108     }
00109     return false; // didn't find a good point
00110   }
00111   else {
00112       std::cout << "dataset is not initialized properly" << std::endl;
00113   }
00114 
00115    return true;
00116   
00117 }
00118 
00119 //____________________________________________________________________
00120 RooArgSet* PointSetInterval::GetParameters() const
00121 {  
00122    // returns list of parameters
00123    return new RooArgSet(*(fParameterPointsInInterval->get()) );
00124 }
00125 
00126 //____________________________________________________________________
00127 Bool_t PointSetInterval::CheckParameters(const RooArgSet &parameterPoint) const
00128 {  
00129    if (parameterPoint.getSize() != fParameterPointsInInterval->get()->getSize() ) {
00130      std::cout << "PointSetInterval: argument size is wrong, parameters don't match: arg=" << parameterPoint
00131                << " interval=" << (*fParameterPointsInInterval->get()) << std::endl;
00132       return false;
00133    }
00134    if ( ! parameterPoint.equals( *(fParameterPointsInInterval->get() ) ) ) {
00135       std::cout << "PointSetInterval: size is ok, but parameters don't match" << std::endl;
00136       return false;
00137    }
00138    return true;
00139 }
00140 
00141 
00142 //____________________________________________________________________
00143 Double_t PointSetInterval::UpperLimit(RooRealVar& param ) 
00144 {  
00145   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPointsInInterval );
00146   Double_t low, high;
00147   if( tree ){
00148     tree->getRange(param, low, high);
00149     return high;
00150  }
00151   return param.getMax();
00152 }
00153 
00154 //____________________________________________________________________
00155 Double_t PointSetInterval::LowerLimit(RooRealVar& param ) 
00156 {  
00157   RooDataSet*  tree = dynamic_cast<RooDataSet*>(  fParameterPointsInInterval );
00158   Double_t low, high;
00159   if( tree ){
00160     tree->getRange(param, low, high);
00161     return low;
00162  }
00163   return param.getMin();
00164 }

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