Logo ROOT   6.07/09
Reference Guide
MCMCInterval.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Authors: Kevin Belasco 17/06/2009
3 // Authors: Kyle Cranmer 17/06/2009
4 /*************************************************************************
5  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef ROOT_Rtypes
16 #include "Rtypes.h"
17 #endif
18 
19 #ifndef ROOT_TMath
20 #include "TMath.h"
21 #endif
22 
23 #ifndef RooStats_MCMCInterval
24 #include "RooStats/MCMCInterval.h"
25 #endif
26 #ifndef ROOSTATS_MarkovChain
27 #include "RooStats/MarkovChain.h"
28 #endif
29 #ifndef RooStats_Heaviside
30 #include "RooStats/Heaviside.h"
31 #endif
32 #ifndef ROO_DATA_HIST
33 #include "RooDataHist.h"
34 #endif
35 #ifndef ROO_KEYS_PDF
36 #include "RooNDKeysPdf.h"
37 #endif
38 #ifndef ROO_PRODUCT
39 #include "RooProduct.h"
40 #endif
41 #ifndef RooStats_RooStatsUtils
42 #include "RooStats/RooStatsUtils.h"
43 #endif
44 #ifndef ROO_REAL_VAR
45 #include "RooRealVar.h"
46 #endif
47 #ifndef ROO_ARG_LIST
48 #include "RooArgList.h"
49 #endif
50 #ifndef ROOT_TIterator
51 #include "TIterator.h"
52 #endif
53 #ifndef ROOT_TH1
54 #include "TH1.h"
55 #endif
56 #ifndef ROOT_TH1F
57 #include "TH1F.h"
58 #endif
59 #ifndef ROOT_TH2F
60 #include "TH2F.h"
61 #endif
62 #ifndef ROOT_TH3F
63 #include "TH3F.h"
64 #endif
65 #ifndef ROO_MSG_SERVICE
66 #include "RooMsgService.h"
67 #endif
68 #ifndef ROO_GLOBAL_FUNC
69 #include "RooGlobalFunc.h"
70 #endif
71 #ifndef ROOT_TObject
72 #include "TObject.h"
73 #endif
74 #ifndef ROOT_THnSparse
75 #include "THnSparse.h"
76 #endif
77 #ifndef ROO_NUMBER
78 #include "RooNumber.h"
79 #endif
80 //#ifndef ROOT_TFile
81 //#include "TFile.h"
82 //#endif
83 
84 #include <cstdlib>
85 #include <string>
86 #include <algorithm>
87 
89 
90 using namespace RooFit;
91 using namespace RooStats;
92 using namespace std;
93 
94 static const Double_t DEFAULT_EPSILON = 0.01;
95 static const Double_t DEFAULT_DELTA = 10e-6;
96 
97 MCMCInterval::MCMCInterval(const char* name)
98  : ConfInterval(name)
99 {
100  fConfidenceLevel = 0.0;
101  fHistConfLevel = 0.0;
102  fKeysConfLevel = 0.0;
103  fTFConfLevel = 0.0;
104  fFull = 0.0;
105  fChain = NULL;
106  fAxes = NULL;
107  fDataHist = NULL;
108  fSparseHist = NULL;
109  fVector.clear();
110  fKeysPdf = NULL;
111  fProduct = NULL;
112  fHeaviside = NULL;
114  fCutoffVar = NULL;
115  fHist = NULL;
116  fNumBurnInSteps = 0;
117  fHistCutoff = -1;
118  fKeysCutoff = -1;
119  fDimension = 1;
120  fUseKeys = kFALSE;
126  fTFLower = -1.0 * RooNumber::infinity();
128  fVecWeight = 0;
129  fLeftSideTF = -1;
130 }
131 
133  const RooArgSet& parameters, MarkovChain& chain) : ConfInterval(name)
134 {
135  fNumBurnInSteps = 0;
136  fConfidenceLevel = 0.0;
137  fHistConfLevel = 0.0;
138  fKeysConfLevel = 0.0;
139  fTFConfLevel = 0.0;
140  fFull = 0.0;
141  fAxes = NULL;
142  fChain = &chain;
143  fDataHist = NULL;
144  fSparseHist = NULL;
145  fVector.clear();
146  fKeysPdf = NULL;
147  fProduct = NULL;
148  fHeaviside = NULL;
150  fCutoffVar = NULL;
151  fHist = NULL;
152  fHistCutoff = -1;
153  fKeysCutoff = -1;
154  fUseKeys = kFALSE;
158  SetParameters(parameters);
161  fTFLower = -1.0 * RooNumber::infinity();
163  fVecWeight = 0;
164  fLeftSideTF = -1;
165 }
166 
168 {
169  // destructor
170  delete[] fAxes;
171  delete fHist;
172  delete fChain;
173  // kbelasco: check here for memory management errors
174  delete fDataHist;
175  delete fSparseHist;
176  delete fKeysPdf;
177  delete fProduct;
178  delete fHeaviside;
179  delete fKeysDataHist;
180  delete fCutoffVar;
181 }
182 
183 struct CompareDataHistBins {
184  CompareDataHistBins(RooDataHist* hist) : fDataHist(hist) {}
185  bool operator() (Int_t bin1 , Int_t bin2) {
186  fDataHist->get(bin1);
187  Double_t n1 = fDataHist->weight();
188  fDataHist->get(bin2);
189  Double_t n2 = fDataHist->weight();
190  return (n1 < n2);
191  }
193 };
194 
195 struct CompareSparseHistBins {
196  CompareSparseHistBins(THnSparse* hist) : fSparseHist(hist) {}
197  bool operator() (Long_t bin1, Long_t bin2) {
198  Double_t n1 = fSparseHist->GetBinContent(bin1);
199  Double_t n2 = fSparseHist->GetBinContent(bin2);
200  return (n1 < n2);
201  }
203 };
204 
205 struct CompareVectorIndices {
206  CompareVectorIndices(MarkovChain* chain, RooRealVar* param) :
207  fChain(chain), fParam(param) {}
208  bool operator() (Int_t i, Int_t j) {
209  Double_t xi = fChain->Get(i)->getRealValue(fParam->GetName());
210  Double_t xj = fChain->Get(j)->getRealValue(fParam->GetName());
211  return (xi < xj);
212  }
214  RooRealVar* fParam;
215 };
216 
217 // kbelasco: for this method, consider running DetermineInterval() if
218 // fKeysPdf==NULL, fSparseHist==NULL, fDataHist==NULL, or fVector.size()==0
219 // rather than just returning false. Though this should not be an issue
220 // because nobody should be able to get an MCMCInterval that has their interval
221 // or posterior representation NULL/empty since they should only get this
222 // through the MCMCCalculator
224 {
225  if (fIntervalType == kShortest) {
226  if (fUseKeys) {
227  if (fKeysPdf == NULL)
228  return false;
229 
230  // evaluate keyspdf at point and return whether >= cutoff
231  RooStats::SetParameters(&point, const_cast<RooArgSet *>(&fParameters));
232  return fKeysPdf->getVal(&fParameters) >= fKeysCutoff;
233  } else {
234  if (fUseSparseHist) {
235  if (fSparseHist == NULL)
236  return false;
237 
238  // evalute sparse hist at bin where point lies and return
239  // whether >= cutoff
241  const_cast<RooArgSet*>(&fParameters));
242  Long_t bin;
243  // kbelasco: consider making x static
244  Double_t* x = new Double_t[fDimension];
245  for (Int_t i = 0; i < fDimension; i++)
246  x[i] = fAxes[i]->getVal();
247  bin = fSparseHist->GetBin(x, kFALSE);
248  Double_t weight = fSparseHist->GetBinContent((Long64_t)bin);
249  delete[] x;
250  return (weight >= (Double_t)fHistCutoff);
251  } else {
252  if (fDataHist == NULL)
253  return false;
254 
255  // evaluate data hist at bin where point lies and return whether
256  // >= cutoff
257  Int_t bin;
258  bin = fDataHist->getIndex(point);
259  fDataHist->get(bin);
260  return (fDataHist->weight() >= (Double_t)fHistCutoff);
261  }
262  }
263  } else if (fIntervalType == kTailFraction) {
264  if (fVector.size() == 0)
265  return false;
266 
267  // return whether value of point is within the range
268  Double_t x = point.getRealValue(fAxes[0]->GetName());
269  if (fTFLower <= x && x <= fTFUpper)
270  return true;
271 
272  return false;
273  }
274 
275  coutE(InputArguments) << "Error in MCMCInterval::IsInInterval: "
276  << "Interval type not set. Returning false." << endl;
277  return false;
278 }
279 
281 {
282  fConfidenceLevel = cl;
284 }
285 
286 // kbelasco: update this or just take it out
287 // kbelasco: consider keeping this around but changing the implementation
288 // to set the number of bins for each RooRealVar and then reacreating the
289 // histograms
290 //void MCMCInterval::SetNumBins(Int_t numBins)
291 //{
292 // if (numBins > 0) {
293 // fPreferredNumBins = numBins;
294 // for (Int_t d = 0; d < fDimension; d++)
295 // fNumBins[d] = numBins;
296 // }
297 // else {
298 // coutE(Eval) << "* Error in MCMCInterval::SetNumBins: " <<
299 // "Negative number of bins given: " << numBins << endl;
300 // return;
301 // }
302 //
303 // // If the histogram already exists, recreate it with the new bin numbers
304 // if (fHist != NULL)
305 // CreateHist();
306 //}
307 
309 {
310  Int_t size = axes.getSize();
311  if (size != fDimension) {
312  coutE(InputArguments) << "* Error in MCMCInterval::SetAxes: " <<
313  "number of variables in axes (" << size <<
314  ") doesn't match number of parameters ("
315  << fDimension << ")" << endl;
316  return;
317  }
318  for (Int_t i = 0; i < size; i++)
319  fAxes[i] = (RooRealVar*)axes.at(i);
320 }
321 
323 {
324  // kbelasco: check here for memory leak. does RooNDKeysPdf use
325  // the RooArgList passed to it or does it make a clone?
326  // also check for memory leak from chain, does RooNDKeysPdf clone that?
327  if (fAxes == NULL || fParameters.getSize() == 0) {
328  coutE(InputArguments) << "Error in MCMCInterval::CreateKeysPdf: "
329  << "parameters have not been set." << endl;
330  return;
331  }
332 
333  if (fNumBurnInSteps >= fChain->Size()) {
335  "MCMCInterval::CreateKeysPdf: creation of Keys PDF failed: " <<
336  "Number of burn-in steps (num steps to ignore) >= number of steps " <<
337  "in Markov chain." << endl;
338  delete fKeysPdf;
339  delete fCutoffVar;
340  delete fHeaviside;
341  delete fProduct;
342  fKeysPdf = NULL;
343  fCutoffVar = NULL;
344  fHeaviside = NULL;
345  fProduct = NULL;
346  return;
347  }
348 
351  RooArgList* paramsList = new RooArgList();
352  for (Int_t i = 0; i < fDimension; i++)
353  paramsList->add(*fAxes[i]);
354 
355  // kbelasco: check for memory leaks with chain. who owns it? does
356  // RooNDKeysPdf take ownership?
357  fKeysPdf = new RooNDKeysPdf("keysPDF", "Keys PDF", *paramsList, *chain, "a");
358  fCutoffVar = new RooRealVar("cutoff", "cutoff", 0);
359  fHeaviside = new Heaviside("heaviside", "Heaviside", *fKeysPdf, *fCutoffVar);
360  fProduct = new RooProduct("product", "Keys PDF & Heaviside Product",
362 }
363 
365 {
366  if (fAxes == NULL || fChain == NULL) {
367  coutE(Eval) << "* Error in MCMCInterval::CreateHist(): " <<
368  "Crucial data member was NULL." << endl;
369  coutE(Eval) << "Make sure to fully construct/initialize." << endl;
370  return;
371  }
372  if (fHist != NULL)
373  delete fHist;
374 
375  if (fNumBurnInSteps >= fChain->Size()) {
377  "MCMCInterval::CreateHist: creation of histogram failed: " <<
378  "Number of burn-in steps (num steps to ignore) >= number of steps " <<
379  "in Markov chain." << endl;
380  fHist = NULL;
381  return;
382  }
383 
384  if (fDimension == 1)
385  fHist = new TH1F("posterior", "MCMC Posterior Histogram",
386  fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax());
387 
388  else if (fDimension == 2)
389  fHist = new TH2F("posterior", "MCMC Posterior Histogram",
390  fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
391  fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax());
392 
393  else if (fDimension == 3)
394  fHist = new TH3F("posterior", "MCMC Posterior Histogram",
395  fAxes[0]->numBins(), fAxes[0]->getMin(), fAxes[0]->getMax(),
396  fAxes[1]->numBins(), fAxes[1]->getMin(), fAxes[1]->getMax(),
397  fAxes[2]->numBins(), fAxes[2]->getMin(), fAxes[2]->getMax());
398 
399  else {
400  coutE(Eval) << "* Error in MCMCInterval::CreateHist() : " <<
401  "TH1* couldn't handle dimension: " << fDimension << endl;
402  return;
403  }
404 
405  // Fill histogram
406  Int_t size = fChain->Size();
407  const RooArgSet* entry;
408  for (Int_t i = fNumBurnInSteps; i < size; i++) {
409  entry = fChain->Get(i);
410  if (fDimension == 1)
411  ((TH1F*)fHist)->Fill(entry->getRealValue(fAxes[0]->GetName()),
412  fChain->Weight());
413  else if (fDimension == 2)
414  ((TH2F*)fHist)->Fill(entry->getRealValue(fAxes[0]->GetName()),
415  entry->getRealValue(fAxes[1]->GetName()),
416  fChain->Weight());
417  else
418  ((TH3F*)fHist)->Fill(entry->getRealValue(fAxes[0]->GetName()),
419  entry->getRealValue(fAxes[1]->GetName()),
420  entry->getRealValue(fAxes[2]->GetName()),
421  fChain->Weight());
422  }
423 
424  if (fDimension >= 1)
425  fHist->GetXaxis()->SetTitle(fAxes[0]->GetName());
426  if (fDimension >= 2)
427  fHist->GetYaxis()->SetTitle(fAxes[1]->GetName());
428  if (fDimension >= 3)
429  fHist->GetZaxis()->SetTitle(fAxes[2]->GetName());
430 }
431 
433 {
434  if (fAxes == NULL || fChain == NULL) {
435  coutE(InputArguments) << "* Error in MCMCInterval::CreateSparseHist(): "
436  << "Crucial data member was NULL." << endl;
437  coutE(InputArguments) << "Make sure to fully construct/initialize."
438  << endl;
439  return;
440  }
441  if (fSparseHist != NULL)
442  delete fSparseHist;
443 
444  Double_t* min = new Double_t[fDimension];
445  Double_t* max = new Double_t[fDimension];
446  Int_t* bins = new Int_t[fDimension];
447  for (Int_t i = 0; i < fDimension; i++) {
448  min[i] = fAxes[i]->getMin();
449  max[i] = fAxes[i]->getMax();
450  bins[i] = fAxes[i]->numBins();
451  }
452  fSparseHist = new THnSparseF("posterior", "MCMC Posterior Histogram",
453  fDimension, bins, min, max);
454 
455  delete[] min;
456  delete[] max;
457  delete[] bins;
458 
459  // kbelasco: it appears we need to call Sumw2() just to get the
460  // histogram to keep a running total of the weight so that Getsumw doesn't
461  // just return 0
462  fSparseHist->Sumw2();
463 
464  if (fNumBurnInSteps >= fChain->Size()) {
466  "MCMCInterval::CreateSparseHist: creation of histogram failed: " <<
467  "Number of burn-in steps (num steps to ignore) >= number of steps " <<
468  "in Markov chain." << endl;
469  }
470 
471  // Fill histogram
472  Int_t size = fChain->Size();
473  const RooArgSet* entry;
474  Double_t* x = new Double_t[fDimension];
475  for (Int_t i = fNumBurnInSteps; i < size; i++) {
476  entry = fChain->Get(i);
477  for (Int_t ii = 0; ii < fDimension; ii++)
478  x[ii] = entry->getRealValue(fAxes[ii]->GetName());
479  fSparseHist->Fill(x, fChain->Weight());
480  }
481  delete[] x;
482 }
483 
485 {
486  if (fParameters.getSize() == 0 || fChain == NULL) {
487  coutE(Eval) << "* Error in MCMCInterval::CreateDataHist(): " <<
488  "Crucial data member was NULL or empty." << endl;
489  coutE(Eval) << "Make sure to fully construct/initialize." << endl;
490  return;
491  }
492 
493  if (fNumBurnInSteps >= fChain->Size()) {
495  "MCMCInterval::CreateDataHist: creation of histogram failed: " <<
496  "Number of burn-in steps (num steps to ignore) >= number of steps " <<
497  "in Markov chain." << endl;
498  fDataHist = NULL;
499  return;
500  }
501 
504 }
505 
507 {
508  fVector.clear();
509  fVecWeight = 0;
510 
511  if (fChain == NULL) {
512  coutE(InputArguments) << "* Error in MCMCInterval::CreateVector(): " <<
513  "Crucial data member (Markov chain) was NULL." << endl;
514  coutE(InputArguments) << "Make sure to fully construct/initialize."
515  << endl;
516  return;
517  }
518 
519  if (fNumBurnInSteps >= fChain->Size()) {
521  "MCMCInterval::CreateVector: creation of vector failed: " <<
522  "Number of burn-in steps (num steps to ignore) >= number of steps " <<
523  "in Markov chain." << endl;
524  }
525 
526  // Fill vector
527  Int_t size = fChain->Size() - fNumBurnInSteps;
528  fVector.resize(size);
529  Int_t i;
530  Int_t chainIndex;
531  for (i = 0; i < size; i++) {
532  chainIndex = i + fNumBurnInSteps;
533  fVector[i] = chainIndex;
534  fVecWeight += fChain->Weight(chainIndex);
535  }
536 
537  stable_sort(fVector.begin(), fVector.end(),
538  CompareVectorIndices(fChain, param));
539 }
540 
541 void MCMCInterval::SetParameters(const RooArgSet& parameters)
542 {
544  fParameters.add(parameters);
546  if (fAxes != NULL)
547  delete[] fAxes;
548  fAxes = new RooRealVar*[fDimension];
550  Int_t n = 0;
551  TObject* obj;
552  while ((obj = it->Next()) != NULL) {
553  if (dynamic_cast<RooRealVar*>(obj) != NULL)
554  fAxes[n] = (RooRealVar*)obj;
555  else
556  coutE(Eval) << "* Error in MCMCInterval::SetParameters: " <<
557  obj->GetName() << " not a RooRealVar*" << std::endl;
558  n++;
559  }
560  delete it;
561 }
562 
564 {
565  switch (fIntervalType) {
566  case kShortest:
568  break;
569  case kTailFraction:
571  break;
572  default:
573  coutE(InputArguments) << "MCMCInterval::DetermineInterval(): " <<
574  "Error: Interval type not set" << endl;
575  break;
576  }
577 }
578 
580 {
581  if (fUseKeys)
582  DetermineByKeys();
583  else
584  DetermineByHist();
585 }
586 
588 {
589  if (fLeftSideTF < 0 || fLeftSideTF > 1) {
590  coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval: "
591  << "Fraction must be in the range [0, 1]. "
592  << fLeftSideTF << "is not allowed." << endl;
593  return;
594  }
595 
596  if (fDimension != 1) {
597  coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
598  << "Error: Can only find a tail-fraction interval for 1-D intervals"
599  << endl;
600  return;
601  }
602 
603  if (fAxes == NULL) {
604  coutE(InputArguments) << "MCMCInterval::DetermineTailFractionInterval(): "
605  << "Crucial data member was NULL." << endl;
606  coutE(InputArguments) << "Make sure to fully construct/initialize."
607  << endl;
608  return;
609  }
610 
611  // kbelasco: fill in code here to find interval
612  //
613  // also make changes so that calling GetPosterior...() returns NULL
614  // when fIntervalType == kTailFraction, since there really
615  // is no posterior for this type of interval determination
616  if (fVector.size() == 0)
617  CreateVector(fAxes[0]);
618 
619  if (fVector.size() == 0 || fVecWeight == 0) {
620  // if size is still 0, then creation failed.
621  // if fVecWeight == 0, then there are no entries (indicates the same
622  // error as fVector.size() == 0 because that only happens when
623  // fNumBurnInSteps >= fChain->Size())
624  // either way, reset and return
625  fVector.clear();
626  fTFLower = -1.0 * RooNumber::infinity();
628  fTFConfLevel = 0.0;
629  fVecWeight = 0;
630  return;
631  }
632 
633  RooRealVar* param = fAxes[0];
634 
636  Double_t leftTailCutoff = fVecWeight * (1 - c) * fLeftSideTF;
637  Double_t rightTailCutoff = fVecWeight * (1 - c) * (1 - fLeftSideTF);
638  Double_t leftTailSum = 0;
639  Double_t rightTailSum = 0;
640 
641  // kbelasco: consider changing these values to +infinty and -infinity
642  Double_t ll = param->getMin();
643  Double_t ul = param->getMax();
644 
645  Double_t x;
646  Double_t w;
647 
648  // save a lot of GetName() calls if compiler does not already optimize this
649  const char* name = param->GetName();
650 
651  // find lower limit
652  Int_t i;
653  for (i = 0; i < (Int_t)fVector.size(); i++) {
654  x = fChain->Get(fVector[i])->getRealValue(name);
655  w = fChain->Weight();
656 
657  if (TMath::Abs(leftTailSum + w - leftTailCutoff) <
658  TMath::Abs(leftTailSum - leftTailCutoff)) {
659  // moving the lower limit to x would bring us closer to the desired
660  // left tail size
661  ll = x;
662  leftTailSum += w;
663  } else
664  break;
665  }
666 
667  // find upper limit
668  for (i = (Int_t)fVector.size() - 1; i >= 0; i--) {
669  x = fChain->Get(fVector[i])->getRealValue(name);
670  w = fChain->Weight();
671 
672  if (TMath::Abs(rightTailSum + w - rightTailCutoff) <
673  TMath::Abs(rightTailSum - rightTailCutoff)) {
674  // moving the lower limit to x would bring us closer to the desired
675  // left tail size
676  ul = x;
677  rightTailSum += w;
678  } else
679  break;
680  }
681 
682  fTFLower = ll;
683  fTFUpper = ul;
684  fTFConfLevel = 1 - (leftTailSum + rightTailSum) / fVecWeight;
685 }
686 
688 {
689  if (fKeysPdf == NULL)
690  CreateKeysPdf();
691 
692  if (fKeysPdf == NULL) {
693  // if fKeysPdf is still NULL, then it means CreateKeysPdf failed
694  // so clear all the data members this function would normally determine
695  // and return
696  fFull = 0.0;
697  fKeysCutoff = -1;
698  fKeysConfLevel = 0.0;
699  return;
700  }
701 
702  // now we have a keys pdf of the posterior
703 
704  Double_t cutoff = 0.0;
705  fCutoffVar->setVal(cutoff);
707  Double_t full = integral->getVal(fParameters);
708  fFull = full;
709  delete integral;
710  if (full < 0.98) {
711  coutW(Eval) << "Warning: Integral of Keys PDF came out to " << full
712  << " intead of expected value 1. Will continue using this "
713  << "factor to normalize further integrals of this PDF." << endl;
714  }
715 
716  // kbelasco: Is there a better way to set the search range?
717  // from 0 to max value of Keys
718  // kbelasco: how to get max value?
719  //Double_t max = product.maxVal(product.getMaxVal(fParameters));
720 
721  Double_t volume = 1.0;
723  RooRealVar* var;
724  while ((var = (RooRealVar*)it->Next()) != NULL)
725  volume *= (var->getMax() - var->getMin());
726  delete it;
727 
728  Double_t topCutoff = full / volume;
729  Double_t bottomCutoff = topCutoff;
730  Double_t confLevel = CalcConfLevel(topCutoff, full);
731  if (AcceptableConfLevel(confLevel)) {
732  fKeysConfLevel = confLevel;
733  fKeysCutoff = topCutoff;
734  return;
735  }
736  Bool_t changed = kFALSE;
737  // find high end of range
738  while (confLevel > fConfidenceLevel) {
739  topCutoff *= 2.0;
740  confLevel = CalcConfLevel(topCutoff, full);
741  if (AcceptableConfLevel(confLevel)) {
742  fKeysConfLevel = confLevel;
743  fKeysCutoff = topCutoff;
744  return;
745  }
746  changed = kTRUE;
747  }
748  if (changed) {
749  bottomCutoff = topCutoff / 2.0;
750  } else {
751  changed = kFALSE;
752  bottomCutoff /= 2.0;
753  confLevel = CalcConfLevel(bottomCutoff, full);
754  if (AcceptableConfLevel(confLevel)) {
755  fKeysConfLevel = confLevel;
756  fKeysCutoff = bottomCutoff;
757  return;
758  }
759  while (confLevel < fConfidenceLevel) {
760  bottomCutoff /= 2.0;
761  confLevel = CalcConfLevel(bottomCutoff, full);
762  if (AcceptableConfLevel(confLevel)) {
763  fKeysConfLevel = confLevel;
764  fKeysCutoff = bottomCutoff;
765  return;
766  }
767  changed = kTRUE;
768  }
769  if (changed) {
770  topCutoff = bottomCutoff * 2.0;
771  }
772  }
773 
774  coutI(Eval) << "range set: [" << bottomCutoff << ", " << topCutoff << "]"
775  << endl;
776 
777  cutoff = (topCutoff + bottomCutoff) / 2.0;
778  confLevel = CalcConfLevel(cutoff, full);
779 
780  // need to use WithinDeltaFraction() because sometimes the integrating the
781  // posterior in this binary search seems to not have enough granularity to
782  // find an acceptable conf level (small no. of strange cases).
783  // WithinDeltaFraction causes the search to terminate when
784  // topCutoff is essentially equal to bottomCutoff (compared to the magnitude
785  // of their mean).
786  while (!AcceptableConfLevel(confLevel) &&
787  !WithinDeltaFraction(topCutoff, bottomCutoff)) {
788  if (confLevel > fConfidenceLevel)
789  bottomCutoff = cutoff;
790  else if (confLevel < fConfidenceLevel)
791  topCutoff = cutoff;
792  cutoff = (topCutoff + bottomCutoff) / 2.0;
793  coutI(Eval) << "cutoff range: [" << bottomCutoff << ", "
794  << topCutoff << "]" << endl;
795  confLevel = CalcConfLevel(cutoff, full);
796  }
797 
798  fKeysCutoff = cutoff;
799  fKeysConfLevel = confLevel;
800 }
801 
803 {
804  if (fUseSparseHist)
806  else
808 }
809 
811 {
812  Long_t numBins;
813  if (fSparseHist == NULL)
815 
816  if (fSparseHist == NULL) {
817  // if fSparseHist is still NULL, then CreateSparseHist failed
818  fHistCutoff = -1;
819  fHistConfLevel = 0.0;
820  return;
821  }
822 
823  numBins = (Long_t)fSparseHist->GetNbins();
824 
825  std::vector<Long_t> bins(numBins);
826  for (Int_t ibin = 0; ibin < numBins; ibin++)
827  bins[ibin] = (Long_t)ibin;
828  std::stable_sort(bins.begin(), bins.end(), CompareSparseHistBins(fSparseHist));
829 
830  Double_t nEntries = fSparseHist->GetSumw();
831  Double_t sum = 0;
832  Double_t content;
833  Int_t i;
834  // see above note on indexing to understand numBins - 3
835  for (i = numBins - 1; i >= 0; i--) {
836  content = fSparseHist->GetBinContent(bins[i]);
837  if ((sum + content) / nEntries >= fConfidenceLevel) {
838  fHistCutoff = content;
839  if (fIsHistStrict) {
840  sum += content;
841  i--;
842  break;
843  } else {
844  i++;
845  break;
846  }
847  }
848  sum += content;
849  }
850 
851  if (fIsHistStrict) {
852  // keep going to find the sum
853  for ( ; i >= 0; i--) {
854  content = fSparseHist->GetBinContent(bins[i]);
855  if (content == fHistCutoff)
856  sum += content;
857  else
858  break; // content must be < fHistCutoff
859  }
860  } else {
861  // backtrack to find the cutoff and sum
862  for ( ; i < numBins; i++) {
863  content = fSparseHist->GetBinContent(bins[i]);
864  if (content > fHistCutoff) {
865  fHistCutoff = content;
866  break;
867  } else // content == fHistCutoff
868  sum -= content;
869  if (i == numBins - 1)
870  // still haven't set fHistCutoff correctly yet, and we have no bins
871  // left, so set fHistCutoff to something higher than the tallest bin
872  fHistCutoff = content + 1.0;
873  }
874  }
875 
876  fHistConfLevel = sum / nEntries;
877 }
878 
880 {
881  Int_t numBins;
882  if (fDataHist == NULL)
883  CreateDataHist();
884  if (fDataHist == NULL) {
885  // if fDataHist is still NULL, then CreateDataHist failed
886  fHistCutoff = -1;
887  fHistConfLevel = 0.0;
888  return;
889  }
890 
891  numBins = fDataHist->numEntries();
892 
893  std::vector<Int_t> bins(numBins);
894  for (Int_t ibin = 0; ibin < numBins; ibin++)
895  bins[ibin] = ibin;
896  std::stable_sort(bins.begin(), bins.end(), CompareDataHistBins(fDataHist));
897 
898  Double_t nEntries = fDataHist->sum(kFALSE);
899  Double_t sum = 0;
900  Double_t content;
901  Int_t i;
902  for (i = numBins - 1; i >= 0; i--) {
903  fDataHist->get(bins[i]);
904  content = fDataHist->weight();
905  if ((sum + content) / nEntries >= fConfidenceLevel) {
906  fHistCutoff = content;
907  if (fIsHistStrict) {
908  sum += content;
909  i--;
910  break;
911  } else {
912  i++;
913  break;
914  }
915  }
916  sum += content;
917  }
918 
919  if (fIsHistStrict) {
920  // keep going to find the sum
921  for ( ; i >= 0; i--) {
922  fDataHist->get(bins[i]);
923  content = fDataHist->weight();
924  if (content == fHistCutoff)
925  sum += content;
926  else
927  break; // content must be < fHistCutoff
928  }
929  } else {
930  // backtrack to find the cutoff and sum
931  for ( ; i < numBins; i++) {
932  fDataHist->get(bins[i]);
933  content = fDataHist->weight();
934  if (content > fHistCutoff) {
935  fHistCutoff = content;
936  break;
937  } else // content == fHistCutoff
938  sum -= content;
939  if (i == numBins - 1)
940  // still haven't set fHistCutoff correctly yet, and we have no bins
941  // left, so set fHistCutoff to something higher than the tallest bin
942  fHistCutoff = content + 1.0;
943  }
944  }
945 
946  fHistConfLevel = sum / nEntries;
947 }
948 
950 {
951  if (fIntervalType == kShortest) {
952  if (fUseKeys)
953  return fKeysConfLevel;
954  else
955  return fHistConfLevel;
956  } else if (fIntervalType == kTailFraction) {
957  return fTFConfLevel;
958  } else {
959  coutE(InputArguments) << "MCMCInterval::GetActualConfidenceLevel: "
960  << "not implemented for this type of interval. Returning 0." << endl;
961  return 0;
962  }
963 }
964 
966 {
967  switch (fIntervalType) {
968  case kShortest:
969  return LowerLimitShortest(param);
970  case kTailFraction:
971  return LowerLimitTailFraction(param);
972  default:
973  coutE(InputArguments) << "MCMCInterval::LowerLimit(): " <<
974  "Error: Interval type not set" << endl;
975  return RooNumber::infinity();
976  }
977 }
978 
980 {
981  switch (fIntervalType) {
982  case kShortest:
983  return UpperLimitShortest(param);
984  case kTailFraction:
985  return UpperLimitTailFraction(param);
986  default:
987  coutE(InputArguments) << "MCMCInterval::UpperLimit(): " <<
988  "Error: Interval type not set" << endl;
989  return RooNumber::infinity();
990  }
991 }
992 
994 {
995  if (fTFLower == -1.0 * RooNumber::infinity())
997 
998  return fTFLower;
999 }
1000 
1002 {
1003  if (fTFUpper == RooNumber::infinity())
1005 
1006  return fTFUpper;
1007 }
1008 
1010 {
1011  if (fUseKeys)
1012  return LowerLimitByKeys(param);
1013  else
1014  return LowerLimitByHist(param);
1015 }
1016 
1018 {
1019  if (fUseKeys)
1020  return UpperLimitByKeys(param);
1021  else
1022  return UpperLimitByHist(param);
1023 }
1024 
1025 // Determine the lower limit for param on this interval
1026 // using the binned data set
1028 {
1029  if (fUseSparseHist)
1030  return LowerLimitBySparseHist(param);
1031  else
1032  return LowerLimitByDataHist(param);
1033 }
1034 
1035 // Determine the upper limit for param on this interval
1036 // using the binned data set
1038 {
1039  if (fUseSparseHist)
1040  return UpperLimitBySparseHist(param);
1041  else
1042  return UpperLimitByDataHist(param);
1043 }
1044 
1045 // Determine the lower limit for param on this interval
1046 // using the binned data set
1048 {
1049  if (fDimension != 1) {
1050  coutE(InputArguments) << "In MCMCInterval::LowerLimitBySparseHist: "
1051  << "Sorry, will not compute lower limit unless dimension == 1" << endl;
1052  return param.getMin();
1053  }
1054  if (fHistCutoff < 0)
1055  DetermineBySparseHist(); // this initializes fSparseHist
1056 
1057  if (fHistCutoff < 0) {
1058  // if fHistCutoff < 0 still, then determination of interval failed
1059  coutE(Eval) << "In MCMCInterval::LowerLimitBySparseHist: "
1060  << "couldn't determine cutoff. Check that num burn in steps < num "
1061  << "steps in the Markov chain. Returning param.getMin()." << endl;
1062  return param.getMin();
1063  }
1064 
1065  std::vector<Int_t> coord(fDimension);
1066  for (Int_t d = 0; d < fDimension; d++) {
1067  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1068  Long_t numBins = (Long_t)fSparseHist->GetNbins();
1069  Double_t lowerLimit = param.getMax();
1070  Double_t val;
1071  for (Long_t i = 0; i < numBins; i++) {
1072  if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1073  val = fSparseHist->GetAxis(d)->GetBinCenter(coord[d]);
1074  if (val < lowerLimit)
1075  lowerLimit = val;
1076  }
1077  }
1078  return lowerLimit;
1079  }
1080  }
1081  return param.getMin();
1082 }
1083 
1084 // Determine the lower limit for param on this interval
1085 // using the binned data set
1087 {
1088  if (fHistCutoff < 0)
1089  DetermineByDataHist(); // this initializes fDataHist
1090 
1091  if (fHistCutoff < 0) {
1092  // if fHistCutoff < 0 still, then determination of interval failed
1093  coutE(Eval) << "In MCMCInterval::LowerLimitByDataHist: "
1094  << "couldn't determine cutoff. Check that num burn in steps < num "
1095  << "steps in the Markov chain. Returning param.getMin()." << endl;
1096  return param.getMin();
1097  }
1098 
1099  for (Int_t d = 0; d < fDimension; d++) {
1100  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1101  Int_t numBins = fDataHist->numEntries();
1102  Double_t lowerLimit = param.getMax();
1103  Double_t val;
1104  for (Int_t i = 0; i < numBins; i++) {
1105  fDataHist->get(i);
1106  if (fDataHist->weight() >= fHistCutoff) {
1107  val = fDataHist->get()->getRealValue(param.GetName());
1108  if (val < lowerLimit)
1109  lowerLimit = val;
1110  }
1111  }
1112  return lowerLimit;
1113  }
1114  }
1115  return param.getMin();
1116 }
1117 
1118 // Determine the upper limit for param on this interval
1119 // using the binned data set
1121 {
1122  if (fDimension != 1) {
1123  coutE(InputArguments) << "In MCMCInterval::UpperLimitBySparseHist: "
1124  << "Sorry, will not compute upper limit unless dimension == 1" << endl;
1125  return param.getMax();
1126  }
1127  if (fHistCutoff < 0)
1128  DetermineBySparseHist(); // this initializes fSparseHist
1129 
1130  if (fHistCutoff < 0) {
1131  // if fHistCutoff < 0 still, then determination of interval failed
1132  coutE(Eval) << "In MCMCInterval::UpperLimitBySparseHist: "
1133  << "couldn't determine cutoff. Check that num burn in steps < num "
1134  << "steps in the Markov chain. Returning param.getMax()." << endl;
1135  return param.getMax();
1136  }
1137 
1138  std::vector<Int_t> coord(fDimension);
1139  for (Int_t d = 0; d < fDimension; d++) {
1140  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1141  Long_t numBins = (Long_t)fSparseHist->GetNbins();
1142  Double_t upperLimit = param.getMin();
1143  Double_t val;
1144  for (Long_t i = 0; i < numBins; i++) {
1145  if (fSparseHist->GetBinContent(i, &coord[0]) >= fHistCutoff) {
1146  val = fSparseHist->GetAxis(d)->GetBinCenter(coord[d]);
1147  if (val > upperLimit)
1148  upperLimit = val;
1149  }
1150  }
1151  return upperLimit;
1152  }
1153  }
1154  return param.getMax();
1155 }
1156 
1157 // Determine the upper limit for param on this interval
1158 // using the binned data set
1160 {
1161  if (fHistCutoff < 0)
1162  DetermineByDataHist(); // this initializes fDataHist
1163 
1164  if (fHistCutoff < 0) {
1165  // if fHistCutoff < 0 still, then determination of interval failed
1166  coutE(Eval) << "In MCMCInterval::UpperLimitByDataHist: "
1167  << "couldn't determine cutoff. Check that num burn in steps < num "
1168  << "steps in the Markov chain. Returning param.getMax()." << endl;
1169  return param.getMax();
1170  }
1171 
1172  for (Int_t d = 0; d < fDimension; d++) {
1173  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1174  Int_t numBins = fDataHist->numEntries();
1175  Double_t upperLimit = param.getMin();
1176  Double_t val;
1177  for (Int_t i = 0; i < numBins; i++) {
1178  fDataHist->get(i);
1179  if (fDataHist->weight() >= fHistCutoff) {
1180  val = fDataHist->get()->getRealValue(param.GetName());
1181  if (val > upperLimit)
1182  upperLimit = val;
1183  }
1184  }
1185  return upperLimit;
1186  }
1187  }
1188  return param.getMax();
1189 }
1190 
1191 // Determine the lower limit for param on this interval
1192 // using the keys pdf
1194 {
1195  if (fKeysCutoff < 0)
1196  DetermineByKeys();
1197 
1198  if (fKeysDataHist == NULL)
1200 
1201  if (fKeysCutoff < 0 || fKeysDataHist == NULL) {
1202  // failure in determination of cutoff and/or creation of histogram
1203  coutE(Eval) << "in MCMCInterval::LowerLimitByKeys(): "
1204  << "couldn't find lower limit, check that the number of burn in "
1205  << "steps < number of total steps in the Markov chain. Returning "
1206  << "param.getMin()" << endl;
1207  return param.getMin();
1208  }
1209 
1210  for (Int_t d = 0; d < fDimension; d++) {
1211  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1212  Int_t numBins = fKeysDataHist->numEntries();
1213  Double_t lowerLimit = param.getMax();
1214  Double_t val;
1215  for (Int_t i = 0; i < numBins; i++) {
1216  fKeysDataHist->get(i);
1217  if (fKeysDataHist->weight() >= fKeysCutoff) {
1218  val = fKeysDataHist->get()->getRealValue(param.GetName());
1219  if (val < lowerLimit)
1220  lowerLimit = val;
1221  }
1222  }
1223  return lowerLimit;
1224  }
1225  }
1226  return param.getMin();
1227 }
1228 
1229 // Determine the upper limit for param on this interval
1230 // using the keys pdf
1232 {
1233  if (fKeysCutoff < 0)
1234  DetermineByKeys();
1235 
1236  if (fKeysDataHist == NULL)
1238 
1239  if (fKeysCutoff < 0 || fKeysDataHist == NULL) {
1240  // failure in determination of cutoff and/or creation of histogram
1241  coutE(Eval) << "in MCMCInterval::UpperLimitByKeys(): "
1242  << "couldn't find upper limit, check that the number of burn in "
1243  << "steps < number of total steps in the Markov chain. Returning "
1244  << "param.getMax()" << endl;
1245  return param.getMax();
1246  }
1247 
1248  for (Int_t d = 0; d < fDimension; d++) {
1249  if (strcmp(fAxes[d]->GetName(), param.GetName()) == 0) {
1250  Int_t numBins = fKeysDataHist->numEntries();
1251  Double_t upperLimit = param.getMin();
1252  Double_t val;
1253  for (Int_t i = 0; i < numBins; i++) {
1254  fKeysDataHist->get(i);
1255  if (fKeysDataHist->weight() >= fKeysCutoff) {
1256  val = fKeysDataHist->get()->getRealValue(param.GetName());
1257  if (val > upperLimit)
1258  upperLimit = val;
1259  }
1260  }
1261  return upperLimit;
1262  }
1263  }
1264  return param.getMax();
1265 }
1266 
1267 // Determine the approximate maximum value of the Keys PDF
1269 {
1270  if (fKeysCutoff < 0)
1271  DetermineByKeys();
1272 
1273  if (fKeysDataHist == NULL)
1275 
1276  if (fKeysDataHist == NULL) {
1277  // failure in determination of cutoff and/or creation of histogram
1278  coutE(Eval) << "in MCMCInterval::KeysMax(): "
1279  << "couldn't find Keys max value, check that the number of burn in "
1280  << "steps < number of total steps in the Markov chain. Returning 0"
1281  << endl;
1282  return 0;
1283  }
1284 
1285  Int_t numBins = fKeysDataHist->numEntries();
1286  Double_t max = 0;
1287  Double_t w;
1288  for (Int_t i = 0; i < numBins; i++) {
1289  fKeysDataHist->get(i);
1290  w = fKeysDataHist->weight();
1291  if (w > max)
1292  max = w;
1293  }
1294 
1295  return max;
1296 }
1297 
1299 {
1300  if (fHistCutoff < 0)
1301  DetermineByHist();
1302 
1303  return fHistCutoff;
1304 }
1305 
1307 {
1308  if (fKeysCutoff < 0)
1309  DetermineByKeys();
1310 
1311  // kbelasco: if fFull hasn't been set (because Keys creation failed because
1312  // fNumBurnInSteps >= fChain->Size()) then this will return infinity, which
1313  // seems ok to me since it will indicate error
1314 
1315  return fKeysCutoff / fFull;
1316 }
1317 
1319 {
1320  RooAbsReal* integral;
1321  Double_t confLevel;
1322  fCutoffVar->setVal(cutoff);
1324  confLevel = integral->getVal(fParameters) / full;
1325  coutI(Eval) << "cutoff = " << cutoff << ", conf = " << confLevel << endl;
1326  //cout << "tmp: cutoff = " << cutoff << ", conf = " << confLevel << endl;
1327  delete integral;
1328  return confLevel;
1329 }
1330 
1332 {
1333  if(fConfidenceLevel == 0)
1334  coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorHist: "
1335  << "confidence level not set " << endl;
1336  if (fHist == NULL)
1337  CreateHist();
1338 
1339  if (fHist == NULL)
1340  // if fHist is still NULL, then CreateHist failed
1341  return NULL;
1342 
1343  return (TH1*) fHist->Clone("MCMCposterior_hist");
1344 }
1345 
1347 {
1348  if (fConfidenceLevel == 0)
1349  coutE(InputArguments) << "Error in MCMCInterval::GetPosteriorKeysPdf: "
1350  << "confidence level not set " << endl;
1351  if (fKeysPdf == NULL)
1352  CreateKeysPdf();
1353 
1354  if (fKeysPdf == NULL)
1355  // if fKeysPdf is still NULL, then it means CreateKeysPdf failed
1356  return NULL;
1357 
1358  return (RooNDKeysPdf*) fKeysPdf->Clone("MCMCPosterior_keys");
1359 }
1360 
1362 {
1363  if (fConfidenceLevel == 0)
1364  coutE(InputArguments) << "MCMCInterval::GetPosteriorKeysProduct: "
1365  << "confidence level not set " << endl;
1366  if (fProduct == NULL) {
1367  CreateKeysPdf();
1368  DetermineByKeys();
1369  }
1370 
1371  if (fProduct == NULL)
1372  // if fProduct is still NULL, then it means CreateKeysPdf failed
1373  return NULL;
1374 
1375  return (RooProduct*) fProduct->Clone("MCMCPosterior_keysproduct");
1376 }
1377 
1379 {
1380  // returns list of parameters
1381  return new RooArgSet(fParameters);
1382 }
1383 
1385 {
1386  return (TMath::Abs(confLevel - fConfidenceLevel) < fEpsilon);
1387 }
1388 
1390 {
1391  return (TMath::Abs(a - b) < TMath::Abs(fDelta * (a + b)/2));
1392 }
1393 
1395 {
1396  if (fAxes == NULL)
1397  return;
1398  if (fProduct == NULL)
1399  DetermineByKeys();
1400  if (fProduct == NULL)
1401  // if fProduct still NULL, then creation failed
1402  return;
1403 
1404  //RooAbsBinning** savedBinning = new RooAbsBinning*[fDimension];
1405  Int_t* savedBins = new Int_t[fDimension];
1406  Int_t i;
1407  Double_t numBins;
1408  RooRealVar* var;
1409 
1410  // kbelasco: Note - the accuracy is only increased here if the binning for
1411  // each RooRealVar is uniform
1412 
1413  // kbelasco: look into why saving the binnings and replacing them doesn't
1414  // work (replaces with 1 bin always).
1415  // Note: this code modifies the binning for the parameters (if they are
1416  // uniform) and sets them back to what they were. If the binnings are not
1417  // uniform, this code does nothing.
1418 
1419  // first scan through fAxes to make sure all binnings are uniform, or else
1420  // we can't change the number of bins because there seems to be an error
1421  // when setting the binning itself rather than just the number of bins
1422  Bool_t tempChangeBinning = true;
1423  for (i = 0; i < fDimension; i++) {
1424  if (!fAxes[i]->getBinning(NULL, false, false).isUniform()) {
1425  tempChangeBinning = false;
1426  break;
1427  }
1428  }
1429 
1430  // kbelasco: for 1 dimension this should be fine, but for more dimensions
1431  // the total nubmer of bins in the histogram increases exponentially with
1432  // the dimension, so don't do this above 1-D for now.
1433  if (fDimension >= 2)
1434  tempChangeBinning = false;
1435 
1436  if (tempChangeBinning) {
1437  // set high nubmer of bins for high accuracy on lower/upper limit by keys
1438  for (i = 0; i < fDimension; i++) {
1439  var = fAxes[i];
1440  //savedBinning[i] = &var->getBinning("__binning_clone", false, true);
1441  savedBins[i] = var->getBinning(NULL, false, false).numBins();
1442  numBins = (var->getMax() - var->getMin()) / fEpsilon;
1443  var->setBins((Int_t)numBins);
1444  }
1445  }
1446 
1447  fKeysDataHist = new RooDataHist("_productDataHist",
1448  "Keys PDF & Heaviside Product Data Hist", fParameters);
1450 
1451  if (tempChangeBinning) {
1452  // set the binning back to normal
1453  for (i = 0; i < fDimension; i++)
1454  //fAxes[i]->setBinning(*savedBinning[i], NULL);
1455  //fAxes[i]->setBins(savedBinning[i]->numBins(), NULL);
1456  fAxes[i]->setBins(savedBins[i], NULL);
1457  }
1458 
1459  //delete[] savedBinning;
1460  delete[] savedBins;
1461 }
1462 
1463 Bool_t MCMCInterval::CheckParameters(const RooArgSet& parameterPoint) const
1464 {
1465  // check that the parameters are correct
1466 
1467  if (parameterPoint.getSize() != fParameters.getSize() ) {
1468  coutE(Eval) << "MCMCInterval: size is wrong, parameters don't match" << std::endl;
1469  return kFALSE;
1470  }
1471  if ( ! parameterPoint.equals( fParameters ) ) {
1472  coutE(Eval) << "MCMCInterval: size is ok, but parameters don't match" << std::endl;
1473  return kFALSE;
1474  }
1475  return kTRUE;
1476 }
MarkovChain * fChain
Definition: MCMCInterval.h:330
static long int sum(long int i)
Definition: Factory.cxx:1785
#define coutE(a)
Definition: RooMsgService.h:35
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Double_t LowerLimitShortest(RooRealVar &param)
get the lower limit of param in the shortest confidence interval Note that this works better for some...
virtual Double_t UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
virtual Double_t LowerLimitTailFraction(RooRealVar &param)
determine lower limit of the lower confidence interval
virtual Int_t numBins(const char *rangeName=0) const
long long Long64_t
Definition: RtypesCore.h:69
virtual TH1 * GetPosteriorHist()
set the number of bins to use (same for all axes, for now) virtual void SetNumBins(Int_t numBins); ...
virtual RooProduct * GetPosteriorKeysProduct()
Get a clone of the (keyspdf * heaviside) product of the posterior.
virtual void CreateKeysPdf()
tomato 3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:271
Long64_t Fill(const Double_t *x, Double_t w=1.)
Definition: THnBase.h:153
return c
#define coutI(a)
Definition: RooMsgService.h:32
virtual void DetermineByKeys()
virtual void CreateVector(RooRealVar *param)
virtual Double_t GetHistCutoff()
get the cutoff bin height for being considered in the confidence interval
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically named contents.
std::vector< Int_t > fVector
Definition: MCMCInterval.h:349
RooRealVar * fCutoffVar
Definition: MCMCInterval.h:342
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
RooCmdArg NormSet(const RooArgSet &nset)
Int_t getIndex(const RooArgSet &coord, Bool_t fast=kFALSE)
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:69
virtual Double_t UpperLimitByKeys(RooRealVar &param)
determine upper limit in the shortest interval by using keys pdf
virtual void SetAxes(RooArgList &axes)
Set which parameters go on which axis.
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:267
virtual void DetermineInterval()
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
virtual Double_t getMin(const char *name=0) const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t IsInInterval(const RooArgSet &point) const
determine whether this point is in the confidence interval
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:34
Long64_t GetNbins() const
Definition: THnSparse.h:107
virtual void CreateKeysDataHist()
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Iterator abstract base class.
Definition: TIterator.h:32
virtual void DetermineShortestInterval()
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TH1.cxx:2546
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
virtual void CreateHist()
virtual Double_t LowerLimitByHist(RooRealVar &param)
determine lower limit using histogram
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
RooNDKeysPdf * fKeysPdf
Definition: MCMCInterval.h:338
Double_t x[n]
Definition: legend1.C:17
Bool_t WithinDeltaFraction(Double_t a, Double_t b)
Efficient multidimensional histogram.
Definition: THnSparse.h:52
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Double_t UpperLimitByHist(RooRealVar &param)
determine upper limit using histogram
virtual RooDataHist * GetAsDataHist(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataHist whose entries contain the values of whichVars.
Int_t numBins() const
Definition: RooAbsBinning.h:37
TIterator * createIterator(Bool_t dir=kIterForward) const
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:78
virtual RooDataSet * GetAsDataSet(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataSet whose entries contain the values of whichVars.
THnSparseT< TArrayF > THnSparseF
Definition: THnSparse.h:233
Long64_t GetBin(const Int_t *idx) const
Definition: THnSparse.h:110
Double_t sum(Bool_t correctForBinSize, Bool_t inverseCorr=kFALSE) const
Return the sum of the weights of all hist bins.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooDataHist * fKeysDataHist
Definition: MCMCInterval.h:341
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:205
virtual void DetermineByDataHist()
MCMCInterval(const char *name=0)
default constructor
enum IntervalType fIntervalType
Definition: MCMCInterval.h:377
RooCmdArg SelectVars(const RooArgSet &vars)
virtual Double_t GetKeysPdfCutoff()
get the cutoff RooNDKeysPdf value for being considered in the confidence interval ...
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual Double_t weight() const
Definition: RooDataHist.h:96
virtual Double_t LowerLimitBySparseHist(RooRealVar &param)
determine lower limit using histogram
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:255
void Sumw2()
Enable calculation of errors.
Definition: THnSparse.cxx:949
virtual void DetermineByHist()
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:49
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TAxis * GetYaxis()
Definition: TH1.h:325
RooDataHist * fDataHist
Definition: MCMCInterval.h:333
static const Double_t DEFAULT_EPSILON
TAxis * GetAxis(Int_t dim) const
Definition: THnBase.h:135
virtual Double_t UpperLimit(RooRealVar &param)
get the highest value of param that is within the confidence interval
virtual void SetConfidenceLevel(Double_t cl)
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
Represents the Heaviside function.
Definition: Heaviside.h:37
Generic N-dimensional implementation of a kernel estimation p.d.f.
Definition: RooNDKeysPdf.h:45
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
Definition: RooProduct.h:32
virtual Double_t GetActualConfidenceLevel()
virtual Double_t GetKeysPdfCutoff() { return fKeysCutoff; }
static const Double_t DEFAULT_DELTA
long Long_t
Definition: RtypesCore.h:50
ConfInterval is an interface class for a generic interval in the RooStats framework.
Definition: ConfInterval.h:44
Stores the steps in a Markov Chain of points.
Definition: MarkovChain.h:53
Namespace for the RooStats classes.
Definition: Asimov.h:20
RooCmdArg EventRange(Int_t nStart, Int_t nStop)
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
#define ClassImp(name)
Definition: Rtypes.h:279
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual void CreateDataHist()
virtual Double_t LowerLimit(RooRealVar &param)
get the lowest value of param that is within the confidence interval
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
Bool_t CheckParameters(const RooArgSet &point) const
check if parameters are correct. (dummy implementation to start)
Double_t GetSumw() const
Definition: THnBase.h:193
The TH1 histogram class.
Definition: TH1.h:80
Double_t GetBinContent(const Int_t *idx) const
Definition: THnSparse.h:132
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, Double_t scaleFactor, Bool_t correctForBinVolume=kFALSE, Bool_t showProgress=kFALSE) const
Fill a RooDataHist with values sampled from this function at the bin centers.
Bool_t AcceptableConfLevel(Double_t confLevel)
virtual Int_t numEntries() const
Return the number of bins.
Double_t GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
virtual void CreateSparseHist()
THist< 3, float, THistStatContent, THistStatUncertainty > TH3F
Definition: THist.hxx:314
TAxis * GetZaxis()
Definition: TH1.h:326
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
Mother of all ROOT objects.
Definition: TObject.h:44
virtual Double_t getMax(const char *name=0) const
virtual void DetermineTailFractionInterval()
virtual Double_t UpperLimitByDataHist(RooRealVar &param)
determine upper limit using histogram
virtual void SetParameters(const RooArgSet &parameters)
Set the parameters of interest for this interval and change other internal data members accordingly...
virtual TObject * Next()=0
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define NULL
Definition: Rtypes.h:82
virtual Int_t Size() const
get the number of steps in the chain
Definition: MarkovChain.h:72
virtual Double_t UpperLimitTailFraction(RooRealVar &param)
determine upper limit of the lower confidence interval
virtual Double_t LowerLimitByKeys(RooRealVar &param)
determine lower limit in the shortest interval by using keys pdf
MCMCInterval is a concrete implementation of the RooStats::ConfInterval interface.
Definition: MCMCInterval.h:88
Int_t getSize() const
virtual void DetermineBySparseHist()
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
Definition: MarkovChain.h:74
virtual Double_t UpperLimitShortest(RooRealVar &param)
get the upper limit of param in the confidence interval Note that this works better for some distribu...
const Int_t n
Definition: legend1.C:16
virtual Double_t CalcConfLevel(Double_t cutoff, Double_t full)
char name[80]
Definition: TGX11.cxx:109
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
virtual Double_t LowerLimitByDataHist(RooRealVar &param)
determine lower limit using histogram
TAxis * GetXaxis()
Definition: TH1.h:324
virtual Double_t Weight() const
get the weight of the current (last indexed) entry
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:503
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Definition: RooArgSet.cxx:527
virtual RooArgSet * GetParameters() const
return a set containing the parameters of this interval the caller owns the returned RooArgSet* ...