51 ClassImp(RooStats::MCMCCalculator);
53 using namespace RooFit;
54 using namespace RooStats;
60 MCMCCalculator::MCMCCalculator() :
71 fUseSparseHist = kFALSE;
73 fIntervalType = MCMCInterval::kShortest;
83 MCMCCalculator::MCMCCalculator(RooAbsData& data,
const ModelConfig & model) :
92 void MCMCCalculator::SetModel(
const ModelConfig & model) {
94 fPdf = model.GetPdf();
95 fPriorPdf = model.GetPriorPdf();
97 fNuisParams.removeAll();
98 fConditionalObs.removeAll();
99 fGlobalObs.removeAll();
100 if (model.GetParametersOfInterest())
101 fPOI.add(*model.GetParametersOfInterest());
102 if (model.GetNuisanceParameters())
103 fNuisParams.add(*model.GetNuisanceParameters());
104 if (model.GetConditionalObservables())
105 fConditionalObs.add( *(model.GetConditionalObservables() ) );
106 if (model.GetGlobalObservables())
107 fGlobalObs.add( *(model.GetGlobalObservables() ) );
117 void MCMCCalculator::SetupBasicUsage()
121 fNumBurnInSteps = 40;
124 fUseSparseHist = kFALSE;
126 fIntervalType = MCMCInterval::kShortest;
134 void MCMCCalculator::SetLeftSideTailFraction(Double_t a)
136 if (a < 0 || a > 1) {
137 coutE(InputArguments) <<
"MCMCCalculator::SetLeftSideTailFraction: "
138 <<
"Fraction must be in the range [0, 1]. "
139 << a <<
"is not allowed." << endl;
144 fIntervalType = MCMCInterval::kTailFraction;
150 MCMCInterval* MCMCCalculator::GetInterval()
const
153 if (!fData || !fPdf )
return 0;
154 if (fPOI.getSize() == 0)
return 0;
157 coutE(InputArguments) <<
"MCMCCalculator::GetInterval: "
158 <<
"Test size/Confidence level not set. Returning NULL." << endl;
163 bool useDefaultPropFunc = (fPropFunc == 0);
164 bool usePriorPdf = (fPriorPdf != 0);
165 if (useDefaultPropFunc) fPropFunc =
new UniformProposal();
168 RooAbsPdf * prodPdf = fPdf;
170 TString prodName = TString(
"product_") + TString(fPdf->GetName()) + TString(
"_") + TString(fPriorPdf->GetName() );
171 prodPdf =
new RooProdPdf(prodName,prodName,RooArgList(*fPdf,*fPriorPdf) );
174 RooArgSet* constrainedParams = prodPdf->getParameters(*fData);
175 RooAbsReal* nll = prodPdf->createNLL(*fData, Constrain(*constrainedParams),ConditionalObservables(fConditionalObs),GlobalObservables(fGlobalObs));
176 delete constrainedParams;
178 RooArgSet* params = nll->getParameters(*fData);
179 RemoveConstantParameters(params);
181 SetBins(*params, fNumBins);
182 SetBins(fPOI, fNumBins);
183 if (dynamic_cast<PdfProposal*>(fPropFunc)) {
184 RooArgSet* proposalVars = ((PdfProposal*)fPropFunc)->GetPdf()->
185 getParameters((RooAbsData*)NULL);
186 SetBins(*proposalVars, fNumBins);
190 MetropolisHastings mh;
191 mh.SetFunction(*nll);
192 mh.SetType(MetropolisHastings::kLog);
193 mh.SetSign(MetropolisHastings::kNegative);
194 mh.SetParameters(*params);
195 if (fChainParams.getSize() > 0) mh.SetChainParameters(fChainParams);
196 mh.SetProposalFunction(*fPropFunc);
197 mh.SetNumIters(fNumIters);
199 MarkovChain* chain = mh.ConstructChain();
201 TString name = TString(
"MCMCInterval_") + TString(GetName() );
202 MCMCInterval* interval =
new MCMCInterval(name, fPOI, *chain);
204 interval->SetAxes(*fAxes);
205 if (fNumBurnInSteps > 0)
206 interval->SetNumBurnInSteps(fNumBurnInSteps);
207 interval->SetUseKeys(fUseKeys);
208 interval->SetUseSparseHist(fUseSparseHist);
209 interval->SetIntervalType(fIntervalType);
210 if (fIntervalType == MCMCInterval::kTailFraction)
211 interval->SetLeftSideTailFraction(fLeftSideTF);
213 interval->SetEpsilon(fEpsilon);
215 interval->SetDelta(fDelta);
216 interval->SetConfidenceLevel(1.0 - fSize);
218 if (useDefaultPropFunc)
delete fPropFunc;
219 if (usePriorPdf)
delete prodPdf;