Belle II Software  release-05-01-25
spacePointTrackCand.cc
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2014 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Thomas Madlener *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 // google test framework
12 #include <gtest/gtest.h>
13 
14 // class to be tested
15 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
16 
17 // stuff needed for setting up the tests
18 
19 using namespace std;
20 
21 namespace Belle2 {
30  class SpacePointTrackCandTest : public ::testing::Test {
31  public:
33  VXD::SensorInfoBase createSensorInfo(VxdID aVxdID, double width = 1., double length = 1., double width2 = -1.)
34  {
35  // (SensorType type, VxdID id, double width, double length, double thickness, int uCells, int vCells, double width2=-1, double splitLength=-1, int vCells2=0)
36  VXD::SensorInfoBase sensorInfoBase(VXD::SensorInfoBase::PXD, aVxdID, width, length, 0.3, 2, 4, width2);
37 
38  TGeoRotation r1;
39  r1.SetAngles(45, 20, 30); // rotation defined by Euler angles
40  TGeoTranslation t1(-10, 10, 1);
41  TGeoCombiTrans c1(t1, r1);
42  TGeoHMatrix transform = c1;
43  sensorInfoBase.setTransformation(transform);
44 
45  return sensorInfoBase;
46  }
47  protected:
48  };
49 
53  TEST_F(SpacePointTrackCandTest, testConstructorFromVector)
54  {
55  // set up some SpacePoints and group them to a vector
56  VxdID aVxdID = VxdID(1, 1, 1);
57  VXD::SensorInfoBase aSensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
58  PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
59  const SpacePoint aPXDSpacePoint = SpacePoint(&aCluster, &aSensorInfoBase);
60 
61  VxdID anotherVxdID = VxdID(3, 3, 3);
62  VXD::SensorInfoBase anotherSensorInfoBase = createSensorInfo(anotherVxdID, 2.3, 4.2);
63  SVDCluster aUCluster = SVDCluster(anotherVxdID, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
64  SVDCluster aVCluster = SVDCluster(anotherVxdID, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
65  std::vector<const SVDCluster*> a2HitCluster = { &aUCluster, &aVCluster };
66  const SpacePoint aSVDSpacePoint = SpacePoint(a2HitCluster, &anotherSensorInfoBase);
67 
68  SVDCluster anotherUCluster = SVDCluster(anotherVxdID, true, 0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
69  std::vector<const SVDCluster*> a1HitCluster = { &anotherUCluster };
70  const SpacePoint anotherSVDSpacePoint = SpacePoint(a1HitCluster, &anotherSensorInfoBase);
71 
72  const std::vector<const Belle2::SpacePoint*> aSpacePointVec = { &aPXDSpacePoint, &aSVDSpacePoint, &anotherSVDSpacePoint };
73 
74 
75  // construct SpacePointTrackCand with (more or less arbitrary) values for pdg code, charge and MC-TrackID
76  SpacePointTrackCand aSpacePointTC = SpacePointTrackCand(aSpacePointVec, 11, -1, 23);
77 
78  // do some checks
79  // check if all SpacePoints are actually in the TrackCand
80  EXPECT_EQ(aSpacePointTC.getNHits(), aSpacePointVec.size());
81  // check pdg, charge, etc...
82  EXPECT_EQ(aSpacePointTC.getPdgCode(), 11);
83  EXPECT_DOUBLE_EQ(aSpacePointTC.getChargeSeed(), -1);
84  EXPECT_EQ(aSpacePointTC.getMcTrackID(), 23);
85 
86  // get SpacePoints and compare them with the original vector
87  const std::vector<const SpacePoint*> returnSPVector = aSpacePointTC.getHits();
88  for (unsigned int i = 0; i < aSpacePointTC.getNHits(); i++) {
89  EXPECT_TRUE(returnSPVector[i] == aSpacePointVec[i]);
90  }
91  }
92 
96  TEST_F(SpacePointTrackCandTest, testEqualityOperator)
97  {
98  // set up some set up some space points and add them to SpacePointTrackCands
99  // many parts copied from spacePoint.cc (tracking/tests/)
100 
101  VxdID aVxdID = VxdID(1, 1, 1);
102  VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
103  PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
104  const SpacePoint aPXDSpacePoint = SpacePoint(&aCluster, &sensorInfoBase);
105 
106  VxdID anotherVxdID = VxdID(3, 3, 3);
107  VXD::SensorInfoBase anotherSensorInfoBase = createSensorInfo(anotherVxdID, 2.3, 4.2);
108  SVDCluster aUCluster = SVDCluster(anotherVxdID, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
109  SVDCluster aVCluster = SVDCluster(anotherVxdID, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
110  std::vector<const SVDCluster*> a2HitCluster = { &aUCluster, &aVCluster };
111  const SpacePoint aSVDSpacePoint = SpacePoint(a2HitCluster, &anotherSensorInfoBase);
112 
113  SVDCluster anotherUCluster = SVDCluster(anotherVxdID, true, 0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
114  std::vector<const SVDCluster*> a1HitCluster = { &anotherUCluster };
115  const SpacePoint anotherSVDSpacePoint = SpacePoint(a1HitCluster, &anotherSensorInfoBase);
116 
117  const std::vector<const Belle2::SpacePoint*> aSpacePointVec = { &aPXDSpacePoint, &aSVDSpacePoint };
118  const std::vector<const Belle2::SpacePoint*> sameSpacePointVec = { &aPXDSpacePoint, &aSVDSpacePoint };
119  const std::vector<const Belle2::SpacePoint*> anotherSpacePointVec = { &aPXDSpacePoint, &anotherSVDSpacePoint };
120 
121  // set up two SpacePointTrackCands from the SpacePoint* vectors above
122  Belle2::SpacePointTrackCand aSpacePointTC = SpacePointTrackCand(aSpacePointVec, 1);
123  Belle2::SpacePointTrackCand anotherSpacePointTC = SpacePointTrackCand(sameSpacePointVec);
124 
125  // getting undefined reference here!
126  EXPECT_TRUE(aSpacePointTC == anotherSpacePointTC);
127 
128  // change pdg code and compare again (should not have any influence)
129  anotherSpacePointTC.setPdgCode(-11);
130  EXPECT_TRUE(aSpacePointTC == anotherSpacePointTC);
131 
132  // add a space point with arbitrary sorting parameter and compare again, should now give false
133  anotherSpacePointTC.addSpacePoint(&anotherSVDSpacePoint, 1.0);
134 
135  EXPECT_FALSE(aSpacePointTC == anotherSpacePointTC);
136 
137  // create another TC with different SVD SpacePoint and compare again with the previously created TCs.
138  Belle2::SpacePointTrackCand changedSVDSpacePointTC = SpacePointTrackCand(anotherSpacePointVec, 2, 3, 4);
139 
140  EXPECT_FALSE(aSpacePointTC == changedSVDSpacePointTC);
141  EXPECT_FALSE(changedSVDSpacePointTC == anotherSpacePointTC);
142 
143  // create an empty TC and add SpacePoints by hand and compare again with the other TCs
144  Belle2::SpacePointTrackCand newSpacePointTC;
145  newSpacePointTC.addSpacePoint(&aPXDSpacePoint, 1.0);
146  newSpacePointTC.addSpacePoint(&aSVDSpacePoint, 1.1);
147 
148  EXPECT_TRUE(newSpacePointTC == aSpacePointTC);
149 
150  newSpacePointTC.addSpacePoint(&anotherSVDSpacePoint, 1.2);
151 
152  EXPECT_TRUE(newSpacePointTC == anotherSpacePointTC);
153 
154  }
155 
160  {
161  SpacePointTrackCand aSpacePointTC;
162 
163  // pdg code of electron is 11
164  aSpacePointTC.setPdgCode(11);
165  EXPECT_DOUBLE_EQ(aSpacePointTC.getChargeSeed(), -1);
166  // positron
167  aSpacePointTC.setPdgCode(-11);
168  EXPECT_DOUBLE_EQ(aSpacePointTC.getChargeSeed(), 1);
169 
170  // B+ Meson
171  aSpacePointTC.setPdgCode(521);
172  EXPECT_DOUBLE_EQ(aSpacePointTC.getChargeSeed(), 1);
173  }
174 
178  TEST_F(SpacePointTrackCandTest, testGetHitsInRange)
179  {
180  SpacePointTrackCand fullTrackCand;
181 
182  // set up some SpacePoints and add them to a SpacePointTrackCand
183  VxdID aVxdID1 = VxdID(1, 1, 1);
184  VXD::SensorInfoBase sensorInfoBase1 = createSensorInfo(aVxdID1, 2.3, 4.2);
185  PXDCluster aCluster = PXDCluster(aVxdID1, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
186  const SpacePoint aPXDSpacePoint = SpacePoint(&aCluster, &sensorInfoBase1);
187  fullTrackCand.addSpacePoint(&aPXDSpacePoint, 1.23); // add a SpacePoint with an arbitrary sorting parameter
188 
189  VxdID aVxdID2 = VxdID(2, 2, 2);
190  VXD::SensorInfoBase sensorInfoBase2 = createSensorInfo(aVxdID2, 2.3, 4.2);
191  SVDCluster aUCluster = SVDCluster(aVxdID2, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
192  SVDCluster aVCluster = SVDCluster(aVxdID2, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
193  std::vector<const SVDCluster*> UVClusterVec1 = { &aUCluster, &aVCluster };
194  std::vector<const SVDCluster*> VClusterVec = { &aVCluster };
195  std::vector<const SVDCluster*> UClusterVec = { &aUCluster };
196  const SpacePoint SVDSpacePoint1 = SpacePoint(UVClusterVec1, &sensorInfoBase2);
197  const SpacePoint SVDSpacePoint2 = SpacePoint(VClusterVec, &sensorInfoBase2);
198  const SpacePoint SVDSpacePoint3 = SpacePoint(UClusterVec, &sensorInfoBase2);
199  fullTrackCand.addSpacePoint(&SVDSpacePoint1, 2.34);
200  fullTrackCand.addSpacePoint(&SVDSpacePoint2, 3.45);
201  fullTrackCand.addSpacePoint(&SVDSpacePoint3, 4.56);
202 
203  VxdID aVxdId3 = VxdID(3, 3, 3);
204  VXD::SensorInfoBase sensorInfoBase3 = createSensorInfo(aVxdId3, 2.3, 4.2);
205  SVDCluster aUCluster2 = SVDCluster(aVxdId3, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
206  SVDCluster aVCluster2 = SVDCluster(aVxdId3, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
207  std::vector<const SVDCluster*> UVClusterVec2 = { &aUCluster2, &aVCluster2 };
208  std::vector<const SVDCluster*> VClusterVec2 = { &aVCluster2 };
209  std::vector<const SVDCluster*> UClusterVec2 = { &aUCluster2 };
210  const SpacePoint SVDSpacePoint4 = SpacePoint(UVClusterVec2, &sensorInfoBase3);
211  const SpacePoint SVDSpacePoint5 = SpacePoint(VClusterVec2, &sensorInfoBase3);
212  const SpacePoint SVDSpacePoint6 = SpacePoint(UClusterVec2, &sensorInfoBase3);
213  fullTrackCand.addSpacePoint(&SVDSpacePoint4, 5.67);
214  fullTrackCand.addSpacePoint(&SVDSpacePoint5, 6.78);
215  fullTrackCand.addSpacePoint(&SVDSpacePoint6, 7.89);
216 
217  // set up some 'shorter' SpacePointTrackCands
218  SpacePointTrackCand shortTC1;
219  shortTC1.addSpacePoint(&aPXDSpacePoint, 1.23);
220  shortTC1.addSpacePoint(&SVDSpacePoint1, 2.34);
221  shortTC1.addSpacePoint(&SVDSpacePoint2, 3.45);
222 
223  SpacePointTrackCand shortTC2;
224  shortTC2.addSpacePoint(&SVDSpacePoint2, 3.45);
225  shortTC2.addSpacePoint(&SVDSpacePoint3, 4.56);
226  shortTC2.addSpacePoint(&SVDSpacePoint4, 5.67);
227  shortTC2.addSpacePoint(&SVDSpacePoint5, 6.78);
228 
229  SpacePointTrackCand subTrackCand1 = SpacePointTrackCand(fullTrackCand.getHitsInRange(0, 3));
230  EXPECT_TRUE(subTrackCand1 == shortTC1);
231  std::vector<double> sortParams1 = { 1.23, 2.34, 3.45 };
232  std::vector<double> sortParamsTC1 = fullTrackCand.getSortingParametersInRange(0, 3);
233  EXPECT_EQ(sortParams1.size(), sortParamsTC1.size());
234  for (unsigned int i = 0; i < sortParamsTC1.size(); ++i) { EXPECT_DOUBLE_EQ(sortParams1.at(i), sortParamsTC1.at(i)); }
235 
236  SpacePointTrackCand subTrackCand2 = SpacePointTrackCand(fullTrackCand.getHitsInRange(2, 6));
237  EXPECT_TRUE(subTrackCand2 == shortTC2);
238  std::vector<double> sortParams2 = { 3.45, 4.56, 5.67, 6.78 };
239  std::vector<double> sortParamsTC2 = fullTrackCand.getSortingParametersInRange(2, 6);
240  EXPECT_EQ(sortParams2.size(), sortParamsTC2.size());
241  for (unsigned int i = 0; i < sortParamsTC2.size(); ++i) { EXPECT_DOUBLE_EQ(sortParams2.at(i), sortParamsTC2.at(i)); }
242 
243  // test throwing of exceptions
244  unsigned int nHits = fullTrackCand.getNHits();
245  ASSERT_THROW(fullTrackCand.getHitsInRange(0, nHits + 1),
246  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too high final index
247  ASSERT_NO_THROW(fullTrackCand.getHitsInRange(nHits - 2, nHits));
248  ASSERT_THROW(fullTrackCand.getHitsInRange(-1, 3),
249  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to negative starting index
250  ASSERT_THROW(fullTrackCand.getHitsInRange(0, 10), SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too high final index
251  ASSERT_THROW(fullTrackCand.getHitsInRange(10, 0),
252  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too high starting index
253  ASSERT_THROW(fullTrackCand.getHitsInRange(2, -1), SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too low final index
254  ASSERT_THROW(fullTrackCand.getSortingParametersInRange(-1, 2),
255  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to negative starting index
256  ASSERT_THROW(fullTrackCand.getSortingParametersInRange(0, nHits + 1),
257  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too high final index
258  ASSERT_THROW(fullTrackCand.getSortingParametersInRange(12, 3),
259  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too high starting index
260  ASSERT_THROW(fullTrackCand.getSortingParametersInRange(2, -2),
261  SpacePointTrackCand::SPTCIndexOutOfBounds); // throw due to too low final index
262  ASSERT_NO_THROW(fullTrackCand.getSortingParametersInRange(0, nHits));
263  }
264 
268  TEST_F(SpacePointTrackCandTest, testRefereeStatus)
269  {
270  SpacePointTrackCand trackCand; // default constructor -> should initialize the referee status to c_initialState
271 
272  // currently c_isActive is the initialState:
273  EXPECT_EQ(trackCand.getRefereeStatus(), SpacePointTrackCand::c_isActive);
274  EXPECT_EQ(SpacePointTrackCand::c_initialState, SpacePointTrackCand::c_isActive);
275 
276  unsigned short int initialStatus = trackCand.getRefereeStatus();
277  EXPECT_EQ(initialStatus, SpacePointTrackCand::c_initialState);
278 
279  // design an arbitrary status and set it, then test if the returned status is the set status
280  unsigned short int newStatus = 0;
281  newStatus += SpacePointTrackCand::c_checkedByReferee;
282  newStatus += SpacePointTrackCand::c_checkedTrueHits;
283  trackCand.setRefereeStatus(newStatus);
284  EXPECT_EQ(trackCand.getRefereeStatus(), newStatus);
285 
286  // clear the status and test if its 0
287  trackCand.clearRefereeStatus();
288  EXPECT_EQ(trackCand.getRefereeStatus(), 0);
289 
290  // reset the status and test if it's the initial state
291  trackCand.resetRefereeStatus();
292  EXPECT_EQ(trackCand.getRefereeStatus(), SpacePointTrackCand::c_initialState);
293 
294 
295  trackCand.clearRefereeStatus(); // enforce empty refereeStatus
296  // add several statusses one by one and test if the overall status is as expected (once with 'overall status' and once with status one by one)
297  trackCand.addRefereeStatus(SpacePointTrackCand::c_checkedClean);
298  EXPECT_TRUE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_checkedClean));
299  trackCand.addRefereeStatus(SpacePointTrackCand::c_hitsOnSameSensor);
300  EXPECT_TRUE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_hitsOnSameSensor));
301  EXPECT_FALSE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_hitsLowDistance));
302 
303  trackCand.addRefereeStatus(SpacePointTrackCand::c_checkedByReferee);
304  unsigned short int expectedStatus = SpacePointTrackCand::c_checkedClean + SpacePointTrackCand::c_hitsOnSameSensor +
305  SpacePointTrackCand::c_checkedByReferee;
306  EXPECT_EQ(trackCand.getRefereeStatus(), expectedStatus);
307 
308 
309  // remove one status and test if it actuall gets removed
310  trackCand.removeRefereeStatus(SpacePointTrackCand::c_checkedClean);
311  expectedStatus -= SpacePointTrackCand::c_checkedClean;
312  EXPECT_EQ(trackCand.getRefereeStatus(), expectedStatus);
313  EXPECT_FALSE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_checkedClean));
314  trackCand.removeRefereeStatus(SpacePointTrackCand::c_checkedClean); // remove again and check if nothing changes
315  EXPECT_EQ(trackCand.getRefereeStatus(), expectedStatus);
316 
317  EXPECT_TRUE(trackCand.hasRefereeStatus(expectedStatus));
318 
319  // test if the status that remains is still set
320  EXPECT_TRUE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_hitsOnSameSensor));
321  EXPECT_TRUE(trackCand.hasHitsOnSameSensor()); // echeck the wrapper function
322 
323 
324  // check if adding of the same status twice works
325  trackCand.clearRefereeStatus();
326  trackCand.addRefereeStatus(SpacePointTrackCand::c_checkedSameSensors);
327  trackCand.addRefereeStatus(SpacePointTrackCand::c_checkedSameSensors);
328  EXPECT_TRUE(trackCand.hasRefereeStatus(SpacePointTrackCand::c_checkedSameSensors));
329  EXPECT_TRUE(trackCand.checkedSameSensors());
330 
331  trackCand.addRefereeStatus(SpacePointTrackCand::c_curlingTrack);
332  EXPECT_TRUE(trackCand.isCurling());
333 
334 
335  trackCand.clearRefereeStatus();
336  // test that at least n bits are present for storing stuff in the m_refereeStatus (update this test if you add a new flag to the RefereeStatusBit)
337  // WARNING: hardcoded -> make sure to keep this thing up to date!
338  int n = 13;
339  int maxUsedStatus = pow(2, n);
340  trackCand.addRefereeStatus(maxUsedStatus);
341  EXPECT_TRUE(trackCand.hasRefereeStatus(maxUsedStatus));
342 
343  int maxN = 15; // unsigned short int has 2 bytes (-> 16 bits) to store information
344  int maxPossibleStatus = pow(2, maxN); // maximum possible status to store
345  trackCand.addRefereeStatus(maxPossibleStatus);
346  EXPECT_TRUE(trackCand.hasRefereeStatus(maxPossibleStatus));
347 
348  int impossibleStatus = maxPossibleStatus * 2; // create an integer that is too big to be stored in a unsigned short integer
349  trackCand.clearRefereeStatus();
350  trackCand.setRefereeStatus(impossibleStatus); // this should lead to an overflow in SpacePointTrackCand::m_refereeStatus
351  EXPECT_NE(trackCand.getRefereeStatus(), impossibleStatus); // -> overflow leads this test to fail
352 
353  trackCand.clearRefereeStatus();
354  int wrongStatus = 7; // set a wrong status, that causes some of the checks to be true although they shouldn't
355  trackCand.addRefereeStatus(wrongStatus);
356  EXPECT_TRUE(trackCand.hasRefereeStatus(1));
357  EXPECT_TRUE(trackCand.hasRefereeStatus(2));
358  EXPECT_TRUE(trackCand.hasRefereeStatus(4));
359  wrongStatus = 15;
360  trackCand.addRefereeStatus(wrongStatus);
361  EXPECT_TRUE(trackCand.hasRefereeStatus(8));
362  }
363 
367  TEST_F(SpacePointTrackCandTest, testRemoveSpacePoints)
368  {
369  // set up SpacePointTrackCand
370  SpacePointTrackCand fullTrackCand;
371 
372  // set up some SpacePoints and add them to a SpacePointTrackCand
373  VxdID aVxdID1 = VxdID(1, 1, 1);
374  VXD::SensorInfoBase sensorInfoBase1 = createSensorInfo(aVxdID1, 2.3, 4.2);
375  PXDCluster aCluster = PXDCluster(aVxdID1, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
376  const SpacePoint aPXDSpacePoint = SpacePoint(&aCluster, &sensorInfoBase1);
377  fullTrackCand.addSpacePoint(&aPXDSpacePoint, 1.23); // add a SpacePoint with an arbitrary sorting parameter
378 
379  VxdID aVxdID2 = VxdID(2, 2, 2);
380  VXD::SensorInfoBase sensorInfoBase2 = createSensorInfo(aVxdID2, 2.3, 4.2);
381  SVDCluster aUCluster = SVDCluster(aVxdID2, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
382  SVDCluster aVCluster = SVDCluster(aVxdID2, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
383  std::vector<const SVDCluster*> UVClusterVec1 = { &aUCluster, &aVCluster };
384  std::vector<const SVDCluster*> VClusterVec = { &aVCluster };
385  std::vector<const SVDCluster*> UClusterVec = { &aUCluster };
386  const SpacePoint SVDSpacePoint1 = SpacePoint(UVClusterVec1, &sensorInfoBase2);
387  const SpacePoint SVDSpacePoint2 = SpacePoint(VClusterVec, &sensorInfoBase2);
388  const SpacePoint SVDSpacePoint3 = SpacePoint(UClusterVec, &sensorInfoBase2);
389  fullTrackCand.addSpacePoint(&SVDSpacePoint1, 2.34);
390  fullTrackCand.addSpacePoint(&SVDSpacePoint2, 3.45);
391  fullTrackCand.addSpacePoint(&SVDSpacePoint3, 4.56);
392 
393  // set up a second TC, but ommit one SpacePoint
394  SpacePointTrackCand expectedTC;
395  expectedTC.addSpacePoint(&aPXDSpacePoint, 1.23);
396  expectedTC.addSpacePoint(&SVDSpacePoint2, 3.45);
397  expectedTC.addSpacePoint(&SVDSpacePoint3, 4.56);
398 
399  // remove SpcePoint from first TrackCand amd compare it with the expected TrackCand
400  fullTrackCand.removeSpacePoint(1);
401  EXPECT_TRUE(expectedTC == fullTrackCand);
402 
403  std::vector<double> expectedSortParams = { 1.23, 3.45, 4.56 };
404  std::vector<double> sortParams = fullTrackCand.getSortingParameters();
405  EXPECT_EQ(expectedSortParams.size(), sortParams.size());
406  for (unsigned int i = 0; i < sortParams.size(); ++i) { EXPECT_DOUBLE_EQ(sortParams.at(i), expectedSortParams.at(i)); }
407 
408  // try to remove a SpacePoint that is out of bounds
409  ASSERT_THROW(fullTrackCand.removeSpacePoint(fullTrackCand.getNHits()), SpacePointTrackCand::SPTCIndexOutOfBounds);
410  }
411 
415  TEST_F(SpacePointTrackCandTest, testGetSortedHits)
416  {
417  // set up some SpacePoints and add them to a SpacePointTrackCand
418  VxdID aVxdID1 = VxdID(1, 1, 1);
419  VXD::SensorInfoBase sensorInfoBase1 = createSensorInfo(aVxdID1, 2.3, 4.2);
420  PXDCluster aCluster = PXDCluster(aVxdID1, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
421  const SpacePoint aPXDSpacePoint = SpacePoint(&aCluster, &sensorInfoBase1);
422 
423  VxdID aVxdID2 = VxdID(2, 2, 2);
424  VXD::SensorInfoBase sensorInfoBase2 = createSensorInfo(aVxdID2, 2.3, 4.2);
425  SVDCluster aUCluster = SVDCluster(aVxdID2, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
426  SVDCluster aVCluster = SVDCluster(aVxdID2, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
427  std::vector<const SVDCluster*> UVClusterVec1 = { &aUCluster, &aVCluster };
428  std::vector<const SVDCluster*> VClusterVec = { &aVCluster };
429  std::vector<const SVDCluster*> UClusterVec = { &aUCluster };
430  const SpacePoint SVDSpacePoint1 = SpacePoint(UVClusterVec1, &sensorInfoBase2);
431  const SpacePoint SVDSpacePoint2 = SpacePoint(VClusterVec, &sensorInfoBase2);
432  const SpacePoint SVDSpacePoint3 = SpacePoint(UClusterVec, &sensorInfoBase2);
433 
434  VxdID aVxdId3 = VxdID(3, 3, 3);
435  VXD::SensorInfoBase sensorInfoBase3 = createSensorInfo(aVxdId3, 2.3, 4.2);
436  SVDCluster aUCluster2 = SVDCluster(aVxdId3, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
437  SVDCluster aVCluster2 = SVDCluster(aVxdId3, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1.0);
438  std::vector<const SVDCluster*> UVClusterVec2 = { &aUCluster2, &aVCluster2 };
439  std::vector<const SVDCluster*> VClusterVec2 = { &aVCluster2 };
440  std::vector<const SVDCluster*> UClusterVec2 = { &aUCluster2 };
441  const SpacePoint SVDSpacePoint4 = SpacePoint(UVClusterVec2, &sensorInfoBase3);
442  const SpacePoint SVDSpacePoint5 = SpacePoint(VClusterVec2, &sensorInfoBase3);
443  const SpacePoint SVDSpacePoint6 = SpacePoint(UClusterVec2, &sensorInfoBase3);
444 
445 
446  SpacePointTrackCand unsortedConstructed;
447  // add a SpacePoint with sorting parameter
448  unsortedConstructed.addSpacePoint(&aPXDSpacePoint, 1.0);
449  // add some SVD SpacePoints in logical order
450  unsortedConstructed.addSpacePoint(&SVDSpacePoint1, 2.34);
451  unsortedConstructed.addSpacePoint(&SVDSpacePoint2, 3.45);
452  unsortedConstructed.addSpacePoint(&SVDSpacePoint3, 4.56);
453  // add some SpacePoints in 'wrong' order
454  unsortedConstructed.addSpacePoint(&SVDSpacePoint4, 5.67);
455  unsortedConstructed.addSpacePoint(&SVDSpacePoint6, 7.89);
456  unsortedConstructed.addSpacePoint(&SVDSpacePoint5, 6.78);
457 
458  // set up a SpacePointTrackCands already properly sorted
459  SpacePointTrackCand sortedConstructed;
460  sortedConstructed.addSpacePoint(&aPXDSpacePoint, 1.23);
461  sortedConstructed.addSpacePoint(&SVDSpacePoint1, 2.34);
462  sortedConstructed.addSpacePoint(&SVDSpacePoint2, 3.45);
463  sortedConstructed.addSpacePoint(&SVDSpacePoint3, 4.56);
464  sortedConstructed.addSpacePoint(&SVDSpacePoint4, 5.67);
465  sortedConstructed.addSpacePoint(&SVDSpacePoint5, 6.78);
466  sortedConstructed.addSpacePoint(&SVDSpacePoint6, 7.89);
467 
468  // test sorting
469  SpacePointTrackCand sorted = SpacePointTrackCand(unsortedConstructed.getSortedHits());
470  // == compares the spacepoints
471  EXPECT_TRUE(sorted == sortedConstructed);
472 
473  SpacePointTrackCand nothingChanged = SpacePointTrackCand(sortedConstructed.getSortedHits());
474  EXPECT_TRUE(nothingChanged == sortedConstructed);
475 
476 
477  std::vector<double> sortParams1 = { 1.0, 2.0, 3.0 , 4.0, 5.0, 7.0, 6.0};
478  sortedConstructed.setSortingParameters(sortParams1);
479 
480  // verify that sorting changed according to new sortParams
481  SpacePointTrackCand unsorted = SpacePointTrackCand(sortedConstructed.getSortedHits());
482  EXPECT_TRUE(unsorted == unsortedConstructed);
483  }
485 }
Belle2::SpacePointTrackCandTest
Test class for the SpacePointTrackCand class.
Definition: spacePointTrackCand.cc:30
Belle2::SpacePointTrackCand::getSortedHits
const std::vector< const Belle2::SpacePoint * > getSortedHits() const
get hits (space points) sorted by their respective sorting parameter
Definition: SpacePointTrackCand.cc:103
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SpacePointTrackCand::isCurling
bool isCurling() const
get if the TrackCand is curling.
Definition: SpacePointTrackCand.h:261
Belle2::SpacePointTrackCand::hasHitsOnSameSensor
bool hasHitsOnSameSensor() const
Check if the SpacePointTrackCand contains consecutive SpacePoints that are on the same sensor WARNING...
Definition: SpacePointTrackCand.h:228
Belle2::SpacePointTrackCand::getHitsInRange
const std::vector< const Belle2::SpacePoint * > getHitsInRange(int firstInd, int lastInd) const
get hits (SpacePoints) in range (indices of SpacePoint inside SpacePointTrackCand) including first in...
Definition: SpacePointTrackCand.cc:69
Belle2::SpacePointTrackCandTest::createSensorInfo
VXD::SensorInfoBase createSensorInfo(VxdID aVxdID, double width=1., double length=1., double width2=-1.)
this is a small helper function to create a sensorInfo to be used
Definition: spacePointTrackCand.cc:33
Belle2::SpacePointTrackCand::setRefereeStatus
void setRefereeStatus(unsigned short int bitmask)
set referee status (resets the complete to the passed status!)
Definition: SpacePointTrackCand.h:341
Belle2::SpacePointTrackCand::addRefereeStatus
void addRefereeStatus(unsigned short int bitmask)
add a referee status
Definition: SpacePointTrackCand.h:344
Belle2::SpacePointTrackCand::setSortingParameters
void setSortingParameters(const std::vector< double > &sortParams)
set the sorting parameters
Definition: SpacePointTrackCand.cc:136
Belle2::SpacePointTrackCand::removeRefereeStatus
void removeRefereeStatus(unsigned short int bitmask)
remove a referee status
Definition: SpacePointTrackCand.h:347
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::TEST_F
TEST_F(SpacePointTrackCandTest, testGetSortedHits)
Test setPdgCode method, by comparing its results with the expected values for the according particles...
Definition: spacePointTrackCand.cc:415
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::SpacePointTrackCand::getNHits
unsigned int getNHits() const
get the number of hits (space points) in the track candidate
Definition: SpacePointTrackCand.h:154
Belle2::SpacePointTrackCand::getSortingParametersInRange
const std::vector< double > getSortingParametersInRange(int firstIndex, int lastIndex) const
get the sorting parameters in range (indices of SpacePoints inside SpacePointTrackCand) including fir...
Definition: SpacePointTrackCand.cc:86
Belle2::VXD::SensorInfoBase::setTransformation
void setTransformation(const TGeoHMatrix &transform, bool reco=false)
Set the transformation matrix of the Sensor.
Definition: SensorInfoBase.h:305
Belle2::SpacePointTrackCand::removeSpacePoint
void removeSpacePoint(int indexInTrackCand)
remove a SpacePoint (and its sorting parameter) from the SpacePointTrackCand
Definition: SpacePointTrackCand.cc:146
Belle2::SpacePointTrackCand::getPdgCode
int getPdgCode() const
get pdg code
Definition: SpacePointTrackCand.h:164
Belle2::SpacePointTrackCand::getHits
const std::vector< const Belle2::SpacePoint * > & getHits() const
get hits (space points) of track candidate
Definition: SpacePointTrackCand.h:131
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SpacePointTrackCand::resetRefereeStatus
void resetRefereeStatus()
resets the referee status to the initial value
Definition: SpacePointTrackCand.h:353
Belle2::SpacePointTrackCand::setPdgCode
void setPdgCode(int pdgCode)
set a hypothesis for the particle by setting a pdgcode (will also set the appropriate charge)
Definition: SpacePointTrackCand.cc:128
Belle2::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::SpacePointTrackCand::hasRefereeStatus
bool hasRefereeStatus(unsigned int short bitmask) const
Check if the SpacePointTrackCand has the status characterized by the bitmask.
Definition: SpacePointTrackCand.h:217
Belle2::SpacePointTrackCand::checkedSameSensors
bool checkedSameSensors() const
Check if the SpacePointTrackCand has been checked for consecutive hits on same sensor.
Definition: SpacePointTrackCand.h:233
Belle2::SpacePointTrackCand::getSortingParameters
const std::vector< double > & getSortingParameters() const
get the sorting parameters
Definition: SpacePointTrackCand.h:186
Belle2::SpacePointTrackCand::getChargeSeed
double getChargeSeed() const
get charge
Definition: SpacePointTrackCand.h:169
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::SpacePointTrackCand::clearRefereeStatus
void clearRefereeStatus()
clear the referee status.
Definition: SpacePointTrackCand.h:350
Belle2::SpacePointTrackCand::getRefereeStatus
unsigned short int getRefereeStatus(unsigned short int bitmask=USHRT_MAX) const
Return the refere status code of the SpacePointTrackCand.
Definition: SpacePointTrackCand.h:212
Belle2::SpacePointTrackCand::addSpacePoint
void addSpacePoint(const SpacePoint *newSP, double sortParam)
add a new SpacePoint and its according sorting parameter to the track candidate
Definition: SpacePointTrackCand.h:326
Belle2::SpacePointTrackCand::getMcTrackID
int getMcTrackID() const
get the MC Track ID
Definition: SpacePointTrackCand.h:201
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51