00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00078 static const Double_t SIGMA_RANGE_DIVISOR = 5;
00079 static const Int_t DEFAULT_CACHE_SIZE = 100;
00080
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
00108
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
00140
00141
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 }