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