~mwinter4/maus/ckov-reco

« back to all changes in this revision

Viewing changes to tests/cpp_unit/Optics/PhaseSpaceVectorTest.cc

  • Committer: Durga Rajaram
  • Date: 2014-01-14 07:07:02 UTC
  • mfrom: (659.1.80 relcand)
  • Revision ID: durga@fnal.gov-20140114070702-2l1fuj1w6rraw7xe
Tags: MAUS-v0.7.6
MAUS-v0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "gtest/gtest.h"
26
26
 
27
 
#include "Interface/Squeal.hh"
 
27
#include "Utils/Exception.hh"
28
28
#include "src/common_cpp/Optics/PhaseSpaceVector.hh"
29
29
#include "Maths/Vector.hh"
30
30
 
47
47
 
48
48
 protected:
49
49
  static const double kData[10];
 
50
  static const double kDoubleData[6];
50
51
};
51
52
 
52
53
// *************************************************
55
56
 
56
57
const double PhaseSpaceVectorTest::kData[10]
57
58
  = {3.1, 4.1, 5.9, 2.6, 5.3, 5.8, 9.7, 9.3, 2.3, 8.4};  // 10 elem.
 
59
const double PhaseSpaceVectorTest::kDoubleData[6]
 
60
  = {6.2, 8.2, 11.8, 5.2, 10.6, 11.6};
58
61
 
59
62
 
60
63
// ***********
82
85
  try {
83
86
    const PhaseSpaceVector bad_ps_vector(bad_vector);
84
87
    testpass = false;
85
 
  } catch (Squeal squeal) {}
 
88
  } catch (MAUS::Exception exc) {}
86
89
  ASSERT_TRUE(testpass);
87
90
}
88
91
 
113
116
  }
114
117
}
115
118
 
 
119
TEST_F(PhaseSpaceVectorTest, VectorAsignmentOperators) {
 
120
  const PhaseSpaceVector ps_vector(kData);
 
121
  PhaseSpaceVector test_vector;
 
122
  test_vector = ps_vector;
 
123
  for (size_t index = 0; index < 6; ++index) {
 
124
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
125
  }
 
126
 
 
127
  const double multiplier[6] = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
 
128
  const PhaseSpaceVector multiplier_vector(multiplier);
 
129
 
 
130
  test_vector += ps_vector;
 
131
  for (size_t index = 0; index < 6; ++index) {
 
132
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
133
  }
 
134
 
 
135
  test_vector -= ps_vector;
 
136
  for (size_t index = 0; index < 6; ++index) {
 
137
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
138
  }
 
139
 
 
140
  test_vector *= multiplier_vector;
 
141
  for (size_t index = 0; index < 6; ++index) {
 
142
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
143
  }
 
144
 
 
145
  test_vector /= multiplier_vector;
 
146
  for (size_t index = 0; index < 6; ++index) {
 
147
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
148
  }
 
149
}
 
150
 
 
151
TEST_F(PhaseSpaceVectorTest, ScalarAssignmentOperators) {
 
152
  const PhaseSpaceVector ps_vector(kData);
 
153
 
 
154
  const double summand = 1.0;
 
155
  const double summand_array[6] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
 
156
  const PhaseSpaceVector summand_vector(summand_array);
 
157
  PhaseSpaceVector compare_vector(kData);
 
158
  compare_vector += summand_vector;
 
159
  PhaseSpaceVector test_vector(kData);
 
160
  test_vector += summand;
 
161
  for (size_t index = 0; index < 6; ++index) {
 
162
    EXPECT_NEAR(test_vector[index], compare_vector[index], 1.e-6);
 
163
  }
 
164
 
 
165
  test_vector -= summand;
 
166
  for (size_t index = 0; index < 6; ++index) {
 
167
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
168
  }
 
169
 
 
170
  const double multiplier = 2.0;
 
171
  test_vector *= multiplier;
 
172
  for (size_t index = 0; index < 6; ++index) {
 
173
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
174
  }
 
175
 
 
176
  test_vector /= multiplier;
 
177
  for (size_t index = 0; index < 6; ++index) {
 
178
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
179
  }
 
180
}
 
181
 
 
182
TEST_F(PhaseSpaceVectorTest, VectorAlgebraicOperators) {
 
183
  const PhaseSpaceVector ps_vector(kData);
 
184
  PhaseSpaceVector test_vector;
 
185
 
 
186
  const PhaseSpaceVector summand_vector(kData);
 
187
  test_vector = ps_vector + summand_vector;
 
188
  for (size_t index = 0; index < 6; ++index) {
 
189
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
190
  }
 
191
 
 
192
  const PhaseSpaceVector zero_vector;
 
193
  test_vector = ps_vector - summand_vector;
 
194
  for (size_t index = 0; index < 6; ++index) {
 
195
    EXPECT_NEAR(test_vector[index], 0.0, 1.e-6);
 
196
  }
 
197
 
 
198
  const double multiplier[6] = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
 
199
  const PhaseSpaceVector multiplier_vector(multiplier);
 
200
  test_vector = ps_vector * multiplier_vector;
 
201
  for (size_t index = 0; index < 6; ++index) {
 
202
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
203
  }
 
204
 
 
205
  const PhaseSpaceVector one_vector;
 
206
  test_vector = test_vector / multiplier_vector;
 
207
  for (size_t index = 0; index < 6; ++index) {
 
208
    EXPECT_NEAR(test_vector[index], kData[index], 1.e-6);
 
209
  }
 
210
}
 
211
 
 
212
TEST_F(PhaseSpaceVectorTest, ScalarAlgebraicOperators) {
 
213
  const PhaseSpaceVector ps_vector(kData);
 
214
 
 
215
  const double summand = 1.0;
 
216
  const double summand_array[6] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
 
217
  const PhaseSpaceVector summand_vector(summand_array);
 
218
  PhaseSpaceVector compare_vector(kData);
 
219
  compare_vector += summand_vector;
 
220
  PhaseSpaceVector test_vector;
 
221
 
 
222
  test_vector = ps_vector + summand;
 
223
  for (size_t index = 0; index < 6; ++index) {
 
224
    EXPECT_NEAR(test_vector[index], compare_vector[index], 1.e-6);
 
225
  }
 
226
 
 
227
  compare_vector = PhaseSpaceVector(kData);
 
228
  compare_vector -= summand_vector;
 
229
  test_vector = ps_vector - summand;
 
230
  for (size_t index = 0; index < 6; ++index) {
 
231
    EXPECT_NEAR(test_vector[index], compare_vector[index], 1.e-6);
 
232
  }
 
233
 
 
234
  const double multiplier = 2.0;
 
235
  test_vector = ps_vector * multiplier;
 
236
  for (size_t index = 0; index < 6; ++index) {
 
237
    EXPECT_NEAR(test_vector[index], kDoubleData[index], 1.e-6);
 
238
  }
 
239
 
 
240
  test_vector = ps_vector / multiplier;
 
241
  compare_vector = PhaseSpaceVector(kData);
 
242
  compare_vector /= multiplier;
 
243
  for (size_t index = 0; index < 6; ++index) {
 
244
    EXPECT_NEAR(test_vector[index], compare_vector[index], 1.e-6);
 
245
  }
 
246
}
 
247
 
116
248
TEST_F(PhaseSpaceVectorTest, Accessors) {
117
249
  const PhaseSpaceVector ps_vector(kData);
118
250
  EXPECT_EQ(ps_vector.time(), kData[0]);