-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path00_verysimple.cc
More file actions
55 lines (39 loc) · 1.83 KB
/
Copy path00_verysimple.cc
File metadata and controls
55 lines (39 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <APLCON.hpp>
using namespace std;
int main() {
// this example shows how to do standard Gaussian error propagation
// with two measured variables A and B
// APLCON will calculate their sum C=A+B and the propagated error
APLCON a("Error propagation");
a.AddMeasuredVariable("A", 10, 0.3);
a.AddMeasuredVariable("B", 20, 0.4);
a.AddUnmeasuredVariable("C"); // default value 0, unmeasured means sigma=0
// setup a lambda function which returns 0
// if C=A+B aka C - A - B = 0 holds
auto equality_constraint = [] (double a, double b, double c) { return c - a - b; };
a.AddConstraint("A+B=C", {"A", "B", "C"}, equality_constraint);
// do the fit, obtain ra structure
const APLCON::Result_t& ra = a.DoFit();
cout << ra << endl;
// this shows what can access in the result structure "ra"
// note that the correlations must be calculated on demand
cout << "C's value (should be 30 due to constraint): "
<< ra.Variables.at("C").Value.After << endl;
cout << "C's sigma (should be 0.5 due to error propagation): "
<< ra.Variables.at("C").Sigma.After << endl;
const auto& correlations = APLCON::CalculateCorrelations(ra.Variables);
cout << "Correlation between C and B: ";
cout << 100*correlations.at("C").After.at("B") << " %" << endl << endl;
// let's try the same with Poissonian variables
APLCON b("Poissonian error propagation");
APLCON::Variable_Settings_t settings = APLCON::Variable_Settings_t::Default;
settings.Distribution = APLCON::Distribution_t::Poissonian;
b.AddMeasuredVariable("A", 10, 1, settings);
b.AddMeasuredVariable("B", 20, 2, settings);
b.AddUnmeasuredVariable("C");
b.AddConstraint("A+B=C", {"A", "B", "C"}, equality_constraint);
const APLCON::Result_t& rb = b.DoFit();
cout << rb << endl;
return 0;
}