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