myModel.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 
8 #include "myModel.h"
9 
10 /* Define mandatory model parameters here. */
11 const std::string myModel::myModelvars[NmyModelvars] = {"c1", "c2", "c3", "c4"};
12 
14 : StandardModel()
15 {
16  /* Define all the parameters here and port them as observables too */
17  ModelParamMap.insert(std::pair<std::string, boost::reference_wrapper<const double> >("c1", boost::cref(c1)));
18  ModelParamMap.insert(std::pair<std::string, boost::reference_wrapper<const double> >("c2", boost::cref(c2)));
19  ModelParamMap.insert(std::pair<std::string, boost::reference_wrapper<const double> >("c3", boost::cref(c3)));
20  ModelParamMap.insert(std::pair<std::string, boost::reference_wrapper<const double> >("c4", boost::cref(c4)));
21 }
22 
24 {
25  if (IsModelInitialized()) {
26  /* Destroy whatever you want, e.g. potentially dangerous pointers. */
27  }
28 }
29 
30 /* Initialize model here */
32 {
33  condition = false;
35  return(true);
36 }
37 
38 bool myModel::Init(const std::map<std::string, double>& DPars)
39 {
40  return(StandardModel::Init(DPars));
41 }
42 
43 /* Do whatever is necessary before parameters are updated by the MCMC. */
45 {
46  if(!StandardModel::PreUpdate()) return (false);
47  return (true);
48 }
49 
50 /* Model update method used be the MCMC to update the model parameters. */
51 bool myModel::Update(const std::map<std::string, double>& DPars)
52 {
53  if(!PreUpdate()) return (false);
54 
55  UpdateError = false;
56 
57  for (std::map<std::string, double>::const_iterator it = DPars.begin(); it != DPars.end(); it++)
58  setParameter(it->first, it->second);
59 
60  if (UpdateError) return (false);
61 
62  if(!PostUpdate()) return (false);
63 
64  return (true);
65 
66  return (true);
67 }
68 
69 /* Postupdate method to update whatever is needed after the model parameters are updated */
71 {
72  if(!StandardModel::PostUpdate()) return (false);
73 
74  return (true);
75 }
76 
77 /* Model parameters and their derived quantities can be set here. */
78 void myModel::setParameter(const std::string name, const double& value)
79 {
80  if(name.compare("c1") == 0)
81  c1 = value;
82  else if(name.compare("c2") == 0)
83  c2 = value;
84  else if(name.compare("c3") == 0)
85  c3 = value;
86  else if(name.compare("c4") == 0)
87  c4 = value;
88  else
89  StandardModel::setParameter(name,value);
90 }
91 
92 bool myModel::CheckParameters(const std::map<std::string, double>& DPars)
93 {
94  for (int i = 0; i < NmyModelvars; i++) {
95  if (DPars.find(myModelvars[i]) == DPars.end()) {
96  std::cout << "missing mandatory myModel parameter " << myModelvars[i] << std::endl;
97  return false;
98  }
99  }
100  return(StandardModel::CheckParameters(DPars));
101 }
102 
103 
104 /* Model Flags can be set here. */
105 bool myModel::setFlag(const std::string name, const bool value)
106 {
107  bool res = false;
108 
109  if(name.compare("condition") == 0){
110  condition = value;
111  res = true;
112  } else {
113  res = StandardModel::setFlag(name,value);
114  }
115 
116  return(res);
117 }
virtual bool PostUpdate()
The post-update method for StandardModel.
virtual bool CheckParameters(const std::map< std::string, double > &DPars)
Definition: myModel.cpp:92
virtual bool Init(const std::map< std::string, double > &DPars)
Definition: myModel.cpp:38
virtual void setParameter(const std::string, const double &)
Definition: myModel.cpp:78
virtual bool Update(const std::map< std::string, double > &DPars)
Definition: myModel.cpp:51
virtual bool PreUpdate()
Definition: myModel.cpp:44
double c2
Definition: myModel.h:100
virtual bool InitializeModel()
Definition: myModel.cpp:31
double c4
Definition: myModel.h:100
bool UpdateError
A boolean set to false if update is successful.
Definition: Model.h:192
static const std::string myModelvars[NmyModelvars]
Definition: myModel.h:21
virtual bool InitializeModel()
A method to initialize the model.
virtual bool PostUpdate()
Definition: myModel.cpp:70
A model class for the Standard Model.
static const int NmyModelvars
Definition: myModel.h:20
void setModelInitialized(bool ModelInitialized)
A set method to fix the failure or success of the initialization of the model.
Definition: Model.h:142
bool IsModelInitialized() const
A method to check if the model is initialized.
Definition: Model.h:133
virtual bool Init(const std::map< std::string, double > &DPars)
A method to initialize the model parameters.
virtual void setParameter(const std::string name, const double &value)
A method to set the value of a parameter of StandardModel.
virtual bool PreUpdate()
The pre-update method for StandardModel.
~myModel()
myModel destructor
Definition: myModel.cpp:23
myModel()
myModel constructor
Definition: myModel.cpp:13
virtual bool CheckParameters(const std::map< std::string, double > &DPars)
A method to check if all the mandatory parameters for StandardModel have been provided in model initi...
bool condition
Definition: myModel.h:101
virtual bool setFlag(const std::string name, const bool value)
Definition: myModel.cpp:105
double c1
Definition: myModel.h:100
virtual bool setFlag(const std::string name, const bool value)
A method to set a flag of StandardModel.
std::map< std::string, boost::reference_wrapper< const double > > ModelParamMap
Definition: Model.h:200
double c3
Definition: myModel.h:100