56
52
class LinearApproximationOpticsModelTest : public testing::Test {
58
54
LinearApproximationOpticsModelTest()
59
: default_virtual_planes_(new MAUS::VirtualPlaneManager(*
60
MAUS::MAUSGeant4Manager::GetInstance()->GetVirtualPlanes())) {
55
: default_virtual_planes_(new MAUS::VirtualPlaneManager(
56
*MAUS::MAUSGeant4Manager::GetInstance()->GetVirtualPlanes())),
57
virtual_planes_(new MAUS::VirtualPlaneManager()) {
61
58
MAUS::MAUSGeant4Manager * simulation
62
59
= MAUS::MAUSGeant4Manager::GetInstance();
64
char path1[MAXPATHLEN]; // This is a buffer for the text
65
getcwd(path1, MAXPATHLEN);
66
std::cout << "CWD: " << path1 << std::endl;
69
const std::string maus_root_dir(getenv("MAUS_ROOT_DIR"));
70
const std::string geometry_filename = maus_root_dir + "/"
74
61
Json::Value * config = MAUS::Globals::GetConfigurationCards();
75
63
(*config)["verbose_level"] = Json::Value(2);
77
64
(*config)["reference_physics_processes"] = Json::Value("none");
78
65
(*config)["physics_processes"] = Json::Value("none");
79
66
(*config)["particle_decay"] = Json::Value(false);
80
67
simulation->GetPhysicsList()->Setup();
82
(*config)["simulation_reference_particle"] = JsonWrapper::StringToJson(
83
std::string("{\"position\":{\"x\":0.0,\"y\":0.0,\"z\":-1000.0},")+
84
std::string("\"momentum\":{\"x\":0.0,\"y\":0.0,\"z\":200.0},")+
85
std::string("\"particle_id\":-13,\"energy\":226.1939223,\"time\":0.0,")+
86
std::string("\"random_seed\":2}")
69
std::stringstream reference_particle_string;
70
reference_particle_string
71
<< std::setprecision(1)
72
<< "{\"position\":{\"x\":0.0,\"y\":0.0,\"z\":" << kPrimaryPlane << "},"
73
<< "\"momentum\":{\"x\":0.0,\"y\":0.0,\"z\":200.0},"
74
<< "\"particle_id\":-13,\"energy\":226.1939223,\"time\":0.0,"
75
<< "\"random_seed\":2}";
76
(*config)["simulation_reference_particle"]
77
= JsonWrapper::StringToJson(reference_particle_string.str());
89
79
Json::Value ellipse(Json::objectValue);
90
80
ellipse["Emittance_T"] = Json::Value(10.0);
109
99
MAUS::GlobalsManager::DeleteGlobals();
110
100
MAUS::GlobalsManager::InitialiseGlobals(config_string);
112
std::cout << "Globals:" << std::endl
113
<< (*MAUS::Globals::GetConfigurationCards()) << std::endl;
114
virtual_planes_ = new MAUS::VirtualPlaneManager();
115
102
simulation->SetVirtualPlanes(virtual_planes_);
116
103
MAUS::VirtualPlane start_plane = MAUS::VirtualPlane::BuildVirtualPlane(
117
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., -1000.), -1, true,
118
-1000., BTTracker::z, MAUS::VirtualPlane::ignore, false);
104
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., kPrimaryPlane), -1,
105
true, kPrimaryPlane, BTTracker::z, MAUS::VirtualPlane::ignore, false);
119
106
virtual_planes_->AddPlane(new MAUS::VirtualPlane(start_plane), NULL);
121
108
MAUS::VirtualPlane mid_plane = MAUS::VirtualPlane::BuildVirtualPlane(
122
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., 0.), -1, true,
123
0., BTTracker::z, MAUS::VirtualPlane::ignore, false);
109
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., kPrimaryPlane+1000.),
110
-1, true, kPrimaryPlane+1000., BTTracker::z, MAUS::VirtualPlane::ignore,
124
112
virtual_planes_->AddPlane(new MAUS::VirtualPlane(mid_plane), NULL);
126
114
MAUS::VirtualPlane end_plane = MAUS::VirtualPlane::BuildVirtualPlane(
127
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., 1000.), -1, true,
128
1000., BTTracker::z, MAUS::VirtualPlane::ignore, false);
115
CLHEP::HepRotation(), CLHEP::Hep3Vector(0., 0., kPrimaryPlane+2000.),
116
-1, true, kPrimaryPlane+2000., BTTracker::z, MAUS::VirtualPlane::ignore,
129
118
virtual_planes_->AddPlane(new MAUS::VirtualPlane(end_plane), NULL);
179
170
TEST_F(LinearApproximationOpticsModelTest, Constructor) {
180
171
const LinearApproximationOpticsModel optics_model(
181
*MAUS::Globals::GetConfigurationCards());
172
MAUS::Globals::GetConfigurationCards());
184
175
TEST_F(LinearApproximationOpticsModelTest, Accessors) {
185
176
LinearApproximationOpticsModel optics_model(
186
*MAUS::Globals::GetConfigurationCards());
187
double first_plane = optics_model.first_plane();
188
ASSERT_DOUBLE_EQ(-1000., first_plane);
177
MAUS::Globals::GetConfigurationCards());
178
double primary_plane = optics_model.primary_plane();
179
ASSERT_DOUBLE_EQ(kPrimaryPlane, primary_plane);
190
optics_model.set_first_plane(0.);
191
first_plane = optics_model.first_plane();
192
ASSERT_DOUBLE_EQ(0., first_plane);
181
optics_model.set_primary_plane(0.);
182
primary_plane = optics_model.primary_plane();
183
ASSERT_DOUBLE_EQ(0., primary_plane);
195
186
TEST_F(LinearApproximationOpticsModelTest, Transport) {
196
187
LinearApproximationOpticsModel optics_model(
197
*MAUS::Globals::GetConfigurationCards());
188
MAUS::Globals::GetConfigurationCards());
199
189
// The configuration specifies a 2m drift between -1m and +1 m.
200
190
optics_model.Build();
202
192
// Check transport to start plane
203
193
MAUS::PhaseSpaceVector input_vector(0., 226., 1., 0., 3., 0.);
204
194
MAUS::PhaseSpaceVector output_vector = optics_model.Transport(input_vector,
206
196
EXPECT_EQ(input_vector, output_vector);
208
198
MAUS::CovarianceMatrix output_errors
209
= optics_model.Transport(kCovarianceMatrix, -1000.);
199
= optics_model.Transport(kCovarianceMatrix, kPrimaryPlane);
210
200
EXPECT_EQ(kCovarianceMatrix, output_errors);
212
202
// Check transport to end plane
213
203
MAUS::PhaseSpaceVector expected_vector(7.5466, 226., 1., 0., 3., 0.);
214
output_vector = optics_model.Transport(input_vector, 1000.);
204
output_vector = optics_model.Transport(input_vector, kPrimaryPlane+2000.);
215
205
for (int index = 0; index < 6; ++index) {
216
206
EXPECT_NEAR(expected_vector[index], output_vector[index], 5.0e-4);
219
output_errors = optics_model.Transport(kCovarianceMatrix, 1000.);
209
output_errors = optics_model.Transport(kCovarianceMatrix,
210
kPrimaryPlane+2000.);
220
211
EXPECT_EQ(kCovarianceMatrix, output_errors);
222
213
// Check transport to mid plane
223
214
expected_vector = MAUS::PhaseSpaceVector(3.7733, 226., 1., 0., 3., 0.);
224
output_vector = optics_model.Transport(input_vector, 0.);
215
output_vector = optics_model.Transport(input_vector, kPrimaryPlane+1000.);
225
216
for (int index = 0; index < 6; ++index) {
226
217
EXPECT_NEAR(expected_vector[index], output_vector[index], 5.0e-4);
229
output_errors = optics_model.Transport(kCovarianceMatrix, 0.);
220
output_errors = optics_model.Transport(kCovarianceMatrix,
221
kPrimaryPlane+1000.);
230
222
EXPECT_EQ(kCovarianceMatrix, output_errors);
232
224
// Check transport between mid plane and end plane
233
output_vector = optics_model.Transport(input_vector, 0., 1000.);
225
output_vector = optics_model.Transport(input_vector,
227
kPrimaryPlane+2000.);
234
228
for (int index = 0; index < 6; ++index) {
235
229
EXPECT_NEAR(expected_vector[index], output_vector[index], 5.0e-4);
238
output_errors = optics_model.Transport(kCovarianceMatrix, 0., 1000.);
232
output_errors = optics_model.Transport(kCovarianceMatrix,
234
kPrimaryPlane+2000.);
239
235
EXPECT_EQ(kCovarianceMatrix, output_errors);
241
237
// Check failure for off mass shell particle transport
242
238
MAUS::PhaseSpaceVector off_shell_vector(0., 1., 0., 0., 0., 0.);
243
239
bool transport_failed = false;
245
optics_model.Transport(off_shell_vector, -1000.);
246
} catch (Squeal squeal) {
241
optics_model.Transport(off_shell_vector, kPrimaryPlane);
242
} catch (MAUS::Exception exc) {
247
243
transport_failed = true;
249
245
EXPECT_TRUE(transport_failed);