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