```// @(#)root/roostats:\$Id\$
// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
/*************************************************************************
*                                                                       *
* For the licensing terms see \$ROOTSYS/LICENSE.                         *
* For the list of contributors see \$ROOTSYS/README/CREDITS.             *
*************************************************************************/

//_________________________________________________
/*
BEGIN_HTML
<p>
BayesianCalculator is a concrete implementation of IntervalCalculator, providing the computation
of a credible interval using a Bayesian method.
The class works only for one single parameter of interest and it integrates the likelihood function with the given prior
probability density function to compute the posterior probability. The result of the class is a one dimensional interval
(class SimpleInterval ), which is obtained from inverting the cumulative posterior distribution.
</p>

<p>
The interface allows one to construct the class by passing the data set, probability density function for the model, the prior
functions and then the parameter of interest to scan. The nuisance parameters can also be passed to be marginalized when
computing the posterior. Alternatively, the class can be constructed by passing the data and the ModelConfig containing
all the needed information (model pdf, prior pdf, parameter of interest, nuisance parameters, etc..)
</p>
<p>
After configuring the calculator, one only needs to ask GetInterval(), which
will return an SimpleInterval object. By default the extrem of the integral are obtained by inverting directly the
cumulative posterior distribution. By using the method <tt>SetScanOfPosterior(nbins)</tt> the interval is then obtained by
scanning  the posterior function in the given number of points. The firts method is in general faster but it requires an
integration one extra dimension  ( in the poi in addition to the nuisance parameters), therefore in some case it can be
less robust.
</p>
The class can also return the posterior function (method <tt>GetPosteriorFunction</tt>) or if needed the normalized
posterior function (the posterior pdf) (method <tt>GetPosteriorPdf</tt>). A posterior plot is also obtained using
the <tt>GetPosteriorPlot</tt> method.
<p>
The class allows to use different integration methods for integrating in the nuisances and in the poi. All the numerical
integration methods of ROOT can be used via the method <tt>SetIntegrationType</tt> (see more in the documentation of
this method).

END_HTML
*/
//_________________________________________________

#include "RooAbsFunc.h"
#include "RooAbsReal.h"
#include "RooRealVar.h"
#include "RooArgSet.h"
#include "RooBrentRootFinder.h"
#include "RooFormulaVar.h"
#include "RooGenericPdf.h"
#include "RooPlot.h"
#include "RooProdPdf.h"
#include "RooDataSet.h"

// include header file of this class
#include "RooStats/BayesianCalculator.h"
#include "RooStats/ModelConfig.h"
#include "RooStats/RooStatsUtils.h"

#include "Math/IFunction.h"
#include "Math/IntegratorMultiDim.h"
#include "Math/Integrator.h"
#include "Math/RootFinder.h"
#include "Math/BrentMinimizer1D.h"
#include "RooFunctor.h"
#include "RooFunctor1DBinding.h"
#include "RooTFnBinding.h"
#include "RooMsgService.h"

#include "TAxis.h"
#include "TF1.h"
#include "TH1.h"
#include "TMath.h"
#include "TCanvas.h"

#include <map>
#include <cmath>

//#include "TRandom.h"
#include "RConfigure.h"

ClassImp(RooStats::BayesianCalculator)

using namespace std;

namespace RooStats {

// first some utility classes and functions

#ifdef R__HAS_MATHMORE
const ROOT::Math::RootFinder::EType kRootFinderType = ROOT::Math::RootFinder::kGSL_BRENT;
#else
const ROOT::Math::RootFinder::EType kRootFinderType = ROOT::Math::RootFinder::kBRENT;
#endif

struct  LikelihoodFunction {
LikelihoodFunction(RooFunctor & f, RooFunctor * prior = 0, double offset = 0) :
fFunc(f), fPrior(prior),
fOffset(offset), fMaxL(0) {
fFunc.binding().resetNumCall();
}

void SetPrior(RooFunctor * prior) { fPrior = prior; }

double operator() (const double *x ) const {
double nll = fFunc(x) - fOffset;
double likelihood =  std::exp(-nll);

if (fPrior) likelihood *= (*fPrior)(x);

int nCalls = fFunc.binding().numCall();
if (nCalls > 0 && nCalls % 1000 == 0) {
ooccoutD((TObject*)0,Eval) << "Likelihood evaluation ncalls = " << nCalls
<< " x0 " << x[0] << "  nll = " << nll+fOffset;
if (fPrior) ooccoutD((TObject*)0,Eval) << " prior(x) = " << (*fPrior)(x);
ooccoutD((TObject*)0,Eval) << " likelihood " << likelihood
<< " max Likelihood " << fMaxL << std::endl;
}

if  (likelihood > fMaxL ) {
fMaxL = likelihood;
if ( likelihood > 1.E10) {
ooccoutW((TObject*)0,Eval) << "LikelihoodFunction::()  WARNING - Huge likelihood value found for  parameters ";
for (int i = 0; i < fFunc.nObs(); ++i)
ooccoutW((TObject*)0,Eval) << " x[" << i << " ] = " << x[i];
ooccoutW((TObject*)0,Eval) << "  nll = " << nll << " L = " << likelihood << std::endl;
}
}

return likelihood;
}

// for the 1D case
double operator() (double x) const {
// just call the previous method
assert(fFunc.nObs() == 1); // check nobs = 1
double tmp = x;
return (*this)(&tmp);
}

RooFunctor & fFunc;     // functor representing the nll function
RooFunctor * fPrior;     // functor representing the prior function
double fOffset;         //  offset used to bring the nll in a reasanble range for computing the exponent
mutable double fMaxL;
};

// Posterior CDF Function class
// for integral of posterior function in nuisance and POI
// 1-Dim function as function of the poi

class PosteriorCdfFunction : public ROOT::Math::IGenFunction {

public:

PosteriorCdfFunction(RooAbsReal & nll,  RooArgList & bindParams, RooAbsReal * prior = 0, const char * integType = 0, double nllMinimum = 0) :
fFunctor(nll, bindParams, RooArgList() ),              // functor
fPriorFunc(std::shared_ptr<RooFunctor>((RooFunctor*)0)),
fLikelihood(fFunctor, 0, nllMinimum),         // integral of exp(-nll) function
fIntegrator(ROOT::Math::IntegratorMultiDim::GetType(integType) ),  // integrator
fXmin(bindParams.getSize() ),               // vector of parameters (min values)
fXmax(bindParams.getSize() ),               // vector of parameter (max values)
fNorm(1.0), fNormErr(0.0), fOffset(0), fMaxPOI(0),
fHasNorm(false),  fUseOldValues(true), fError(false)
{

if (prior) {
fPriorFunc = std::shared_ptr<RooFunctor>(new RooFunctor(*prior, bindParams, RooArgList() ));
fLikelihood.SetPrior(fPriorFunc.get() );
}

fIntegrator.SetFunction(fLikelihood, bindParams.getSize() );

ooccoutD((TObject*)0,NumIntegration) << "PosteriorCdfFunction::Compute integral of posterior in nuisance and poi. "
<< " nllMinimum is " << nllMinimum << std::endl;

std::vector<double> par(bindParams.getSize());
for (unsigned int i = 0; i < fXmin.size(); ++i) {
RooRealVar & var = (RooRealVar &) bindParams[i];
fXmin[i] = var.getMin();
fXmax[i] = var.getMax();
par[i] = var.getVal();
ooccoutD((TObject*)0,NumIntegration) << "PosteriorFunction::Integrate" << var.GetName()
<< " in interval [ " <<  fXmin[i] << " , " << fXmax[i] << " ] " << std::endl;
}

fIntegrator.Options().Print(ooccoutD((TObject*)0,NumIntegration));

// store max POI value because it will be changed when evaluating the function
fMaxPOI = fXmax[0];

// compute first the normalization with  the poi
fNorm = (*this)( fMaxPOI );
if (fError) ooccoutE((TObject*)0,NumIntegration) << "PosteriorFunction::Error computing normalization - norm = " << fNorm << std::endl;
fHasNorm = true;
fNormCdfValues.insert(std::make_pair(fXmin[0], 0) );
fNormCdfValues.insert(std::make_pair(fXmax[0], 1.0) );

}

// copy constructor (needed for Cloning the object)
// need special treatment because integrator
// has no copy constuctor
PosteriorCdfFunction(const PosteriorCdfFunction & rhs) :
ROOT::Math::IGenFunction(),
fFunctor(rhs.fFunctor),
//fPriorFunc(std::shared_ptr<RooFunctor>((RooFunctor*)0)),
fPriorFunc(rhs.fPriorFunc),
fLikelihood(fFunctor, fPriorFunc.get(), rhs.fLikelihood.fOffset),
fIntegrator(ROOT::Math::IntegratorMultiDim::GetType( rhs.fIntegrator.Name().c_str() ) ),  // integrator
fXmin( rhs.fXmin),
fXmax( rhs.fXmax),
fNorm( rhs.fNorm),
fNormErr( rhs.fNormErr),
fOffset(rhs.fOffset),
fMaxPOI(rhs.fMaxPOI),
fHasNorm(rhs.fHasNorm),
fUseOldValues(rhs.fUseOldValues),
fError(rhs.fError),
fNormCdfValues(rhs.fNormCdfValues)
{
fIntegrator.SetFunction(fLikelihood, fXmin.size() );
// need special treatment for the smart pointer
// if (rhs.fPriorFunc.get() ) {
//    fPriorFunc = std::shared_ptr<RooFunctor>(new RooFunctor(*(rhs.fPriorFunc) ) );
//    fLikelihood.SetPrior( fPriorFunc.get() );
// }
}

bool HasError() const { return fError; }

ROOT::Math::IGenFunction * Clone() const {
ooccoutD((TObject*)0,NumIntegration) << " cloning function .........." << std::endl;
return new PosteriorCdfFunction(*this);
}

// offset value for computing the root
void SetOffset(double offset) { fOffset = offset; }

private:

// make assignment operator private
PosteriorCdfFunction& operator=(const PosteriorCdfFunction &) {
return *this;
}

double DoEval (double x) const {

// evaluate cdf at poi value x by integrating poi from [xmin,x] and all the nuisances
fXmax[0] = x;
if (x <= fXmin[0] ) return -fOffset;
// could also avoid a function evaluation at maximum
if (x >= fMaxPOI && fHasNorm) return 1. - fOffset;  // cdf is bound to these values

// computes the integral using a previous cdf estimate
double  normcdf0 = 0;
if (fHasNorm && fUseOldValues) {
// look in the map of the stored cdf values the closes one
std::map<double,double>::iterator itr = fNormCdfValues.upper_bound(x);
itr--;   // upper bound returns a poistion 1 up of the value we want
if (itr != fNormCdfValues.end() ) {
fXmin[0] = itr->first;
normcdf0 = itr->second;
// ooccoutD((TObject*)0,NumIntegration) << "PosteriorCdfFunction:   computing integral between in poi interval : "
//                                      << fXmin[0] << " -  " << fXmax[0] << std::endl;
}
}

fFunctor.binding().resetNumCall();  // reset number of calls for debug

double cdf = fIntegrator.Integral(&fXmin[0],&fXmax[0]);
double error = fIntegrator.Error();
double normcdf =  cdf/fNorm;  // normalize the cdf

ooccoutD((TObject*)0,NumIntegration) << "PosteriorCdfFunction: poi = [" << fXmin[0] << " , "
<< fXmax[0] << "] integral =  " << cdf << " +/- " << error
<< "  norm-integ = " << normcdf << " cdf(x) = " << normcdf+normcdf0
<< " ncalls = " << fFunctor.binding().numCall() << std::endl;

if (TMath::IsNaN(cdf) || cdf > std::numeric_limits<double>::max()) {
ooccoutE((TObject*)0,NumIntegration) << "PosteriorFunction::Error computing integral - cdf = "
<< cdf << std::endl;
fError = true;
}

if (cdf != 0 && error/cdf > 0.2 )
oocoutW((TObject*)0,NumIntegration) << "PosteriorCdfFunction: integration error  is larger than 20 %   x0 = " << fXmin[0]
<< " x = " << x << " cdf(x) = " << cdf << " +/- " << error << std::endl;

if (!fHasNorm) {
oocoutI((TObject*)0,NumIntegration) << "PosteriorCdfFunction - integral of posterior = "
<< cdf << " +/- " << error << std::endl;
fNormErr = error;
return cdf;
}

normcdf += normcdf0;

// store values in the map
if (fUseOldValues) {
fNormCdfValues.insert(std::make_pair(x, normcdf) );
}

double errnorm = sqrt( error*error + normcdf*normcdf * fNormErr * fNormErr )/fNorm;
if (normcdf > 1. + 3 * errnorm) {
oocoutW((TObject*)0,NumIntegration) << "PosteriorCdfFunction: normalized cdf values is larger than 1"
<< " x = " << x << " normcdf(x) = " << normcdf << " +/- " << error/fNorm << std::endl;
}

return normcdf - fOffset;  // apply an offset (for finding the roots)
}

mutable RooFunctor fFunctor;                   // functor binding nll
mutable std::shared_ptr<RooFunctor> fPriorFunc;  // functor binding the prior
LikelihoodFunction fLikelihood;               // likelihood function
mutable ROOT::Math::IntegratorMultiDim  fIntegrator; // integrator  (mutable because Integral() is not const
mutable std::vector<double> fXmin;    // min value of parameters (poi+nuis) -
mutable std::vector<double> fXmax;   // max value of parameters (poi+nuis) - max poi changes so it is mutable
double fNorm;      // normalization value (computed in ctor)
mutable double fNormErr;    // normalization error value (computed in ctor)
double fOffset;   // offset for computing the root
double fMaxPOI;  // maximum value of POI
bool fHasNorm; // flag to control first call to the function
bool fUseOldValues;  // use old cdf values
mutable bool fError;     // flag to indicate if a numerical evaluation error occurred
mutable std::map<double,double> fNormCdfValues;
};

//__________________________________________________________________
// Posterior Function class
// 1-Dim function as function of the poi
// and it integrated all the nuisance parameters

class PosteriorFunction : public ROOT::Math::IGenFunction {

public:

PosteriorFunction(RooAbsReal & nll, RooRealVar & poi, RooArgList & nuisParams, RooAbsReal * prior = 0, const char * integType = 0, double
norm = 1.0,  double nllOffset = 0, int niter = 0) :
fFunctor(nll, nuisParams, RooArgList() ),
fPriorFunc(std::shared_ptr<RooFunctor>((RooFunctor*)0)),
fLikelihood(fFunctor, 0, nllOffset),
fPoi(&poi),
fXmin(nuisParams.getSize() ),
fXmax(nuisParams.getSize() ),
fNorm(norm),
fError(0)
{

if (prior) {
fPriorFunc = std::shared_ptr<RooFunctor>(new RooFunctor(*prior, nuisParams, RooArgList() ));
fLikelihood.SetPrior(fPriorFunc.get() );
}

ooccoutD((TObject*)0,NumIntegration) << "PosteriorFunction::Evaluate the posterior function by integrating the nuisances: " << std::endl;
for (unsigned int i = 0; i < fXmin.size(); ++i) {
RooRealVar & var = (RooRealVar &) nuisParams[i];
fXmin[i] = var.getMin();
fXmax[i] = var.getMax();
ooccoutD((TObject*)0,NumIntegration) << "PosteriorFunction::Integrate " << var.GetName()
<< " in interval [" <<  fXmin[i] << " , " << fXmax[i] << " ] " << std::endl;
}
if (fXmin.size() == 1) { // 1D case
fIntegratorOneDim.reset( new ROOT::Math::Integrator(ROOT::Math::IntegratorOneDim::GetType(integType) ) );

fIntegratorOneDim->SetFunction(fLikelihood);
// interested only in relative tolerance
//fIntegratorOneDim->SetAbsTolerance(1.E-300);
fIntegratorOneDim->Options().Print(ooccoutD((TObject*)0,NumIntegration) );
}
else if (fXmin.size() > 1) { // multiDim case
fIntegratorMultiDim.reset(new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegratorMultiDim::GetType(integType) ) );
fIntegratorMultiDim->SetFunction(fLikelihood, fXmin.size());
ROOT::Math::IntegratorMultiDimOptions opt = fIntegratorMultiDim->Options();
if (niter > 0) {
opt.SetNCalls(niter);
fIntegratorMultiDim->SetOptions(opt);
}
//fIntegratorMultiDim->SetAbsTolerance(1.E-300);
// print the options
opt.Print(ooccoutD((TObject*)0,NumIntegration) );
}
}

ROOT::Math::IGenFunction * Clone() const {
assert(1);
return 0; // cannot clone this function for integrator
}

double Error() const { return fError;}

private:
double DoEval (double x) const {

// evaluate posterior function at a poi value x by integrating all nuisance parameters

fPoi->setVal(x);
fFunctor.binding().resetNumCall();  // reset number of calls for debug

double f = 0;
double error = 0;
if (fXmin.size() == 1) { // 1D case
f = fIntegratorOneDim->Integral(fXmin[0],fXmax[0]);
error = fIntegratorOneDim->Error();
}
else if (fXmin.size() > 1) { // multi-dim case
f = fIntegratorMultiDim->Integral(&fXmin[0],&fXmax[0]);
error = fIntegratorMultiDim->Error();
} else {
// no integration to be done
f = fLikelihood(x);
}

// debug
ooccoutD((TObject*)0,NumIntegration) << "PosteriorFunction:  POI value  =  "
<< x << "\tf(x) =  " << f << " +/- " << error
<< "  norm-f(x) = " << f/fNorm
<< " ncalls = " << fFunctor.binding().numCall() << std::endl;

if (f != 0 && error/f > 0.2 )
ooccoutW((TObject*)0,NumIntegration) << "PosteriorFunction::DoEval - Error from integration in "
<< fXmin.size() <<  " Dim is larger than 20 % "
<< "x = " << x << " p(x) = " << f << " +/- " << error << std::endl;

fError = error / fNorm;
return f / fNorm;
}

mutable RooFunctor fFunctor;
mutable std::shared_ptr<RooFunctor> fPriorFunc;  // functor binding the prior
LikelihoodFunction fLikelihood;
RooRealVar * fPoi;
std::unique_ptr<ROOT::Math::Integrator>  fIntegratorOneDim;
std::unique_ptr<ROOT::Math::IntegratorMultiDim>  fIntegratorMultiDim;
std::vector<double> fXmin;
std::vector<double> fXmax;
double fNorm;
mutable double fError;
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Posterior function obtaining sampling  toy MC for th enuisance according to their pdf
class PosteriorFunctionFromToyMC : public ROOT::Math::IGenFunction {

public:

PosteriorFunctionFromToyMC(RooAbsReal & nll, RooAbsPdf & pdf, RooRealVar & poi, RooArgList & nuisParams, RooAbsReal * prior = 0, double
nllOffset = 0, int niter = 0, bool redoToys = true ) :
fFunctor(nll, nuisParams, RooArgList() ),
fPriorFunc(std::shared_ptr<RooFunctor>((RooFunctor*)0)),
fLikelihood(fFunctor, 0, nllOffset),
fPdf(&pdf),
fPoi(&poi),
fNuisParams(nuisParams),
fGenParams(0),
fNumIterations(niter),
fError(-1),
fRedoToys(redoToys)
{
if (niter == 0) fNumIterations = 100; // default value

if (prior) {
fPriorFunc = std::shared_ptr<RooFunctor>(new RooFunctor(*prior, nuisParams, RooArgList() ));
fLikelihood.SetPrior(fPriorFunc.get() );
}

ooccoutI((TObject*)0,InputArguments) << "PosteriorFunctionFromToyMC::Evaluate the posterior function by randomizing the nuisances:  niter " << fNumIterations << std::endl;

ooccoutI((TObject*)0,InputArguments) << "PosteriorFunctionFromToyMC::Pdf used for randomizing the nuisance is " << fPdf->GetName() << std::endl;
// check that pdf contains  the nuisance
RooArgSet * vars = fPdf->getVariables();
for (int i = 0; i < fNuisParams.getSize(); ++i) {
if (!vars->find( fNuisParams[i].GetName() ) ) {
ooccoutW((TObject*)0,InputArguments) << "Nuisance parameter " << fNuisParams[i].GetName()
<< " is not part of sampling pdf. "
<< "they will be trated as constant " << std::endl;
}
}
delete vars;

if (!fRedoToys) {
ooccoutI((TObject*)0,InputArguments) << "PosteriorFunctionFromToyMC::Generate nuisance toys only one time (for all POI points)" << std::endl;
GenerateToys();
}
}

virtual ~PosteriorFunctionFromToyMC() { if (fGenParams) delete fGenParams; }

// generate first n-samples of the nuisance parameters
void GenerateToys() const {
if (fGenParams) delete fGenParams;
fGenParams = fPdf->generate(fNuisParams, fNumIterations);
if(fGenParams==0) {
ooccoutE((TObject*)0,InputArguments) << "PosteriorFunctionFromToyMC - failed to generate nuisance parameters" << std::endl;
}
}

double Error() const { return fError;}

ROOT::Math::IGenFunction * Clone() const {
// use defsult copy constructor
//return new PosteriorFunctionFromToyMC(*this);
//  clone not implemented
assert(1);
return 0;
}

private:
// evaluate the posterior at the poi value x
double DoEval( double x) const {

int npar = fNuisParams.getSize();
assert (npar > 0);

// generate the toys
if (fRedoToys) GenerateToys();
if (!fGenParams) return 0;

// evaluate posterior function at a poi value x by integrating all nuisance parameters

fPoi->setVal(x);

// loop over all of the generate data
double sum = 0;
double sum2 = 0;

for(int iter=0; iter<fNumIterations; ++iter) {

// get the set of generated parameters and set the nuisance parameters to the generated values
std::vector<double> p(npar);
for (int i = 0; i < npar; ++i) {
const RooArgSet* genset=fGenParams->get(iter);
RooAbsArg * arg = genset->find( fNuisParams[i].GetName() );
RooRealVar * var = dynamic_cast<RooRealVar*>(arg);
assert(var != 0);
p[i] = var->getVal();
((RooRealVar &) fNuisParams[i]).setVal(p[i]);
}

// evaluate now the likelihood function
double fval =  fLikelihood( &p.front() );

// liklihood already must contained the pdf we have sampled
// so we must divided by it. The value must be normalized on all
// other parameters
RooArgSet arg(fNuisParams);
double nuisPdfVal = fPdf->getVal(&arg);
fval /= nuisPdfVal;

if( fval > std::numeric_limits<double>::max()  ) {
ooccoutE((TObject*)0,Eval) <<  "BayesianCalculator::EvalPosteriorFunctionFromToy : "
<< "Likelihood evaluates to infinity " << std::endl;
ooccoutE((TObject*)0,Eval) <<  "poi value =  " << x << std::endl;
ooccoutE((TObject*)0,Eval) <<  "Nuisance  parameter values :  ";
for (int i = 0; i < npar; ++i)
ooccoutE((TObject*)0,Eval) << fNuisParams[i].GetName() << " = " << p[i] << " ";
ooccoutE((TObject*)0,Eval) <<  " - return 0   " << std::endl;

fError = 1.E30;
return 0;
}
if(  TMath::IsNaN(fval) ) {
ooccoutE((TObject*)0,Eval) <<  "BayesianCalculator::EvalPosteriorFunctionFromToy : "
<< "Likelihood is a NaN " << std::endl;
ooccoutE((TObject*)0,Eval) <<  "poi value =  " << x << std::endl;
ooccoutE((TObject*)0,Eval) <<  "Nuisance  parameter values :  ";
for (int i = 0; i < npar; ++i)
ooccoutE((TObject*)0,Eval) << fNuisParams[i].GetName() << " = " << p[i] << " ";
ooccoutE((TObject*)0,Eval) <<  " - return 0   " << std::endl;
fError = 1.E30;
return 0;
}

sum += fval;
sum2 += fval*fval;
}

// compute the average and variance
double val = sum/double(fNumIterations);
double dval2 = std::max( sum2/double(fNumIterations) - val*val, 0.0);
fError = std::sqrt( dval2 / fNumIterations);

// debug
ooccoutD((TObject*)0,NumIntegration) << "PosteriorFunctionFromToyMC:  POI value  =  "
<< x << "\tp(x) =  " << val << " +/- " << fError << std::endl;

if (val != 0 && fError/val > 0.2 ) {
ooccoutW((TObject*)0,NumIntegration) << "PosteriorFunctionFromToyMC::DoEval"
<< " - Error in estimating posterior is larger than 20% ! "
<< "x = " << x << " p(x) = " << val << " +/- " << fError << std::endl;
}

return val;
}

mutable RooFunctor fFunctor;
mutable std::shared_ptr<RooFunctor> fPriorFunc;  // functor binding the prior
LikelihoodFunction fLikelihood;
mutable RooAbsPdf * fPdf;
RooRealVar * fPoi;
RooArgList fNuisParams;
mutable RooDataSet * fGenParams;
int fNumIterations;
mutable double fError;
bool fRedoToys;                    // do toys every iteration

};

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation of BayesianCalculator
/////////////////////////////////////////////////////////////////////////////////////////////////////

BayesianCalculator::BayesianCalculator() :
fData(0),
fPdf(0),
fPriorPdf(0),
fNuisancePdf(0),
fProductPdf (0), fLogLike(0), fLikelihood (0), fIntegratedLikelihood (0), fPosteriorPdf(0),
fPosteriorFunction(0), fApproxPosterior(0),
fLower(0), fUpper(0),
fNLLMin(0),
fSize(0.05), fLeftSideFraction(0.5),
fBrfPrecision(0.00005),
fNScanBins(-1),
fNumIterations(0),
fValidInterval(false)
{
// default constructor
}

BayesianCalculator::BayesianCalculator( /* const char* name,  const char* title, */
RooAbsData& data,
RooAbsPdf& pdf,
const RooArgSet& POI,
RooAbsPdf& priorPdf,
const RooArgSet* nuisanceParameters ) :
fData(&data),
fPdf(&pdf),
fPOI(POI),
fPriorPdf(&priorPdf),
fNuisancePdf(0),
fProductPdf (0), fLogLike(0), fLikelihood (0), fIntegratedLikelihood (0), fPosteriorPdf(0),
fPosteriorFunction(0), fApproxPosterior(0),
fLower(0), fUpper(0),
fNLLMin(0),
fSize(0.05), fLeftSideFraction(0.5),
fBrfPrecision(0.00005),
fNScanBins(-1),
fNumIterations(0),
fValidInterval(false)
{
// Constructor from data set, model pdf, parameter of interests and prior pdf
// If nuisance parameters are given they will be integrated according either to the prior or
// their constraint term included in the model

// remove constant nuisance parameters
RemoveConstantParameters(&fNuisanceParameters);
}

BayesianCalculator::BayesianCalculator( RooAbsData& data,
ModelConfig & model) :
fData(&data),
fPdf(model.GetPdf()),
fPriorPdf( model.GetPriorPdf()),
fNuisancePdf(0),
fProductPdf (0), fLogLike(0), fLikelihood (0), fIntegratedLikelihood (0), fPosteriorPdf(0),
fPosteriorFunction(0), fApproxPosterior(0),
fLower(0), fUpper(0),
fNLLMin(0),
fSize(0.05), fLeftSideFraction(0.5),
fBrfPrecision(0.00005),
fNScanBins(-1),
fNumIterations(0),
fValidInterval(false)
{
// Constructor from a data set and a ModelConfig
// model pdf, poi and nuisances will be taken from the ModelConfig
SetModel(model);
}

BayesianCalculator::~BayesianCalculator()
{
// destructor
ClearAll();
}

void BayesianCalculator::ClearAll() const {
// clear all cached pdf objects
if (fProductPdf) delete fProductPdf;
if (fLogLike) delete fLogLike;
if (fLikelihood) delete fLikelihood;
if (fIntegratedLikelihood) delete fIntegratedLikelihood;
if (fPosteriorPdf) delete fPosteriorPdf;
if (fPosteriorFunction) delete fPosteriorFunction;
if (fApproxPosterior) delete fApproxPosterior;
fPosteriorPdf = 0;
fPosteriorFunction = 0;
fProductPdf = 0;
fLogLike = 0;
fLikelihood = 0;
fIntegratedLikelihood = 0;
fLower = 0;
fUpper = 0;
fNLLMin = 0;
fValidInterval = false;
}

void BayesianCalculator::SetModel(const ModelConfig & model) {
// set the model to use
// The model pdf, prior pdf, parameter of interest and nuisances
// will be taken according to the model

fPdf = model.GetPdf();
fPriorPdf =  model.GetPriorPdf();
// assignment operator = does not do a real copy the sets (must use add method)
fPOI.removeAll();
fNuisanceParameters.removeAll();
fConditionalObs.removeAll();
if (model.GetNuisanceParameters())  fNuisanceParameters.add( *(model.GetNuisanceParameters() ) );
if (model.GetConditionalObservables())  fConditionalObs.add( *(model.GetConditionalObservables() ) );
// remove constant nuisance parameters
RemoveConstantParameters(&fNuisanceParameters);

// invalidate the cached pointers
ClearAll();
}

RooAbsReal* BayesianCalculator::GetPosteriorFunction() const
{
// Build and return the posterior function (not normalized) as a RooAbsReal
// the posterior is obtained from the product of the likelihood function and the
// prior pdf which is then intergated in the nuisance parameters (if existing).
// A prior function for the nuisance can be specified either in the prior pdf object
// or in the model itself. If no prior nuisance is specified, but prior parameters are then
// the integration is performed assuming a flat prior for the nuisance parameters.
// NOTE: the return object is managed by the class, users do not need to delete it

if (fIntegratedLikelihood) return fIntegratedLikelihood;
if (fLikelihood) return fLikelihood;

// run some sanity checks
if (!fPdf ) {
coutE(InputArguments) << "BayesianCalculator::GetPosteriorPdf - missing pdf model" << std::endl;
return 0;
}
if (fPOI.getSize() == 0) {
coutE(InputArguments) << "BayesianCalculator::GetPosteriorPdf - missing parameter of interest" << std::endl;
return 0;
}
if (fPOI.getSize() > 1) {
coutE(InputArguments) << "BayesianCalculator::GetPosteriorPdf - current implementation works only on 1D intervals" << std::endl;
return 0;
}

RooArgSet* constrainedParams = fPdf->getParameters(*fData);
// remove the constant parameters
RemoveConstantParameters(constrainedParams);

//constrainedParams->Print("V");

// use RooFit::Constrain() to be sure constraints terms are taken into account
fLogLike = fPdf->createNLL(*fData, RooFit::Constrain(*constrainedParams), RooFit::ConditionalObservables(fConditionalObs) );

ccoutD(Eval) <<  "BayesianCalculator::GetPosteriorFunction : "
<< " pdf value " <<  fPdf->getVal()
<< " neglogLikelihood = " << fLogLike->getVal() << std::endl;

if (fPriorPdf)
ccoutD(Eval)  << "\t\t\t priorPOI value " << fPriorPdf->getVal() << std::endl;

// check that likelihood evaluation is not inifinity
double nllVal =  fLogLike->getVal();
if ( nllVal > std::numeric_limits<double>::max() ) {
coutE(Eval) <<  "BayesianCalculator::GetPosteriorFunction : "
<< " Negative log likelihood evaluates to infinity " << std::endl
<< " Non-const Parameter values : ";
RooArgList p(*constrainedParams);
for (int i = 0; i < p.getSize(); ++i) {
RooRealVar * v = dynamic_cast<RooRealVar *>(&p[i] );
if (v!=0) ccoutE(Eval) << v->GetName() << " = " << v->getVal() << "   ";
}
ccoutE(Eval) << std::endl;
ccoutE(Eval) << "--  Perform a full likelihood fit of the model before or set more reasanable parameter values"
<< std::endl;
coutE(Eval) << "BayesianCalculator::GetPosteriorFunction : " << " cannot compute posterior function "  << std::endl;
return 0;
}

// need do find minimum of log-likelihood in the range to shift function
// to avoid numerical errors when we compute the likelihood (overflows in the exponent)
// N.B.: this works for only 1 parameter of interest otherwise Minuit should be used for finding the minimum
RooFunctor * nllFunc = fLogLike->functor(fPOI);
assert(nllFunc);
ROOT::Math::Functor1D wnllFunc(*nllFunc);
RooRealVar* poi = dynamic_cast<RooRealVar*>( fPOI.first() );
assert(poi);

// try to reduce some error messages
//Bool_t silentMode = (RooMsgService::instance().globalKillBelow() >= RooFit::ERROR || RooMsgService::instance().silentMode()) ;
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CountErrors);

coutI(Eval) <<  "BayesianCalculator::GetPosteriorFunction : "
<< " nll value " <<  nllVal << " poi value = " << poi->getVal() << std::endl;

ROOT::Math::BrentMinimizer1D minim;
minim.SetFunction(wnllFunc,poi->getMin(),poi->getMax() );
bool ret  = minim.Minimize(100,1.E-3,1.E-3);
fNLLMin = 0;
if (ret) fNLLMin = minim.FValMinimum();

coutI(Eval) << "BayesianCalculator::GetPosteriorFunction : minimum of NLL vs POI for POI =  "
<< poi->getVal() << " min NLL = " << fNLLMin << std::endl;

delete nllFunc;

delete constrainedParams;

if ( fNuisanceParameters.getSize() == 0 ||  fIntegrationType.Contains("ROOFIT") ) {

ccoutD(Eval) << "BayesianCalculator::GetPosteriorFunction : use ROOFIT integration  "
<< std::endl;

#ifdef DOLATER // (not clear why this does not work)
// need to make in this case a likelihood from the nll and make the product with the prior
TString likeName = TString("likelihood_times_prior_") + TString(fPriorPdf->GetName());
TString formula;
formula.Form("exp(-@0+%f+log(@1))",fNLLMin);
fLikelihood = new RooFormulaVar(likeName,formula,RooArgList(*fLogLike,*fPriorPdf));
#else
// here use RooProdPdf (not very nice) but working

if (fLogLike) delete fLogLike;
if (fProductPdf) {
delete fProductPdf;
fProductPdf = 0;
}

// // create a unique name for the product pdf
RooAbsPdf *  pdfAndPrior = fPdf;
if (fPriorPdf) {
TString prodName = TString("product_") + TString(fPdf->GetName()) + TString("_") + TString(fPriorPdf->GetName() );
// save this as data member since it needs to be deleted afterwards
fProductPdf = new RooProdPdf(prodName,"",RooArgList(*fPdf,*fPriorPdf));
pdfAndPrior = fProductPdf;
}

RooArgSet* constrParams = fPdf->getParameters(*fData);
// remove the constant parameters
RemoveConstantParameters(constrParams);
fLogLike = pdfAndPrior->createNLL(*fData, RooFit::Constrain(*constrParams),RooFit::ConditionalObservables(fConditionalObs) );
delete constrParams;

TString likeName = TString("likelihood_times_prior_") + TString(pdfAndPrior->GetName());
TString formula;
formula.Form("exp(-@0+%f)",fNLLMin);
fLikelihood = new RooFormulaVar(likeName,formula,RooArgList(*fLogLike));
#endif

// if no nuisance parameter we can just return the likelihood function
if (fNuisanceParameters.getSize() == 0) {
fIntegratedLikelihood = fLikelihood;
fLikelihood = 0;
}
else
// case of using RooFit for the integration
fIntegratedLikelihood = fLikelihood->createIntegral(fNuisanceParameters);

}

else if ( fIntegrationType.Contains("TOYMC") ) {
// compute the posterior as expectation values of the likelihood function
// sampling on the nuisance parameters

RooArgList nuisParams(fNuisanceParameters);

bool doToysEveryIteration = true;
// if type is 1-TOYMC or TOYMC-1
if ( fIntegrationType.Contains("1") || fIntegrationType.Contains("ONE")  ) doToysEveryIteration = false;

RooAbsPdf * samplingPdf = (fNuisancePdf) ? fNuisancePdf : fPdf;
if (!fNuisancePdf) {
ccoutI(Eval) << "BayesianCalculator::GetPosteriorFunction : no nuisance pdf is provided, try using global pdf (this will be slower)"
<< std::endl;
}
fPosteriorFunction = new PosteriorFunctionFromToyMC(*fLogLike, *samplingPdf, *poi, nuisParams, fPriorPdf, fNLLMin,
fNumIterations, doToysEveryIteration );

TString name = "toyposteriorfunction_from_";
name += fLogLike->GetName();
fIntegratedLikelihood = new RooFunctor1DBinding(name,name,*fPosteriorFunction,*poi);

// need to scan likelihood in this case
if (fNScanBins <= 0) fNScanBins = 100;

}

else  {

// use ROOT integration method if there are nuisance parameters

RooArgList nuisParams(fNuisanceParameters);
fPosteriorFunction = new PosteriorFunction(*fLogLike, *poi, nuisParams, fPriorPdf, fIntegrationType, 1., fNLLMin, fNumIterations );

TString name = "posteriorfunction_from_";
name += fLogLike->GetName();
fIntegratedLikelihood = new RooFunctor1DBinding(name,name,*fPosteriorFunction,*poi);

}

if (RooAbsReal::numEvalErrors() > 0)
coutW(Eval) << "BayesianCalculator::GetPosteriorFunction : " << RooAbsReal::numEvalErrors() << " errors reported in evaluating log-likelihood function "
<< std::endl;
RooAbsReal::clearEvalErrorLog();
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors);

return fIntegratedLikelihood;

}

RooAbsPdf* BayesianCalculator::GetPosteriorPdf() const
{
// Build and return the posterior pdf (i.e posterior function normalized to all range of poi)
// Note that an extra integration in the POI is required for the normalization
// NOTE: user must delete the returned object

RooAbsReal * plike = GetPosteriorFunction();
if (!plike) return 0;

// create a unique name on the posterior from the names of the components
TString posteriorName = this->GetName() + TString("_posteriorPdf_") + plike->GetName();

RooAbsPdf * posteriorPdf = new RooGenericPdf(posteriorName,"@0",*plike);

return posteriorPdf;
}

RooPlot* BayesianCalculator::GetPosteriorPlot(bool norm, double precision ) const
{
// return a RooPlot with the posterior  and the credibility region
// NOTE: User takes ownership of the returned object

GetPosteriorFunction();

// if a scan is requested approximate the posterior
if (fNScanBins > 0)
ApproximatePosterior();

RooAbsReal * posterior = fIntegratedLikelihood;
if (norm) {
// delete and re-do always posterior pdf (could be invalid after approximating it)
if (fPosteriorPdf) delete fPosteriorPdf;
fPosteriorPdf = GetPosteriorPdf();
posterior = fPosteriorPdf;
}
if (!posterior) return 0;

if (!fValidInterval) GetInterval();

RooAbsRealLValue* poi = dynamic_cast<RooAbsRealLValue*>( fPOI.first() );
assert(poi);

RooPlot* plot = poi->frame();
if (!plot) return 0;

// try to reduce some error messages
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CountErrors);

plot->SetTitle(TString("Posterior probability of parameter \"")+TString(poi->GetName())+TString("\""));
posterior->plotOn(plot,RooFit::Range(fLower,fUpper,kFALSE),RooFit::VLines(),RooFit::DrawOption("F"),RooFit::MoveToBack(),RooFit::FillColor(kGray),RooFit::Precision(precision));
posterior->plotOn(plot);
plot->GetYaxis()->SetTitle("posterior function");

// reset the counts and default mode
RooAbsReal::clearEvalErrorLog();
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors);

return plot;
}

void BayesianCalculator::SetIntegrationType(const char * type) {
// set the integration type (possible type are) :
// 1D integration ( used when only one nuisance and when the posterior is scanned):
// multidim:
//                    The parameter numIters (settable with SetNumIters) is  the max number of function calls.
//                    It can be reduced to make teh integration faster but it will be difficult to reach the required tolerance
//       VEGAS   MC integration method based on importance sampling - numIters is number of function calls
//                Extra Vegas parameter can be set using  IntegratorMultiDimOptions class
//       MISER    MC integration method based on stratified sampling
//       PLAIN    simple MC integration method, where the max  number of calls can be specified using SetNumIters(numIters)
//
// Extra integration types are:
//
//    TOYMC:
//       evaluate posterior by generating toy MC for the nuisance parameters. It is a MC
//       integration, where the function is sampled according to the nuisance. It is convenient to use when all
//       the nuisance are uncorrelated and it is efficient to generate them
//       The toy are generated by default for each  poi values
//       (this method has been proposed and provided by J.P Chou)
//    1-TOYMC  : same method as before but in this case the toys are generated only one time and then used for
//       each poi value. It can be convenient when the generation time is much larger than the evaluation time,
//       otherwise it is recoomended to re-generate the toy for each poi scanned point of the posterior function
//
//
//    ROOFIT:
//       use roofit default integration methods which will produce a nested integral (not reccomended for more
//       than 1 nuisance parameters)
//
// if type = 0 use default specified via class IntegratorMultiDimOptions::SetDefaultIntegrator
fIntegrationType = TString(type);
fIntegrationType.ToUpper();
}

SimpleInterval* BayesianCalculator::GetInterval() const
{
// Compute the interval. By Default a central interval is computed
// and the result is a SimpleInterval object.
// Using the method (to be called before SetInterval) SetLeftSideTailFraction the user can choose the type of interval.
// By default the returned interval is a central interval with the confidence level specified
// previously in the constructor ( LeftSideTailFraction = 0.5).
//  For lower limit use SetLeftSideTailFraction = 1
//  For upper limit use SetLeftSideTailFraction = 0
//  for shortest intervals use SetLeftSideTailFraction = -1 or call the method SetShortestInterval()
// NOTE: The BayesianCalculator covers only the case with one
// single parameter of interest
// NOTE: User takes ownership of the returned object

if (fValidInterval)
coutW(Eval) << "BayesianCalculator::GetInterval - recomputing interval for the same CL and same model" << std::endl;

RooRealVar* poi = dynamic_cast<RooRealVar*>( fPOI.first() );
if (!poi) {
coutE(Eval) << "BayesianCalculator::GetInterval - no parameter of interest is set " << std::endl;
return 0;
}

// get integrated likelihood (posterior function)
GetPosteriorFunction();

//Bool_t silentMode = (RooMsgService::instance().globalKillBelow() >= RooFit::ERROR || RooMsgService::instance().silentMode()) ;
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CountErrors);

if (fLeftSideFraction < 0 ) {
// compute short intervals
ComputeShortestInterval();
}
else {
// compute the other intervals

double lowerCutOff = fLeftSideFraction * fSize;
double upperCutOff = 1. - (1.- fLeftSideFraction) * fSize;

if (fNScanBins > 0) {
ComputeIntervalFromApproxPosterior(lowerCutOff, upperCutOff);
}

else {
// use integration method if there are nuisance parameters
if (fNuisanceParameters.getSize() > 0) {
ComputeIntervalFromCdf(lowerCutOff, upperCutOff);
}
else {
// case of no nuisance - just use createCdf from roofit
ComputeIntervalUsingRooFit(lowerCutOff, upperCutOff);
}
// case cdf failed (scan then the posterior)
if (!fValidInterval) {
fNScanBins = 100;
coutW(Eval) << "BayesianCalculator::GetInterval - computing integral from cdf failed - do a scan in "
<< fNScanBins << " nbins " << std::endl;
ComputeIntervalFromApproxPosterior(lowerCutOff, upperCutOff);
}
}
}

// reset the counts and default mode
if (RooAbsReal::numEvalErrors() > 0)
coutW(Eval) << "BayesianCalculator::GetInterval : " << RooAbsReal::numEvalErrors() << " errors reported in evaluating log-likelihood function "
<< std::endl;

RooAbsReal::clearEvalErrorLog();
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors);

if (!fValidInterval) {
fLower = 1; fUpper = 0;
coutE(Eval) << "BayesianCalculator::GetInterval - cannot compute a valid interval - return a dummy [1,0] interval"
<<  std::endl;
}
else {
coutI(Eval) << "BayesianCalculator::GetInterval - found a valid interval : [" << fLower << " , "
<< fUpper << " ]" << std::endl;
}

TString interval_name = TString("BayesianInterval_a") + TString(this->GetName());
SimpleInterval * interval = new SimpleInterval(interval_name,*poi,fLower,fUpper,ConfidenceLevel());
interval->SetTitle("SimpleInterval from BayesianCalculator");

return interval;
}

double BayesianCalculator::GetMode() const {
/// Returns the value of the parameter for the point in
/// parameter-space that is the most likely.
///  How do we do if there are points that are equi-probable?
/// use approximate posterior
/// t.b.d use real function to find the mode

ApproximatePosterior();
TH1 * h = fApproxPosterior->GetHistogram();
return h->GetBinCenter(h->GetMaximumBin() );
//return  fApproxPosterior->GetMaximumX();
}

void BayesianCalculator::ComputeIntervalUsingRooFit(double lowerCutOff, double upperCutOff ) const {
// internal function compute the interval using RooFit

coutI(Eval) <<  "BayesianCalculator: Compute interval using RooFit:  posteriorPdf + createCdf + RooBrentRootFinder " << std::endl;

RooRealVar* poi = dynamic_cast<RooRealVar*>( fPOI.first() );
assert(poi);

fValidInterval = false;
if (!fPosteriorPdf) fPosteriorPdf = (RooAbsPdf*) GetPosteriorPdf();
if (!fPosteriorPdf) return;

RooAbsReal* cdf = fPosteriorPdf->createCdf(fPOI,RooFit::ScanNoCdf());
if (!cdf) return;

RooAbsFunc* cdf_bind = cdf->bindVars(fPOI,&fPOI);
if (!cdf_bind) return;

RooBrentRootFinder brf(*cdf_bind);
brf.setTol(fBrfPrecision); // set the brf precision

double tmpVal = poi->getVal();  // patch used because findRoot changes the value of poi

bool ret = true;
if (lowerCutOff > 0) {
double y = lowerCutOff;
ret &= brf.findRoot(fLower,poi->getMin(),poi->getMax(),y);
}
else
fLower = poi->getMin();

if (upperCutOff < 1.0) {
double y=upperCutOff;
ret &= brf.findRoot(fUpper,poi->getMin(),poi->getMax(),y);
}
else
fUpper = poi->getMax();
if (!ret)  coutE(Eval) << "BayesianCalculator::GetInterval "
<< "Error returned from Root finder, estimated interval is not fully correct"
<< std::endl;
else
fValidInterval = true;

poi->setVal(tmpVal); // patch: restore the original value of poi

delete cdf_bind;
delete cdf;
}

void BayesianCalculator::ComputeIntervalFromCdf(double lowerCutOff, double upperCutOff ) const {
// internal function compute the interval using Cdf integration

fValidInterval = false;

coutI(InputArguments) <<  "BayesianCalculator:GetInterval Compute the interval from the posterior cdf " << std::endl;

RooRealVar* poi = dynamic_cast<RooRealVar*>( fPOI.first() );
assert(poi);
if (GetPosteriorFunction() == 0) {
coutE(InputArguments) <<  "BayesianCalculator::GetInterval() cannot make posterior Function " << std::endl;
return;
}

// need to remove the constant parameters
RooArgList bindParams;

// this code could be put inside the PosteriorCdfFunction

//bindParams.Print("V");

PosteriorCdfFunction cdf(*fLogLike, bindParams, fPriorPdf, fIntegrationType, fNLLMin );
if( cdf.HasError() ) {
coutE(Eval) <<  "BayesianCalculator: Numerical error computing CDF integral - try a different method " << std::endl;
return;
}

//find the roots

ROOT::Math::RootFinder rf(kRootFinderType);

ccoutD(Eval) << "BayesianCalculator::GetInterval - finding roots of posterior using RF " << rf.Name()
<< " with precision = " << fBrfPrecision;

if (lowerCutOff > 0) {
cdf.SetOffset(lowerCutOff);
ccoutD(NumIntegration) << "Integrating posterior to get cdf and search lower limit at p =" << lowerCutOff << std::endl;
bool ok = rf.Solve(cdf, poi->getMin(),poi->getMax() , 200,fBrfPrecision, fBrfPrecision);
if( cdf.HasError() )
coutW(Eval) <<  "BayesianCalculator: Numerical error integrating the  CDF   " << std::endl;
if (!ok) {
coutE(NumIntegration) << "BayesianCalculator::GetInterval - Error from root finder when searching lower limit !" << std::endl;
return;
}
fLower = rf.Root();
}
else {
fLower = poi->getMin();
}
if (upperCutOff < 1.0) {
cdf.SetOffset(upperCutOff);
ccoutD(NumIntegration) << "Integrating posterior to get cdf and search upper interval limit at p =" << upperCutOff << std::endl;
bool ok = rf.Solve(cdf, fLower,poi->getMax() , 200, fBrfPrecision, fBrfPrecision);
if( cdf.HasError() )
coutW(Eval) <<  "BayesianCalculator: Numerical error integrating the  CDF   " << std::endl;
if (!ok)  {
coutE(NumIntegration) << "BayesianCalculator::GetInterval - Error from root finder when searching upper limit !" << std::endl;
return;
}
fUpper = rf.Root();
}
else {
fUpper = poi->getMax();
}

fValidInterval = true;
}

void BayesianCalculator::ApproximatePosterior() const {
// approximate posterior in nbins using a TF1
// scan the poi values and evaluate the posterior at each point
// and save the result in a cloned TF1
// For each point the posterior is evaluated by integrating the nuisance
// parameters

if (fApproxPosterior) {
// if number of bins of existing function is >= requested one - no need to redo the scan
if (fApproxPosterior->GetNpx() >= fNScanBins) return;
// otherwise redo the scan
delete fApproxPosterior;
fApproxPosterior = 0;
}

RooAbsReal * posterior = GetPosteriorFunction();
if (!posterior) return;

TF1 * tmp = posterior->asTF(fPOI);
assert(tmp != 0);
// binned the function in nbins and evaluate at thos points
if (fNScanBins > 0)  tmp->SetNpx(fNScanBins);  // if not use default of TF1 (which is 100)

coutI(Eval) << "BayesianCalculator - scan posterior function in nbins = " << tmp->GetNpx() << std::endl;

fApproxPosterior = (TF1*) tmp->Clone();
// save this function for future reuse
// I can delete now original posterior and use this approximated copy
delete tmp;
TString name = posterior->GetName() + TString("_approx");
TString title = posterior->GetTitle() + TString("_approx");
RooAbsReal * posterior2 = new RooTFnBinding(name,title,fApproxPosterior,fPOI);
if (posterior == fIntegratedLikelihood) {
delete fIntegratedLikelihood;
fIntegratedLikelihood = posterior2;
}
else if (posterior == fLikelihood) {
delete fLikelihood;
fLikelihood = posterior2;
}
else {
assert(1); // should never happen this case
}
}

void BayesianCalculator::ComputeIntervalFromApproxPosterior(double lowerCutOff, double upperCutOff ) const {
// compute the interval using the approximate posterior function

ccoutD(Eval) <<  "BayesianCalculator: Compute interval from the approximate posterior " << std::endl;

ApproximatePosterior();
if (!fApproxPosterior) return;

double prob[2];
double limits[2] = {0,0};
prob[0] = lowerCutOff;
prob[1] = upperCutOff;
fApproxPosterior->GetQuantiles(2,limits,prob);
fLower = limits[0];
fUpper = limits[1];
fValidInterval = true;
}

void BayesianCalculator::ComputeShortestInterval( ) const {
// compute the shortest interval
coutI(Eval) << "BayesianCalculator - computing shortest interval with CL = " << 1.-fSize << std::endl;

// compute via the approx posterior function
ApproximatePosterior();
if (!fApproxPosterior) return;

TH1D * h1 = dynamic_cast<TH1D*>(fApproxPosterior->GetHistogram() );
assert(h1 != 0);
h1->SetName(fApproxPosterior->GetName());
// get bins and sort them
double * bins = h1->GetArray();
int n = h1->GetSize()-2; // exclude under/overflow bins
std::vector<int> index(n);
TMath::Sort(n, bins, &index[0]);
// find cut off as test size
double sum = 0;
double actualCL = 0;
double upper =  h1->GetXaxis()->GetXmin();
double lower =  h1->GetXaxis()->GetXmax();
double norm = h1->GetSumOfWeights();

for (int i = 0; i < n; ++i)  {
int idx = index[i];
double p = bins[ idx] / norm;
sum += p;
if (sum > 1.-fSize ) {
actualCL = sum - p;
break;
}

if ( h1->GetBinLowEdge(idx) < lower)
lower = h1->GetBinLowEdge(idx);
if ( h1->GetXaxis()->GetBinUpEdge(idx) > upper)
upper = h1->GetXaxis()->GetBinUpEdge(idx);
}

ccoutD(Eval) << "BayesianCalculator::ComputeShortestInterval - actual interval CL = "
<< actualCL << " difference from requested is " << (actualCL-(1.-fSize))/fSize*100. << "%  "
<< " limits are [ " << lower << " , " << " upper ] " << std::endl;

if (lower < upper) {
fLower = lower;
fUpper = upper;

if ( std::abs(actualCL-(1.-fSize)) > 0.1*(1.-fSize) )
coutW(Eval) << "BayesianCalculator::ComputeShortestInterval - actual interval CL = "
<< actualCL << " differs more than 10% from desired CL value - must increase nbins "
<< n << " to an higher value " << std::endl;
}
else
coutE(Eval) << "BayesianCalculator::ComputeShortestInterval " << n << " bins are not sufficient " << std::endl;

fValidInterval = true;

}

} // end namespace RooStats

```
BayesianCalculator.cxx:1
BayesianCalculator.cxx:2
BayesianCalculator.cxx:3
BayesianCalculator.cxx:4
BayesianCalculator.cxx:5
BayesianCalculator.cxx:6
BayesianCalculator.cxx:7
BayesianCalculator.cxx:8
BayesianCalculator.cxx:9
BayesianCalculator.cxx:10
BayesianCalculator.cxx:11
BayesianCalculator.cxx:12
BayesianCalculator.cxx:13
BayesianCalculator.cxx:14
BayesianCalculator.cxx:15
BayesianCalculator.cxx:16
BayesianCalculator.cxx:17
BayesianCalculator.cxx:18
BayesianCalculator.cxx:19
BayesianCalculator.cxx:20
BayesianCalculator.cxx:21
BayesianCalculator.cxx:22
BayesianCalculator.cxx:23
BayesianCalculator.cxx:24
BayesianCalculator.cxx:25
BayesianCalculator.cxx:26
BayesianCalculator.cxx:27
BayesianCalculator.cxx:28
BayesianCalculator.cxx:29
BayesianCalculator.cxx:30
BayesianCalculator.cxx:31
BayesianCalculator.cxx:32
BayesianCalculator.cxx:33
BayesianCalculator.cxx:34
BayesianCalculator.cxx:35
BayesianCalculator.cxx:36
BayesianCalculator.cxx:37
BayesianCalculator.cxx:38
BayesianCalculator.cxx:39
BayesianCalculator.cxx:40
BayesianCalculator.cxx:41
BayesianCalculator.cxx:42
BayesianCalculator.cxx:43
BayesianCalculator.cxx:44
BayesianCalculator.cxx:45
BayesianCalculator.cxx:46
BayesianCalculator.cxx:47
BayesianCalculator.cxx:48
BayesianCalculator.cxx:49
BayesianCalculator.cxx:50
BayesianCalculator.cxx:51
BayesianCalculator.cxx:52
BayesianCalculator.cxx:53
BayesianCalculator.cxx:54
BayesianCalculator.cxx:55
BayesianCalculator.cxx:56
BayesianCalculator.cxx:57
BayesianCalculator.cxx:58
BayesianCalculator.cxx:59
BayesianCalculator.cxx:60
BayesianCalculator.cxx:61
BayesianCalculator.cxx:62
BayesianCalculator.cxx:63
BayesianCalculator.cxx:64
BayesianCalculator.cxx:65
BayesianCalculator.cxx:66
BayesianCalculator.cxx:67
BayesianCalculator.cxx:68
BayesianCalculator.cxx:69
BayesianCalculator.cxx:70
BayesianCalculator.cxx:71
BayesianCalculator.cxx:72
BayesianCalculator.cxx:73
BayesianCalculator.cxx:74
BayesianCalculator.cxx:75
BayesianCalculator.cxx:76
BayesianCalculator.cxx:77
BayesianCalculator.cxx:78
BayesianCalculator.cxx:79
BayesianCalculator.cxx:80
BayesianCalculator.cxx:81
BayesianCalculator.cxx:82
BayesianCalculator.cxx:83
BayesianCalculator.cxx:84
BayesianCalculator.cxx:85
BayesianCalculator.cxx:86
BayesianCalculator.cxx:87
BayesianCalculator.cxx:88
BayesianCalculator.cxx:89
BayesianCalculator.cxx:90
BayesianCalculator.cxx:91
BayesianCalculator.cxx:92
BayesianCalculator.cxx:93
BayesianCalculator.cxx:94
BayesianCalculator.cxx:95
BayesianCalculator.cxx:96
BayesianCalculator.cxx:97
BayesianCalculator.cxx:98
BayesianCalculator.cxx:99
BayesianCalculator.cxx:100
BayesianCalculator.cxx:101
BayesianCalculator.cxx:102
BayesianCalculator.cxx:103
BayesianCalculator.cxx:104
BayesianCalculator.cxx:105
BayesianCalculator.cxx:106
BayesianCalculator.cxx:107
BayesianCalculator.cxx:108
BayesianCalculator.cxx:109
BayesianCalculator.cxx:110
BayesianCalculator.cxx:111
BayesianCalculator.cxx:112
BayesianCalculator.cxx:113
BayesianCalculator.cxx:114
BayesianCalculator.cxx:115
BayesianCalculator.cxx:116
BayesianCalculator.cxx:117
BayesianCalculator.cxx:118
BayesianCalculator.cxx:119
BayesianCalculator.cxx:120
BayesianCalculator.cxx:121
BayesianCalculator.cxx:122
BayesianCalculator.cxx:123
BayesianCalculator.cxx:124
BayesianCalculator.cxx:125
BayesianCalculator.cxx:126
BayesianCalculator.cxx:127
BayesianCalculator.cxx:128
BayesianCalculator.cxx:129
BayesianCalculator.cxx:130
BayesianCalculator.cxx:131
BayesianCalculator.cxx:132
BayesianCalculator.cxx:133
BayesianCalculator.cxx:134
BayesianCalculator.cxx:135
BayesianCalculator.cxx:136
BayesianCalculator.cxx:137
BayesianCalculator.cxx:138
BayesianCalculator.cxx:139
BayesianCalculator.cxx:140
BayesianCalculator.cxx:141
BayesianCalculator.cxx:142
BayesianCalculator.cxx:143
BayesianCalculator.cxx:144
BayesianCalculator.cxx:145
BayesianCalculator.cxx:146
BayesianCalculator.cxx:147
BayesianCalculator.cxx:148
BayesianCalculator.cxx:149
BayesianCalculator.cxx:150
BayesianCalculator.cxx:151
BayesianCalculator.cxx:152
BayesianCalculator.cxx:153
BayesianCalculator.cxx:154
BayesianCalculator.cxx:155
BayesianCalculator.cxx:156
BayesianCalculator.cxx:157
BayesianCalculator.cxx:158
BayesianCalculator.cxx:159
BayesianCalculator.cxx:160
BayesianCalculator.cxx:161
BayesianCalculator.cxx:162
BayesianCalculator.cxx:163
BayesianCalculator.cxx:164
BayesianCalculator.cxx:165
BayesianCalculator.cxx:166
BayesianCalculator.cxx:167
BayesianCalculator.cxx:168
BayesianCalculator.cxx:169
BayesianCalculator.cxx:170
BayesianCalculator.cxx:171
BayesianCalculator.cxx:172
BayesianCalculator.cxx:173
BayesianCalculator.cxx:174
BayesianCalculator.cxx:175
BayesianCalculator.cxx:176
BayesianCalculator.cxx:177
BayesianCalculator.cxx:178
BayesianCalculator.cxx:179
BayesianCalculator.cxx:180
BayesianCalculator.cxx:181
BayesianCalculator.cxx:182
BayesianCalculator.cxx:183
BayesianCalculator.cxx:184
BayesianCalculator.cxx:185
BayesianCalculator.cxx:186
BayesianCalculator.cxx:187
BayesianCalculator.cxx:188
BayesianCalculator.cxx:189
BayesianCalculator.cxx:190
BayesianCalculator.cxx:191
BayesianCalculator.cxx:192
BayesianCalculator.cxx:193
BayesianCalculator.cxx:194
BayesianCalculator.cxx:195
BayesianCalculator.cxx:196
BayesianCalculator.cxx:197
BayesianCalculator.cxx:198
BayesianCalculator.cxx:199
BayesianCalculator.cxx:200
BayesianCalculator.cxx:201
BayesianCalculator.cxx:202
BayesianCalculator.cxx:203
BayesianCalculator.cxx:204
BayesianCalculator.cxx:205
BayesianCalculator.cxx:206
BayesianCalculator.cxx:207
BayesianCalculator.cxx:208
BayesianCalculator.cxx:209
BayesianCalculator.cxx:210
BayesianCalculator.cxx:211
BayesianCalculator.cxx:212
BayesianCalculator.cxx:213
BayesianCalculator.cxx:214
BayesianCalculator.cxx:215
BayesianCalculator.cxx:216
BayesianCalculator.cxx:217
BayesianCalculator.cxx:218
BayesianCalculator.cxx:219
BayesianCalculator.cxx:220
BayesianCalculator.cxx:221
BayesianCalculator.cxx:222
BayesianCalculator.cxx:223
BayesianCalculator.cxx:224
BayesianCalculator.cxx:225
BayesianCalculator.cxx:226
BayesianCalculator.cxx:227
BayesianCalculator.cxx:228
BayesianCalculator.cxx:229
BayesianCalculator.cxx:230
BayesianCalculator.cxx:231
BayesianCalculator.cxx:232
BayesianCalculator.cxx:233
BayesianCalculator.cxx:234
BayesianCalculator.cxx:235
BayesianCalculator.cxx:236
BayesianCalculator.cxx:237
BayesianCalculator.cxx:238
BayesianCalculator.cxx:239
BayesianCalculator.cxx:240
BayesianCalculator.cxx:241
BayesianCalculator.cxx:242
BayesianCalculator.cxx:243
BayesianCalculator.cxx:244
BayesianCalculator.cxx:245
BayesianCalculator.cxx:246
BayesianCalculator.cxx:247
BayesianCalculator.cxx:248
BayesianCalculator.cxx:249
BayesianCalculator.cxx:250
BayesianCalculator.cxx:251
BayesianCalculator.cxx:252
BayesianCalculator.cxx:253
BayesianCalculator.cxx:254
BayesianCalculator.cxx:255
BayesianCalculator.cxx:256
BayesianCalculator.cxx:257
BayesianCalculator.cxx:258
BayesianCalculator.cxx:259
BayesianCalculator.cxx:260
BayesianCalculator.cxx:261
BayesianCalculator.cxx:262
BayesianCalculator.cxx:263
BayesianCalculator.cxx:264
BayesianCalculator.cxx:265
BayesianCalculator.cxx:266
BayesianCalculator.cxx:267
BayesianCalculator.cxx:268
BayesianCalculator.cxx:269
BayesianCalculator.cxx:270
BayesianCalculator.cxx:271
BayesianCalculator.cxx:272
BayesianCalculator.cxx:273
BayesianCalculator.cxx:274
BayesianCalculator.cxx:275
BayesianCalculator.cxx:276
BayesianCalculator.cxx:277
BayesianCalculator.cxx:278
BayesianCalculator.cxx:279
BayesianCalculator.cxx:280
BayesianCalculator.cxx:281
BayesianCalculator.cxx:282
BayesianCalculator.cxx:283
BayesianCalculator.cxx:284
BayesianCalculator.cxx:285
BayesianCalculator.cxx:286
BayesianCalculator.cxx:287
BayesianCalculator.cxx:288
BayesianCalculator.cxx:289
BayesianCalculator.cxx:290
BayesianCalculator.cxx:291
BayesianCalculator.cxx:292
BayesianCalculator.cxx:293
BayesianCalculator.cxx:294
BayesianCalculator.cxx:295
BayesianCalculator.cxx:296
BayesianCalculator.cxx:297
BayesianCalculator.cxx:298
BayesianCalculator.cxx:299
BayesianCalculator.cxx:300
BayesianCalculator.cxx:301
BayesianCalculator.cxx:302
BayesianCalculator.cxx:303
BayesianCalculator.cxx:304
BayesianCalculator.cxx:305
BayesianCalculator.cxx:306
BayesianCalculator.cxx:307
BayesianCalculator.cxx:308
BayesianCalculator.cxx:309
BayesianCalculator.cxx:310
BayesianCalculator.cxx:311
BayesianCalculator.cxx:312
BayesianCalculator.cxx:313
BayesianCalculator.cxx:314
BayesianCalculator.cxx:315
BayesianCalculator.cxx:316
BayesianCalculator.cxx:317
BayesianCalculator.cxx:318
BayesianCalculator.cxx:319
BayesianCalculator.cxx:320
BayesianCalculator.cxx:321
BayesianCalculator.cxx:322
BayesianCalculator.cxx:323
BayesianCalculator.cxx:324
BayesianCalculator.cxx:325
BayesianCalculator.cxx:326
BayesianCalculator.cxx:327
BayesianCalculator.cxx:328
BayesianCalculator.cxx:329
BayesianCalculator.cxx:330
BayesianCalculator.cxx:331
BayesianCalculator.cxx:332
BayesianCalculator.cxx:333
BayesianCalculator.cxx:334
BayesianCalculator.cxx:335
BayesianCalculator.cxx:336
BayesianCalculator.cxx:337
BayesianCalculator.cxx:338
BayesianCalculator.cxx:339
BayesianCalculator.cxx:340
BayesianCalculator.cxx:341
BayesianCalculator.cxx:342
BayesianCalculator.cxx:343
BayesianCalculator.cxx:344
BayesianCalculator.cxx:345
BayesianCalculator.cxx:346
BayesianCalculator.cxx:347
BayesianCalculator.cxx:348
BayesianCalculator.cxx:349
BayesianCalculator.cxx:350
BayesianCalculator.cxx:351
BayesianCalculator.cxx:352
BayesianCalculator.cxx:353
BayesianCalculator.cxx:354
BayesianCalculator.cxx:355
BayesianCalculator.cxx:356
BayesianCalculator.cxx:357
BayesianCalculator.cxx:358
BayesianCalculator.cxx:359
BayesianCalculator.cxx:360
BayesianCalculator.cxx:361
BayesianCalculator.cxx:362
BayesianCalculator.cxx:363
BayesianCalculator.cxx:364
BayesianCalculator.cxx:365
BayesianCalculator.cxx:366
BayesianCalculator.cxx:367
BayesianCalculator.cxx:368
BayesianCalculator.cxx:369
BayesianCalculator.cxx:370
BayesianCalculator.cxx:371
BayesianCalculator.cxx:372
BayesianCalculator.cxx:373
BayesianCalculator.cxx:374
BayesianCalculator.cxx:375
BayesianCalculator.cxx:376
BayesianCalculator.cxx:377
BayesianCalculator.cxx:378
BayesianCalculator.cxx:379
BayesianCalculator.cxx:380
BayesianCalculator.cxx:381
BayesianCalculator.cxx:382
BayesianCalculator.cxx:383
BayesianCalculator.cxx:384
BayesianCalculator.cxx:385
BayesianCalculator.cxx:386
BayesianCalculator.cxx:387
BayesianCalculator.cxx:388
BayesianCalculator.cxx:389
BayesianCalculator.cxx:390
BayesianCalculator.cxx:391
BayesianCalculator.cxx:392
BayesianCalculator.cxx:393
BayesianCalculator.cxx:394
BayesianCalculator.cxx:395
BayesianCalculator.cxx:396
BayesianCalculator.cxx:397
BayesianCalculator.cxx:398
BayesianCalculator.cxx:399
BayesianCalculator.cxx:400
BayesianCalculator.cxx:401
BayesianCalculator.cxx:402
BayesianCalculator.cxx:403
BayesianCalculator.cxx:404
BayesianCalculator.cxx:405
BayesianCalculator.cxx:406
BayesianCalculator.cxx:407
BayesianCalculator.cxx:408
BayesianCalculator.cxx:409
BayesianCalculator.cxx:410
BayesianCalculator.cxx:411
BayesianCalculator.cxx:412
BayesianCalculator.cxx:413
BayesianCalculator.cxx:414
BayesianCalculator.cxx:415
BayesianCalculator.cxx:416
BayesianCalculator.cxx:417
BayesianCalculator.cxx:418
BayesianCalculator.cxx:419
BayesianCalculator.cxx:420
BayesianCalculator.cxx:421
BayesianCalculator.cxx:422
BayesianCalculator.cxx:423
BayesianCalculator.cxx:424
BayesianCalculator.cxx:425
BayesianCalculator.cxx:426
BayesianCalculator.cxx:427
BayesianCalculator.cxx:428
BayesianCalculator.cxx:429
BayesianCalculator.cxx:430
BayesianCalculator.cxx:431
BayesianCalculator.cxx:432
BayesianCalculator.cxx:433
BayesianCalculator.cxx:434
BayesianCalculator.cxx:435
BayesianCalculator.cxx:436
BayesianCalculator.cxx:437
BayesianCalculator.cxx:438
BayesianCalculator.cxx:439
BayesianCalculator.cxx:440
BayesianCalculator.cxx:441
BayesianCalculator.cxx:442
BayesianCalculator.cxx:443
BayesianCalculator.cxx:444
BayesianCalculator.cxx:445
BayesianCalculator.cxx:446
BayesianCalculator.cxx:447
BayesianCalculator.cxx:448
BayesianCalculator.cxx:449
BayesianCalculator.cxx:450
BayesianCalculator.cxx:451
BayesianCalculator.cxx:452
BayesianCalculator.cxx:453
BayesianCalculator.cxx:454
BayesianCalculator.cxx:455
BayesianCalculator.cxx:456
BayesianCalculator.cxx:457
BayesianCalculator.cxx:458
BayesianCalculator.cxx:459
BayesianCalculator.cxx:460
BayesianCalculator.cxx:461
BayesianCalculator.cxx:462
BayesianCalculator.cxx:463
BayesianCalculator.cxx:464
BayesianCalculator.cxx:465
BayesianCalculator.cxx:466
BayesianCalculator.cxx:467
BayesianCalculator.cxx:468
BayesianCalculator.cxx:469
BayesianCalculator.cxx:470
BayesianCalculator.cxx:471
BayesianCalculator.cxx:472
BayesianCalculator.cxx:473
BayesianCalculator.cxx:474
BayesianCalculator.cxx:475
BayesianCalculator.cxx:476
BayesianCalculator.cxx:477
BayesianCalculator.cxx:478
BayesianCalculator.cxx:479
BayesianCalculator.cxx:480
BayesianCalculator.cxx:481
BayesianCalculator.cxx:482
BayesianCalculator.cxx:483
BayesianCalculator.cxx:484
BayesianCalculator.cxx:485
BayesianCalculator.cxx:486
BayesianCalculator.cxx:487
BayesianCalculator.cxx:488
BayesianCalculator.cxx:489
BayesianCalculator.cxx:490
BayesianCalculator.cxx:491
BayesianCalculator.cxx:492
BayesianCalculator.cxx:493
BayesianCalculator.cxx:494
BayesianCalculator.cxx:495
BayesianCalculator.cxx:496
BayesianCalculator.cxx:497
BayesianCalculator.cxx:498
BayesianCalculator.cxx:499
BayesianCalculator.cxx:500
BayesianCalculator.cxx:501
BayesianCalculator.cxx:502
BayesianCalculator.cxx:503
BayesianCalculator.cxx:504
BayesianCalculator.cxx:505
BayesianCalculator.cxx:506
BayesianCalculator.cxx:507
BayesianCalculator.cxx:508
BayesianCalculator.cxx:509
BayesianCalculator.cxx:510
BayesianCalculator.cxx:511
BayesianCalculator.cxx:512
BayesianCalculator.cxx:513
BayesianCalculator.cxx:514
BayesianCalculator.cxx:515
BayesianCalculator.cxx:516
BayesianCalculator.cxx:517
BayesianCalculator.cxx:518
BayesianCalculator.cxx:519
BayesianCalculator.cxx:520
BayesianCalculator.cxx:521
BayesianCalculator.cxx:522
BayesianCalculator.cxx:523
BayesianCalculator.cxx:524
BayesianCalculator.cxx:525
BayesianCalculator.cxx:526
BayesianCalculator.cxx:527
BayesianCalculator.cxx:528
BayesianCalculator.cxx:529
BayesianCalculator.cxx:530
BayesianCalculator.cxx:531
BayesianCalculator.cxx:532
BayesianCalculator.cxx:533
BayesianCalculator.cxx:534
BayesianCalculator.cxx:535
BayesianCalculator.cxx:536
BayesianCalculator.cxx:537
BayesianCalculator.cxx:538
BayesianCalculator.cxx:539
BayesianCalculator.cxx:540
BayesianCalculator.cxx:541
BayesianCalculator.cxx:542
BayesianCalculator.cxx:543
BayesianCalculator.cxx:544
BayesianCalculator.cxx:545
BayesianCalculator.cxx:546
BayesianCalculator.cxx:547
BayesianCalculator.cxx:548
BayesianCalculator.cxx:549
BayesianCalculator.cxx:550
BayesianCalculator.cxx:551
BayesianCalculator.cxx:552
BayesianCalculator.cxx:553
BayesianCalculator.cxx:554
BayesianCalculator.cxx:555
BayesianCalculator.cxx:556
BayesianCalculator.cxx:557
BayesianCalculator.cxx:558
BayesianCalculator.cxx:559
BayesianCalculator.cxx:560
BayesianCalculator.cxx:561
BayesianCalculator.cxx:562
BayesianCalculator.cxx:563
BayesianCalculator.cxx:564
BayesianCalculator.cxx:565
BayesianCalculator.cxx:566
BayesianCalculator.cxx:567
BayesianCalculator.cxx:568
BayesianCalculator.cxx:569
BayesianCalculator.cxx:570
BayesianCalculator.cxx:571
BayesianCalculator.cxx:572
BayesianCalculator.cxx:573
BayesianCalculator.cxx:574
BayesianCalculator.cxx:575
BayesianCalculator.cxx:576
BayesianCalculator.cxx:577
BayesianCalculator.cxx:578
BayesianCalculator.cxx:579
BayesianCalculator.cxx:580
BayesianCalculator.cxx:581
BayesianCalculator.cxx:582
BayesianCalculator.cxx:583
BayesianCalculator.cxx:584
BayesianCalculator.cxx:585
BayesianCalculator.cxx:586
BayesianCalculator.cxx:587
BayesianCalculator.cxx:588
BayesianCalculator.cxx:589
BayesianCalculator.cxx:590
BayesianCalculator.cxx:591
BayesianCalculator.cxx:592
BayesianCalculator.cxx:593
BayesianCalculator.cxx:594
BayesianCalculator.cxx:595
BayesianCalculator.cxx:596
BayesianCalculator.cxx:597
BayesianCalculator.cxx:598
BayesianCalculator.cxx:599
BayesianCalculator.cxx:600
BayesianCalculator.cxx:601
BayesianCalculator.cxx:602
BayesianCalculator.cxx:603
BayesianCalculator.cxx:604
BayesianCalculator.cxx:605
BayesianCalculator.cxx:606
BayesianCalculator.cxx:607
BayesianCalculator.cxx:608
BayesianCalculator.cxx:609
BayesianCalculator.cxx:610
BayesianCalculator.cxx:611
BayesianCalculator.cxx:612
BayesianCalculator.cxx:613
BayesianCalculator.cxx:614
BayesianCalculator.cxx:615
BayesianCalculator.cxx:616
BayesianCalculator.cxx:617
BayesianCalculator.cxx:618
BayesianCalculator.cxx:619
BayesianCalculator.cxx:620
BayesianCalculator.cxx:621
BayesianCalculator.cxx:622
BayesianCalculator.cxx:623
BayesianCalculator.cxx:624
BayesianCalculator.cxx:625
BayesianCalculator.cxx:626
BayesianCalculator.cxx:627
BayesianCalculator.cxx:628
BayesianCalculator.cxx:629
BayesianCalculator.cxx:630
BayesianCalculator.cxx:631
BayesianCalculator.cxx:632
BayesianCalculator.cxx:633
BayesianCalculator.cxx:634
BayesianCalculator.cxx:635
BayesianCalculator.cxx:636
BayesianCalculator.cxx:637
BayesianCalculator.cxx:638
BayesianCalculator.cxx:639
BayesianCalculator.cxx:640
BayesianCalculator.cxx:641
BayesianCalculator.cxx:642
BayesianCalculator.cxx:643
BayesianCalculator.cxx:644
BayesianCalculator.cxx:645
BayesianCalculator.cxx:646
BayesianCalculator.cxx:647
BayesianCalculator.cxx:648
BayesianCalculator.cxx:649
BayesianCalculator.cxx:650
BayesianCalculator.cxx:651
BayesianCalculator.cxx:652
BayesianCalculator.cxx:653
BayesianCalculator.cxx:654
BayesianCalculator.cxx:655
BayesianCalculator.cxx:656
BayesianCalculator.cxx:657
BayesianCalculator.cxx:658
BayesianCalculator.cxx:659
BayesianCalculator.cxx:660
BayesianCalculator.cxx:661
BayesianCalculator.cxx:662
BayesianCalculator.cxx:663
BayesianCalculator.cxx:664
BayesianCalculator.cxx:665
BayesianCalculator.cxx:666
BayesianCalculator.cxx:667
BayesianCalculator.cxx:668
BayesianCalculator.cxx:669
BayesianCalculator.cxx:670
BayesianCalculator.cxx:671
BayesianCalculator.cxx:672
BayesianCalculator.cxx:673
BayesianCalculator.cxx:674
BayesianCalculator.cxx:675
BayesianCalculator.cxx:676
BayesianCalculator.cxx:677
BayesianCalculator.cxx:678
BayesianCalculator.cxx:679
BayesianCalculator.cxx:680
BayesianCalculator.cxx:681
BayesianCalculator.cxx:682
BayesianCalculator.cxx:683
BayesianCalculator.cxx:684
BayesianCalculator.cxx:685
BayesianCalculator.cxx:686
BayesianCalculator.cxx:687
BayesianCalculator.cxx:688
BayesianCalculator.cxx:689
BayesianCalculator.cxx:690
BayesianCalculator.cxx:691
BayesianCalculator.cxx:692
BayesianCalculator.cxx:693
BayesianCalculator.cxx:694
BayesianCalculator.cxx:695
BayesianCalculator.cxx:696
BayesianCalculator.cxx:697
BayesianCalculator.cxx:698
BayesianCalculator.cxx:699
BayesianCalculator.cxx:700
BayesianCalculator.cxx:701
BayesianCalculator.cxx:702
BayesianCalculator.cxx:703
BayesianCalculator.cxx:704
BayesianCalculator.cxx:705
BayesianCalculator.cxx:706
BayesianCalculator.cxx:707
BayesianCalculator.cxx:708
BayesianCalculator.cxx:709
BayesianCalculator.cxx:710
BayesianCalculator.cxx:711
BayesianCalculator.cxx:712
BayesianCalculator.cxx:713
BayesianCalculator.cxx:714
BayesianCalculator.cxx:715
BayesianCalculator.cxx:716
BayesianCalculator.cxx:717
BayesianCalculator.cxx:718
BayesianCalculator.cxx:719
BayesianCalculator.cxx:720
BayesianCalculator.cxx:721
BayesianCalculator.cxx:722
BayesianCalculator.cxx:723
BayesianCalculator.cxx:724
BayesianCalculator.cxx:725
BayesianCalculator.cxx:726
BayesianCalculator.cxx:727
BayesianCalculator.cxx:728
BayesianCalculator.cxx:729
BayesianCalculator.cxx:730
BayesianCalculator.cxx:731
BayesianCalculator.cxx:732
BayesianCalculator.cxx:733
BayesianCalculator.cxx:734
BayesianCalculator.cxx:735
BayesianCalculator.cxx:736
BayesianCalculator.cxx:737
BayesianCalculator.cxx:738
BayesianCalculator.cxx:739
BayesianCalculator.cxx:740
BayesianCalculator.cxx:741
BayesianCalculator.cxx:742
BayesianCalculator.cxx:743
BayesianCalculator.cxx:744
BayesianCalculator.cxx:745
BayesianCalculator.cxx:746
BayesianCalculator.cxx:747
BayesianCalculator.cxx:748
BayesianCalculator.cxx:749
BayesianCalculator.cxx:750
BayesianCalculator.cxx:751
BayesianCalculator.cxx:752
BayesianCalculator.cxx:753
BayesianCalculator.cxx:754
BayesianCalculator.cxx:755
BayesianCalculator.cxx:756
BayesianCalculator.cxx:757
BayesianCalculator.cxx:758
BayesianCalculator.cxx:759
BayesianCalculator.cxx:760
BayesianCalculator.cxx:761
BayesianCalculator.cxx:762
BayesianCalculator.cxx:763
BayesianCalculator.cxx:764
BayesianCalculator.cxx:765
BayesianCalculator.cxx:766
BayesianCalculator.cxx:767
BayesianCalculator.cxx:768
BayesianCalculator.cxx:769
BayesianCalculator.cxx:770
BayesianCalculator.cxx:771
BayesianCalculator.cxx:772
BayesianCalculator.cxx:773
BayesianCalculator.cxx:774
BayesianCalculator.cxx:775
BayesianCalculator.cxx:776
BayesianCalculator.cxx:777
BayesianCalculator.cxx:778
BayesianCalculator.cxx:779
BayesianCalculator.cxx:780
BayesianCalculator.cxx:781
BayesianCalculator.cxx:782
BayesianCalculator.cxx:783
BayesianCalculator.cxx:784
BayesianCalculator.cxx:785
BayesianCalculator.cxx:786
BayesianCalculator.cxx:787
BayesianCalculator.cxx:788
BayesianCalculator.cxx:789
BayesianCalculator.cxx:790
BayesianCalculator.cxx:791
BayesianCalculator.cxx:792
BayesianCalculator.cxx:793
BayesianCalculator.cxx:794
BayesianCalculator.cxx:795
BayesianCalculator.cxx:796
BayesianCalculator.cxx:797
BayesianCalculator.cxx:798
BayesianCalculator.cxx:799
BayesianCalculator.cxx:800
BayesianCalculator.cxx:801
BayesianCalculator.cxx:802
BayesianCalculator.cxx:803
BayesianCalculator.cxx:804
BayesianCalculator.cxx:805
BayesianCalculator.cxx:806
BayesianCalculator.cxx:807
BayesianCalculator.cxx:808
BayesianCalculator.cxx:809
BayesianCalculator.cxx:810
BayesianCalculator.cxx:811
BayesianCalculator.cxx:812
BayesianCalculator.cxx:813
BayesianCalculator.cxx:814
BayesianCalculator.cxx:815
BayesianCalculator.cxx:816
BayesianCalculator.cxx:817
BayesianCalculator.cxx:818
BayesianCalculator.cxx:819
BayesianCalculator.cxx:820
BayesianCalculator.cxx:821
BayesianCalculator.cxx:822
BayesianCalculator.cxx:823
BayesianCalculator.cxx:824
BayesianCalculator.cxx:825
BayesianCalculator.cxx:826
BayesianCalculator.cxx:827
BayesianCalculator.cxx:828
BayesianCalculator.cxx:829
BayesianCalculator.cxx:830
BayesianCalculator.cxx:831
BayesianCalculator.cxx:832
BayesianCalculator.cxx:833
BayesianCalculator.cxx:834
BayesianCalculator.cxx:835
BayesianCalculator.cxx:836
BayesianCalculator.cxx:837
BayesianCalculator.cxx:838
BayesianCalculator.cxx:839
BayesianCalculator.cxx:840
BayesianCalculator.cxx:841
BayesianCalculator.cxx:842
BayesianCalculator.cxx:843
BayesianCalculator.cxx:844
BayesianCalculator.cxx:845
BayesianCalculator.cxx:846
BayesianCalculator.cxx:847
BayesianCalculator.cxx:848
BayesianCalculator.cxx:849
BayesianCalculator.cxx:850
BayesianCalculator.cxx:851
BayesianCalculator.cxx:852
BayesianCalculator.cxx:853
BayesianCalculator.cxx:854
BayesianCalculator.cxx:855
BayesianCalculator.cxx:856
BayesianCalculator.cxx:857
BayesianCalculator.cxx:858
BayesianCalculator.cxx:859
BayesianCalculator.cxx:860
BayesianCalculator.cxx:861
BayesianCalculator.cxx:862
BayesianCalculator.cxx:863
BayesianCalculator.cxx:864
BayesianCalculator.cxx:865
BayesianCalculator.cxx:866
BayesianCalculator.cxx:867
BayesianCalculator.cxx:868
BayesianCalculator.cxx:869
BayesianCalculator.cxx:870
BayesianCalculator.cxx:871
BayesianCalculator.cxx:872
BayesianCalculator.cxx:873
BayesianCalculator.cxx:874
BayesianCalculator.cxx:875
BayesianCalculator.cxx:876
BayesianCalculator.cxx:877
BayesianCalculator.cxx:878
BayesianCalculator.cxx:879
BayesianCalculator.cxx:880
BayesianCalculator.cxx:881
BayesianCalculator.cxx:882
BayesianCalculator.cxx:883
BayesianCalculator.cxx:884
BayesianCalculator.cxx:885
BayesianCalculator.cxx:886
BayesianCalculator.cxx:887
BayesianCalculator.cxx:888
BayesianCalculator.cxx:889
BayesianCalculator.cxx:890
BayesianCalculator.cxx:891
BayesianCalculator.cxx:892
BayesianCalculator.cxx:893
BayesianCalculator.cxx:894
BayesianCalculator.cxx:895
BayesianCalculator.cxx:896
BayesianCalculator.cxx:897
BayesianCalculator.cxx:898
BayesianCalculator.cxx:899
BayesianCalculator.cxx:900
BayesianCalculator.cxx:901
BayesianCalculator.cxx:902
BayesianCalculator.cxx:903
BayesianCalculator.cxx:904
BayesianCalculator.cxx:905
BayesianCalculator.cxx:906
BayesianCalculator.cxx:907
BayesianCalculator.cxx:908
BayesianCalculator.cxx:909
BayesianCalculator.cxx:910
BayesianCalculator.cxx:911
BayesianCalculator.cxx:912
BayesianCalculator.cxx:913
BayesianCalculator.cxx:914
BayesianCalculator.cxx:915
BayesianCalculator.cxx:916
BayesianCalculator.cxx:917
BayesianCalculator.cxx:918
BayesianCalculator.cxx:919
BayesianCalculator.cxx:920
BayesianCalculator.cxx:921
BayesianCalculator.cxx:922
BayesianCalculator.cxx:923
BayesianCalculator.cxx:924
BayesianCalculator.cxx:925
BayesianCalculator.cxx:926
BayesianCalculator.cxx:927
BayesianCalculator.cxx:928
BayesianCalculator.cxx:929
BayesianCalculator.cxx:930
BayesianCalculator.cxx:931
BayesianCalculator.cxx:932
BayesianCalculator.cxx:933
BayesianCalculator.cxx:934
BayesianCalculator.cxx:935
BayesianCalculator.cxx:936
BayesianCalculator.cxx:937
BayesianCalculator.cxx:938
BayesianCalculator.cxx:939
BayesianCalculator.cxx:940
BayesianCalculator.cxx:941
BayesianCalculator.cxx:942
BayesianCalculator.cxx:943
BayesianCalculator.cxx:944
BayesianCalculator.cxx:945
BayesianCalculator.cxx:946
BayesianCalculator.cxx:947
BayesianCalculator.cxx:948
BayesianCalculator.cxx:949
BayesianCalculator.cxx:950
BayesianCalculator.cxx:951
BayesianCalculator.cxx:952
BayesianCalculator.cxx:953
BayesianCalculator.cxx:954
BayesianCalculator.cxx:955
BayesianCalculator.cxx:956
BayesianCalculator.cxx:957
BayesianCalculator.cxx:958
BayesianCalculator.cxx:959
BayesianCalculator.cxx:960
BayesianCalculator.cxx:961
BayesianCalculator.cxx:962
BayesianCalculator.cxx:963
BayesianCalculator.cxx:964
BayesianCalculator.cxx:965
BayesianCalculator.cxx:966
BayesianCalculator.cxx:967
BayesianCalculator.cxx:968
BayesianCalculator.cxx:969
BayesianCalculator.cxx:970
BayesianCalculator.cxx:971
BayesianCalculator.cxx:972
BayesianCalculator.cxx:973
BayesianCalculator.cxx:974
BayesianCalculator.cxx:975
BayesianCalculator.cxx:976
BayesianCalculator.cxx:977
BayesianCalculator.cxx:978
BayesianCalculator.cxx:979
BayesianCalculator.cxx:980
BayesianCalculator.cxx:981
BayesianCalculator.cxx:982
BayesianCalculator.cxx:983
BayesianCalculator.cxx:984
BayesianCalculator.cxx:985
BayesianCalculator.cxx:986
BayesianCalculator.cxx:987
BayesianCalculator.cxx:988
BayesianCalculator.cxx:989
BayesianCalculator.cxx:990
BayesianCalculator.cxx:991
BayesianCalculator.cxx:992
BayesianCalculator.cxx:993
BayesianCalculator.cxx:994
BayesianCalculator.cxx:995
BayesianCalculator.cxx:996
BayesianCalculator.cxx:997
BayesianCalculator.cxx:998
BayesianCalculator.cxx:999
BayesianCalculator.cxx:1000
BayesianCalculator.cxx:1001
BayesianCalculator.cxx:1002
BayesianCalculator.cxx:1003
BayesianCalculator.cxx:1004
BayesianCalculator.cxx:1005
BayesianCalculator.cxx:1006
BayesianCalculator.cxx:1007
BayesianCalculator.cxx:1008
BayesianCalculator.cxx:1009
BayesianCalculator.cxx:1010
BayesianCalculator.cxx:1011
BayesianCalculator.cxx:1012
BayesianCalculator.cxx:1013
BayesianCalculator.cxx:1014
BayesianCalculator.cxx:1015
BayesianCalculator.cxx:1016
BayesianCalculator.cxx:1017
BayesianCalculator.cxx:1018
BayesianCalculator.cxx:1019
BayesianCalculator.cxx:1020
BayesianCalculator.cxx:1021
BayesianCalculator.cxx:1022
BayesianCalculator.cxx:1023
BayesianCalculator.cxx:1024
BayesianCalculator.cxx:1025
BayesianCalculator.cxx:1026
BayesianCalculator.cxx:1027
BayesianCalculator.cxx:1028
BayesianCalculator.cxx:1029
BayesianCalculator.cxx:1030
BayesianCalculator.cxx:1031
BayesianCalculator.cxx:1032
BayesianCalculator.cxx:1033
BayesianCalculator.cxx:1034
BayesianCalculator.cxx:1035
BayesianCalculator.cxx:1036
BayesianCalculator.cxx:1037
BayesianCalculator.cxx:1038
BayesianCalculator.cxx:1039
BayesianCalculator.cxx:1040
BayesianCalculator.cxx:1041
BayesianCalculator.cxx:1042
BayesianCalculator.cxx:1043
BayesianCalculator.cxx:1044
BayesianCalculator.cxx:1045
BayesianCalculator.cxx:1046
BayesianCalculator.cxx:1047
BayesianCalculator.cxx:1048
BayesianCalculator.cxx:1049
BayesianCalculator.cxx:1050
BayesianCalculator.cxx:1051
BayesianCalculator.cxx:1052
BayesianCalculator.cxx:1053
BayesianCalculator.cxx:1054
BayesianCalculator.cxx:1055
BayesianCalculator.cxx:1056
BayesianCalculator.cxx:1057
BayesianCalculator.cxx:1058
BayesianCalculator.cxx:1059
BayesianCalculator.cxx:1060
BayesianCalculator.cxx:1061
BayesianCalculator.cxx:1062
BayesianCalculator.cxx:1063
BayesianCalculator.cxx:1064
BayesianCalculator.cxx:1065
BayesianCalculator.cxx:1066
BayesianCalculator.cxx:1067
BayesianCalculator.cxx:1068
BayesianCalculator.cxx:1069
BayesianCalculator.cxx:1070
BayesianCalculator.cxx:1071
BayesianCalculator.cxx:1072
BayesianCalculator.cxx:1073
BayesianCalculator.cxx:1074
BayesianCalculator.cxx:1075
BayesianCalculator.cxx:1076
BayesianCalculator.cxx:1077
BayesianCalculator.cxx:1078
BayesianCalculator.cxx:1079
BayesianCalculator.cxx:1080
BayesianCalculator.cxx:1081
BayesianCalculator.cxx:1082
BayesianCalculator.cxx:1083
BayesianCalculator.cxx:1084
BayesianCalculator.cxx:1085
BayesianCalculator.cxx:1086
BayesianCalculator.cxx:1087
BayesianCalculator.cxx:1088
BayesianCalculator.cxx:1089
BayesianCalculator.cxx:1090
BayesianCalculator.cxx:1091
BayesianCalculator.cxx:1092
BayesianCalculator.cxx:1093
BayesianCalculator.cxx:1094
BayesianCalculator.cxx:1095
BayesianCalculator.cxx:1096
BayesianCalculator.cxx:1097
BayesianCalculator.cxx:1098
BayesianCalculator.cxx:1099
BayesianCalculator.cxx:1100
BayesianCalculator.cxx:1101
BayesianCalculator.cxx:1102
BayesianCalculator.cxx:1103
BayesianCalculator.cxx:1104
BayesianCalculator.cxx:1105
BayesianCalculator.cxx:1106
BayesianCalculator.cxx:1107
BayesianCalculator.cxx:1108
BayesianCalculator.cxx:1109
BayesianCalculator.cxx:1110
BayesianCalculator.cxx:1111
BayesianCalculator.cxx:1112
BayesianCalculator.cxx:1113
BayesianCalculator.cxx:1114
BayesianCalculator.cxx:1115
BayesianCalculator.cxx:1116
BayesianCalculator.cxx:1117
BayesianCalculator.cxx:1118
BayesianCalculator.cxx:1119
BayesianCalculator.cxx:1120
BayesianCalculator.cxx:1121
BayesianCalculator.cxx:1122
BayesianCalculator.cxx:1123
BayesianCalculator.cxx:1124
BayesianCalculator.cxx:1125
BayesianCalculator.cxx:1126
BayesianCalculator.cxx:1127
BayesianCalculator.cxx:1128
BayesianCalculator.cxx:1129
BayesianCalculator.cxx:1130
BayesianCalculator.cxx:1131
BayesianCalculator.cxx:1132
BayesianCalculator.cxx:1133
BayesianCalculator.cxx:1134
BayesianCalculator.cxx:1135
BayesianCalculator.cxx:1136
BayesianCalculator.cxx:1137
BayesianCalculator.cxx:1138
BayesianCalculator.cxx:1139
BayesianCalculator.cxx:1140
BayesianCalculator.cxx:1141
BayesianCalculator.cxx:1142
BayesianCalculator.cxx:1143
BayesianCalculator.cxx:1144
BayesianCalculator.cxx:1145
BayesianCalculator.cxx:1146
BayesianCalculator.cxx:1147
BayesianCalculator.cxx:1148
BayesianCalculator.cxx:1149
BayesianCalculator.cxx:1150
BayesianCalculator.cxx:1151
BayesianCalculator.cxx:1152
BayesianCalculator.cxx:1153
BayesianCalculator.cxx:1154
BayesianCalculator.cxx:1155
BayesianCalculator.cxx:1156
BayesianCalculator.cxx:1157
BayesianCalculator.cxx:1158
BayesianCalculator.cxx:1159
BayesianCalculator.cxx:1160
BayesianCalculator.cxx:1161
BayesianCalculator.cxx:1162
BayesianCalculator.cxx:1163
BayesianCalculator.cxx:1164
BayesianCalculator.cxx:1165
BayesianCalculator.cxx:1166
BayesianCalculator.cxx:1167
BayesianCalculator.cxx:1168
BayesianCalculator.cxx:1169
BayesianCalculator.cxx:1170
BayesianCalculator.cxx:1171
BayesianCalculator.cxx:1172
BayesianCalculator.cxx:1173
BayesianCalculator.cxx:1174
BayesianCalculator.cxx:1175
BayesianCalculator.cxx:1176
BayesianCalculator.cxx:1177
BayesianCalculator.cxx:1178
BayesianCalculator.cxx:1179
BayesianCalculator.cxx:1180
BayesianCalculator.cxx:1181
BayesianCalculator.cxx:1182
BayesianCalculator.cxx:1183
BayesianCalculator.cxx:1184
BayesianCalculator.cxx:1185
BayesianCalculator.cxx:1186
BayesianCalculator.cxx:1187
BayesianCalculator.cxx:1188
BayesianCalculator.cxx:1189
BayesianCalculator.cxx:1190
BayesianCalculator.cxx:1191
BayesianCalculator.cxx:1192
BayesianCalculator.cxx:1193
BayesianCalculator.cxx:1194
BayesianCalculator.cxx:1195
BayesianCalculator.cxx:1196
BayesianCalculator.cxx:1197
BayesianCalculator.cxx:1198
BayesianCalculator.cxx:1199
BayesianCalculator.cxx:1200
BayesianCalculator.cxx:1201
BayesianCalculator.cxx:1202
BayesianCalculator.cxx:1203
BayesianCalculator.cxx:1204
BayesianCalculator.cxx:1205
BayesianCalculator.cxx:1206
BayesianCalculator.cxx:1207
BayesianCalculator.cxx:1208
BayesianCalculator.cxx:1209
BayesianCalculator.cxx:1210
BayesianCalculator.cxx:1211
BayesianCalculator.cxx:1212
BayesianCalculator.cxx:1213
BayesianCalculator.cxx:1214
BayesianCalculator.cxx:1215
BayesianCalculator.cxx:1216
BayesianCalculator.cxx:1217
BayesianCalculator.cxx:1218
BayesianCalculator.cxx:1219
BayesianCalculator.cxx:1220
BayesianCalculator.cxx:1221
BayesianCalculator.cxx:1222
BayesianCalculator.cxx:1223
BayesianCalculator.cxx:1224
BayesianCalculator.cxx:1225
BayesianCalculator.cxx:1226
BayesianCalculator.cxx:1227
BayesianCalculator.cxx:1228
BayesianCalculator.cxx:1229
BayesianCalculator.cxx:1230
BayesianCalculator.cxx:1231
BayesianCalculator.cxx:1232
BayesianCalculator.cxx:1233
BayesianCalculator.cxx:1234
BayesianCalculator.cxx:1235
BayesianCalculator.cxx:1236
BayesianCalculator.cxx:1237
BayesianCalculator.cxx:1238
BayesianCalculator.cxx:1239
BayesianCalculator.cxx:1240
BayesianCalculator.cxx:1241
BayesianCalculator.cxx:1242
BayesianCalculator.cxx:1243
BayesianCalculator.cxx:1244
BayesianCalculator.cxx:1245
BayesianCalculator.cxx:1246
BayesianCalculator.cxx:1247
BayesianCalculator.cxx:1248
BayesianCalculator.cxx:1249
BayesianCalculator.cxx:1250
BayesianCalculator.cxx:1251
BayesianCalculator.cxx:1252
BayesianCalculator.cxx:1253
BayesianCalculator.cxx:1254
BayesianCalculator.cxx:1255
BayesianCalculator.cxx:1256
BayesianCalculator.cxx:1257
BayesianCalculator.cxx:1258
BayesianCalculator.cxx:1259
BayesianCalculator.cxx:1260
BayesianCalculator.cxx:1261
BayesianCalculator.cxx:1262
BayesianCalculator.cxx:1263
BayesianCalculator.cxx:1264
BayesianCalculator.cxx:1265
BayesianCalculator.cxx:1266
BayesianCalculator.cxx:1267
BayesianCalculator.cxx:1268
BayesianCalculator.cxx:1269
BayesianCalculator.cxx:1270
BayesianCalculator.cxx:1271
BayesianCalculator.cxx:1272
BayesianCalculator.cxx:1273
BayesianCalculator.cxx:1274
BayesianCalculator.cxx:1275
BayesianCalculator.cxx:1276
BayesianCalculator.cxx:1277
BayesianCalculator.cxx:1278
BayesianCalculator.cxx:1279
BayesianCalculator.cxx:1280
BayesianCalculator.cxx:1281
BayesianCalculator.cxx:1282
BayesianCalculator.cxx:1283
BayesianCalculator.cxx:1284
BayesianCalculator.cxx:1285
BayesianCalculator.cxx:1286
BayesianCalculator.cxx:1287
BayesianCalculator.cxx:1288
BayesianCalculator.cxx:1289
BayesianCalculator.cxx:1290
BayesianCalculator.cxx:1291
BayesianCalculator.cxx:1292
BayesianCalculator.cxx:1293
BayesianCalculator.cxx:1294
BayesianCalculator.cxx:1295
BayesianCalculator.cxx:1296
BayesianCalculator.cxx:1297
BayesianCalculator.cxx:1298
BayesianCalculator.cxx:1299
BayesianCalculator.cxx:1300
BayesianCalculator.cxx:1301
BayesianCalculator.cxx:1302
BayesianCalculator.cxx:1303
BayesianCalculator.cxx:1304
BayesianCalculator.cxx:1305
BayesianCalculator.cxx:1306
BayesianCalculator.cxx:1307
BayesianCalculator.cxx:1308
BayesianCalculator.cxx:1309
BayesianCalculator.cxx:1310
BayesianCalculator.cxx:1311
BayesianCalculator.cxx:1312
BayesianCalculator.cxx:1313
BayesianCalculator.cxx:1314
BayesianCalculator.cxx:1315
BayesianCalculator.cxx:1316
BayesianCalculator.cxx:1317
BayesianCalculator.cxx:1318
BayesianCalculator.cxx:1319
BayesianCalculator.cxx:1320
BayesianCalculator.cxx:1321
BayesianCalculator.cxx:1322
BayesianCalculator.cxx:1323
BayesianCalculator.cxx:1324
BayesianCalculator.cxx:1325
BayesianCalculator.cxx:1326
BayesianCalculator.cxx:1327
BayesianCalculator.cxx:1328
BayesianCalculator.cxx:1329
BayesianCalculator.cxx:1330
BayesianCalculator.cxx:1331
BayesianCalculator.cxx:1332
BayesianCalculator.cxx:1333
BayesianCalculator.cxx:1334
BayesianCalculator.cxx:1335
BayesianCalculator.cxx:1336
BayesianCalculator.cxx:1337
BayesianCalculator.cxx:1338
BayesianCalculator.cxx:1339
BayesianCalculator.cxx:1340
BayesianCalculator.cxx:1341
BayesianCalculator.cxx:1342
BayesianCalculator.cxx:1343
BayesianCalculator.cxx:1344
BayesianCalculator.cxx:1345
BayesianCalculator.cxx:1346
BayesianCalculator.cxx:1347
BayesianCalculator.cxx:1348
BayesianCalculator.cxx:1349
BayesianCalculator.cxx:1350
BayesianCalculator.cxx:1351
BayesianCalculator.cxx:1352
BayesianCalculator.cxx:1353
BayesianCalculator.cxx:1354
BayesianCalculator.cxx:1355
BayesianCalculator.cxx:1356
BayesianCalculator.cxx:1357
BayesianCalculator.cxx:1358
BayesianCalculator.cxx:1359
BayesianCalculator.cxx:1360
BayesianCalculator.cxx:1361
BayesianCalculator.cxx:1362
BayesianCalculator.cxx:1363
BayesianCalculator.cxx:1364
BayesianCalculator.cxx:1365
BayesianCalculator.cxx:1366
BayesianCalculator.cxx:1367
BayesianCalculator.cxx:1368
BayesianCalculator.cxx:1369
BayesianCalculator.cxx:1370
BayesianCalculator.cxx:1371
BayesianCalculator.cxx:1372
BayesianCalculator.cxx:1373
BayesianCalculator.cxx:1374
BayesianCalculator.cxx:1375
BayesianCalculator.cxx:1376
BayesianCalculator.cxx:1377
BayesianCalculator.cxx:1378
BayesianCalculator.cxx:1379
BayesianCalculator.cxx:1380
BayesianCalculator.cxx:1381
BayesianCalculator.cxx:1382
BayesianCalculator.cxx:1383
BayesianCalculator.cxx:1384
BayesianCalculator.cxx:1385
BayesianCalculator.cxx:1386
BayesianCalculator.cxx:1387
BayesianCalculator.cxx:1388
BayesianCalculator.cxx:1389
BayesianCalculator.cxx:1390
BayesianCalculator.cxx:1391
BayesianCalculator.cxx:1392
BayesianCalculator.cxx:1393
BayesianCalculator.cxx:1394
BayesianCalculator.cxx:1395
BayesianCalculator.cxx:1396
BayesianCalculator.cxx:1397
BayesianCalculator.cxx:1398
BayesianCalculator.cxx:1399
BayesianCalculator.cxx:1400
BayesianCalculator.cxx:1401
BayesianCalculator.cxx:1402
BayesianCalculator.cxx:1403
BayesianCalculator.cxx:1404
BayesianCalculator.cxx:1405
BayesianCalculator.cxx:1406
BayesianCalculator.cxx:1407
BayesianCalculator.cxx:1408
BayesianCalculator.cxx:1409
BayesianCalculator.cxx:1410
BayesianCalculator.cxx:1411
BayesianCalculator.cxx:1412
BayesianCalculator.cxx:1413
BayesianCalculator.cxx:1414
BayesianCalculator.cxx:1415
BayesianCalculator.cxx:1416
BayesianCalculator.cxx:1417