-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestBlue.cc
163 lines (138 loc) · 4.48 KB
/
testBlue.cc
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Unit tests for AverageTools
// S. Kluth, 9/2012
#include "Blue.hh"
// C++:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <math.h>
// ROOT includes:
#include "TMatrixD.h"
#include "TMatrixDSym.h"
// BOOST test stuff:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE bluetests
#include <boost/test/unit_test.hpp>
// Namespaces:
using std::string;
using std::vector;
using std::map;
// Blue functionality tests:
class BlueTestFixture {
public:
BlueTestFixture() : blue( "test.txt" ) {}
Blue blue;
};
BOOST_FIXTURE_TEST_SUITE( bluesuite, BlueTestFixture )
BOOST_AUTO_TEST_CASE( testgetWeightsMatrix ) {
BOOST_MESSAGE( "testgetWeightsMatrix" );
double expected[]= { 1.33903066, -0.16163493, -0.17739573 };
TMatrixD result= blue.getWeightsMatrix();
for( Int_t i = 0; i < 3; i++) {
BOOST_CHECK_CLOSE( expected[i], result(0,i), 1.0e-4 );
}
}
BOOST_AUTO_TEST_CASE( testgetAverage ) {
BOOST_MESSAGE( "testgetAverage" );
Double_t expected= 170.709197;
TVectorD result= blue.getAverage();
BOOST_CHECK_CLOSE( expected, result[0], 1.0e-4 );
}
BOOST_AUTO_TEST_CASE( testgetChisq ) {
BOOST_MESSAGE( "testgetChisq" );
double obtained= blue.getChisq();
double expected= 0.770025;
BOOST_CHECK_CLOSE( obtained, expected, 1.0e-4 );
}
BOOST_AUTO_TEST_CASE( testgetPulls ) {
BOOST_MESSAGE( "testgetPulls" );
TVectorD obtained= blue.getPulls();
Double_t expected[]= { 0.25222701, 0.5089246205, 0.70200057 };
for( int i= 0; i < 3; i++ ) {
BOOST_CHECK_CLOSE( obtained[i], expected[i], 1.0e-4 );
}
}
BOOST_AUTO_TEST_CASE( testgetErrors ) {
BOOST_MESSAGE( "testgetErrors" );
MatrixMap obtained= blue.getErrors();
map<string,Double_t> expected;
expected["00stat"]= 0.4114006127938109;
expected["01err1"]= 1.132605331048375;
expected["02err2"]= 0.62562331148619099;
expected["03err3"]= 2.5071108260136228;
expected["04err4"]= 0.82049571716089753;
expected["syst"]= 2.9381996663923697;
expected["total"]= 2.9668615983552984;
BOOST_CHECK_EQUAL( obtained.size(), expected.size() );
MatrixMap::const_iterator obtitr;
map<string,Double_t>::const_iterator expitr;
for( obtitr= obtained.begin(), expitr= expected.begin();
expitr != expected.end(); obtitr++, expitr++ ) {
BOOST_CHECK_EQUAL( obtitr->first, expitr->first );
Double_t obtainederror= sqrt( (obtitr->second)(0,0) );
Double_t expectederror= expitr->second;
BOOST_CHECK_CLOSE( obtainederror, expectederror, 1.0e-4 );
}
}
BOOST_AUTO_TEST_SUITE_END()
// Blue Printing tests:
class BluePrintTestFixture {
public:
BluePrintTestFixture() : blue( "valassi5.txt" ) {}
Blue blue;
std::ostringstream osst;
};
BOOST_FIXTURE_TEST_SUITE( blueprintsuite, BluePrintTestFixture )
BOOST_AUTO_TEST_CASE( testprintChisq ) {
BOOST_MESSAGE( "testprintChisq" );
blue.printChisq( osst );
string obtained= osst.str();
string expected= "Chi^2= 1.23 for 2 d.o.f, chi^2/d.o.f= 0.62, P(chi^2)= 0.5404\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_CASE( testprintWeights ) {
BOOST_MESSAGE( "testprintWeights" );
blue.printWeights( osst );
string obtained= osst.str();
string expected=
" Weights a: 0.8195 0.1805 0.0897 -0.0897\n"
" Weights b: 0.8076 -0.8076 0.0981 0.9019\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_CASE( testprintPulls ) {
BOOST_MESSAGE( "testprintPulls" );
blue.printPulls( osst );
string obtained= osst.str();
string expected= " Pulls: -0.1377 0.9549 -0.5453 0.9556\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_CASE( testprintAverages ) {
BOOST_MESSAGE( "testprintAverages" );
blue.printAverages( osst );
string obtained= osst.str();
string expected= " Average: 10.6377 11.1358\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_CASE( testprintErrors ) {
BOOST_MESSAGE( "testprintErrors" );
blue.printErrors( osst );
string obtained= osst.str();
string expected=
" stat: 0.8636 0.8963\n"
" exp: 0.2714 0.2820\n"
" syst: 0.2714 0.2820\n"
" total: 0.9053 0.9397\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_CASE( testprintCorrelations ) {
BOOST_MESSAGE( "testprintCorrelations" );
blue.printCorrelations( osst );
string obtained= osst.str();
string expected= "Total correlations:\n"
" a b\n"
" a 1.00 0.95\n"
" b 0.95 1.00\n";
BOOST_CHECK_EQUAL( obtained, expected );
}
BOOST_AUTO_TEST_SUITE_END()