340.1.11
by Chris Rogers
Add extra tests |
1 |
// Copyright 2011 Chris Rogers
|
2 |
//
|
|
3 |
// This file is a part of G4MICE
|
|
4 |
//
|
|
5 |
// G4MICE is free software: you can redistribute it and/or modify
|
|
6 |
// it under the terms of the GNU General Public License as published by
|
|
7 |
// the Free Software Foundation, either version 3 of the License, or
|
|
8 |
// (at your option) any later version.
|
|
9 |
//
|
|
10 |
// G4MICE is distributed in the hope that it will be useful,
|
|
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
// GNU General Public License for more details.
|
|
14 |
//
|
|
15 |
// You should have received a copy of the GNU General Public License
|
|
16 |
// along with G4MICE in the doc folder. If not, see
|
|
17 |
// <http://www.gnu.org/licenses/>.
|
|
18 |
||
19 |
#include "gtest/gtest.h" |
|
20 |
||
600.1.150
by Peter Lane
Mass substitution of Squeal->Exception, squeal->exception, squee->exception. |
21 |
#include "Utils/Exception.hh" |
340.1.11
by Chris Rogers
Add extra tests |
22 |
#include "Interface/dataCards.hh" |
23 |
||
24 |
#include "Config/MiceModule.hh" |
|
25 |
||
663.9.24
by Chris Rogers
Move BTFastSolenoid out of legacy (and rename DerivativesSolenoid |
26 |
#include "src/common_cpp/FieldTools/DerivativesSolenoid.hh" |
663.5.8
by Chris Rogers
Just committing recent changes (atm getting segv but havent committed in a while) |
27 |
#include "src/common_cpp/FieldTools/SectorMagneticFieldMap.hh" |
28 |
#include "src/common_cpp/FieldTools/SectorField.hh" |
|
29 |
||
340.1.11
by Chris Rogers
Add extra tests |
30 |
#include "BeamTools/BTCombinedFunction.hh" |
31 |
#include "BeamTools/BTMultipole.hh" |
|
32 |
#include "BeamTools/BTFieldConstructor.hh" |
|
33 |
||
34 |
namespace { |
|
35 |
class BTFieldConstructorTest : public ::testing::Test { |
|
36 |
protected: |
|
37 |
BTFieldConstructorTest() { |
|
38 |
_field = new BTFieldConstructor(); |
|
39 |
for (size_t i=0; i<20; ++i) _mod.push_back(new MiceModule()); |
|
40 |
}
|
|
41 |
virtual ~BTFieldConstructorTest() { |
|
42 |
for (size_t i=0; i<20; ++i) delete _mod[i]; |
|
43 |
delete _field; |
|
44 |
}
|
|
45 |
virtual void SetUp() {} |
|
46 |
virtual void TearDown() {} |
|
47 |
||
48 |
BTFieldConstructor* _field; |
|
49 |
std::vector<MiceModule*> _mod; |
|
50 |
};
|
|
51 |
||
52 |
TEST_F(BTFieldConstructorTest, EndFieldTest) { |
|
53 |
BTMultipole::EndFieldModel * ef1 = _field->GetEndFieldModel(_mod[0], 1); |
|
54 |
EXPECT_EQ(ef1, static_cast<BTMultipole::EndFieldModel*>(NULL)); |
|
55 |
_mod[0]->addPropertyString("EndFieldType", "HardEdged"); |
|
56 |
ef1 = _field->GetEndFieldModel(_mod[0], 1); |
|
57 |
EXPECT_EQ(ef1, static_cast<BTMultipole::EndFieldModel*>(NULL)); |
|
58 |
_mod[1]->addPropertyString("EndFieldType", "Tanh"); |
|
59 |
_mod[1]->addPropertyDouble("EndLength", 1.); |
|
60 |
_mod[1]->addPropertyDouble("CentreLength", 5.); |
|
61 |
_mod[1]->addPropertyInt("MaxEndPole", 3); |
|
62 |
ef1 = _field->GetEndFieldModel(_mod[1], 1); |
|
63 |
BTMultipole::TanhEndField tanh(5., 1., 2); |
|
64 |
for (double x = 0; x < 10; ++x) |
|
65 |
EXPECT_DOUBLE_EQ(tanh.Function(x,0), ef1->Function(x,0)); |
|
66 |
delete ef1; |
|
67 |
||
68 |
double enge_a[2] = {1., 0.5}; |
|
69 |
_mod[2]->addPropertyString("EndFieldType", "Enge"); |
|
70 |
_mod[2]->addPropertyDouble("EndLength", 1.); |
|
71 |
_mod[2]->addPropertyDouble("CentreLength", 5.); |
|
72 |
_mod[2]->addPropertyInt("MaxEndPole", 3); |
|
73 |
_mod[2]->addPropertyDouble("Enge1", enge_a[0]); |
|
74 |
_mod[2]->addPropertyDouble("Enge2", enge_a[1]); |
|
75 |
ef1 = _field->GetEndFieldModel(_mod[2], 1); |
|
76 |
BTMultipole::EngeEndField enge |
|
77 |
(std::vector<double>(enge_a, enge_a+2), 5., 1., 2); |
|
78 |
for (double x = 0; x < 10; ++x) |
|
79 |
EXPECT_DOUBLE_EQ(enge.Function(x,0), ef1->Function(x,0)); |
|
80 |
delete ef1; |
|
81 |
||
82 |
//This is a UI so check for invalid input
|
|
83 |
_mod[0]->setProperty<std::string>("EndFieldType","SomeNonsense"); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
84 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[0], 1), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
85 |
_mod[0]->setProperty<std::string>("EndFieldType","Tanh"); |
86 |
||
87 |
// tanh //
|
|
88 |
_mod[1]->setProperty<double>("EndLength", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
89 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[1], 1), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
90 |
_mod[1]->setProperty<double>("EndLength", 1); |
91 |
||
92 |
_mod[1]->setProperty<double>("CentreLength", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
93 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[1], 1), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
94 |
_mod[1]->setProperty<double>("CentreLength", 5); |
95 |
||
96 |
_mod[1]->setProperty<int>("MaxEndPole", 1); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
97 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[1], 2), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
98 |
_mod[1]->setProperty<int>("MaxEndPole", 3); |
99 |
||
100 |
// enge //
|
|
101 |
_mod[2]->setProperty<double>("EndLength", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
102 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[2], 1), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
103 |
_mod[2]->setProperty<double>("EndLength", 1); |
104 |
||
105 |
_mod[2]->setProperty<double>("CentreLength", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
106 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[2], 1), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
107 |
_mod[2]->setProperty<double>("CentreLength", 5); |
108 |
||
109 |
_mod[2]->setProperty<int>("MaxEndPole", 1); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
110 |
EXPECT_THROW(delete _field->GetEndFieldModel(_mod[2], 2), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
111 |
_mod[2]->setProperty<int>("MaxEndPole", 3); |
112 |
}
|
|
113 |
||
114 |
TEST_F(BTFieldConstructorTest, GetMultipoleTest) { |
|
115 |
_mod[0]->addPropertyString("EndFieldType", "Tanh"); |
|
116 |
_mod[0]->addPropertyDouble("EndLength", 1.); |
|
117 |
_mod[0]->addPropertyDouble("CentreLength", 5.); |
|
118 |
_mod[0]->addPropertyInt("MaxEndPole", 3); |
|
119 |
BTMultipole::EndFieldModel * ef1 = _field->GetEndFieldModel(_mod[0], 1); |
|
120 |
_mod[0]->addPropertyString("FieldType", "Multipole"); |
|
121 |
_mod[0]->addPropertyInt("Pole", 1); |
|
122 |
_mod[0]->addPropertyDouble("Height", 2); |
|
123 |
_mod[0]->addPropertyDouble("Width", 3); |
|
124 |
_mod[0]->addPropertyDouble("Length", 4); |
|
125 |
_mod[0]->addPropertyDouble("FieldStrength", 5); |
|
126 |
BTMultipole* mult1 = new BTMultipole(); |
|
127 |
mult1->Init(1, 5, 4, 2, 3, "", 0., ef1, 2); |
|
128 |
BTMultipole* mult2 = static_cast<BTMultipole*>(_field->GetMultipole(_mod[0])); |
|
129 |
for (double x = 0; x < 4; ++x) |
|
130 |
for (double z = 0; z < 5; ++z) { |
|
131 |
double pos[4] = {x, 0, z, 0}; |
|
132 |
double field1[6] = {0, 0, 0, 0, 0, 0}; |
|
133 |
double field2[6] = {0, 0, 0, 0, 0, 0}; |
|
134 |
mult1->GetFieldValue(pos, field1); |
|
135 |
mult2->GetFieldValue(pos, field2); |
|
136 |
for (size_t i = 0; i < 3; ++i) { |
|
137 |
EXPECT_DOUBLE_EQ(field1[i], field2[i]); |
|
138 |
}
|
|
139 |
}
|
|
140 |
delete mult2; |
|
141 |
delete mult1; |
|
142 |
delete ef1; |
|
143 |
||
144 |
//This is a UI so check for invalid input
|
|
145 |
_mod[0]->setProperty<int>("Pole", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
146 |
EXPECT_THROW(delete _field->GetMultipole(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
147 |
_mod[0]->setProperty<int>("Pole", 1); |
148 |
||
149 |
_mod[0]->setProperty<double>("Height", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
150 |
EXPECT_THROW(delete _field->GetMultipole(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
151 |
_mod[0]->setProperty<double>("Height", 2); |
152 |
||
153 |
_mod[0]->setProperty<double>("Width", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
154 |
EXPECT_THROW(delete _field->GetMultipole(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
155 |
_mod[0]->setProperty<double>("Width", 3); |
156 |
||
157 |
_mod[0]->setProperty<double>("Length", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
158 |
EXPECT_THROW(delete _field->GetMultipole(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
159 |
_mod[0]->setProperty<double>("Length", 4); |
160 |
}
|
|
161 |
||
162 |
TEST_F(BTFieldConstructorTest, GetCombinedFunctionTest) { |
|
163 |
_mod[0]->addPropertyString("EndFieldType", "Tanh"); |
|
164 |
_mod[0]->addPropertyDouble("EndLength", 1.); |
|
165 |
_mod[0]->addPropertyDouble("CentreLength", 5.); |
|
166 |
_mod[0]->addPropertyInt("MaxEndPole", 3); |
|
167 |
BTMultipole::EndFieldModel * ef1 = _field->GetEndFieldModel(_mod[0], 1); |
|
168 |
_mod[0]->addPropertyString("FieldType", "CombinedFunction"); |
|
169 |
_mod[0]->addPropertyInt("Pole", 1); |
|
170 |
_mod[0]->addPropertyDouble("FieldIndex", 1.3); |
|
171 |
_mod[0]->addPropertyDouble("BendingField", 2.3); |
|
172 |
_mod[0]->addPropertyDouble("Height", 2); |
|
173 |
_mod[0]->addPropertyDouble("Width", 3); |
|
174 |
_mod[0]->addPropertyDouble("Length", 4); |
|
175 |
BTCombinedFunction* cf1 = |
|
176 |
new BTCombinedFunction(1, 2.3, 1.3, 4, 2, 3, "", 0., ef1, 2); |
|
177 |
BTCombinedFunction* cf2 = |
|
178 |
static_cast<BTCombinedFunction*>(_field->GetCombinedFunction(_mod[0])); |
|
179 |
for (double x = 0; x < 4; ++x) |
|
180 |
for (double z = 0; z < 5; ++z) { |
|
181 |
double pos[4] = {x, 0, z, 0}; |
|
182 |
double field1[6] = {0, 0, 0, 0, 0, 0}; |
|
183 |
double field2[6] = {0, 0, 0, 0, 0, 0}; |
|
184 |
cf1->GetFieldValue(pos, field1); |
|
185 |
cf2->GetFieldValue(pos, field2); |
|
186 |
for (size_t i = 0; i < 3; ++i) { |
|
187 |
EXPECT_DOUBLE_EQ(field1[i], field2[i]); |
|
188 |
}
|
|
189 |
}
|
|
190 |
delete cf2; |
|
191 |
delete cf1; |
|
192 |
delete ef1; |
|
193 |
||
194 |
//This is a UI so check for invalid input
|
|
195 |
_mod[0]->setProperty<int>("Pole", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
196 |
EXPECT_THROW(delete _field->GetCombinedFunction(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
197 |
_mod[0]->setProperty<int>("Pole", 1); |
198 |
||
199 |
_mod[0]->setProperty<double>("FieldIndex", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
200 |
EXPECT_THROW(delete _field->GetCombinedFunction(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
201 |
_mod[0]->setProperty<double>("FieldIndex", 2); |
202 |
||
203 |
_mod[0]->setProperty<double>("Height", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
204 |
EXPECT_THROW(delete _field->GetCombinedFunction(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
205 |
_mod[0]->setProperty<double>("Height", 3); |
206 |
||
207 |
_mod[0]->setProperty<double>("Width", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
208 |
EXPECT_THROW(delete _field->GetCombinedFunction(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
209 |
_mod[0]->setProperty<double>("Width", 3); |
210 |
||
211 |
_mod[0]->setProperty<double>("Length", 0); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
212 |
EXPECT_THROW(delete _field->GetCombinedFunction(_mod[0]), MAUS::Exception); |
340.1.11
by Chris Rogers
Add extra tests |
213 |
_mod[0]->setProperty<double>("Length", 4); |
663.5.8
by Chris Rogers
Just committing recent changes (atm getting segv but havent committed in a while) |
214 |
}
|
215 |
||
216 |
TEST_F(BTFieldConstructorTest, GetSectorMagneticFieldMapTest) { |
|
217 |
_mod[0]->addPropertyString("FieldType", "SectorMagneticFieldMap"); |
|
218 |
_mod[0]->addPropertyString("FileName", |
|
219 |
"${MAUS_ROOT_DIR}/tests/cpp_unit/FieldTools/test_sector_map.table"); |
|
220 |
_mod[0]->addPropertyString("FileType", "tosca_sector_1"); |
|
221 |
MAUS::SectorMagneticFieldMap* map = static_cast<MAUS::SectorMagneticFieldMap*> |
|
222 |
(_field->GetField(_mod[0])); |
|
223 |
Interpolator3dGridTo3d* null_interpolator = NULL; |
|
224 |
EXPECT_NE(map->GetInterpolator(), null_interpolator); |
|
225 |
EXPECT_EQ(map->GetSymmetry(), "None"); |
|
226 |
double point[4] = {210.+1e-9, 1.-1.e-9, 22.5/180.*M_PI-1.e-9, 0.}; |
|
227 |
double field_in[6] = {0., 0., 0., 0., 0., 0.}; |
|
228 |
double field_ex[3] = {-0.10002656988, -5.3512047987, -0.42126847878E-01}; |
|
229 |
MAUS::SectorField::ConvertToCartesian(point); |
|
230 |
map->GetFieldValue(point, field_in); |
|
231 |
for (int k = 0; k < 3; ++k) { |
|
232 |
EXPECT_NEAR(field_in[k], field_ex[k], 1e-6) |
|
233 |
<< "axis " << k << ": " << point[0] << " " << point[1] << " " << point[2]; |
|
234 |
}
|
|
235 |
delete map; |
|
236 |
||
237 |
_mod[0]->addPropertyString("Symmetry", "Dipole"); |
|
238 |
_mod[0]->addPropertyDouble("Unit1", 10.); |
|
239 |
_mod[0]->addPropertyDouble("Unit2", 10.); |
|
240 |
_mod[0]->addPropertyDouble("Unit3", 10.); |
|
241 |
_mod[0]->addPropertyDouble("Unit4", 1.e-4); |
|
242 |
_mod[0]->addPropertyDouble("Unit5", 1.e-4); |
|
243 |
_mod[0]->addPropertyDouble("Unit6", 1.e-4); |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
244 |
EXPECT_THROW(_field->GetField(_mod[0]), MAUS::Exception); |
663.5.10
by Chris Rogers
cpp unit tests pass |
245 |
MAUS::SectorMagneticFieldMap::ClearFieldCache(); |
663.5.8
by Chris Rogers
Just committing recent changes (atm getting segv but havent committed in a while) |
246 |
map = static_cast<MAUS::SectorMagneticFieldMap*>(_field->GetField(_mod[0])); |
247 |
for (int i = 0; i < 3; ++i) { |
|
248 |
point[i] *= 10.; |
|
249 |
}
|
|
250 |
point[1] *= -1.; |
|
251 |
map->GetFieldValue(point, field_in); |
|
252 |
double field_ex_2[3] = {0.10002656988, -5.3512047987, 0.42126847878E-01}; |
|
253 |
for (int k = 0; k < 3; ++k) { |
|
254 |
EXPECT_NEAR(field_in[k], field_ex_2[k]*1e-4, 1e-9) |
|
255 |
<< "axis " << k << ": " << point[0] << " " << point[1] << " " << point[2]; |
|
256 |
}
|
|
663.5.10
by Chris Rogers
cpp unit tests pass |
257 |
MAUS::SectorMagneticFieldMap::ClearFieldCache(); |
340.1.11
by Chris Rogers
Add extra tests |
258 |
}
|
663.9.24
by Chris Rogers
Move BTFastSolenoid out of legacy (and rename DerivativesSolenoid |
259 |
|
260 |
TEST_F(BTFieldConstructorTest, GetDerivativesSolenoidTest) { |
|
261 |
_mod[0]->addPropertyString("FieldType", "DerivativesSolenoid"); |
|
262 |
_mod[0]->addPropertyString("EndFieldType", "Tanh"); |
|
263 |
_mod[0]->addPropertyDouble("EndLength", 1.); |
|
264 |
_mod[0]->addPropertyDouble("CentreLength", 5.); |
|
265 |
_mod[0]->addPropertyInt("MaxEndPole", 3); |
|
266 |
_mod[0]->addPropertyDouble("PeakField", 2.); |
|
267 |
_mod[0]->addPropertyDouble("ZMax", 5.); |
|
268 |
_mod[0]->addPropertyDouble("RMax", 4.); |
|
269 |
||
270 |
MAUS::DerivativesSolenoid* map = static_cast<MAUS::DerivativesSolenoid*> |
|
271 |
(_field->GetField(_mod[0])); |
|
272 |
EXPECT_EQ(map->GetPeakField(), 2.); |
|
273 |
EXPECT_EQ(map->GetRMax(), 4.); |
|
274 |
EXPECT_EQ(map->GetZMax(), 5.); |
|
275 |
EXPECT_EQ(map->GetHighestOrder(), 3); |
|
276 |
EXPECT_NEAR(map->GetEndFieldModel()->Function(5.0, 0), 0.5, 1e-6); |
|
277 |
}
|
|
340.1.11
by Chris Rogers
Add extra tests |
278 |
}
|
279 |