An engine class for Monte Carlo. More...
#include <MonteCarloEngine.h>
An engine class for Monte Carlo.
The MonteCarlo engine is has overloaded from BCEngineMCMC class in the BAT libraries and user defined fumctions to facilitate the Monte Carlo run.
Definition at line 46 of file MonteCarloEngine.h.
Public Member Functions | |
| void | AddChains () |
| A method to add the observable values and weights to the chain information. More... | |
| void | CheckHistogram (const TH1D &hist, const std::string name) |
| This member checks if there is overflow of the 1D histogram. More... | |
| void | CheckHistogram (const TH2D &hist, const std::string name) |
| This member checks if there is overflow of the 2D histogram. More... | |
| double | computeNormalization () |
| std::string | computeStatistics () |
| A get method to compute the mean and rms of the computed observables. More... | |
| void | DefineParameters () |
| A member to classify the prior of the model parameters varied in the Monte Carlo. More... | |
| double | FirstDerivative (const BCParameter *par, std::vector< double > point) |
| double | Function_h (std::vector< double > point) |
| std::map< std::string, BCH1D * > | getHistograms1D () const |
| std::map< std::string, BCH2D * > | getHistograms2D () const |
| std::string | getHistoLog () const |
| A get method to access the stream that stores the log messages coming from histogram printing and checking. More... | |
| int | getNumOfDiscardedEvents () const |
| A get method to access the number of events discarded due to failure to update model. These events are not used for the MCMC run. More... | |
| int | getNumOfUsedEvents () const |
| A get method to access the number of events used in the MCMC run. More... | |
| void | Initialize (Model *Mod_i) |
| Initialization of the Monte Carlo Engine. More... | |
| double | LogLikelihood (const std::vector< double > ¶meters) |
| This member calculates the loglikelihood for the observables included in the MCMC run. More... | |
| void | MCMCIterationInterface () |
| Overloaded from BCEngineMCMC in BAT More... | |
| MonteCarloEngine (const std::vector< ModelParameter > &ModPars_i, boost::ptr_vector< Observable > &Obs_i, std::vector< Observable2D > &Obs2D_i, std::vector< CorrelatedGaussianObservables > &CGO_i, std::vector< CorrelatedGaussianParameters > &CGP_i) | |
| Constructor. More... | |
| void | PrintCorrelationMatrix (const std::string filename) |
| This member generates the correlation matrix using BCH2D from the BAT libraries. More... | |
| void | PrintHistogram (BCModelOutput &out, Observable &it, const std::string OutputDir) |
| Overloaded from PrintHistogram(BCModelOutput&, const std::string) to print histogram for observables. More... | |
| void | PrintHistogram (BCModelOutput &out, const std::string OutputDir) |
| Member used for printing histograms for observables, observable2D, correlated Gaussian observables and model parameters vs. observables. More... | |
| double | SecondDerivative (const BCParameter *par1, const BCParameter *par2, std::vector< double > point) |
| void | setDParsFromParameters (const std::vector< double > ¶meters, std::map< std::string, double > &DPars_i) |
| void | setHistogramOverFlow (bool overflow) |
| void | setNChains (unsigned int i) |
| A set method to fix the number of chains. More... | |
| std::string | writePreRunData () |
| A method to write in a text file the best fit parameters and the prerun scale factors. More... | |
| ~MonteCarloEngine () | |
| The default destructor. Some pointers defined in this class are explicitly freed. More... | |
Private Attributes | |
| std::vector< CorrelatedGaussianObservables > & | CGO |
| A vector of correlated Gaussian observables. More... | |
| const std::vector< CorrelatedGaussianParameters > & | CGP |
| A vector of correlated Gaussian parameters. More... | |
| std::map< std::string, TPrincipal * > | CorrelationMap |
| A map between the name of a theory observable and its maximum value. More... | |
| std::map< std::string, double > | DPars |
| A map between parameter names and their values. More... | |
| std::map< std::string, BCH1D * > | Histo1D |
| A map between pointers to objects of type BCH1D (BAT) and their given names. More... | |
| std::map< std::string, BCH2D * > | Histo2D |
| A map between pointers to objects of type BCH2D (BAT) and their given names. More... | |
| std::ostringstream | HistoLog |
| A stream to store the output messages from printing and checking histograms. More... | |
| unsigned int | kmax |
| The number of observables. More... | |
| unsigned int | kwmax |
| The number of observables whose weights are used for the MCMC. More... | |
| Model * | Mod |
| A pointer to an abject of type Model. More... | |
| const std::vector< ModelParameter > & | ModPars |
| A vector of model parameters. More... | |
| int | NumOfDiscardedEvents |
| The number of events for which the update of the model fails and these events are not used for the MCMC run. More... | |
| int | NumOfUsedEvents |
| The number of events for which the model is successfully updated and hence used for the MCMC run. More... | |
| std::vector< Observable2D > & | Obs2D_ALL |
| A vector of all pairs of observable for Observable2D. More... | |
| boost::ptr_vector< Observable > & | Obs_ALL |
| A vector of all observables. More... | |
| double * | obval |
| A pointer to the vector of observable values. More... | |
| double * | obweight |
| A pointer to the vector of observable weights. More... | |
| int | rank |
| Rank of the process for a MPI run. Value is 0 for a serial run. More... | |
| std::map< std::string, double > | thMax |
| A map between the name of a theory observable and its maximum value. More... | |
| std::map< std::string, double > | thMin |
| A map between the name of a theory observable and its minimum value. More... | |
| MonteCarloEngine::MonteCarloEngine | ( | const std::vector< ModelParameter > & | ModPars_i, |
| boost::ptr_vector< Observable > & | Obs_i, | ||
| std::vector< Observable2D > & | Obs2D_i, | ||
| std::vector< CorrelatedGaussianObservables > & | CGO_i, | ||
| std::vector< CorrelatedGaussianParameters > & | CGP_i | ||
| ) |
Constructor.
| [in] | ModPars_i | the vector of model parameters as defined in SomeModel.conf |
| [in] | Obs_i | the vector of observables as defined in SomeModel.conf |
| [in] | Obs2D_i | the vector of observables2D as defined in SomeModel.conf |
| [in] | CGO_i | the vector of correlated Gaussian observables as defined in SomeModel.conf |
Definition at line 23 of file MonteCarloEngine.cpp.
| MonteCarloEngine::~MonteCarloEngine | ( | ) |
The default destructor. Some pointers defined in this class are explicitly freed.
Definition at line 132 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::AddChains | ( | ) |
A method to add the observable values and weights to the chain information.
If the WriteChain flag is set to true in the MonteCarlo.conf file then chain information is written. This method adds the observable values and weights (for the observables included in the MCMC) to the chain information.
Definition at line 590 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::CheckHistogram | ( | const TH1D & | hist, |
| const std::string | name | ||
| ) |
This member checks if there is overflow of the 1D histogram.
| [in] | hist | a reference to an object of type TH1D as defined in the ROOT libraries |
| [in] | name | the name for the histogram |
Definition at line 494 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::CheckHistogram | ( | const TH2D & | hist, |
| const std::string | name | ||
| ) |
This member checks if there is overflow of the 2D histogram.
| [in] | hist | a reference to an object of type TH2D as defined in the ROOT libraries |
| [in] | name | the name for the histogram |
Definition at line 509 of file MonteCarloEngine.cpp.
| double MonteCarloEngine::computeNormalization | ( | ) |
Definition at line 832 of file MonteCarloEngine.cpp.
| std::string MonteCarloEngine::computeStatistics | ( | ) |
A get method to compute the mean and rms of the computed observables.
Definition at line 640 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::DefineParameters | ( | ) |
A member to classify the prior of the model parameters varied in the Monte Carlo.
The model parameters being varied are first sorted out checking for the existence of of Gaussian error ( \(\delta_{g}\)) or flat error ( \(\delta_{f}\)). The SetPriorGaus method and SetPriorConstant method in BCEngineMCMC (BAT) is used to set a Gaussian or flat prior for the model parameters respectively. In case a model parameter has both a Gaussian and a flat error then the combined function is built using TF1. The definition of the combined error is
\[ \delta_{combined}(x) = \frac{1}{4\delta_f}\left(\frac{Erf(x - x_{ave}+\delta_f)}{\sqrt{2}\delta_g} - \frac{Erf(x - x_{ave}-\delta_f)}{\sqrt{2}\delta_g}\right), \]
with
\[ Erf(x)=\frac{1}{\sqrt{2}\pi}\int_0^x \exp^{-\frac{t^2}{2}}dt. \]
Definition at line 153 of file MonteCarloEngine.cpp.
| double MonteCarloEngine::FirstDerivative | ( | const BCParameter * | par, |
| std::vector< double > | point | ||
| ) |
Definition at line 884 of file MonteCarloEngine.cpp.
| double MonteCarloEngine::Function_h | ( | std::vector< double > | point | ) |
Definition at line 919 of file MonteCarloEngine.cpp.
|
inline |
Definition at line 225 of file MonteCarloEngine.h.
|
inline |
Definition at line 230 of file MonteCarloEngine.h.
|
inline |
A get method to access the stream that stores the log messages coming from histogram printing and checking.
Definition at line 182 of file MonteCarloEngine.h.
|
inline |
A get method to access the number of events discarded due to failure to update model. These events are not used for the MCMC run.
Definition at line 211 of file MonteCarloEngine.h.
|
inline |
A get method to access the number of events used in the MCMC run.
Definition at line 220 of file MonteCarloEngine.h.
| void MonteCarloEngine::Initialize | ( | Model * | Mod_i | ) |
Initialization of the Monte Carlo Engine.
The initialization of the Monte Carlo Engine performs the following tasks
| [in] | Mod_i | the pointer to the model defined in SomeModel.conf |
Definition at line 42 of file MonteCarloEngine.cpp.
| double MonteCarloEngine::LogLikelihood | ( | const std::vector< double > & | parameters | ) |
This member calculates the loglikelihood for the observables included in the MCMC run.
The model is updated with the new set of parameters through the Model::Update() method. If this is successful this even is counted as a used event. Otherwise it is counted as a discarded event. The log probability is calculated using Weight(const Observable&, const double& ) function for the observables, Weight(const Observable2D&, const double&, const double& ) for the observable2D and Weight(const CorrelatedGaussianObservables& ) for the correlated Gaussian observables. Overloaded from BCEngineMCMC in BAT.
| [in] | parameters | the vector of the parameters that are being varied in the Monte Carlo |
Definition at line 248 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::MCMCIterationInterface | ( | ) |
Overloaded from BCEngineMCMC in BAT
The interface is used to update the model parameters using the Model::Update() method. Then the values of the observables are computed and the respective histograms are filled. If the checkTheoryRange flag is true then the minimum and maximum of the theory value is checked and reset to include the current theory values.
Definition at line 293 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::PrintCorrelationMatrix | ( | const std::string | filename | ) |
This member generates the correlation matrix using BCH2D from the BAT libraries.
| [in] | filename | the name of the file where the correlation matrix is printed |
Definition at line 611 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::PrintHistogram | ( | BCModelOutput & | out, |
| Observable & | it, | ||
| const std::string | OutputDir | ||
| ) |
Overloaded from PrintHistogram(BCModelOutput&, const std::string) to print histogram for observables.
| [in] | out | a reference to an object of type BCModelOutput as defined in the BAT libraries |
| [in] | it | a reference to an object of type Observable |
| [in] | OutputDir | the name of the output directory |
Definition at line 520 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::PrintHistogram | ( | BCModelOutput & | out, |
| const std::string | OutputDir | ||
| ) |
Member used for printing histograms for observables, observable2D, correlated Gaussian observables and model parameters vs. observables.
| [in] | out | a reference to an object of type BCModelOutput as defined in the BAT libraries |
| [in] | OutputDir | the name of the output directory |
Definition at line 545 of file MonteCarloEngine.cpp.
| double MonteCarloEngine::SecondDerivative | ( | const BCParameter * | par1, |
| const BCParameter * | par2, | ||
| std::vector< double > | point | ||
| ) |
Definition at line 849 of file MonteCarloEngine.cpp.
| void MonteCarloEngine::setDParsFromParameters | ( | const std::vector< double > & | parameters, |
| std::map< std::string, double > & | DPars_i | ||
| ) |
Definition at line 199 of file MonteCarloEngine.cpp.
|
inline |
Definition at line 235 of file MonteCarloEngine.h.
| void MonteCarloEngine::setNChains | ( | unsigned int | i | ) |
A set method to fix the number of chains.
The number of chains are set using the MCMCSetNChains() from BCEngineMCMC class in BAT. This also creates pointers to the vector of observable values and weights for all the chains.
| [in] | i | the number of chains |
Definition at line 124 of file MonteCarloEngine.cpp.
| std::string MonteCarloEngine::writePreRunData | ( | ) |
A method to write in a text file the best fit parameters and the prerun scale factors.
Definition at line 822 of file MonteCarloEngine.cpp.
|
private |
A vector of correlated Gaussian observables.
Definition at line 256 of file MonteCarloEngine.h.
|
private |
A vector of correlated Gaussian parameters.
Definition at line 253 of file MonteCarloEngine.h.
|
private |
A map between the name of a theory observable and its maximum value.
Definition at line 263 of file MonteCarloEngine.h.
|
private |
A map between parameter names and their values.
Definition at line 258 of file MonteCarloEngine.h.
|
private |
A map between pointers to objects of type BCH1D (BAT) and their given names.
Definition at line 259 of file MonteCarloEngine.h.
|
private |
A map between pointers to objects of type BCH2D (BAT) and their given names.
Definition at line 260 of file MonteCarloEngine.h.
|
private |
A stream to store the output messages from printing and checking histograms.
Definition at line 268 of file MonteCarloEngine.h.
|
private |
The number of observables.
Definition at line 267 of file MonteCarloEngine.h.
|
private |
The number of observables whose weights are used for the MCMC.
Definition at line 266 of file MonteCarloEngine.h.
|
private |
A pointer to an abject of type Model.
Definition at line 257 of file MonteCarloEngine.h.
|
private |
A vector of model parameters.
Definition at line 252 of file MonteCarloEngine.h.
|
private |
The number of events for which the update of the model fails and these events are not used for the MCMC run.
Definition at line 270 of file MonteCarloEngine.h.
|
private |
The number of events for which the model is successfully updated and hence used for the MCMC run.
Definition at line 269 of file MonteCarloEngine.h.
|
private |
A vector of all pairs of observable for Observable2D.
Definition at line 255 of file MonteCarloEngine.h.
|
private |
A vector of all observables.
Definition at line 254 of file MonteCarloEngine.h.
|
private |
A pointer to the vector of observable values.
Definition at line 264 of file MonteCarloEngine.h.
|
private |
A pointer to the vector of observable weights.
Definition at line 265 of file MonteCarloEngine.h.
|
private |
Rank of the process for a MPI run. Value is 0 for a serial run.
Definition at line 271 of file MonteCarloEngine.h.
|
private |
A map between the name of a theory observable and its maximum value.
Definition at line 262 of file MonteCarloEngine.h.
|
private |
A map between the name of a theory observable and its minimum value.
Definition at line 261 of file MonteCarloEngine.h.