a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
EventGeneration.cpp

This is an example of how to perform a Bayesian Markov Chain Monte Carlo analysis with HEPfit and BAT.

/*
* Copyright (C) 2016 HEPfit Collaboration
*
*
* For the licensing terms see doc/COPYING.
*/
#include <iostream>
#include <HEPfit.h>
/* Necessary if MPI support is enabled during compilation. */
#ifdef _MPI
#include <mpi.h>
#endif
int main(int argc, char** argv)
{
/* Necessary if MPI support is enabled during compilation. */
#ifdef _MPI
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#else
/* In our MPI implementation the process with rank 0 is the master. */
int rank = 0;
#endif
try {
if(argc < 3){
/* Print usage and exit. */
if (rank == 0) std::cout << "\nusage: " << argv[0] << " ModelConf.conf nEvents [OutputFolder]\n" << std::endl;
return EXIT_SUCCESS;
}
/* Define the model configuration file. */
/* Here it is passed as the first argument to the executable. The */
/* model configuration file provides the values with errors for the */
/* mandatory model parameters, as well as the list of observables, */
/* observables2D, correlated Gaussian observables. */
/* See documentation for details. */
std::string ModelConf = argv[1];
/* Define the number of iterations.*/
int nIterations = atoi(argv[2]);
/* Define the output folder. Results will be put in ./GeneratedEvents/<outputFolder>*/
std::string outputFolder = "";
if(argc == 4) outputFolder = argv[3];
/* Define the seed. 0 for using processor time.*/
int seed = 1;
/* Define whether weight will be calculated.*/
bool weight = true;
/* Define the optional job tag. */
std::string JobTag = "";
/* Create objects of the classes ModelFactory and ThObsFactory */
ThObsFactory ThObsF;
ModelFactory ModelF;
/* register user-defined model named ModelName defined in class ModelClass using the following syntax: */
/* ModelF.addModelToFactory(ModelName, boost::factory<ModelClass*>() ) */
/* register user-defined ThObservable named ThObsName defined in class ThObsClass using the following syntax: */
/* ThObsF.addObsToFactory(ThObsName, boost::factory<ThObsClass*>() )*/
/* Create an object of the class GenerateEvent. */
GenerateEvent GE(ModelF, ThObsF, ModelConf, outputFolder, JobTag);
/* Initiate the Mote Carlo run. */
GE.generate(nIterations, seed, weight);
/* Necessary if MPI support is enabled during compilation. */
#ifdef _MPI
MPI_Finalize();
#endif
return EXIT_SUCCESS;
} catch (const std::runtime_error& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
}
ModelFactory
A class for.
Definition: ModelFactory.h:25
main
int main(int argc, char **argv)
Definition: Doxygen/examples-src/EventGeneration/EventGeneration.cpp:22
GenerateEvent
A class for generating events.
Definition: GenerateEvent.h:41
ThObsFactory
A class for.
Definition: ThObsFactory.h:26
GenerateEvent::generate
void generate(int unsigned nIteration_i, int seed=0, bool weight_i=false)
The method used to generate events and format output.
Definition: GenerateEvent.cpp:52