gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
demo.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
20 
21 
22 #ifndef __demo_hpp__
23 #define __demo_hpp__
24 
25 // This is the normal distribution toy model used in ExampleBit_A.
26 #define MODEL NormalDist
29 #undef MODEL
30 
31 // A one-parameter model for testing simple prior transformations
32 #define MODEL TestModel1D
34  DEFINEPARS(x)
35 #undef MODEL
36 
37 // The following are some examples that demonstrate the available ways to declare
38 // models and their relationships. These are commented out as they are not necessary for
39 // any of the module examples, but you can uncomment and experiment with them in order to
40 // learn about model declaration in GAMBIT if you like.
41 
42 /*
43 
44 #include "gambit/Logs/logging.hpp"
45 #include <string>
46 
47 // Start a new model family tree, beginning at the top. The_ancient_one has no parent.
48 #define MODEL the_ancient_one
49  START_MODEL
50  DEFINEPARS(p1,p2,p3)
51 #undef MODEL
52 
53 // This is a model that everything else is connected through, but really does nothing -- kinda like Kevin Bacon.
54 // Feel free to rename it after your most unresponsive senior collaborator.
55 #define MODEL kevin_bacon
56 #define PARENT the_ancient_one
57  START_MODEL
58  DEFINEPARS(M1,M2,M3) // You can call this more than once:
59  DEFINEPARS(AU1,AU2,AU3)
60 
61  // Declare the interpret-as-parent function. This function gets CAPABILITY = PARENT_parameters,
62  // TYPE = ModelParameters and MODULE = MODEL. It converts parameter values of the MODEL to
63  // parameter values of the PARENT. The user-defined part of the function can go anywhere, so
64  // long as you properly attach it to this declaration (which puts the function here:
65  // Gambit::Models::MODEL::<FUNCTION>). The MODEL_NAMESPACE macro gets you the Gambit::Models::MODEL
66  // part, if MODEL is defined.
67  INTERPRET_AS_PARENT_FUNCTION(kevin_bacon_IAPfunc)
68 
69  // Define the interpret-as-parent function.
70  // Note that "myparams" must be const. You're not allowed to change them here. Change "parentparams".
71  // To be able to access the Pipes, in case dependencies exist, this function has to be put in
72  // the correct namespace, and be defined after it has been declared using the INTERPRET_AS_PARENT macro.
73  // To make it easier to attach the function definition to the correct declaration, use the macro "MODEL_NAMESPACE".
74  void MODEL_NAMESPACE::kevin_bacon_IAPfunc (const ModelParameters &myparams, ModelParameters &parentparams)
75  {
76  logger()<<"Running interpret_as_parent calculations for kevin_bacon -> the_ancient_one ..."<<EOM;
77 
78  double M1 = myparams["M1"];
79  double M2 = myparams["M2"];
80  double M3 = myparams["M3"];
81  double AU1 = myparams["AU1"];
82  double AU2 = myparams["AU2"];
83  double AU3 = myparams["AU3"];
84 
85  parentparams.setValue("p1", 0.01*M1*M2+AU1);
86  parentparams.setValue("p2", 0.10*M2*M3+AU2);
87  parentparams.setValue("p3", 1.00*M1*M3+AU3);
88  }
89 #undef PARENT
90 #undef MODEL
91 
92 
93 #define MODEL demo_A
94 #define PARENT kevin_bacon
95  START_MODEL
96  DEFINEPARS(M0, M12, A0, Mstop, tanb, sgnmu)
97 
98  // Attach a CAPABILITY to a parameter.
99  // This creates a new module function with CAPABILITY = Mstop_obs, TYPE = double and MODULE = MODEL.
100  MAP_TO_CAPABILITY(Mstop, Mstop_obs)
101 
102  // Declare the interpret-as-parent function for going up the model hierarchy to kevin_bacon.
103  INTERPRET_AS_PARENT_FUNCTION(demo_A_IAPfunc)
104 
105  // Give the new interpret-as-parent function a dependency, a la regular GAMBIT module functions.
106  INTERPRET_AS_PARENT_DEPENDENCY(id, std::string)
107 
108  // Define the interpret-as-parent function. This can also be done in a source file if you prefer.
109  void MODEL_NAMESPACE::demo_A_IAPfunc (const ModelParameters &myparams, ModelParameters &parentparams)
110  {
111  // Finding the correct Pipes to retrieve dependencies in model functions can take
112  // a little effort. To save this effort, use the USE_MODEL_PIPE(MODEL_X) macro.
113  // This macro just expands to the following:
114  // using namespace Gambit::Models::MODEL::Pipes::MODEL_X_parameters;
115  // which points to the Pipes for the module function that wraps the user-defined
116  // interpret-as function.
117  USE_MODEL_PIPE(PARENT)
118 
119  logger()<<"Running interpret_as_parent calculations for demo_A -> kevin_bacon ..."<<EOM;
120 
121  double M0 = myparams["M0"];
122  double A0 = myparams["A0"];
123 
124  // Play around with the extra info obtained from the dependency.
125  logger()<<"identity dependency has supplied the value: "<<*Dep::id<<EOM;
126 
127  // Grab a reference to the parent parameter object and set some values.
128  // The parent parameter object already exists if we have gotten this
129  // far (it was created along with the functor that wraps this function).
130  parentparams.setValue("M1", M0);
131  parentparams.setValue("M2", 0.5*M0);
132  parentparams.setValue("M3", 3*M0);
133  parentparams.setValue("AU1", A0);
134  parentparams.setValue("AU2", 2*A0);
135  parentparams.setValue("AU3", 0);
136  }
137 #undef PARENT
138 #undef MODEL
139 
140 
141 // Alternative parameterisations of models are treated just like any other model. You may like to have
142 // a "primary" parameterisation, and "alternative" parameterisations which are child models of the
143 // primary, with interpret-as-parent functions defined to convert from the alternate to the primary parameters.
144 #define MODEL demo_A_alternative
145 #define PARENT demo_A
146  START_MODEL
147  DEFINEPARS(M0, M12, A0, Mstop, X_rotated, Y_rotated)
148  INTERPRET_AS_PARENT_FUNCTION(demo_A_alternative_IAPfunc)
149 
150  void MODEL_NAMESPACE::demo_A_alternative_IAPfunc (const ModelParameters &myparams, ModelParameters &parentparams)
151  {
152  // Get the Pipes for the interpret-as-parent function
153  USE_MODEL_PIPE(PARENT)
154  // Get alternative model parameters
155  double xrot = myparams["X_rotated"];
156  double yrot = myparams["Y_rotated"];
157  // Convert to primary model parameters
158  parentparams.setValue("M0", myparams["M0"]);
159  parentparams.setValue("M12", myparams["M12"]);
160  parentparams.setValue("A0", myparams["A0"]);
161  parentparams.setValue("tanb", 0.5*(xrot+yrot));
162  parentparams.setValue("sgnmu", 0.5*(xrot-yrot));
163  }
164 #undef PARENT
165 #undef MODEL
166 
167 
168 // Make a second branch of the model tree, and connect it to the first branch using the INTERPRET_AS_X macro.
169 
170 #define MODEL demo_B_ancestor
171  START_MODEL
172  DEFINEPARS(X, Y, Z)
173 #undef MODEL
174 
175 #define MODEL demo_B
176 #define PARENT demo_B_ancestor
177  START_MODEL
178  DEFINEPARS(X, Y, Z)
179  INTERPRET_AS_PARENT_FUNCTION(to_parent)
180  INTERPRET_AS_X_FUNCTION(kevin_bacon,to_kevin_bacon)
181 
182  void MODEL_NAMESPACE::to_parent(const ModelParameters &myparams, ModelParameters &parentparams)
183  {
184  // Get the Pipes for the interpret-as-parent function
185  USE_MODEL_PIPE(PARENT)
186  logger()<<"Running interpret_as_parent calculations for demo_B -> demo_B_ancestor ..."<<EOM;
187  parentparams.setValue("X",myparams["X"]);
188  parentparams.setValue("Y",2.0*myparams["Y"]);
189  parentparams.setValue("Z",myparams["Z"]);
190  }
191 
192  void MODEL_NAMESPACE::to_kevin_bacon(const ModelParameters &myparams, ModelParameters &kevin_bacon_params)
193  {
194  // Get the Pipes for the interpret-as-X function
195  USE_MODEL_PIPE(kevin_bacon)
196  logger()<<"Running interpret_as_X calculations for demo_B -> kevin_bacon ..."<<EOM;
197  kevin_bacon_params.setValue("M1",myparams["X"]);
198  kevin_bacon_params.setValue("M2",myparams["Y"]);
199  kevin_bacon_params.setValue("M3",myparams["Z"]);
200  kevin_bacon_params.setValue("AU1",1.0);
201  kevin_bacon_params.setValue("AU2",2.0);
202  kevin_bacon_params.setValue("AU3",3.0);
203  }
204 #undef PARENT
205 #undef MODEL
206 
207 
208 #define MODEL demo_B_subspace
209 #define PARENT demo_B
210  START_MODEL
211  DEFINEPARS(Y,Z)
212  INTERPRET_AS_PARENT_FUNCTION(to_parent)
213 
214  void MODEL_NAMESPACE::to_parent(const ModelParameters &myparams, ModelParameters &parentparams)
215  {
216  // Get the Pipes for the interpret-as-parent function
217  USE_MODEL_PIPE(PARENT)
218  logger()<<"Running interpret_as_parent calculations for demo_B_subspace -> demo_B ..."<<EOM;
219  parentparams.setValue("X",1.0);
220  parentparams.setValue("Y",myparams["Y"]);
221  parentparams.setValue("Z",myparams["Z"]);
222  }
223 #undef PARENT
224 #undef MODEL
225 
226 */
227 
228 // Model demonstration the use of "ordinary" module functions directly in a model namespace
229 // (rather than putting them in some other module)
230 // Basically the generalisation of MAP_TO_CAPABILITY, just using the normal module function
231 // macros
232 //
233 #define MODEL demo_CAP
236 
237  #define CAPABILITY a_cap
239 
240  #define FUNCTION get_a_cap
241  START_FUNCTION(unsigned int)
242  ALLOW_MODELS(demo_CAP)
243  DEPENDENCY(xsection, double) // From ExampleBit_A
244  // Other module-function macros not tested in model context
245  // Please submit a bug report if they don't work for you!
246  #undef FUNCTION
247 
248  #undef CAPABILITY
249 
250  // The "module function" definition
251  void MODEL_NAMESPACE::get_a_cap(unsigned int& result)
252  {
253  using namespace Pipes::get_a_cap;
254 
255  double xsec = *Dep::xsection; // Just for demonstration purposes
256 
257  logger()<<"Running 'get_a_cap' function in model-module 'demo_CAP'"<<EOM;
258 
259  result = *Param.at("a") * xsec;
260  }
261 #undef MODEL
262 
263 #endif /* defined(__demo_hpp__) */
#define START_MODEL
START_MODEL b
Definition: demo.hpp:235
START_MODEL DEFINEPARS(mu, sigma) START_MODEL DEFINEPARS(x) START_MODEL DEFINEPARS(a
const double sigma
Definition: SM_Z.hpp:43
const double mu
Definition: SM_Z.hpp:42
#define ALLOW_MODELS(...)
const Logging::endofmessage EOM
Explicit const instance of the end of message struct in Gambit namespace.
Definition: logger.hpp:99
Logging::LogMaster & logger()
Function to retrieve a reference to the Gambit global log object.
Definition: logger.cpp:95
#define DEPENDENCY(DEP, TYPE)
Indicate that the current FUNCTION depends on the presence of another module function that can supply...
START_FUNCTION(unsigned int) ALLOW_MODELS(demo_CAP) DEPENDENCY(xsection
#define START_CAPABILITY
Registers the current CAPABILITY of the current MODULE.