RooExtendPdf.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooExtendPdf.cxx 37221 2010-12-03 13:07:32Z wouter $
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 
00017 ///////////////////////////////////////////////////////////////////////////
00018 //  RooExtendPdf is a wrappper around an existing PDF that adds a 
00019 //  parameteric extended likelihood term to the PDF, optionally divided by a 
00020 //  fractional term from a partial normalization of the PDF:
00021 //
00022 //  nExpected = N   _or Expected = N / frac 
00023 //
00024 //  where N is supplied as a RooAbsReal to RooExtendPdf.
00025 //  The fractional term is defined as
00026 //                          _       _ _   _  _
00027 //            Int(cutRegion[x]) pdf(x,y) dx dy 
00028 //     frac = ---------------_-------_-_---_--_ 
00029 //            Int(normRegion[x]) pdf(x,y) dx dy 
00030 //
00031 //        _                                                               _
00032 //  where x is the set of dependents involved in the selection region and y
00033 //  is the set of remaining dependents.
00034 //            _
00035 //  cutRegion[x] is an limited integration range that is contained in
00036 //  the nominal integration range normRegion[x[]
00037 //
00038 
00039 #include "RooFit.h"
00040 #include "Riostream.h"
00041 
00042 #include "RooExtendPdf.h"
00043 #include "RooExtendPdf.h"
00044 #include "RooArgList.h"
00045 #include "RooRealVar.h"
00046 #include "RooFormulaVar.h"
00047 #include "RooNameReg.h"
00048 #include "RooMsgService.h"
00049 
00050 
00051 
00052 ClassImp(RooExtendPdf)
00053 ;
00054 
00055 
00056 RooExtendPdf::RooExtendPdf() : _rangeName(0)
00057 {
00058   // Default constructor
00059 }
00060 
00061 RooExtendPdf::RooExtendPdf(const char *name, const char *title, const RooAbsPdf& pdf,
00062                            const RooAbsReal& norm, const char* rangeName) :
00063   RooAbsPdf(name,title),
00064   _pdf("pdf","PDF",this,(RooAbsReal&)pdf),
00065   _n("n","Normalization",this,(RooAbsReal&)norm),
00066   _rangeName(RooNameReg::ptr(rangeName))
00067 {
00068   // Constructor. The ExtendedPdf behaves identical to the supplied input pdf,
00069   // but adds an extended likelihood term. The expected number of events return
00070   // is 'norm'. If a rangename is given, the number of events is interpreted as
00071 #  // the number of events in the given range
00072 
00073   // Copy various setting from pdf
00074   setUnit(_pdf.arg().getUnit()) ;
00075   setPlotLabel(_pdf.arg().getPlotLabel()) ;
00076 }
00077 
00078 
00079 
00080 RooExtendPdf::RooExtendPdf(const RooExtendPdf& other, const char* name) :
00081   RooAbsPdf(other,name),
00082   _pdf("pdf",this,other._pdf),
00083   _n("n",this,other._n),
00084   _rangeName(other._rangeName)
00085 {
00086   // Copy constructor
00087 }
00088 
00089 
00090 RooExtendPdf::~RooExtendPdf() 
00091 {
00092   // Destructor
00093 
00094 }
00095 
00096 
00097 
00098 Double_t RooExtendPdf::expectedEvents(const RooArgSet* nset) const 
00099 {
00100   // Return the number of expected events, which is
00101   //
00102   // n / [ Int(xC,yF) pdf(x,y) / Int(xF,yF) pdf(x,y) ]
00103   //
00104   // Where x is the set of dependents with cuts defined
00105   // and y are the other dependents. xC is the integration
00106   // of x over the cut range, xF is the integration of
00107   // x over the full range.
00108 
00109   RooAbsPdf& pdf = (RooAbsPdf&)_pdf.arg() ;
00110 
00111   if (_rangeName && (!nset || nset->getSize()==0)) {
00112     coutW(InputArguments) << "RooExtendPdf::expectedEvents(" << GetName() << ") WARNING: RooExtendPdf needs non-null normalization set to calculate fraction in range " 
00113                           << _rangeName << ".  Results may be nonsensical" << endl ;  
00114   }
00115 
00116   Double_t nExp = _n ;
00117 
00118   // Optionally multiply with fractional normalization
00119   if (_rangeName) {
00120 
00121     globalSelectComp(kTRUE) ;
00122     Double_t fracInt = pdf.getNormObj(nset,nset,_rangeName)->getVal() ;
00123     globalSelectComp(kFALSE) ;
00124 
00125 
00126     if ( fracInt == 0. || _n == 0.) {
00127       coutW(Eval) << "RooExtendPdf(" << GetName() << ") WARNING: nExpected = " << _n << " / " 
00128                   << fracInt << " for nset = " << (nset?*nset:RooArgSet()) << endl ;
00129     }
00130 
00131     nExp /= fracInt ;    
00132 
00133 
00134     // cout << "RooExtendPdf::expectedEvents(" << GetName() << ") fracInt = " << fracInt << " _n = " << _n << " nExpect = " << nExp << endl ;
00135 
00136   }
00137 
00138   // Multiply with original Nexpected, if defined
00139   if (pdf.canBeExtended()) nExp *= pdf.expectedEvents(nset) ;
00140 
00141   return nExp ;
00142 }
00143 
00144 
00145 

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