10 #include <BAT/BCParameter.h>
11 #include <BAT/BCMath.h>
12 #include <BAT/BCGaussianPrior.h>
13 #include <BAT/BCTF1Prior.h>
20 #include <TPaveText.h>
29 const std::vector<ModelParameter>& ModPars_i,
30 boost::ptr_vector<Observable>& Obs_i,
31 std::vector<Observable2D>& Obs2D_i,
32 std::vector<CorrelatedGaussianObservables>& CGO_i,
33 std::vector<CorrelatedGaussianParameters>& CGP_i)
34 : BCModel(
""), ModPars(ModPars_i), CGP(CGP_i), Obs_ALL(Obs_i), Obs2D_ALL(Obs2D_i),
35 CGO(CGO_i), NumOfUsedEvents(0), NumOfDiscardedEvents(0) {
55 MPI_Comm_rank(MPI_COMM_WORLD, &
rank);
60 TH1::StatOverflows(kTRUE);
61 TH1::SetDefaultBufferSize(100000);
63 #if ROOT_VERSION_CODE > ROOT_VERSION(6,0,0)
64 gIdx = TColor::GetFreeColorIndex();
65 rIdx = TColor::GetFreeColorIndex() + 1;
79 int k = 0, kweight = 0;
81 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) {
84 if (it->getDistr().compare(
"noweight") != 0) kweight++;
87 thMin[it->getName()] = std::numeric_limits<double>::max();
88 thMax[it->getName()] = -std::numeric_limits<double>::max();
90 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin(); it <
Obs2D_ALL.end(); it++) {
91 if ((it->getDistr()).compare(
"file") == 0) {
93 throw std::runtime_error(
"ERROR: cannot handle noMCMC for Observable2D file yet!");
94 }
else if (it->getDistr().compare(
"weight") == 0)
95 throw std::runtime_error(
"ERROR: do not use Observable2D for analytic 2D weights!");
97 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 !=
CGO.end(); ++it1) {
98 std::vector<Observable> ObsV(it1->getObs());
99 for (std::vector<Observable>::iterator it = ObsV.begin(); it != ObsV.end(); ++it) {
100 if ((it->getDistr()).compare(
"file") == 0)
101 throw std::runtime_error(
"Cannot use file in CorrelatedGaussianObservables!");
102 if (!(it->isTMCMC())) {
104 if (it->getDistr().compare(
"noweight") != 0)
105 throw std::runtime_error(
"Cannot use weight in CorrelatedGaussianObservables!");
107 thMin[it->getName()] = std::numeric_limits<double>::max();
108 thMax[it->getName()] = -std::numeric_limits<double>::max();
110 if (it1->isPrediction()) {
111 CorrelationMap[it1->getName()] =
new TPrincipal(it1->getObs().size(),
"N");
125 TH1D * lhisto =
new TH1D(
"LogLikelihood",
"LogLikelihood",
nBins1D, 1., -1.);
126 lhisto->GetXaxis()->SetTitle(
"LogLikelihood");
127 BCH1D bclhisto = BCH1D(lhisto);
128 Histo1D[
"LogLikelihood"] = bclhisto;
130 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it !=
Obs_ALL.end(); it++) {
131 std::string HistName = it->getName();
133 TH1D * histo =
new TH1D(HistName.c_str(), it->getLabel().c_str(),
nBins1D, it->getMin(), it->getMax());
134 histo->GetXaxis()->SetTitle(it->getLabel().c_str());
135 BCH1D bchisto = BCH1D(histo);
139 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin(); it !=
Obs2D_ALL.end(); it++) {
140 std::string HistName = it->getName();
142 TH2D * histo2 =
new TH2D(HistName.c_str(), (it->getLabel() +
" vs. " + it->getLabel2()).c_str(),
nBins2D, it->getMin(), it->getMax(),
nBins2D, it->getMin2(), it->getMax2());
143 histo2->GetXaxis()->SetTitle(it->getLabel().c_str());
144 histo2->GetYaxis()->SetTitle(it->getLabel2().c_str());
145 BCH2D bchisto2 = BCH2D(histo2);
149 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 !=
CGO.end(); ++it1) {
150 std::vector<Observable> ObsV(it1->getObs());
151 for (std::vector<Observable>::iterator it = ObsV.begin(); it != ObsV.end(); ++it) {
152 std::string HistName = it->getName();
154 TH1D * histo =
new TH1D(HistName.c_str(), it->getLabel().c_str(),
nBins1D, it->getMin(), it->getMax());
155 histo->GetXaxis()->SetTitle(it->getLabel().c_str());
156 BCH1D bchisto = BCH1D(histo);
163 for (std::vector<ModelParameter>::const_iterator it =
ModPars.begin(); it !=
ModPars.end(); it++) {
164 if (it->IsFixed())
continue;
166 std::string HistName = it->getname() +
"_vs_LogLikelihood";
168 TH2D * histo2 =
new TH2D(HistName.c_str(), (it->getname() +
" vs. LogLikelihood").c_str(),
nBins2D, 1., -1.,
nBins2D, 1., -1.);
169 histo2->GetXaxis()->SetTitle(it->getname().c_str());
170 histo2->GetYaxis()->SetTitle(
"LogLikelihood");
171 BCH2D bchisto2 = BCH2D(histo2);
212 if (
rank == 0) std::cout <<
"\nParameters varied in this run:" << std::endl;
214 for (std::vector<ModelParameter>::const_iterator it =
ModPars.begin();
217 if (it->geterrf() == 0. && it->geterrg() == 0.)
220 AddParameter(it->getname().c_str(), it->getmin(), it->getmax());
221 if (
rank == 0) std::cout << k <<
": " << it->getname() <<
", ";
223 if (it->IsCorrelated()) {
224 for (
unsigned int i = 0; i <
CGP.size(); i++) {
225 if (
CGP[i].getName().compare(it->getCgp_name()) == 0) {
226 std::string index = it->getname().substr(
CGP[i].getName().size());
227 long int lindex = strtol(index.c_str(), NULL, 10);
229 DPars[
CGP[i].getPar(lindex - 1).getname()] = 0.;
231 std::stringstream out;
232 out << it->getname();
233 throw std::runtime_error(
"MonteCarloEngine::DefineParameters(): " + out.str() +
"seems to be part of a CorrelatedGaussianParameters object, but I couldn't find the corresponding object");
238 DPars[it->getname()] = 0.;
239 if (it->geterrf() == 0.) GetParameter(k).SetPrior(
new BCGaussianPrior(it->getave(), it->geterrg()));
240 else if (it->geterrg() == 0.) GetParameter(k).SetPriorConstant();
242 TF1 combined = TF1(it->getname().c_str(),
243 "(TMath::Erf((x-[0]+[2])/sqrt(2.)/[1])-TMath::Erf((x-[0]-[2])/sqrt(2.)/[1]))/4./[2]",
244 it->getmin(), it->getmax());
245 combined.SetParameter(0, it->getave());
246 combined.SetParameter(1, it->geterrg());
247 combined.SetParameter(2, it->geterrf());
248 GetParameter(k).SetPrior(
new BCTF1Prior(combined));
255 std::cout <<
"\n" << std::endl;
257 std::cout <<
"WARNING: unknown parameter " << *it <<
" not added to MCMC" << std::endl;
262 std::map<std::string,double>& DPars_i)
264 std::map<std::string, std::vector<double> > cgpmap;
267 for (std::vector<ModelParameter>::const_iterator it =
ModPars.begin(); it !=
ModPars.end(); it++){
272 if(it->getname().compare(GetParameter(k).GetName()) != 0)
274 std::stringstream out;
275 out << it->getname();
276 throw std::runtime_error(
"MonteCarloEngine::setDParsFromParameters(): " + out.str() +
"is sitting at the wrong position in the BAT parameters vector");
278 if (it->IsCorrelated()) {
279 std::string index = it->getname().substr(it->getCgp_name().size());
280 unsigned long int lindex = strtol(index.c_str(),NULL,10);
281 if (lindex - 1 == cgpmap[it->getCgp_name()].size())
282 cgpmap[it->getCgp_name()].push_back(parameters[k]);
284 std::stringstream out;
285 out << it->getname() <<
" " << lindex;
286 throw std::runtime_error(
"MonteCarloEngine::setDParsFromParameters(): " + out.str() +
"seems to be a CorrelatedGaussianParameters object but the corresponding parameters are missing or not in the right order");
290 DPars_i[it->getname()] = parameters[k];
294 for (
unsigned int j = 0; j <
CGP.size(); j++) {
295 std::vector<double> current = cgpmap.at(
CGP[j].getName());
296 if (current.size() !=
CGP[j].getPars().size()) {
297 std::stringstream out;
298 out <<
CGP[j].getName();
299 throw std::runtime_error(
"MonteCarloEngine::setDParsFromParameters(): " + out.str() +
" appears to be represented in cgpmap with a wrong size");
302 std::vector<double> porig =
CGP[j].getOrigParsValue(current);
304 for(
unsigned int l = 0; l < porig.size(); l++) {
305 DPars_i[
CGP[j].getPar(l).getname()] = porig[l];
323 std::cout <<
"event discarded" << std::endl;
337 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it !=
Obs_ALL.end(); it++) {
338 if (it->isTMCMC()) logprob += it->computeWeight();
341 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin(); it !=
Obs2D_ALL.end(); it++) {
342 if (it->isTMCMC()) logprob += it->computeWeight();
345 for (std::vector<CorrelatedGaussianObservables>::iterator it =
CGO.begin(); it <
CGO.end(); it++) {
346 if(!(it->isPrediction())) logprob += it->computeWeight();
348 if (!std::isfinite(logprob)) {
361 unsigned mychain = 0;
363 unsigned npars = GetNParameters();
364 int buffsize = npars + 1;
365 int index_chain[procnum];
366 double *recvbuff =
new double[buffsize];
367 std::vector<double> pars;
370 buff =
new double*[procnum];
372 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++)
373 obsbuffsize += it1->getObs().size();
374 buff[0] =
new double[procnum * obsbuffsize];
375 for (
int i = 1; i < procnum; i++) {
376 buff[i] = buff[i - 1] + obsbuffsize;
380 double ** sendbuff =
new double *[procnum];
381 sendbuff[0] =
new double[procnum * buffsize];
382 for (
int il = 1; il < procnum; il++)
383 sendbuff[il] = sendbuff[il - 1] + buffsize;
385 while (mychain < fMCMCNChains) {
387 pars = fMCMCStates.at(mychain).parameters;
390 std::map<std::string, double> tmpDPars;
395 for (std::map<std::string, double>::iterator it = tmpDPars.begin(); it != tmpDPars.end(); it++)
hMCMCParameters[mychain][k++] = it->second;
399 index_chain[iproc] = mychain;
402 if (iproc < procnum && mychain < fMCMCNChains)
405 for (
int il = 0; il < iproc; il++) {
408 sendbuff[il][0] = 2.;
409 for (
int im = 1; im < buffsize; im++) sendbuff[il][im] = fMCMCStates.at(index_chain[il]).parameters.at(im - 1);
411 for (
int il = iproc; il < procnum; il++) {
412 sendbuff[il][0] = 3.;
413 index_chain[il] = -1;
416 MPI_Scatter(sendbuff[0], buffsize, MPI_DOUBLE,
417 recvbuff, buffsize, MPI_DOUBLE,
420 if (recvbuff[0] == 2.) {
421 double sbuff[obsbuffsize];
422 pars.assign(recvbuff + 1, recvbuff + buffsize);
427 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) {
428 sbuff[k++] = it->computeTheoryValue();
430 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin(); it <
Obs2D_ALL.end(); it++) {
431 sbuff[k++] = it->computeTheoryValue();
432 sbuff[k++] = it->computeTheoryValue2();
435 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
436 std::vector<Observable> ObsV(it1->getObs());
437 for (std::vector<Observable>::iterator it = ObsV.begin(); it != ObsV.end(); ++it)
438 sbuff[k++] = it->computeTheoryValue();
440 MPI_Gather(sbuff, obsbuffsize, MPI_DOUBLE, buff[0], obsbuffsize, MPI_DOUBLE, 0, MPI_COMM_WORLD);
441 }
else if (recvbuff[0] == 3.) {
442 double sbuff[obsbuffsize];
443 MPI_Gather(sbuff, obsbuffsize, MPI_DOUBLE, buff[0], obsbuffsize, MPI_DOUBLE, 0, MPI_COMM_WORLD);
446 for (
int il = 0; il < procnum; il++) {
447 if (index_chain[il] >= 0) {
450 int ko = 0, kweight = 0, k_all = 0, k_cObs = 0;
451 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin();
453 double th = buff[il][k++];
455 if (th <
thMin[it->getName()])
thMin[it->getName()] = th;
456 if (th >
thMax[it->getName()])
thMax[it->getName()] = th;
457 Histo1D[it->getName()].GetHistogram()->Fill(th);
458 if (fMCMCFlagWriteChainToFile)
hMCMCObservables[index_chain[il]][k_all++] = th;
460 if (!it->isTMCMC()) {
463 if (it->getDistr().compare(
"noweight") != 0 && it->getDistr().compare(
"writeChain") != 0) {
464 double weight = it->computeWeight(th);
473 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin();
475 double th1 = buff[il][k++];
476 double th2 = buff[il][k++];
477 Histo2D[it->getName()].GetHistogram()->Fill(th1, th2);
481 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
482 std::vector<Observable> ObsV(it1->getObs());
483 Double_t * COdata =
new Double_t[ObsV.size()];
485 for (std::vector<Observable>::iterator it = ObsV.begin(); it != ObsV.end(); ++it) {
486 double th = buff[il][k++];
488 if (th <
thMin[it->getName()])
thMin[it->getName()] = th;
489 if (th >
thMax[it->getName()])
thMax[it->getName()] = th;
490 Histo1D[it->getName()].GetHistogram()->Fill(th);
491 if (it1->isPrediction()) COdata[nObs++] = th;
493 if (it1->isPrediction())
CorrelationMap[it1->getName()]->AddRow(COdata);
508 for (
unsigned int i = 0; i < fMCMCNChains; ++i) {
510 std::vector<double>::const_iterator first = fMCMCStates.at(i).parameters.begin();
511 std::vector<double>::const_iterator last = first + GetNParameters();
512 std::vector<double> currvec(first, last);
517 for (std::map<std::string, double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++)
hMCMCParameters[i][k++] = it->second;
522 int k = 0, kweight = 0, k_all = 0, k_cObs = 0;
523 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin();
525 double th = it->computeTheoryValue();
527 if (th <
thMin[it->getName()])
thMin[it->getName()] = th;
528 if (th >
thMax[it->getName()])
thMax[it->getName()] = th;
529 Histo1D[it->getName()].GetHistogram()->Fill(th);
532 if (!it->isTMCMC()) {
535 if (it->getDistr().compare(
"noweight") != 0 && it->getDistr().compare(
"writeChain") != 0) {
536 double weight = it->computeWeight(th);
545 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin();
547 double th1 = it->computeTheoryValue();
548 double th2 = it->computeTheoryValue2();
549 Histo2D[it->getName()].GetHistogram()->Fill(th1, th2);
553 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin();
554 it1 <
CGO.end(); it1++) {
555 std::vector<Observable> ObsV(it1->getObs());
556 Double_t * COdata =
new Double_t[ObsV.size()];
558 for (std::vector<Observable>::iterator it = ObsV.begin();
559 it != ObsV.end(); ++it) {
560 double th = it->computeTheoryValue();
562 if (th <
thMin[it->getName()])
thMin[it->getName()] = th;
563 if (th >
thMax[it->getName()])
thMax[it->getName()] = th;
564 Histo1D[it->getName()].GetHistogram()->Fill(th);
565 if (it1->isPrediction()) COdata[nObs++] = th;
567 if (it1->isPrediction())
CorrelationMap[it1->getName()]->AddRow(COdata);
575 for (
unsigned int i = 0; i < fMCMCNChains; i++) {
583 for (std::vector<ModelParameter>::const_iterator it =
ModPars.begin(); it !=
ModPars.end(); it++) {
584 if (it->IsFixed())
continue;
586 std::string HistName = it->getname() +
"_vs_LogLikelihood";
595 double UnderFlowContent = hist.GetBinContent(0);
596 double OverFlowContent = hist.GetBinContent(
nBins1D + 1);
597 double Integral = hist.Integral();
598 double TotalContent = 0.0;
599 for (
unsigned int n = 0; n <=
nBins1D + 1; n++)
600 TotalContent += hist.GetBinContent(n);
602 << Integral / TotalContent * 100. <<
"% within the range, "
603 << UnderFlowContent / TotalContent * 100. <<
"% underflow, "
604 << OverFlowContent / TotalContent * 100. <<
"% overflow"
609 double Integral = hist.Integral();
610 double TotalContent = 0.0;
611 for (
unsigned int m = 0; m <=
nBins2D + 1; m++)
612 for (
unsigned int n = 0; n <=
nBins2D + 1; n++)
613 TotalContent += hist.GetBinContent(m, n);
615 << Integral / TotalContent * 100. <<
"% within the ranges"
623 c =
new TCanvas(TString::Format(
"c_bch1d_%d",
cindex), TString::Format(
"c_bch1d_%d",
cindex), ww, wh);
625 c =
new TCanvas(TString::Format(
"c_bch1d_%d",
cindex));
627 bch1d.GetHistogram()->Scale(1./bch1d.GetHistogram()->Integral(
"width"));
629 bch1d.SetBandType(BCH1D::kSmallestInterval);
630 bch1d.SetBandColor(0,
gIdx);
631 bch1d.SetBandColor(1,
rIdx);
632 bch1d.SetBandColor(2, kOrange - 3);
635 bch1d.SetDrawGlobalMode(
true);
636 bch1d.SetDrawMean(
true,
true);
638 if (
noLegend) gStyle->SetOptStat(
"emr");
639 bch1d.SetNLegendColumns(1);
640 bch1d.SetStats(
true);
645 double xRange = (bch1d.GetHistogram()->GetXaxis()->GetXmax() - bch1d.GetHistogram()->GetXaxis()->GetXmin())*3./4.;
646 double yRange = (bch1d.GetHistogram()->GetMaximum() - bch1d.GetHistogram()->GetMinimum());
649 if (
noLegend) xL = bch1d.GetHistogram()->GetXaxis()->GetXmin()+0.0475*xRange;
650 else xL = bch1d.GetHistogram()->GetXaxis()->GetXmin() + 0.0375 * xRange;
651 double yL = bch1d.GetHistogram()->GetYaxis()->GetXmin() + 0.89 * yRange;
654 if (
noLegend) xR = xL + 0.21*xRange;
655 else xR = xL + 0.18 * xRange;
656 double yR = yL + 0.09 * yRange;
658 TBox b1 = TBox(xL, yL, xR, yR);
659 b1.SetFillColor(
gIdx);
662 b2 = TBox(xL+0.008*xRange, yL+0.008*yRange, xR-0.008*xRange, yR-0.008*yRange);
663 b2.SetFillColor(kWhite);
665 TPaveText b3 = TPaveText(xL+0.014*xRange, yL+0.013*yRange, xL+0.70*(xR-xL), yR-0.013*yRange);
666 if (
noLegend) b3.SetTextSize(0.056);
667 else b3.SetTextSize(0.051);
669 b3.SetTextColor(kWhite);
671 b3.SetFillColor(
rIdx);
675 b4 =
new TPaveText(xL+0.72*(xR-xL), yL+0.030*yRange, xR-0.008*xRange, yR-0.013*yRange);
676 b4->SetTextSize(0.048);
678 b4 =
new TPaveText(xL + 0.75 * (xR - xL), yL + 0.024 * yRange, xR - 0.008 * xRange, yR - 0.013 * yRange);
679 b4->SetTextSize(0.039);
681 b4->SetTextAlign(33);
682 b4->SetTextColor(
rIdx);
684 b4->SetFillColor(kWhite);
694 }
else c->Print(filename);
705 c =
new TCanvas(TString::Format(
"c_bch2d_%d",
cindex), TString::Format(
"c_bch2d_%d",
cindex), ww, wh);
707 c =
new TCanvas(TString::Format(
"c_bch2d_%d",
cindex));
709 bch2d.GetHistogram()->Scale(1./bch2d.GetHistogram()->Integral(
"width"));
710 bch2d.GetHistogram()->GetYaxis()->SetTitleOffset(1.45);
712 bch2d.SetBandType(BCH2D::kSmallestInterval);
713 bch2d.SetBandColor(0, TColor::GetColorTransparent(kOrange - 3,
alpha2D));
714 bch2d.SetBandColor(1, TColor::GetColorTransparent(
rIdx,
alpha2D));
715 bch2d.SetBandColor(2, TColor::GetColorTransparent(
gIdx,
alpha2D));
719 else bch2d.SetNSmooth(0);
721 bch2d.SetDrawLocalMode(
false);
722 bch2d.SetDrawGlobalMode(
true);
723 bch2d.SetDrawMean(
true,
true);
725 if (
noLegend) gStyle->SetOptStat(
"emr");
726 bch2d.SetNLegendColumns(1);
727 bch2d.SetStats(
true);
732 double xRange = (bch2d.GetHistogram()->GetXaxis()->GetXmax() - bch2d.GetHistogram()->GetXaxis()->GetXmin())*3./4.;
733 double yRange = bch2d.GetHistogram()->GetYaxis()->GetXmax() - bch2d.GetHistogram()->GetYaxis()->GetXmin();
736 if (
noLegend) xL = bch2d.GetHistogram()->GetXaxis()->GetXmin()+0.0475*xRange;
737 else xL = bch2d.GetHistogram()->GetXaxis()->GetXmin() + 0.0375 * xRange;
738 double yL = bch2d.GetHistogram()->GetYaxis()->GetXmin() + 0.89 * yRange;
741 if (
noLegend) xR = xL + 0.21*xRange;
742 else xR = xL + 0.18 * xRange;
743 double yR = yL + 0.09 * yRange;
745 TBox b1 = TBox(xL, yL, xR, yR);
746 b1.SetFillColor(
gIdx);
748 TBox b2 = TBox(xL + 0.008 * xRange, yL + 0.008 * yRange, xR - 0.008 * xRange, yR - 0.008 * yRange);
749 b2.SetFillColor(kWhite);
751 TPaveText b3 = TPaveText(xL + 0.014 * xRange, yL + 0.013 * yRange, xL + 0.70 * (xR - xL), yR - 0.013 * yRange);
752 if (
noLegend) b3.SetTextSize(0.056);
753 else b3.SetTextSize(0.051);
755 b3.SetTextColor(kWhite);
757 b3.SetFillColor(
rIdx);
761 b4 =
new TPaveText(xL+0.72*(xR-xL), yL+0.030*yRange, xR-0.008*xRange, yR-0.013*yRange);
762 b4->SetTextSize(0.048);
764 b4 =
new TPaveText(xL + 0.75 * (xR - xL), yL + 0.024 * yRange, xR - 0.008 * xRange, yR - 0.013 * yRange);
765 b4->SetTextSize(0.039);
767 b4->SetTextAlign(33);
768 b4->SetTextColor(
rIdx);
770 b4->SetFillColor(kWhite);
780 }
else c->Print(filename);
789 std::string HistName = it.
getName();
792 if (
Histo1D[HistName].GetHistogram()->Integral() > 0.0) {
793 std::string fname = OutputDir +
"/" + HistName +
".pdf";
796 std::cout <<
" " + HistName +
".pdf" << std::endl;
797 if(OutFile.compare(
"") == 0) {
798 throw std::runtime_error(
"\nMonteCarloEngine::PrintHistogram ERROR: No root file specified for writing histograms.");
800 TDirectory * dir = gDirectory;
801 GetOutputFile()->cd();
802 Histo1D[HistName].GetHistogram()->Write();
806 HistoLog <<
"WARNING: The histogram of "
807 << it.
getName() <<
" is empty!" << std::endl;
810 HistoLog <<
" [min, max]=[" << min <<
", " << max <<
"]" << std::endl;
816 std::vector<double> mode(GetBestFitParameters());
817 if (mode.size() == 0)
throw std::runtime_error(
"\n ERROR: Global Mode could not be determined possibly because of infinite loglikelihood. Observables histogram cannot be generated.\n");
822 if (
Obs_ALL.size() != 0 ||
CGO.size() != 0) std::cout <<
"\nPrinting 1D histograms in the Observables directory: " << std::endl;
825 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
826 std::vector<Observable> ObsV(it1->getObs());
827 for (std::vector<Observable>::iterator it = ObsV.begin(); it != ObsV.end(); ++it)
PrintHistogram(OutFile, *it, OutputDir);
830 if (
Obs2D_ALL.size() != 0) std::cout <<
"\nPrinting 2D histograms in the Observables directory: " << std::endl;
831 for (std::vector<Observable2D>::iterator it =
Obs2D_ALL.begin(); it <
Obs2D_ALL.end(); it++) {
832 std::string HistName = it->getName();
833 if (
Histo2D[HistName].GetHistogram()->Integral() > 0.0) {
834 std::string fname = OutputDir +
"/" + HistName +
".pdf";
835 std::vector<double> th;
836 th.push_back(it->computeTheoryValue());
837 th.push_back(it->computeTheoryValue2());
838 Histo2D[HistName].SetGlobalMode(th);
840 std::cout <<
" " + HistName +
".pdf" << std::endl;
841 if(OutFile.compare(
"") == 0)
throw std::runtime_error(
"\nMonteCarloEngine::PrintHistogram ERROR: No root file specified for writing histograms.");
842 TDirectory * dir = gDirectory;
843 GetOutputFile()->cd();
844 Histo2D[HistName].GetHistogram()->Write();
847 }
else HistoLog <<
"WARNING: The histogram of " << HistName <<
" is empty!" << std::endl;
850 std::cout <<
"\nPrinting LogLikelihood histogram in the Observables directory: " << std::endl;
851 if (
Histo1D[
"LogLikelihood"].GetHistogram()->Integral() > 0.0) {
852 std::string fname = OutputDir +
"/LogLikelihood.pdf";
854 std::cout <<
" LogLikelihood.pdf" << std::endl;
855 TDirectory * dir = gDirectory;
856 GetOutputFile()->cd();
857 Histo1D[
"LogLikelihood"].GetHistogram()->Write();
863 std::cout <<
"\nPrinting LogLikelihood vs. parameter 2D histograms in the Observables directory: " << std::endl;
864 for (std::vector<ModelParameter>::const_iterator it =
ModPars.begin(); it !=
ModPars.end(); it++) {
865 if (it->IsFixed())
continue;
867 std::string HistName = it->getname() +
"_vs_LogLikelihood";
868 if (
Histo2D[HistName].GetHistogram()->Integral() > 0.0) {
869 std::string fname = OutputDir +
"/LogLikelihoodPlots/" + HistName +
".pdf";
871 std::cout <<
" " + HistName +
".pdf" << std::endl;
872 if (OutFile.compare(
"") == 0)
throw std::runtime_error(
"\nMonteCarloEngine::PrintHistogram ERROR: No root file specified for writing histograms.");
873 TDirectory * dir = gDirectory;
874 GetOutputFile()->cd();
875 Histo2D[HistName].GetHistogram()->Write();
878 }
else HistoLog <<
"WARNING: The histogram of " << HistName <<
" is empty!" << std::endl;
881 if (
noLegend) gStyle->SetOptStat(
"emrn");
885 if (fMCMCFlagWriteChainToFile) InitializeMarkovChainTree();
886 TDirectory* dir = gDirectory;
887 GetOutputFile()->cd();
889 hMCMCObservableTree =
new TTree(TString::Format(
"%s_Observables", GetSafeName().data()), TString::Format(
"%s_Observables", GetSafeName().data()));
897 if (fMCMCFlagWriteChainToFile) {
904 int k = 0, kweight = 0;
905 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) {
907 hMCMCObservableTree->SetAlias(TString::Format(
"HEPfit_Observables%i", k), it->getName().data());
909 if (!it->isTMCMC() && it->getDistr().compare(
"weight") == 0) {
911 hMCMCObservableTree->SetAlias(TString::Format(
"HEPfit_Observables_weight%i", kweight), (it->getName() +
"_weight").data());
919 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) {
920 if (it->isWriteChain()) {
922 hMCMCObservableTree->SetAlias(TString::Format(
"HEPfit_Observables%i", k), it->getName().data());
930 hMCMCParameterTree =
new TTree(TString::Format(
"%s_Parameters", GetSafeName().data()), TString::Format(
"%s_Parameters", GetSafeName().data()));
937 for (std::map<std::string, double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++) {
939 hMCMCParameterTree->SetAlias(TString::Format(
"HEPfit_Parameters%i", k), it->first.data());
952 for (fMCMCTree_Chain = 0; fMCMCTree_Chain < fMCMCNChains; ++fMCMCTree_Chain) {
967 for (fMCMCTree_Chain = 0; fMCMCTree_Chain < fMCMCNChains; ++fMCMCTree_Chain) {
975 out.open(filename.c_str(), std::ios::out);
977 int npar = GetNParameters();
979 for (
int i = 0; i < npar; ++i)
980 out <<
" & " << GetParameter(i).GetName();
981 out <<
" \\\\" << std::endl;
983 for (
int i = 0; i < npar; ++i) {
984 out << GetParameter(i).GetName() <<
" & $";
985 for (
int j = 0; j < npar; ++j) {
987 BCH2D* bch2d_temp =
new BCH2D(GetMarginalized(GetParameter(i).GetName(), GetParameter(j).GetName()));
988 if (bch2d_temp != NULL)
989 out << bch2d_temp->GetHistogram()->GetCorrelationFactor();
996 if (j == npar - 1) out <<
"$ \\\\" << std::endl;
1014 std::vector<double> mode(GetBestFitParameters());
1015 if (mode.size() == 0)
throw std::runtime_error(
"\n ERROR: Global Mode could not be determined possibly because of infinite loglikelihood. Observables statistics cannot be generated.\n");
1016 std::streamsize ss_prec = std::cout.precision();
1017 unsigned int rmsPrecision = 2;
1019 std::ostringstream StatsLog;
1021 StatsLog <<
"Statistics file for Observables, Binned Observables and Correlated Gaussian Observables.\n" << std::endl;
1022 if (
Obs_ALL.size() > 0) StatsLog <<
"Observables:\n" << std::endl;
1023 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) {
1024 StatsLog.precision(ss_prec);
1025 if (it->getObsType().compare(
"BinnedObservable") == 0) {
1026 StatsLog <<
" (" << ++i <<
") Binned Observable \"";
1027 StatsLog << it->getName() <<
"[" << it->getTho()->getBinMin() <<
", " << it->getTho()->getBinMax() <<
"]" <<
"\":";
1028 }
else if (it->getObsType().compare(
"FunctionObservable") == 0) {
1029 StatsLog <<
" (" << ++i <<
") Function Observable \"";
1030 StatsLog << it->getName() <<
"[" << it->getTho()->getBinMin() <<
"]" <<
"\":";
1031 }
else if (it->getObsType().compare(
"HiggsObservable") == 0) {
1032 StatsLog <<
" (" << ++i <<
") Higgs Observable \"";
1033 StatsLog << it->getName() <<
"\":";
1035 StatsLog <<
" (" << ++i <<
") " << it->getObsType() <<
" \"";
1036 StatsLog << it->getName() <<
"\":";
1038 StatsLog << std::endl;
1040 BCH1D bch1d =
Histo1D[it->getName()];
1042 if (bch1d.GetHistogram()->Integral() > 0.0) {
1043 double rms = bch1d.GetHistogram()->GetRMS();
1044 StatsLog <<
" Mean +- sqrt(V): " << std::setprecision(
getPrecision(bch1d.GetHistogram()->GetMean(),rms))
1045 << bch1d.GetHistogram()->GetMean() <<
" +- " << std::setprecision(rmsPrecision)
1048 <<
" (Marginalized) mode: " << std::setprecision(
getPrecision(bch1d.GetLocalMode(0),rms)) << bch1d.GetLocalMode(0) << std::endl;
1049 std::vector<double> intervals;
1050 intervals.push_back(0.682689492137);
1051 intervals.push_back(0.954499736104);
1052 intervals.push_back(0.997300203937);
1053 std::vector<BCH1D::BCH1DSmallestInterval> v = bch1d.GetSmallestIntervals(intervals);
1054 for (
unsigned int i = 0; i < v.size(); i++) {
1055 StatsLog <<
" Smallest interval(s) containing at least " << std::setprecision(ss_prec) << v[i].total_mass * 100 <<
"% and local mode(s):"
1057 for (
unsigned j = 0; j < v[i].intervals.size(); j++) {
1058 double interval_xmin = v[i].intervals[j].xmin;
1059 double interval_xmax = v[i].intervals[j].xmax;
1060 double interval_mode = v[i].intervals[j].mode;
1061 double interval_heignt = v[i].intervals[j].relative_height;
1062 double interval_relative_mass = v[i].intervals[j].relative_mass;
1063 StatsLog <<
" (" << std::setprecision(
getPrecision(interval_xmin, rms)) << interval_xmin <<
", " << std::setprecision(
getPrecision(interval_xmax, rms)) << interval_xmax
1064 <<
") (local mode at " << std::setprecision(
getPrecision(interval_mode, rms)) << interval_mode <<
" with rel. height "
1065 << std::setprecision(
getPrecision(interval_heignt, ss_prec)) << interval_heignt <<
"; rel. area " << std::setprecision(
getPrecision(interval_relative_mass, ss_prec)) << interval_relative_mass <<
")"
1067 StatsLog << std::endl;
1071 StatsLog <<
"\nWARNING: The histogram of " << it->getName() <<
" is empty! Statistics cannot be generated\n" << std::endl;
1075 if (
CGO.size() > 0) StatsLog <<
"\nCorrelated (Gaussian) Observables:\n" << std::endl;
1076 for (std::vector<CorrelatedGaussianObservables>::iterator it1 =
CGO.begin(); it1 <
CGO.end(); it1++) {
1077 StatsLog <<
"\n" << it1->getName() <<
":\n" << std::endl;
1079 std::vector<Observable> CGObs(it1->getObs());
1080 for (std::vector<Observable>::iterator it2 = CGObs.begin(); it2 < CGObs.end(); it2++) {
1081 StatsLog.precision(ss_prec);
1082 if (it2->getObsType().compare(
"BinnedObservable") == 0) {
1083 StatsLog <<
" (" << ++i <<
") Binned Observable \"";
1084 StatsLog << it2->getName() <<
"[" << it2->getTho()->getBinMin() <<
", " << it2->getTho()->getBinMax() <<
"]" <<
"\":";
1085 }
else if (it2->getObsType().compare(
"FunctionObservable") == 0) {
1086 StatsLog <<
" (" << ++i <<
") Function Observable \"";
1087 StatsLog << it2->getName() <<
"[" << it2->getTho()->getBinMin() <<
"]" <<
"\":";
1088 }
else if (it2->getObsType().compare(
"HiggsObservable") == 0) {
1089 StatsLog <<
" (" << ++i <<
") Higgs Observable \"";
1090 StatsLog << it2->getName() <<
"\":";
1092 StatsLog <<
" (" << ++i <<
") " << it2->getObsType() <<
" \"";
1093 StatsLog << it2->getName() <<
"\":";
1096 StatsLog << std::endl;
1097 BCH1D bch1d =
Histo1D[it2->getName()];
1098 if (bch1d.GetHistogram()->Integral() > 0.0) {
1099 double rms = bch1d.GetHistogram()->GetRMS();
1100 StatsLog <<
" Mean +- sqrt(V): " << std::setprecision(
getPrecision(bch1d.GetHistogram()->GetMean(), rms))
1101 << bch1d.GetHistogram()->GetMean() <<
" +- " << std::setprecision(rmsPrecision)
1104 <<
" (Marginalized) mode: " << std::setprecision(
getPrecision(bch1d.GetLocalMode(0), rms)) << bch1d.GetLocalMode(0) << std::endl;
1106 std::vector<double> intervals;
1107 intervals.push_back(0.682689492137);
1108 intervals.push_back(0.954499736104);
1109 intervals.push_back(0.997300203937);
1111 std::vector<BCH1D::BCH1DSmallestInterval> v = bch1d.GetSmallestIntervals(intervals);
1112 for (
unsigned int i = 0; i < v.size(); i++) {
1113 StatsLog <<
" Smallest interval(s) containing at least " << std::setprecision(ss_prec) << v[i].total_mass * 100 <<
"% and local mode(s):" << std::endl;
1114 for (
unsigned j = 0; j < v[i].intervals.size(); j++) {
1115 double interval_xmin = v[i].intervals[j].xmin;
1116 double interval_xmax = v[i].intervals[j].xmax;
1117 double interval_mode = v[i].intervals[j].mode;
1118 double interval_heignt = v[i].intervals[j].relative_height;
1119 double interval_relative_mass = v[i].intervals[j].relative_mass;
1120 StatsLog <<
" (" << std::setprecision(
getPrecision(interval_xmin, rms)) << interval_xmin <<
", " << std::setprecision(
getPrecision(interval_xmax, rms)) << interval_xmax
1121 <<
") (local mode at " << std::setprecision(
getPrecision(interval_mode, rms)) << interval_mode <<
" with rel. height "
1122 << std::setprecision(
getPrecision(interval_heignt, ss_prec)) << interval_heignt <<
"; rel. area " << std::setprecision(
getPrecision(interval_relative_mass, ss_prec)) << interval_relative_mass <<
")"
1124 StatsLog << std::endl;
1128 StatsLog <<
"\nWARNING: The histogram of " << it2->getName() <<
" is empty! Statistics cannot be generated\n" << std::endl;
1131 if (it1->isPrediction()) {
1132 int size = it1->getObs().size();
1135 TMatrixD * corr = const_cast<TMatrixD*>(
CorrelationMap[it1->getName()]->GetCovarianceMatrix());
1136 TVectorD * sigma = const_cast<TVectorD*>(
CorrelationMap[it1->getName()]->GetSigmas());
1137 *corr *= (double)size;
1139 for (
int i = 0; i < size; i++) {
1140 for (
int j = 0; j <= i; j++) {
1141 inverseCovariance(i, j) = (*corr)(i, j) * (*sigma)(i) * (*sigma)(j);
1142 inverseCovariance(j, i) = inverseCovariance(i, j);
1145 bool SingularCovariance = inverseCovariance.
isSingular();
1146 if (!SingularCovariance) inverseCovariance = inverseCovariance.
inverse();
1147 StatsLog <<
"\nThe correlation matrix for " << it1->getName() <<
" is given by the " << size <<
"x"<< size <<
" matrix:\n" << std::endl;
1149 for (
int i = 0; i < size + 1; i++) {
1150 if (i == 0) StatsLog << std::setw(4) <<
"" <<
" | ";
1151 else StatsLog << std::setw(6) << i << std::setw(6) <<
" |";
1153 StatsLog << std::endl;
1154 for (
int i = 0; i < size + 1; i++) {
1155 if (i == 0) StatsLog << std::setw(8) <<
"--------";
1156 else StatsLog << std::setw(12) <<
"------------";
1158 StatsLog << std::endl;
1159 for (
int i = 0; i < size; i++) {
1160 for (
int j = 0; j < size + 1; j++) {
1161 if (j == 0) StatsLog << std::setw(4) << i+1 <<
" |";
1162 else StatsLog << std::setprecision(5) << std::setw(12) << (*corr)(i, j - 1);
1164 StatsLog << std::endl;
1166 StatsLog << std::endl;
1167 if (!SingularCovariance) {
1168 StatsLog <<
" The inverse of the square root of the diagonal elements of the inverse covariance matrix are:\n" << std::endl;
1169 for (
int i = 0; i < size + 1; i++) {
1170 if (i == 0) StatsLog << std::setw(4) <<
"sigma" <<
"|";
1171 else StatsLog << std::setprecision(5) << std::setw(12) << 1. /
sqrt(inverseCovariance(i - 1, i - 1));
1173 }
else StatsLog <<
" The covariance matrix cannot be inverted.\n" << std::endl;
1174 StatsLog << std::endl;
1184 int value_width = 15;
1185 for (std::map<std::string,double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++) par_width = std::max(par_width, (
int)(it->first).size());
1186 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++) obs_width = std::max(obs_width, (
int)(it->getName()).size());
1187 par_width = par_width + 1;
1188 obs_width = obs_width + 1;
1189 const std::string sep =
" |";
1190 const std::string par_line = sep + std::string(par_width + value_width + sep.size() * 2 - 1,
'-') +
'|';
1191 const std::string obs_line = sep + std::string(obs_width + value_width + sep.size() * 2 - 1,
'-') +
'|';
1192 StatsLog << std::setprecision(5);
1194 StatsLog <<
"\n*** Statistical details using global mode ***\n" << std::endl;
1196 StatsLog <<
"\nValue of the parameters at the global mode:" << std::endl;
1197 StatsLog << std::endl;
1198 StatsLog << par_line <<
'\n' << sep
1199 << std::left << std::setw(par_width) <<
"parameter" << sep << std::right << std::setw(value_width) <<
"value at mode" << sep <<
'\n' << par_line <<
'\n';
1201 for (std::map<std::string,double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++)
1202 StatsLog << sep << std::left << std::setw(par_width) << it->first << sep << std::right << std::setw(value_width) << it->second << sep <<
'\n';
1204 StatsLog << par_line <<
'\n';
1205 StatsLog << std::endl;
1207 StatsLog <<
"\nValue of the observables at the global mode:" << std::endl;
1208 StatsLog << std::endl;
1209 StatsLog << obs_line <<
'\n' << sep
1210 << std::left << std::setw(obs_width) <<
"observable" << sep << std::right << std::setw(value_width) <<
"value at mode" << sep <<
'\n' << obs_line <<
'\n';
1212 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++)
1213 StatsLog << sep << std::left << std::setw(obs_width) << it->getName() << sep << std::right << std::setw(value_width) << it->computeTheoryValue() << sep <<
'\n';
1215 StatsLog << obs_line <<
'\n';
1216 StatsLog << std::endl;
1218 StatsLog <<
"LogProbability at mode: " <<
LogLikelihood(mode) + LogAPrioriProbability(mode) << std::endl;
1219 StatsLog <<
"LogLikelihood at mode: " <<
LogLikelihood(mode) << std::endl;
1220 StatsLog <<
"LogAPrioriProbability at mode: " << LogAPrioriProbability(mode) <<
"\n\n" << std::endl;
1222 double llika =
Histo1D[
"LogLikelihood"].GetHistogram()->GetMean();
1223 StatsLog <<
"LogLikelihood mean value: " << llika << std::endl;
1224 double llikv =
Histo1D[
"LogLikelihood"].GetHistogram()->GetRMS();
1226 StatsLog <<
"LogLikelihood variance: " << llikv << std::endl;
1227 double dbar = -2.*llika;
1228 double pd = 2.*llikv;
1229 StatsLog <<
"IC value: " << dbar + 2.*pd << std::endl;
1230 StatsLog <<
"DIC value: " << dbar + pd << std::endl;
1231 StatsLog << std::endl;
1232 StatsLog << std::endl;
1236 const BCEngineMCMC::Statistics& st = GetStatistics();
1238 std::vector<double> parmeans = st.mean;
1243 StatsLog <<
"*** Statistical details using mean values of parameters ***\n" << std::endl;
1245 StatsLog <<
"\nMean value of the parameters:" << std::endl;
1246 StatsLog << std::endl;
1247 StatsLog << par_line <<
'\n' << sep
1248 << std::left << std::setw(par_width) <<
"parameter" << sep << std::right << std::setw(value_width) <<
"mean value" << sep <<
'\n' << par_line <<
'\n';
1250 for (std::map<std::string,double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++)
1251 StatsLog << sep << std::left << std::setw(par_width) << it->first << sep << std::right << std::setw(value_width) << it->second << sep <<
'\n';
1253 StatsLog << par_line <<
'\n';
1254 StatsLog << std::endl;
1256 StatsLog <<
"Mean of LogProbability: " << st.probability_mean << std::endl;
1257 StatsLog <<
"Variance of LogProbability: " << st.probability_variance << std::endl;
1258 StatsLog <<
"LogProbability at mode: " << st.probability_at_mode << std::endl;
1259 StatsLog << std::endl;
1262 StatsLog <<
"LogLikelihood on mean value of parameters: " << llonmean << std::endl;
1263 StatsLog <<
"pD computed using variance: " << pd << std::endl;
1264 pd = 2.*llonmean-2.*llika;
1265 StatsLog <<
"pD computed using 2LL(thetabar) - 2LLbar: " << pd << std::endl;
1266 StatsLog <<
"IC value computed from BAT with alternate pD definition: " << dbar + 2.*pd << std::endl;
1267 StatsLog <<
"DIC value computed from BAT with alternate pD definition: " << dbar + pd << std::endl;
1268 StatsLog << std::endl;
1269 StatsLog << std::endl;
1275 StatsLog <<
"*** Statistical details using parameter values at maximum LogLikelihood ***\n" << std::endl;
1277 StatsLog <<
"\nValue of the parameters at maximum LogLikelihood:" << std::endl;
1278 StatsLog << std::endl;
1279 StatsLog << par_line <<
'\n' << sep
1280 << std::left << std::setw(par_width) <<
"parameter" << sep << std::right << std::setw(value_width) <<
"value at max." << sep <<
'\n' << par_line <<
'\n';
1282 for (std::map<std::string,double>::iterator it =
DPars.begin(); it !=
DPars.end(); it++)
1283 StatsLog << sep << std::left << std::setw(par_width) << it->first << sep << std::right << std::setw(value_width) << it->second << sep <<
'\n';
1285 StatsLog << par_line <<
'\n';
1286 StatsLog << std::endl;
1288 StatsLog <<
"\nValue of the observables at the maximum LogLikelihood:" << std::endl;
1289 StatsLog << std::endl;
1290 StatsLog << obs_line <<
'\n' << sep
1291 << std::left << std::setw(obs_width) <<
"observable" << sep << std::right << std::setw(value_width) <<
"value at max." << sep <<
'\n' << obs_line <<
'\n';
1293 for (boost::ptr_vector<Observable>::iterator it =
Obs_ALL.begin(); it <
Obs_ALL.end(); it++)
1294 StatsLog << sep << std::left << std::setw(obs_width) << it->getName() << sep << std::right << std::setw(value_width) << it->computeTheoryValue() << sep <<
'\n';
1296 StatsLog << obs_line <<
'\n';
1297 StatsLog << std::endl;
1301 StatsLog << std::endl;
1303 return StatsLog.str().c_str();
1308 std::vector<double> mode(GetBestFitParameters());
1309 if (mode.size() == 0) {
1310 throw std::runtime_error(
"\n ERROR: Global Mode could not be determined possibly because of infinite loglikelihood. PreRun Data cannot be stored.\n");
1312 std::vector<double> scales(GetScaleFactors().at(0));
1313 std::ostringstream StatsLog;
1314 for (
unsigned int i = 0; i < mode.size(); i++)
1315 StatsLog << GetParameter(i).GetName() <<
" " << mode.at(i) <<
" " << scales.at(i) << std::endl;
1316 return StatsLog.str().c_str();
1321 SetNIterationsMin(NIterationNormalizationMC);
1322 SetIntegrationMethod(BCIntegrate::kIntMonteCarlo);
1324 std::vector<double> norm;
1326 norm.push_back(GetIntegral());
1327 norm.push_back(GetError());
1329 throw std::runtime_error(
"\n ERROR: Normalization computation cannot be completed since integral is negative.\n");
1337 unsigned int Npars = GetNParameters();
1338 std::vector<double> mode(GetBestFitParameters());
1339 if (mode.size() == 0) {
1340 throw std::runtime_error(
"\n ERROR: Global Mode could not be determined possibly because of infinite loglikelihood. Normalization computation cannot be completed.\n");
1344 for (
unsigned int i = 0; i < Npars; i++)
1345 for (
unsigned int j = 0; j < Npars; j++) {
1351 return exp(Npars / 2. *
log(2. * M_PI) + 0.5 *
log(1. / det_Hessian) +
LogLikelihood(mode) + LogAPrioriProbability(mode));
1356 if (point.size() != GetNParameters()) {
1357 throw std::runtime_error(
"MCMCENgine::SecondDerivative : Invalid number of entries in the vector.");
1361 const double dy1 = par2.GetRangeWidth() / NSTEPS;
1362 const double dy2 = dy1 * 2.;
1363 const double dy3 = dy1 * 3.;
1366 std::vector<double> y1p = point;
1367 std::vector<double> y1m = point;
1368 std::vector<double> y2p = point;
1369 std::vector<double> y2m = point;
1370 std::vector<double> y3p = point;
1371 std::vector<double> y3m = point;
1373 unsigned idy = GetParameters().Index(par2.GetName());
1386 return 3. / 2. * m1 - 3. / 5. * m2 + 1. / 10. * m3;
1391 if (point.size() != GetNParameters()) {
1392 throw std::runtime_error(
"MCMCENgine::FirstDerivative : Invalid number of entries in the vector.");
1396 const double dx1 = par.GetRangeWidth() / NSTEPS;
1397 const double dx2 = dx1 * 2.;
1398 const double dx3 = dx1 * 3.;
1401 std::vector<double> x1p = point;
1402 std::vector<double> x1m = point;
1403 std::vector<double> x2p = point;
1404 std::vector<double> x2m = point;
1405 std::vector<double> x3p = point;
1406 std::vector<double> x3m = point;
1408 unsigned idx = GetParameters().Index(par.GetName());
1421 return 3. / 2. * m1 - 3. / 5. * m2 + 1. / 10. * m3;
1425 if (point.size() != GetNParameters()) {
1426 throw std::runtime_error(
"MCMCENgine::Function_h : Invalid number of entries in the vector.");