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>
15 #include <gtest/gtest.h>
43 r1.SetAngles(45, 20, 30);
44 TGeoTranslation t1(-10, 10, 1);
45 TGeoCombiTrans c1(t1, r1);
46 TGeoHMatrix transform = c1;
49 return sensorInfoBase;
65 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
68 EXPECT_DOUBLE_EQ(aVxdID, testPoint.
getVxdID());
71 TVector3 aPosition = sensorInfoBase.
pointToGlobal(TVector3(aCluster.
getU(), aCluster.
getV(), 0),
true);
82 for (
int i = 0; i < 3; i++) { globalError[i] = sqrt(abs(globalizedVariances[i])); }
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());
117 std::vector<const SVDCluster*> good2D = { &clusterU1, &clusterV1 };
121 std::vector<const SVDCluster*> good1D = { &clusterU3 };
126 std::vector<const SVDCluster*> badNoClusters;
127 EXPECT_B2FATAL(
SpacePoint(badNoClusters, &sensorInfoBase));
130 std::vector<const SVDCluster*> bad3Clusters = { &clusterU1, &clusterV1, &clusterU2 };
131 EXPECT_B2FATAL(
SpacePoint(bad3Clusters, &sensorInfoBase));
134 std::vector<const SVDCluster*> badSameType = { &clusterU1, &clusterU2 };
135 EXPECT_B2FATAL(
SpacePoint(badSameType, &sensorInfoBase));
138 std::vector<const SVDCluster*> badDifferentSensors = { &clusterV1, &clusterU3 };
139 EXPECT_B2FATAL(
SpacePoint(badDifferentSensors, &sensorInfoBase));
144 TVector3 globalizedVariancesFor2D = sensorInfoBase.
vectorToGlobal(
152 TVector3 globalErrorFor2D;
153 for (
int i = 0; i < 3; i++) { globalErrorFor2D[i] = sqrt(abs(globalizedVariancesFor2D[i])); }
156 EXPECT_EQ(aVxdID, testPoint2D.
getVxdID());
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());
172 TVector3 globalizedVariancesFor1D = anotherSensorInfoBase.
vectorToGlobal(
180 TVector3 globalErrorFor1D;
181 for (
int i = 0; i < 3; i++) { globalErrorFor1D[i] = sqrt(abs(globalizedVariancesFor1D[i])); }
185 EXPECT_EQ(anotherVxdID, testPoint1D.
getVxdID());
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());
203 string fNameCluster =
"demoClusters.root";
209 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
213 B2INFO(
"open root file: " << fNameCluster);
214 TFile f(fNameCluster.c_str(),
"recreate");
220 TFile f2(fNameCluster.c_str());
221 if (f2.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
224 f2.GetListOfKeys()->Print();
226 TIter next(f2.GetListOfKeys());
228 while ((key = (TKey*)next())) {
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...");
242 if (remove(fNameCluster.c_str()) != 0)
243 { B2ERROR(
"could not delete file " << fNameCluster <<
"!"); }
245 { B2INFO(fNameCluster <<
" successfully deleted"); }
254 string fNameVec =
"demoB2Vector3s.root";
261 B2INFO(
"open root file: " << fNameVec);
262 TFile f(fNameVec.c_str(),
"recreate");
264 f.WriteObject(&aVec,
"myVec3");
268 TFile f2(fNameVec.c_str());
269 if (f2.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
274 f2.GetObject(
"myVec3", retrievedVector);
277 EXPECT_DOUBLE_EQ(aVec.
X(), retrievedVector->
X());
278 EXPECT_DOUBLE_EQ(aVec.
Y(), retrievedVector->
Y());
279 EXPECT_DOUBLE_EQ(aVec.
Z(), retrievedVector->
Z());
283 if (remove(fNameVec.c_str()) != 0)
284 { B2ERROR(
"could not delete file " << fNameVec <<
"!"); }
286 { B2INFO(fNameVec <<
" successfully deleted"); }
296 string fNameSP =
"demoSPs.root";
302 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
306 EXPECT_EQ(aVxdID, testPoint.
getVxdID());
310 B2INFO(
"open root file:" << fNameSP);
311 TFile f3(fNameSP.c_str(),
"recreate");
314 B2INFO(
"closing file:");
318 TFile f4(fNameSP.c_str());
319 if (f4.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
322 f4.GetListOfKeys()->Print();
324 TIter next(f4.GetListOfKeys());
326 while ((key = (TKey*)next())) {
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...");
348 if (remove(fNameSP.c_str()) != 0)
349 { B2ERROR(
"could not delete file " << fNameSP <<
"!"); }
351 { B2INFO(fNameSP <<
" successfully deleted"); }
366 pair<float, float> sensorCenter = {1.15, 2.1};
368 pair<float, float> hitLocal05 = {0, 0};
369 pair<float, float> resultNormalized05 = {0.5, 0.5};
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};
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};
381 pair<float, float> hitLocal001088 = {0.023, 3.696};
382 hitLocal001088.first -= sensorCenter.first;
383 hitLocal001088.second -= sensorCenter.second;
384 pair<float, float> resultNormalized001088 = {0.01, 0.88};
386 pair<float, float> hitLocalMinMax = { -1.16, 500};
387 pair<float, float> resultNormalizedMinMax = {0., 1.};
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);
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.);
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);
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);
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);
421 pair<float, float> sensorCenter = {1.15, 2.1};
423 pair<float, float> hitNormalized05 = {0.5, 0.5};
424 pair<float, float> resultLocal05 = {0, 0};
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;
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;
436 pair<float, float> hitNormalized001088 = {0.01, 0.88};
437 pair<float, float> resultLocal001088 = {0.023, 3.696};
438 resultLocal001088.first -= sensorCenter.first;
439 resultLocal001088.second -= sensorCenter.second;
441 pair<float, float> hitNormalizedMinMax = { -0.1, 4.2};
442 pair<float, float> resultLocalMinMax = { -1.15, 2.1};
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);
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);
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);
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);
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);
476 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
482 aVxdID =
VxdID(3, 1, 2);
483 sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2, -1, VXD::SensorInfoBase::SVD);
490 vector<const SVDCluster*> clusters2d = { &clusterU1, &clusterV1 };
494 vector<const SVDCluster*> clustersU = { &clusterU1 };
498 vector<const SVDCluster*> clustersV = { &clusterV1 };
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
float getV() const
Get v coordinate of hit position.
float getUSigma() const
Get error of u coordinate of hit position.
float getVSigma() const
Get error in v coordinate of hit position.
VxdID getSensorID() const
Get the sensor ID.
float getU() const
Get u coordinate of hit position.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
float getPositionSigma() const
Get the error of the reconstructed hit coordinate.
Set up a few arrays and objects in the datastore.
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
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
const B2Vector3< double > & getPosition() const
return the position vector in global coordinates
unsigned short getNClustersAssigned() const
Returns the number of Clusters assigned to this SpacePoint.
double getNormalizedLocalV() const
Return normalized local coordinates of the cluster in v (0 <= posV <= 1).
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
const B2Vector3< double > & getPositionError() const
return the hitErrors in sigma of the global position
double getNormalizedLocalU() const
Return normalized local coordinates of the cluster in u (0 <= posU <= 1).
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.
TEST_F(SpacePointTest, testGetNClustersAssigned)
Test if the number of assigned Clusters is obtained correctly NOTE: using the same constructors as in...
Abstract base class for different kinds of events.