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