00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef ROOT_Rtypes
00058 #include "Rtypes.h"
00059 #endif
00060
00061 #ifndef ROOSTATS_PdfProposal
00062 #include "RooStats/PdfProposal.h"
00063 #endif
00064 #ifndef RooStats_RooStatsUtils
00065 #include "RooStats/RooStatsUtils.h"
00066 #endif
00067 #ifndef ROO_ARG_SET
00068 #include "RooArgSet.h"
00069 #endif
00070 #ifndef ROO_DATA_SET
00071 #include "RooDataSet.h"
00072 #endif
00073 #ifndef ROO_ABS_PDF
00074 #include "RooAbsPdf.h"
00075 #endif
00076 #ifndef ROO_MSG_SERVICE
00077 #include "RooMsgService.h"
00078 #endif
00079 #ifndef ROO_REAL_VAR
00080 #include "RooRealVar.h"
00081 #endif
00082 #ifndef ROOT_TIterator
00083 #include "TIterator.h"
00084 #endif
00085
00086 #include <map>
00087
00088 ClassImp(RooStats::PdfProposal);
00089
00090 using namespace RooFit;
00091 using namespace RooStats;
00092
00093
00094
00095 PdfProposal::PdfProposal() : ProposalFunction()
00096 {
00097 fPdf = NULL;
00098 fOwnsPdf = kFALSE;
00099 fCacheSize = 1;
00100 fCachePosition = 0;
00101 fCache = NULL;
00102 }
00103
00104
00105
00106 PdfProposal::PdfProposal(RooAbsPdf& pdf) : ProposalFunction()
00107 {
00108 fPdf = &pdf;
00109 fOwnsPdf = kFALSE;
00110 fCacheSize = 1;
00111 fCachePosition = 0;
00112 fCache = NULL;
00113 }
00114
00115 Bool_t PdfProposal::Equals(RooArgSet& x1, RooArgSet& x2)
00116 {
00117 if (x1.equals(x2)) {
00118 TIterator* it = x1.createIterator();
00119 RooRealVar* r;
00120 while ((r = (RooRealVar*)it->Next()) != NULL)
00121 if (r->getVal() != x2.getRealValue(r->GetName())) {
00122 delete it;
00123 return kFALSE;
00124 }
00125 delete it;
00126 return kTRUE;
00127 }
00128 return kFALSE;
00129 }
00130
00131
00132 void PdfProposal::Propose(RooArgSet& xPrime, RooArgSet& x)
00133 {
00134 if (fLastX.getSize() == 0) {
00135
00136 fLastX.addClone(x);
00137
00138 RooStats::SetParameters(&x, &fMaster);
00139 if (fMap.size() > 0) {
00140 for (fIt = fMap.begin(); fIt != fMap.end(); fIt++)
00141 fIt->first->setVal(fIt->second->getVal(&x));
00142 }
00143 fCache = fPdf->generate(xPrime, fCacheSize);
00144 }
00145
00146 Bool_t moved = false;
00147 if (fMap.size() > 0) {
00148 moved = !Equals(fLastX, x);
00149
00150
00151
00152
00153
00154 if (moved) {
00155
00156 RooStats::SetParameters(&x, &fMaster);
00157
00158 for (fIt = fMap.begin(); fIt != fMap.end(); fIt++)
00159 fIt->first->setVal(fIt->second->getVal(&x));
00160
00161
00162 RooStats::SetParameters(&x, &fLastX);
00163 }
00164 }
00165
00166
00167 if (moved || fCachePosition >= fCacheSize) {
00168 delete fCache;
00169 fCache = fPdf->generate(xPrime, fCacheSize);
00170 fCachePosition = 0;
00171 }
00172
00173 const RooArgSet* proposal = fCache->get(fCachePosition);
00174 fCachePosition++;
00175 RooStats::SetParameters(proposal, &xPrime);
00176 }
00177
00178
00179
00180
00181 Bool_t PdfProposal::IsSymmetric(RooArgSet& , RooArgSet& )
00182 {
00183
00184 return false;
00185 }
00186
00187
00188
00189 Double_t PdfProposal::GetProposalDensity(RooArgSet& x1, RooArgSet& x2)
00190 {
00191 RooStats::SetParameters(&x2, &fMaster);
00192 for (fIt = fMap.begin(); fIt != fMap.end(); fIt++)
00193 fIt->first->setVal(fIt->second->getVal(&x2));
00194 RooArgSet* temp = fPdf->getObservables(x1);
00195 RooStats::SetParameters(&x1, temp);
00196 delete temp;
00197 return fPdf->getVal(&x1);
00198 }
00199
00200 void PdfProposal::AddMapping(RooRealVar& proposalParam, RooAbsReal& update)
00201 {
00202 fMaster.add(*update.getParameters((RooAbsData*)NULL));
00203 if (update.getParameters((RooAbsData*)NULL)->getSize() == 0)
00204 fMaster.add(update);
00205 fMap.insert(pair<RooRealVar*, RooAbsReal*>(&proposalParam, &update));
00206 }