ProposalHelper.cxx

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: ProposalHelper.cxx 34109 2010-06-24 15:00:16Z moneta $
00002 // Authors: Kevin Belasco        7/22/2009
00003 // Authors: Kyle Cranmer         7/22/2009
00004 /*************************************************************************
00005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //_________________________________________________
00013 /*
00014 BEGIN_HTML
00015 END_HTML
00016 */
00017 //_________________________________________________
00018 
00019 #ifndef ROOT_Rtypes
00020 #include "Rtypes.h"
00021 #endif
00022 #ifndef RooStats_ProposalHelper
00023 #include "RooStats/ProposalHelper.h"
00024 #endif
00025 #ifndef ROOSTATS_PdfProposal
00026 #include "RooStats/PdfProposal.h"
00027 #endif
00028 #ifndef RooStats_RooStatsUtils
00029 #include "RooStats/RooStatsUtils.h"
00030 #endif
00031 #ifndef ROO_ARG_SET
00032 #include "RooArgSet.h"
00033 #endif
00034 #ifndef ROO_DATA_SET
00035 #include "RooDataSet.h"
00036 #endif
00037 #ifndef ROO_ABS_PDF
00038 #include "RooAbsPdf.h"
00039 #endif
00040 #ifndef ROO_ADD_PDF
00041 #include "RooAddPdf.h"
00042 #endif
00043 #ifndef ROO_KEYS_PDF
00044 #include "RooNDKeysPdf.h"
00045 #endif
00046 #ifndef ROO_UNIFORM
00047 #include "RooUniform.h"
00048 #endif
00049 #ifndef ROO_MSG_SERVICE
00050 #include "RooMsgService.h"
00051 #endif
00052 #ifndef ROO_REAL_VAR
00053 #include "RooRealVar.h"
00054 #endif
00055 #ifndef ROOT_TIterator
00056 #include "TIterator.h"
00057 #endif
00058 #ifndef ROO_MULTI_VAR_GAUSSIAN
00059 #include "RooMultiVarGaussian.h"
00060 #endif
00061 #ifndef ROO_CONST_VAR
00062 #include "RooConstVar.h"
00063 #endif
00064 #ifndef ROOT_TString
00065 #include "TString.h"
00066 #endif
00067 
00068 #include <map>
00069 
00070 ClassImp(RooStats::ProposalHelper);
00071 
00072 using namespace RooFit;
00073 using namespace RooStats;
00074 
00075 static const Double_t DEFAULT_UNI_FRAC = 0.10;
00076 static const Double_t DEFAULT_CLUES_FRAC = 0.20;
00077 //static const Double_t SIGMA_RANGE_DIVISOR = 6;
00078 static const Double_t SIGMA_RANGE_DIVISOR = 5;
00079 static const Int_t DEFAULT_CACHE_SIZE = 100;
00080 //static const Option_t* CLUES_OPTIONS = "a";
00081 
00082 ProposalHelper::ProposalHelper()
00083 {
00084    fPdfProp = new PdfProposal();
00085    fVars = NULL;
00086    fOwnsPdfProp = kTRUE;
00087    fOwnsPdf = kFALSE;
00088    fOwnsCluesPdf = kFALSE;
00089    fOwnsVars = kFALSE;
00090    fUseUpdates = kFALSE;
00091    fPdf = NULL;
00092    fSigmaRangeDivisor = SIGMA_RANGE_DIVISOR;
00093    fCluesPdf = NULL;
00094    fUniformPdf = NULL;
00095    fClues = NULL;
00096    fCovMatrix = NULL;
00097    fCluesFrac = -1;
00098    fUniFrac = -1;
00099    fCacheSize = -1;
00100    fCluesOptions = NULL;
00101 }
00102 
00103 ProposalFunction* ProposalHelper::GetProposalFunction()
00104 {
00105    if (fPdf == NULL)
00106       CreatePdf();
00107    // kbelasco: check here for memory leaks: does RooAddPdf make copies or
00108    // take ownership of components, coeffs
00109    RooArgList* components = new RooArgList();
00110    RooArgList* coeffs = new RooArgList();
00111    if (fCluesPdf == NULL)
00112       CreateCluesPdf();
00113    if (fCluesPdf != NULL) {
00114       if (fCluesFrac < 0)
00115          fCluesFrac = DEFAULT_CLUES_FRAC;
00116       printf("added clues from dataset %s with fraction %g\n",
00117             fClues->GetName(), fCluesFrac);
00118       components->add(*fCluesPdf);
00119       coeffs->add(RooConst(fCluesFrac));
00120    }
00121    if (fUniFrac > 0.) {
00122       CreateUniformPdf();
00123       components->add(*fUniformPdf);
00124       coeffs->add(RooConst(fUniFrac));
00125    }
00126    components->add(*fPdf);
00127    RooAddPdf* addPdf = new RooAddPdf("proposalFunction", "Proposal Density",
00128          *components, *coeffs);
00129    fPdfProp->SetPdf(*addPdf);
00130    fPdfProp->SetOwnsPdf(kTRUE);
00131    if (fCacheSize > 0)
00132       fPdfProp->SetCacheSize(fCacheSize);
00133    fOwnsPdfProp = kFALSE;
00134    return fPdfProp;
00135 }
00136 
00137 void ProposalHelper::CreatePdf()
00138 {
00139    // kbelasco: check here for memory leaks:
00140    // does RooMultiVarGaussian make copies of xVec and muVec?
00141    // or should we delete them?
00142    if (fVars == NULL) {
00143       coutE(InputArguments) << "ProposalHelper::CreatePdf(): " <<
00144          "Variables to create proposal function for are not set." << endl;
00145       return;
00146    }
00147    RooArgList* xVec = new RooArgList();
00148    RooArgList* muVec = new RooArgList();
00149    TIterator* it = fVars->createIterator();
00150    RooRealVar* r;
00151    RooRealVar* clone;
00152    while ((r = (RooRealVar*)it->Next()) != NULL) {
00153       xVec->add(*r);
00154       TString cloneName = TString::Format("%s%s", "mu__", r->GetName());
00155       clone = (RooRealVar*)r->clone(cloneName.Data());
00156       muVec->add(*clone);
00157       if (fUseUpdates)
00158          fPdfProp->AddMapping(*clone, *r);
00159    }
00160    if (fCovMatrix == NULL)
00161       CreateCovMatrix(*xVec);
00162    fPdf = new RooMultiVarGaussian("mvg", "MVG Proposal", *xVec, *muVec,
00163                                   *fCovMatrix);
00164    delete xVec;
00165    delete muVec;
00166    delete it;
00167 }
00168 
00169 void ProposalHelper::CreateCovMatrix(RooArgList& xVec)
00170 {
00171    Int_t size = xVec.getSize();
00172    fCovMatrix = new TMatrixDSym(size);
00173    RooRealVar* r;
00174    for (Int_t i = 0; i < size; i++) {
00175       r = (RooRealVar*)xVec.at(i);
00176       Double_t range = r->getMax() - r->getMin();
00177       (*fCovMatrix)(i,i) = range / fSigmaRangeDivisor;
00178    }
00179 }
00180 
00181 void ProposalHelper::CreateCluesPdf()
00182 {
00183    if (fClues != NULL) {
00184       if (fCluesOptions == NULL)
00185          fCluesPdf = new RooNDKeysPdf("cluesPdf", "Clues PDF", *fVars, *fClues);
00186       else
00187          fCluesPdf = new RooNDKeysPdf("cluesPdf", "Clues PDF", *fVars, *fClues,
00188                fCluesOptions);
00189    }
00190 }
00191 
00192 void ProposalHelper::CreateUniformPdf()
00193 {
00194    fUniformPdf = new RooUniform("uniform", "Uniform Proposal PDF",
00195          RooArgSet(*fVars));
00196 }

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