BCPriorModel.cxx
1 /*
2  * Copyright (C) 2007-2018, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 // ---------------------------------------------------------
10 
11 #include "BCPriorModel.h"
12 
13 #include <TH1.h>
14 
15 // ---------------------------------------------------------
16 BCPriorModel::BCPriorModel(BCModel& model, bool call_likelihood) :
17  BCModel(model.GetName() + "_prior"),
18  fModel(model),
19  fCallLikelihood(call_likelihood)
20 {
22 }
23 
24 // ---------------------------------------------------------
26 {
27  // copy parameters and observables
30 
31  // but use binning that was used by model
32  for (unsigned i = 0; i < fModel.GetNVariables(); ++i)
34  // Set binning from marginalization rather than parameter copy
35  GetVariable(i).SetNbins(fModel.GetMarginalizedHistogram(i)->GetNbinsX());
36 
37  // set default MCMC setup to the one of the original model
39 
40  return true;
41 }
42 
43 // ---------------------------------------------------------
44 void BCPriorModel::CalculateObservables(const std::vector<double>& parameters)
45 {
46  // help with thread safety and correctness of sampling
48 
49  if (fCallLikelihood)
50  fModel.LogLikelihood(parameters);
51  fModel.CalculateObservables(parameters);
52  for (unsigned i = 0; i < GetNObservables(); ++i)
54 }
bool MarginalizedHistogramExists(unsigned index) const
Definition: BCEngineMCMC.h:511
BCObservable & GetObservable(unsigned index)
Definition: BCEngineMCMC.h:685
BCObservableSet fObservables
User-calculated Observables Set.
virtual double LogLikelihood(const std::vector< double > &params)=0
Calculates natural logarithm of the likelihood.
void CalculateObservables(const std::vector< double > &parameters)
Calculates user observables according to the model.
BCObservableSet & GetObservables()
Definition: BCEngineMCMC.h:673
virtual void CalculateObservables(const std::vector< double > &pars)
Evaluates user-defined observables.
void UpdateChainIndex(int chain)
Keep track of which chain is currently computed (within a thread).
The base class for all user-defined models.
Definition: BCModel.h:39
unsigned GetNObservables() const
Definition: BCEngineMCMC.h:711
BCModel & fModel
The original model on which we call the prior.
Definition: BCPriorModel.h:76
void SetPrecision(BCEngineMCMC::Precision precision)
Set the precision for the MCMC run.
double Value() const
Definition: BCObservable.h:69
bool PreparePriorModel()
Prepare PriorModel from Model.
BCParameterSet fParameters
Parameter settings.
TH1 * GetMarginalizedHistogram(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter as a ROOT TH1...
Definition: BCEngineMCMC.h:527
unsigned GetNVariables() const
Definition: BCEngineMCMC.h:613
unsigned GetCurrentChain() const
BCPriorModel(BCModel &model, bool call_likelihood=false)
constructor.
bool fCallLikelihood
Call the likelihood of the original model when evaluating observables.
Definition: BCPriorModel.h:79
BCVariable & GetVariable(unsigned index)
Definition: BCEngineMCMC.h:600
BCParameterSet & GetParameters()
Definition: BCEngineMCMC.h:618