a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
myModel_MCMC.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 HEPfit Collaboration
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  */
7 
19 #include <iostream>
20 #include <HEPfit.h>
21 #include <boost/bind.hpp>
22 #include "myModel.h"
23 #include "myObservables.h"
24 
25 /* Necessary if MPI support is enabled during compilation. */
26 #ifdef _MPI
27 #include <mpi.h>
28 #endif
29 
30 int main(int argc, char** argv)
31 {
32 
33 /* Necessary if MPI support is enabled during compilation. */
34 #ifdef _MPI
35  MPI_Init(&argc, &argv);
36  int rank;
37  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
38 #else
39  /* In our MPI implementation the process with rank 0 is the master. */
40  int rank = 0;
41 #endif
42 
43  try {
44 
45  if(argc != 3){
46  /* Print usage and exit. */
47  if (rank == 0) std::cout << "\nusage: " << argv[0] << " ModelConf.conf MonteCarlo.conf\n" << std::endl;
48  return EXIT_SUCCESS;
49  }
50 
51  /* Define the model configuration file. */
52  /* Here it is passed as the first argument to the executable. The */
53  /* model configuration file provides the values with errors for the */
54  /* mandatory model parameters, as well as the list of observables, */
55  /* observables2D, correlated Gaussian observables. */
56  /* See documentation for details. */
57  std::string ModelConf = argv[1];
58 
59  /* Define the Monte Carlo configuration file. */
60  /* Here it is passed as the second argument to the executable. The */
61  /* Monte Carlo configuration file provides the parameters used in the */
62  /* Monte Carlo run. See documentation for details. */
63  std::string MCMCConf = argv[2];
64 
65  /* Define the ROOT output file (w/o extension, empty string will set it to MCout) */
66  std::string FileOut = "";
67 
68  /* Define the optional job tag. */
69  std::string JobTag = "";
70 
71  /* Create objects of the classes ModelFactory and ThObsFactory */
72  ThObsFactory ThObsF;
73  ModelFactory ModelF;
74  myModel my_model;
75 
76  /* register user-defined model named ModelName defined in class ModelClass using the following syntax: */
77  ModelF.addModelToFactory("myModel", boost::factory<myModel*>() );
78 
79  /* register user-defined ThObservable named ThObsName defined in class ThObsClass using the following syntax: */
80  ThObsF.addObsToFactory("BIN1", boost::bind(boost::factory<yield*>(), _1, 1) );
81  ThObsF.addObsToFactory("BIN2", boost::bind(boost::factory<yield*>(), _1, 2) );
82  ThObsF.addObsToFactory("BIN3", boost::bind(boost::factory<yield*>(), _1, 3) );
83  ThObsF.addObsToFactory("BIN4", boost::bind(boost::factory<yield*>(), _1, 4) );
84  ThObsF.addObsToFactory("BIN5", boost::bind(boost::factory<yield*>(), _1, 5) );
85  ThObsF.addObsToFactory("BIN6", boost::bind(boost::factory<yield*>(), _1, 6) );
86  ThObsF.addObsToFactory("C_3", boost::factory<C_3*>() );
87  ThObsF.addObsToFactory("C_4", boost::factory<C_4*>() );
88 
89  /* Create an object of the class MonteCarlo. */
90  MonteCarlo MC(ModelF, ThObsF, ModelConf, MCMCConf, FileOut, JobTag);
91 
92  /* Do a test run if you wish to see the values of the observables */
93  /* and the correlated Gaussian observables defined in the model */
94  /* configuration file computed with the central value of the mandatory */
95  /* parameters defined in the same file. */
96  // MC.TestRun(rank);
97 
98  /* Initiate the Mote Carlo run. */
99  MC.Run(rank);
100 
101 /* Necessary if MPI support is enabled during compilation. */
102 #ifdef _MPI
103  MPI_Finalize();
104 #endif
105 
106  return EXIT_SUCCESS;
107  } catch (const std::runtime_error& e) {
108  std::cerr << e.what() << std::endl;
109  return EXIT_FAILURE;
110  }
111 }
ModelFactory
A class for.
Definition: ModelFactory.h:25
ModelFactory::addModelToFactory
void addModelToFactory(const std::string name, boost::function< StandardModel *() >)
Definition: ModelFactory.cpp:91
myObservables.h
myModel
My own Model.
Definition: myModel.h:17
ThObsFactory
A class for.
Definition: ThObsFactory.h:26
MonteCarlo::Run
void Run(const int rank)
This member is responsible for setting the Monte Carlo run parameters and conducting the Monte Carlo ...
Definition: MonteCarlo.cpp:128
main
int main(int argc, char **argv)
Definition: myModel_MCMC.cpp:30
ThObsFactory::addObsToFactory
void addObsToFactory(const std::string name, boost::function< ThObservable *(const StandardModel &) >)
Definition: ThObsFactory.cpp:4617
myModel.h
MonteCarlo
A class for Monte Carlo.
Definition: MonteCarlo.h:35