Belle II Software development
spacePoint.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/logging/Logger.h>
10#include <framework/utilities/TestHelpers.h>
11#include <tracking/spacePointCreation/SpacePoint.h>
12#include <vxd/dataobjects/VxdID.h>
13#include <vxd/geometry/SensorInfoBase.h>
14
15#include <gtest/gtest.h>
16
17//root stuff
18#include "TFile.h"
19#include "TKey.h"
20
21using namespace std;
22
23namespace Belle2 {
32 class SpacePointTest : public ::testing::Test {
33
34 public:
36 VXD::SensorInfoBase createSensorInfo(VxdID aVxdID, float width = 1., float length = 1., float width2 = -1.,
38 {
39 // (SensorType type, VxdID id, float width, float length, float thickness, int uCells, int vCells, float width2=-1, double splitLength=-1, int vCells2=0)
40 VXD::SensorInfoBase sensorInfoBase(sensorType, aVxdID, width, length, 0.3, 2, 4, width2);
41
42 TGeoRotation r1;
43 r1.SetAngles(45, 20, 30); // rotation defined by Euler angles
44 TGeoTranslation t1(-10, 10, 1);
45 TGeoCombiTrans c1(t1, r1);
46 TGeoHMatrix transform = c1;
47 sensorInfoBase.setTransformation(transform);
48
49 return sensorInfoBase;
50 }
51 protected:
52 };
53
58 TEST_F(SpacePointTest, testConstructorPXD)
59 {
60 VxdID aVxdID = VxdID(1, 1, 1);
61 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
62
63 // create new PXDCluster and fill it with Info getting a Hit which is not at the origin (here, first layer)
64
65 PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
66 SpacePoint testPoint = SpacePoint(&aCluster, &sensorInfoBase);
67
68 EXPECT_DOUBLE_EQ(aVxdID, testPoint.getVxdID());
69
70 // needing globalized position and error:
71 ROOT::Math::XYZVector aPosition = sensorInfoBase.pointToGlobal(ROOT::Math::XYZVector(aCluster.getU(), aCluster.getV(), 0), true);
72 ROOT::Math::XYZVector globalizedVariances = sensorInfoBase.vectorToGlobal(
73 ROOT::Math::XYZVector(
74 aCluster.getUSigma() * aCluster.getUSigma(),
75 aCluster.getVSigma() * aCluster.getVSigma(),
76 0
77 ),
78 true
79 );
80
81 ROOT::Math::XYZVector globalError;
82 globalError.SetX(sqrt(abs(globalizedVariances.X())));
83 globalError.SetY(sqrt(abs(globalizedVariances.Y())));
84 globalError.SetZ(sqrt(abs(globalizedVariances.Z())));
85
86 EXPECT_DOUBLE_EQ(aPosition.X(), testPoint.getPosition().X());
87 EXPECT_DOUBLE_EQ(aPosition.Y(), testPoint.getPosition().Y());
88 EXPECT_DOUBLE_EQ(aPosition.Z(), testPoint.getPosition().Z());
89 EXPECT_FLOAT_EQ(globalError.X(), testPoint.getPositionError().X());
90 EXPECT_FLOAT_EQ(globalError.Y(), testPoint.getPositionError().Y());
91 EXPECT_FLOAT_EQ(globalError.Z(), testPoint.getPositionError().Z());
92 // normalized coordinates, center of Plane should be at 0.5:
93 EXPECT_DOUBLE_EQ(0.5, testPoint.getNormalizedLocalU());
94 EXPECT_DOUBLE_EQ(0.5, testPoint.getNormalizedLocalV());
95
96 }
97
98
99
104 TEST_F(SpacePointTest, testConstructorSVD)
105 {
106 VxdID aVxdID = VxdID(3, 3, 3), anotherVxdID = VxdID(1, 1, 1);
107 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
108 VXD::SensorInfoBase anotherSensorInfoBase = createSensorInfo(anotherVxdID, 2.3, 4.2);
109
110 // create new SVDClusters and fill it with Info getting a Hit which is not at the origin
111 // SVDCluster (VxdID sensorID, bool isU, float position, float positionSigma, double clsTime, double clsTimeSigma, float seedCharge, float clsCharge, unsigned short clsSize, double clsSNR)
112 SVDCluster clusterU1 = SVDCluster(aVxdID, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1);
113 SVDCluster clusterV1 = SVDCluster(aVxdID, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1);
114 SVDCluster clusterU2 = SVDCluster(aVxdID, true, 0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1);
115 SVDCluster clusterU3 = SVDCluster(anotherVxdID, true, 0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1);
116
117
118 // normal u+v = 2D Cluster (order of input irrelevant):
119 std::vector<const SVDCluster*> good2D = { &clusterU1, &clusterV1 };
120 SpacePoint testPoint2D = SpacePoint(good2D, &sensorInfoBase);
121
122 // normal u-only = 1D Cluster, sensorInfoBase is normally not needed, since constructor can create it on its own, but here the geometry is not set up, therefore we have to pass the infoBase:
123 std::vector<const SVDCluster*> good1D = { &clusterU3 };
124 SpacePoint testPoint1D = SpacePoint(good1D, &anotherSensorInfoBase);
125
126
127 // should throw, since no clusters given:
128 std::vector<const SVDCluster*> badNoClusters;
129 EXPECT_B2FATAL(SpacePoint(badNoClusters, &sensorInfoBase));
130
131 // should throw, since too many clusters (of same sensor) given:
132 std::vector<const SVDCluster*> bad3Clusters = { &clusterU1, &clusterV1, &clusterU2 };
133 EXPECT_B2FATAL(SpacePoint(bad3Clusters, &sensorInfoBase));
134
135 // should throw, since two clusters of same type (but on same sensor) given:
136 std::vector<const SVDCluster*> badSameType = { &clusterU1, &clusterU2 };
137 EXPECT_B2FATAL(SpacePoint(badSameType, &sensorInfoBase));
138
139 // should throw, since two clusters of different sensors given:
140 std::vector<const SVDCluster*> badDifferentSensors = { &clusterV1, &clusterU3 };
141 EXPECT_B2FATAL(SpacePoint(badDifferentSensors, &sensorInfoBase));
142
143
144 // check results for full 2D cluster-combi:
145 ROOT::Math::XYZVector aPositionFor2D = sensorInfoBase.pointToGlobal(ROOT::Math::XYZVector(clusterU1.getPosition(),
146 clusterV1.getPosition(), 0), true);
147 ROOT::Math::XYZVector globalizedVariancesFor2D = sensorInfoBase.vectorToGlobal(
148 ROOT::Math::XYZVector(
149 clusterU1.getPositionSigma() * clusterU1.getPositionSigma(),
150 clusterV1.getPositionSigma() * clusterV1.getPositionSigma(),
151 0
152 ),
153 true
154 );
155 ROOT::Math::XYZVector globalErrorFor2D;
156 globalErrorFor2D.SetX(sqrt(abs(globalizedVariancesFor2D.X())));
157 globalErrorFor2D.SetY(sqrt(abs(globalizedVariancesFor2D.Y())));
158 globalErrorFor2D.SetZ(sqrt(abs(globalizedVariancesFor2D.Z())));
159
160 // vxdID:
161 EXPECT_EQ(aVxdID, testPoint2D.getVxdID());
162 // global position:
163 EXPECT_FLOAT_EQ(aPositionFor2D.X(), testPoint2D.getPosition().X());
164 EXPECT_FLOAT_EQ(aPositionFor2D.Y(), testPoint2D.getPosition().Y());
165 EXPECT_FLOAT_EQ(aPositionFor2D.Z(), testPoint2D.getPosition().Z());
166 //global error:
167 EXPECT_FLOAT_EQ(globalErrorFor2D.X(), testPoint2D.getPositionError().X());
168 EXPECT_FLOAT_EQ(globalErrorFor2D.Y(), testPoint2D.getPositionError().Y());
169 EXPECT_FLOAT_EQ(globalErrorFor2D.Z(), testPoint2D.getPositionError().Z());
170 //local normalized position:
171 EXPECT_FLOAT_EQ(0.4, testPoint2D.getNormalizedLocalU());
172 EXPECT_FLOAT_EQ(0.6, testPoint2D.getNormalizedLocalV());
173
174
175 // check results for single-cluster-only-case:
176 ROOT::Math::XYZVector aPositionFor1D = anotherSensorInfoBase.pointToGlobal(ROOT::Math::XYZVector(clusterU3.getPosition(), 0, 0),
177 true);
178 ROOT::Math::XYZVector globalizedVariancesFor1D = anotherSensorInfoBase.vectorToGlobal(
179 ROOT::Math::XYZVector(
180 clusterU3.getPositionSigma() * clusterU3.getPositionSigma(),
181 anotherSensorInfoBase.getVSize() * anotherSensorInfoBase.getVSize() / 12.,
182 0
183 ),
184 true
185 );
186 ROOT::Math::XYZVector globalErrorFor1D;
187 globalErrorFor1D.SetX(sqrt(abs(globalizedVariancesFor1D.X())));
188 globalErrorFor1D.SetY(sqrt(abs(globalizedVariancesFor1D.Y())));
189 globalErrorFor1D.SetZ(sqrt(abs(globalizedVariancesFor1D.Z())));
190
191
192 // vxdID:
193 EXPECT_EQ(anotherVxdID, testPoint1D.getVxdID());
194 // global position:
195 EXPECT_FLOAT_EQ(aPositionFor1D.X(), testPoint1D.getPosition().X());
196 EXPECT_FLOAT_EQ(aPositionFor1D.Y(), testPoint1D.getPosition().Y());
197 EXPECT_FLOAT_EQ(aPositionFor1D.Z(), testPoint1D.getPosition().Z());
198 //global error:
199 EXPECT_FLOAT_EQ(globalErrorFor1D.X(), testPoint1D.getPositionError().X());
200 EXPECT_FLOAT_EQ(globalErrorFor1D.Y(), testPoint1D.getPositionError().Y());
201 EXPECT_FLOAT_EQ(globalErrorFor1D.Z(), testPoint1D.getPositionError().Z());
202 //local normalized position:
203 EXPECT_FLOAT_EQ(0.6, testPoint1D.getNormalizedLocalU());
204 EXPECT_FLOAT_EQ(0.5, testPoint1D.getNormalizedLocalV()); // center of sensor since v-cluster was not given
205 }
206
209 TEST_F(SpacePointTest, testRootIOPXDCluster)
210 {
211 string fNameCluster = "demoClusters.root";
212 VxdID aVxdID = VxdID(1, 2, 3);
213 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
214
215
217 PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
218 EXPECT_EQ(aVxdID, aCluster.getSensorID());
219
221 B2INFO("open root file: " << fNameCluster);
222 TFile f(fNameCluster.c_str(), "recreate");
223 f.cd();
224 aCluster.Write();
225 f.Close();
226
228 TFile f2(fNameCluster.c_str());
229 if (f2.IsZombie()) { B2ERROR("file could not be reopened!"); }
230 else {
231 PXDCluster* retrievedCluster;
232 f2.GetListOfKeys()->Print();
233
234 TIter next(f2.GetListOfKeys());
235 TKey* key;
236 while ((key = (TKey*)next())) {
237
238 try {
239 retrievedCluster = static_cast<PXDCluster*>(key->ReadObj());
240 } catch (exception& e) {
241 B2WARNING("Key was not a PXDCluster, therefore error message: " << e.what() << "\n Skipping this key...");
242 continue;
243 }
244
245 EXPECT_EQ(retrievedCluster->getSensorID(), aCluster.getSensorID());
246 }
247 f2.Close();
248 }
250 if (remove(fNameCluster.c_str()) != 0)
251 { B2ERROR("could not delete file " << fNameCluster << "!"); }
252 else
253 { B2INFO(fNameCluster << " successfully deleted"); }
254 }
255
256
257
260 TEST_F(SpacePointTest, testRootIOB2Vector3)
261 {
262 string fNameVec = "demoB2Vector3s.root";
263
265 B2Vector3F aVec(1.23, 2.34, 3.45);
266
267
269 B2INFO("open root file: " << fNameVec);
270 TFile f(fNameVec.c_str(), "recreate");
271 f.cd();
272 f.WriteObject(&aVec, "myVec3");
273 f.Close();
274
276 TFile f2(fNameVec.c_str());
277 if (f2.IsZombie()) { B2ERROR("file could not be reopened!"); }
278 else {
279
281 B2Vector3F* retrievedVector;
282 f2.GetObject("myVec3", retrievedVector);
283 f2.Close();
284
285 EXPECT_DOUBLE_EQ(aVec.X(), retrievedVector->X());
286 EXPECT_DOUBLE_EQ(aVec.Y(), retrievedVector->Y());
287 EXPECT_DOUBLE_EQ(aVec.Z(), retrievedVector->Z());
288
289 }
291 if (remove(fNameVec.c_str()) != 0)
292 { B2ERROR("could not delete file " << fNameVec << "!"); }
293 else
294 { B2INFO(fNameVec << " successfully deleted"); }
295 }
296
297
298
301 TEST_F(SpacePointTest, testRootIOSP)
302 {
304 string fNameSP = "demoSPs.root";
305 VxdID aVxdID = VxdID(1, 2, 3);
306 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
307
308
310 PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
311 EXPECT_EQ(aVxdID, aCluster.getSensorID());
312
313 SpacePoint testPoint = SpacePoint(&aCluster, &sensorInfoBase);
314 EXPECT_EQ(aVxdID, testPoint.getVxdID());
315
316
318 B2INFO("open root file:" << fNameSP);
319 TFile f3(fNameSP.c_str(), "recreate");
320 f3.cd();
321 testPoint.Write();
322 B2INFO("closing file:");
323 f3.Close();
324
326 TFile f4(fNameSP.c_str());
327 if (f4.IsZombie()) { B2ERROR("file could not be reopened!"); }
328 else {
329 SpacePoint* retrievedSpacePoint;
330 f4.GetListOfKeys()->Print();
331
332 TIter next(f4.GetListOfKeys());
333 TKey* key;
334 while ((key = (TKey*)next())) {
335
336 try {
337 retrievedSpacePoint = static_cast<SpacePoint*>(key->ReadObj());
338 } catch (exception& e) {
339 B2WARNING("Key was not a SpacePoint, therefore error message: " << e.what() << "\n Skipping this key...");
340 continue;
341 }
342
343 EXPECT_EQ(retrievedSpacePoint->getVxdID(), testPoint.getVxdID());
344 EXPECT_DOUBLE_EQ(retrievedSpacePoint->getPosition().X(), testPoint.getPosition().X());
345 EXPECT_DOUBLE_EQ(retrievedSpacePoint->getPosition().Y(), testPoint.getPosition().Y());
346 EXPECT_DOUBLE_EQ(retrievedSpacePoint->getPosition().Z(), testPoint.getPosition().Z());
347 EXPECT_FLOAT_EQ(retrievedSpacePoint->getPositionError().X(), testPoint.getPositionError().X());
348 EXPECT_FLOAT_EQ(retrievedSpacePoint->getPositionError().Y(), testPoint.getPositionError().Y());
349 EXPECT_FLOAT_EQ(retrievedSpacePoint->getPositionError().Z(), testPoint.getPositionError().Z());
350 EXPECT_DOUBLE_EQ(retrievedSpacePoint->getNormalizedLocalU(), testPoint.getNormalizedLocalU());
351 EXPECT_DOUBLE_EQ(retrievedSpacePoint->getNormalizedLocalV(), testPoint.getNormalizedLocalV());
352 }
353 f4.Close();
354 }
356 if (remove(fNameSP.c_str()) != 0)
357 { B2ERROR("could not delete file " << fNameSP << "!"); }
358 else
359 { B2INFO(fNameSP << " successfully deleted"); }
360 }
361
362
363
364
369 TEST_F(SpacePointTest, testConvertLocalToNormalizedCoordinates)
370 {
371 VxdID aVxdID = VxdID(1, 1, 1);
372 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
373
374 pair<float, float> sensorCenter = {1.15, 2.1};
375
376 pair<float, float> hitLocal05 = {0, 0}; // sensorCenter is at 0, 0 in local coordinates
377 pair<float, float> resultNormalized05 = {0.5, 0.5};
378
379 pair<float, float> hitLocal001 = {0.023, 0.042};
380 hitLocal001.first -= sensorCenter.first;
381 hitLocal001.second -= sensorCenter.second;
382 pair<float, float> resultNormalized001 = {0.01, 0.01};
383
384 pair<float, float> hitLocal088 = {2.024, 3.696};
385 hitLocal088.first -= sensorCenter.first;
386 hitLocal088.second -= sensorCenter.second;
387 pair<float, float> resultNormalized088 = {0.88, 0.88};
388
389 pair<float, float> hitLocal001088 = {0.023, 3.696};// asymmetric example verifying that values are not accidentally switched
390 hitLocal001088.first -= sensorCenter.first;
391 hitLocal001088.second -= sensorCenter.second;
392 pair<float, float> resultNormalized001088 = {0.01, 0.88};
393
394 pair<float, float> hitLocalMinMax = { -1.16, 500}; // hit lies way beyond sensor edges (first is below lower threshold, second above higher one)
395 pair<float, float> resultNormalizedMinMax = {0., 1.};
396
397 pair<float, float> hitNormalized05 = SpacePoint::convertLocalToNormalizedCoordinates(hitLocal05, aVxdID, &sensorInfoBase);
398 EXPECT_FLOAT_EQ(resultNormalized05.first, hitNormalized05.first);
399 EXPECT_FLOAT_EQ(resultNormalized05.second, hitNormalized05.second);
400
401 pair<float, float> hitNormalized001 = SpacePoint::convertLocalToNormalizedCoordinates(hitLocal001, aVxdID, &sensorInfoBase);
402 EXPECT_FLOAT_EQ(resultNormalized001.first, hitNormalized001.first);
403 EXPECT_NEAR(resultNormalized001.second, hitNormalized001.second, 1. / 100000.); // resolution of better than 1 nm.
404
405 pair<float, float> hitNormalized088 = SpacePoint::convertLocalToNormalizedCoordinates(hitLocal088, aVxdID, &sensorInfoBase);
406 EXPECT_FLOAT_EQ(resultNormalized088.first, hitNormalized088.first);
407 EXPECT_FLOAT_EQ(resultNormalized088.second, hitNormalized088.second);
408
409 pair<float, float> hitNormalized001088 = SpacePoint::convertLocalToNormalizedCoordinates(hitLocal001088, aVxdID, &sensorInfoBase);
410 EXPECT_FLOAT_EQ(resultNormalized001088.first, hitNormalized001088.first);
411 EXPECT_FLOAT_EQ(resultNormalized001088.second, hitNormalized001088.second);
412
413 pair<float, float> hitNormalizedMinMax = SpacePoint::convertLocalToNormalizedCoordinates(hitLocalMinMax, aVxdID, &sensorInfoBase);
414 EXPECT_FLOAT_EQ(resultNormalizedMinMax.first, hitNormalizedMinMax.first);
415 EXPECT_FLOAT_EQ(resultNormalizedMinMax.second, hitNormalizedMinMax.second);
416 }
417
418
419
424 TEST_F(SpacePointTest, testConvertNormalizedToLocalCoordinates)
425 {
426 VxdID aVxdID = VxdID(1, 1, 1);
427 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
428
429 pair<float, float> sensorCenter = {1.15, 2.1};
430
431 pair<float, float> hitNormalized05 = {0.5, 0.5};
432 pair<float, float> resultLocal05 = {0, 0}; // sensorCenter is at 0, 0 in local coordinates
433
434 pair<float, float> hitNormalized001 = {0.01, 0.01};
435 pair<float, float> resultLocal001 = {0.023, 0.042};
436 resultLocal001.first -= sensorCenter.first;
437 resultLocal001.second -= sensorCenter.second;
438
439 pair<float, float> hitNormalized088 = {0.88, 0.88};
440 pair<float, float> resultLocal088 = {2.024, 3.696};
441 resultLocal088.first -= sensorCenter.first;
442 resultLocal088.second -= sensorCenter.second;
443
444 pair<float, float> hitNormalized001088 = {0.01, 0.88};
445 pair<float, float> resultLocal001088 = {0.023, 3.696};// asymmetric example verifying that values are not accidentally switched
446 resultLocal001088.first -= sensorCenter.first;
447 resultLocal001088.second -= sensorCenter.second;
448
449 pair<float, float> hitNormalizedMinMax = { -0.1, 4.2}; // hit lies way beyond sensor edges (first is below lower threshold, second above higher one)
450 pair<float, float> resultLocalMinMax = { -1.15, 2.1}; // reduced to sensor borders
451
452 pair<float, float> hitLocal05 = SpacePoint::convertNormalizedToLocalCoordinates(hitNormalized05, aVxdID, &sensorInfoBase);
453 EXPECT_FLOAT_EQ(resultLocal05.first, hitLocal05.first);
454 EXPECT_FLOAT_EQ(resultLocal05.second, hitLocal05.second);
455
456 pair<float, float> hitLocal001 = SpacePoint::convertNormalizedToLocalCoordinates(hitNormalized001, aVxdID, &sensorInfoBase);
457 EXPECT_FLOAT_EQ(resultLocal001.first, hitLocal001.first);
458 EXPECT_FLOAT_EQ(resultLocal001.second, hitLocal001.second);
459
460 pair<float, float> hitLocal088 = SpacePoint::convertNormalizedToLocalCoordinates(hitNormalized088, aVxdID, &sensorInfoBase);
461 EXPECT_FLOAT_EQ(resultLocal088.first, hitLocal088.first);
462 EXPECT_FLOAT_EQ(resultLocal088.second, hitLocal088.second);
463
464 pair<float, float> hitLocal001088 = SpacePoint::convertNormalizedToLocalCoordinates(hitNormalized001088, aVxdID, &sensorInfoBase);
465 EXPECT_FLOAT_EQ(resultLocal001088.first, hitLocal001088.first);
466 EXPECT_FLOAT_EQ(resultLocal001088.second, hitLocal001088.second);
467
468 pair<float, float> hitLocalMinMax = SpacePoint::convertNormalizedToLocalCoordinates(hitNormalizedMinMax, aVxdID, &sensorInfoBase);
469 EXPECT_FLOAT_EQ(resultLocalMinMax.first, hitLocalMinMax.first);
470 EXPECT_FLOAT_EQ(resultLocalMinMax.second, hitLocalMinMax.second);
471 }
472 // static pair<float, float> convertToLocalCoordinates(const pair<float, float>& hitNormalized, VxdID::baseType vxdID, const VXD::SensorInfoBase* aSensorInfo = nullptr);
473
474
475
479 TEST_F(SpacePointTest, testGetNClustersAssigned)
480 {
481 // create a PXD SpacePoint and check if there is one Cluster assigned to it
482 VxdID aVxdID = VxdID(1, 1, 1);
483 VXD::SensorInfoBase sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2);
484 PXDCluster aCluster = PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
485 SpacePoint testPoint = SpacePoint(&aCluster, &sensorInfoBase);
486
487 EXPECT_EQ(testPoint.getNClustersAssigned(), 1);
488
489 // create different SVD SpacePoints and check if the number of assigned Clusters is correct
490 aVxdID = VxdID(3, 1, 2);
491 sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2, -1, VXD::SensorInfoBase::SVD);
492
493 // create new SVDClusters and fill it with Info getting a Hit which is not at the origin
494 // SVDCluster (VxdID sensorID, bool isU, float position, float positionSigma, double clsTime, double clsTimeSigma, float seedCharge, float clsCharge, unsigned short clsSize)
495 SVDCluster clusterU1 = SVDCluster(aVxdID, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1, 1);
496 SVDCluster clusterV1 = SVDCluster(aVxdID, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1, 1);
497
498 vector<const SVDCluster*> clusters2d = { &clusterU1, &clusterV1 };
499 SpacePoint testPoint2D = SpacePoint(clusters2d, &sensorInfoBase);
500 EXPECT_EQ(testPoint2D.getNClustersAssigned(), 2);
501
502 vector<const SVDCluster*> clustersU = { &clusterU1 };
503 SpacePoint testPoint1DU = SpacePoint(clustersU, &sensorInfoBase);
504 EXPECT_EQ(testPoint1DU.getNClustersAssigned(), 1);
505
506 vector<const SVDCluster*> clustersV = { &clusterV1 };
507 SpacePoint testPoint1DV = SpacePoint(clustersV, &sensorInfoBase);
508 EXPECT_EQ(testPoint1DV.getNClustersAssigned(), 1);
509 }
510
511
513// TEST_F(SpacePointTest, testGenfitCompatibility)
514// {
515// B2INFO("testGenfitCompatibility: prepare StoreArray-stuff - clusters")
516// // prepare StoreArray-stuff:
517//
518// //Clusters
519// StoreArray<PXDCluster> pxdCL("pxdStuff", DataStore::c_Persistent);
520//
521//
522// StoreArray<SVDCluster> svdCL("svdStuff", DataStore::c_Persistent);
523//
524//
525//
526// B2INFO("testGenfitCompatibility: prepare StoreArray-stuff - SpacePoints including relations")
527// // SpacePoints including relations
528// StoreArray<SpacePoint> sps("spacePoints", DataStore::c_Persistent);
529//
530//
531//
532// // pxdCL.registerRelationTo(sps, DataStore::c_Persistent);
533// // svdCL.registerRelationTo(sps, DataStore::c_Persistent);
534//
535//
536// B2INFO("testGenfitCompatibility: unique StoreArrayPtr to carry the names of the Cluster-storeArrays")
537// // unique StoreArrayPtr to carry the names of the Cluster-storeArrays:
538// StoreObjPtr<SpacePointMetaInfo> spMI("", DataStore::c_Persistent);
539//
540//
541//
542//
543// DataStore::Instance().setInitializeActive(true);
544// pxdCL.registerInDataStore(pxdCL.getName(), DataStore::c_Persistent);
545// svdCL.registerInDataStore(svdCL.getName(), DataStore::c_Persistent);
546// sps.registerInDataStore(sps.getName(), DataStore::c_Persistent);
547// sps.registerRelationTo(pxdCL, DataStore::c_Persistent);
548// sps.registerRelationTo(svdCL, DataStore::c_Persistent);
549// spMI.registerInDataStore("", DataStore::c_Persistent);
550// DataStore::Instance().setInitializeActive(false);
551//
552// EXPECT_TRUE(pxdCL.isValid());
553// EXPECT_TRUE(svdCL.isValid());
554// EXPECT_TRUE(sps.isValid());
555//
556// spMI.create();
557// EXPECT_TRUE(spMI.isValid());
558//
559//
560// unsigned int indexOfpxdCL = spMI->addName(pxdCL.getName());
561// unsigned int indexOfsvdCL = spMI->addName(svdCL.getName());
562//
563// B2INFO("testGenfitCompatibility: creating 1 PXD and 3 SVD Cluster ")
564// // creating 1 PXD and 3 SVD Cluster
565// VxdID aVxdIDL1 = VxdID(1, 1, 1);
566// VxdID aVxdIDL3 = VxdID(3, 3, 3);
567// VxdID aVxdIDL4 = VxdID(4, 4, 4);
568// VXD::SensorInfoBase sensorInfoBase1 = createSensorInfo(aVxdIDL1, 2.3, 4.2);
569// VXD::SensorInfoBase sensorInfoBase3 = createSensorInfo(aVxdIDL3, 5., 23.42);
570// VXD::SensorInfoBase sensorInfoBase4 = createSensorInfo(aVxdIDL3, 23.42, 42.23);
571//
572//
573// B2INFO("testGenfitCompatibility: create new PXDCluster, fill it in storeArray, link it with newly created spacePoint")
574// // create new PXDCluster, fill it in storeArray, link it with newly created spacePoint
575// PXDCluster aCluster = PXDCluster(aVxdIDL1, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
576// unsigned int indexOfPxdCluster = pxdCL.getEntries(); // getting the index before adding, since its minus one
577// B2INFO("indexOfPxdCluster: " << indexOfPxdCluster)
578// pxdCL.appendNew(aCluster);
579//
580// SpacePoint testPoint = SpacePoint(&aCluster, indexOfPxdCluster, indexOfpxdCL, &sensorInfoBase1);
581// SpacePoint* newSP = sps.appendNew(testPoint);
582// newSP->addRelationTo(pxdCL[indexOfPxdCluster]);
583//
584//
585// B2INFO("testGenfitCompatibility: create SVDClusters, two of them are on the same sensor")
586// // create SVDClusters, two of them are on the same sensor
587// SVDCluster clusterU1 = SVDCluster(aVxdIDL3, true, -0.23, 0.1, 0.01, 0.001, 1, 1, 1);
588// unsigned int indexOfSvdClusterU1 = svdCL.getEntries();
589// B2INFO("indexOfSvdClusterU1: " << indexOfSvdClusterU1)
590// svdCL.appendNew(clusterU1);
591//
592// SVDCluster clusterV1 = SVDCluster(aVxdIDL3, false, 0.42, 0.1, 0.01, 0.001, 1, 1, 1);
593// unsigned int indexOfSvdClusterV1 = svdCL.getEntries();
594// B2INFO("indexOfSvdClusterV1: " << indexOfSvdClusterV1)
595// svdCL.appendNew(clusterV1);
596//
597// SpacePoint testPoint2D = SpacePoint({ {&clusterU1, indexOfSvdClusterU1}, {&clusterV1, indexOfSvdClusterV1} }, indexOfsvdCL, &sensorInfoBase3);
598// newSP = sps.appendNew(testPoint2D);
599// newSP->addRelationTo(svdCL[indexOfSvdClusterU1]);
600// newSP->addRelationTo(svdCL[indexOfSvdClusterV1]);
601//
602//
603// B2INFO("testGenfitCompatibility: create SVDCluster, which is alone on its sensor")
604// // create SVDCluster, which is alone on its sensor
605// SVDCluster clusterU2 = SVDCluster(aVxdIDL4, true, 0.23, 0.1, 0.01, 0.001, 1, 1, 1);
606// unsigned int indexOfSvdClusterU2 = svdCL.getEntries();
607// B2INFO("indexOfSvdClusterU2: " << indexOfSvdClusterU2)
608// svdCL.appendNew(clusterU2);
609// SpacePoint testPoint1D = SpacePoint({ {&clusterU2, indexOfSvdClusterU2} }, indexOfsvdCL, &sensorInfoBase4);
610// newSP = sps.appendNew(testPoint1D);
611// newSP->addRelationTo(svdCL[indexOfSvdClusterU2]);
612//
613//
614//
615// /** Situation so far:
616// * now the mockup is fully prepared.
617// * it contains 2 storeArrays, carrying PXD- and SVDClusters and SpacePoints based on them.
618// * The spacePoints are related to them and have a metaInfo-StoreObjPtr telling them, where to retrieve the clusters again.
619// * This is now used to get genfit-compatible output and fill it in a genfit::Track
620// */
621//
622// B2INFO("testGenfitCompatibility: preparing genfit track filled with arbitrary input")
623// // preparing genfit track filled with arbitrary input
624// genfit::AbsTrackRep* trackRep = new genfit::RKTrackRep(211);
625// // ROOT::Math::XYZVector posSeed =
626// // ROOT::Math::XYZVector posSeed =
627// genfit::Track track(trackRep, newSP->getPosition(), ROOT::Math::XYZVector(23., 42., 5.));
628//
629// B2INFO("testGenfitCompatibility: feed the track with spacePoints ported to genfit compatible stuff")
630// // feed the track with spacePoints ported to genfit compatible stuff:
631// // is rather complicated since the assignment operator is protected:
632// std::vector<genfit::AbsMeasurement*> hitOutput;
633// for (auto& aSP : sps) {
634// std::vector<genfit::PlanarMeasurement> tempMeasurements = aSP.getGenfitCompatible();
635// for (genfit::PlanarMeasurement& measurement : tempMeasurements) {
636// hitOutput.emplace_back(measurement.clone());
637// }
638// // hitOutput.insert(hitOutput.end(), temp.begin(), temp.end());
639// }
640//
641// for (unsigned i = 0; i < hitOutput.size(); i++) {
642// track.insertMeasurement(hitOutput[i]);
643// }
644//
645// EXPECT_EQ(track.getNumPoints(), unsigned(pxdCL.getEntries() + svdCL.getEntries()));
646//
647// // garbage collection:
648// delete trackRep;
649// for (auto& hit : hitOutput) { delete hit; }
650// }
651
652
653
654
655
656
658} // namespace
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
float getV() const
Get v coordinate of hit position.
Definition: PXDCluster.h:136
float getUSigma() const
Get error of u coordinate of hit position.
Definition: PXDCluster.h:141
float getVSigma() const
Get error in v coordinate of hit position.
Definition: PXDCluster.h:146
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDCluster.h:126
float getU() const
Get u coordinate of hit position.
Definition: PXDCluster.h:131
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:117
float getPositionSigma() const
Get the error of the reconstructed hit coordinate.
Definition: SVDCluster.h:129
Set up a few arrays and objects in the datastore.
Definition: spacePoint.cc:32
VXD::SensorInfoBase createSensorInfo(VxdID aVxdID, float width=1., float length=1., float width2=-1., VXD::SensorInfoBase::SensorType sensorType=VXD::SensorInfoBase::PXD)
this is a small helper function to create a sensorInfo to be used
Definition: spacePoint.cc:36
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
unsigned short getNClustersAssigned() const
Returns the number of Clusters assigned to this SpacePoint.
Definition: SpacePoint.h:165
double getNormalizedLocalV() const
Return normalized local coordinates of the cluster in v (0 <= posV <= 1).
Definition: SpacePoint.h:154
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:148
static std::pair< double, double > convertLocalToNormalizedCoordinates(const std::pair< double, double > &hitLocal, VxdID vxdID, const VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a local hit into sensor-independent relative coordinates.
Definition: SpacePoint.cc:149
const B2Vector3D & getPositionError() const
return the hitErrors in sigma of the global position
Definition: SpacePoint.h:141
static std::pair< double, double > convertNormalizedToLocalCoordinates(const std::pair< double, double > &hitNormalized, Belle2::VxdID vxdID, const Belle2::VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a hit in sensor-independent relative coordinates into local coordinate of given sensor.
Definition: SpacePoint.cc:178
const B2Vector3D & getPosition() const
return the position vector in global coordinates
Definition: SpacePoint.h:138
double getNormalizedLocalU() const
Return normalized local coordinates of the cluster in u (0 <= posU <= 1).
Definition: SpacePoint.h:151
Base class to provide Sensor Information for PXD and SVD.
double getVSize() const
Return the length of the sensor.
ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a point from local to global coordinates.
SensorType
Enum specifing the type of sensor the SensorInfo represents.
void setTransformation(const TGeoHMatrix &transform, bool reco=false)
Set the transformation matrix of the Sensor.
ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a vector from local to global coordinates.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.