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 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(
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())));
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());
119 std::vector<const SVDCluster*> good2D = { &clusterU1, &clusterV1 };
123 std::vector<const SVDCluster*> good1D = { &clusterU3 };
128 std::vector<const SVDCluster*> badNoClusters;
129 EXPECT_B2FATAL(
SpacePoint(badNoClusters, &sensorInfoBase));
132 std::vector<const SVDCluster*> bad3Clusters = { &clusterU1, &clusterV1, &clusterU2 };
133 EXPECT_B2FATAL(
SpacePoint(bad3Clusters, &sensorInfoBase));
136 std::vector<const SVDCluster*> badSameType = { &clusterU1, &clusterU2 };
137 EXPECT_B2FATAL(
SpacePoint(badSameType, &sensorInfoBase));
140 std::vector<const SVDCluster*> badDifferentSensors = { &clusterV1, &clusterU3 };
141 EXPECT_B2FATAL(
SpacePoint(badDifferentSensors, &sensorInfoBase));
147 ROOT::Math::XYZVector globalizedVariancesFor2D = sensorInfoBase.
vectorToGlobal(
148 ROOT::Math::XYZVector(
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())));
161 EXPECT_EQ(aVxdID, testPoint2D.
getVxdID());
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());
176 ROOT::Math::XYZVector aPositionFor1D = anotherSensorInfoBase.
pointToGlobal(ROOT::Math::XYZVector(clusterU3.
getPosition(), 0, 0),
178 ROOT::Math::XYZVector globalizedVariancesFor1D = anotherSensorInfoBase.
vectorToGlobal(
179 ROOT::Math::XYZVector(
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())));
193 EXPECT_EQ(anotherVxdID, testPoint1D.
getVxdID());
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());
211 string fNameCluster =
"demoClusters.root";
217 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
221 B2INFO(
"open root file: " << fNameCluster);
222 TFile f(fNameCluster.c_str(),
"recreate");
228 TFile f2(fNameCluster.c_str());
229 if (f2.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
232 f2.GetListOfKeys()->Print();
234 TIter next(f2.GetListOfKeys());
236 while ((key = (TKey*)next())) {
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...");
250 if (remove(fNameCluster.c_str()) != 0)
251 { B2ERROR(
"could not delete file " << fNameCluster <<
"!"); }
253 { B2INFO(fNameCluster <<
" successfully deleted"); }
262 string fNameVec =
"demoB2Vector3s.root";
269 B2INFO(
"open root file: " << fNameVec);
270 TFile f(fNameVec.c_str(),
"recreate");
272 f.WriteObject(&aVec,
"myVec3");
276 TFile f2(fNameVec.c_str());
277 if (f2.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
282 f2.GetObject(
"myVec3", retrievedVector);
285 EXPECT_DOUBLE_EQ(aVec.
X(), retrievedVector->
X());
286 EXPECT_DOUBLE_EQ(aVec.
Y(), retrievedVector->
Y());
287 EXPECT_DOUBLE_EQ(aVec.
Z(), retrievedVector->
Z());
291 if (remove(fNameVec.c_str()) != 0)
292 { B2ERROR(
"could not delete file " << fNameVec <<
"!"); }
294 { B2INFO(fNameVec <<
" successfully deleted"); }
304 string fNameSP =
"demoSPs.root";
310 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
314 EXPECT_EQ(aVxdID, testPoint.
getVxdID());
318 B2INFO(
"open root file:" << fNameSP);
319 TFile f3(fNameSP.c_str(),
"recreate");
322 B2INFO(
"closing file:");
326 TFile f4(fNameSP.c_str());
327 if (f4.IsZombie()) { B2ERROR(
"file could not be reopened!"); }
330 f4.GetListOfKeys()->Print();
332 TIter next(f4.GetListOfKeys());
334 while ((key = (TKey*)next())) {
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...");
356 if (remove(fNameSP.c_str()) != 0)
357 { B2ERROR(
"could not delete file " << fNameSP <<
"!"); }
359 { B2INFO(fNameSP <<
" successfully deleted"); }
374 pair<float, float> sensorCenter = {1.15, 2.1};
376 pair<float, float> hitLocal05 = {0, 0};
377 pair<float, float> resultNormalized05 = {0.5, 0.5};
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};
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};
389 pair<float, float> hitLocal001088 = {0.023, 3.696};
390 hitLocal001088.first -= sensorCenter.first;
391 hitLocal001088.second -= sensorCenter.second;
392 pair<float, float> resultNormalized001088 = {0.01, 0.88};
394 pair<float, float> hitLocalMinMax = { -1.16, 500};
395 pair<float, float> resultNormalizedMinMax = {0., 1.};
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);
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.);
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);
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);
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);
429 pair<float, float> sensorCenter = {1.15, 2.1};
431 pair<float, float> hitNormalized05 = {0.5, 0.5};
432 pair<float, float> resultLocal05 = {0, 0};
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;
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;
444 pair<float, float> hitNormalized001088 = {0.01, 0.88};
445 pair<float, float> resultLocal001088 = {0.023, 3.696};
446 resultLocal001088.first -= sensorCenter.first;
447 resultLocal001088.second -= sensorCenter.second;
449 pair<float, float> hitNormalizedMinMax = { -0.1, 4.2};
450 pair<float, float> resultLocalMinMax = { -1.15, 2.1};
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);
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);
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);
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);
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);
484 PXDCluster aCluster =
PXDCluster(aVxdID, 0., 0., 0.1, 0.1, 0, 0, 1, 1, 1, 1, 1, 1);
490 aVxdID =
VxdID(3, 1, 2);
491 sensorInfoBase = createSensorInfo(aVxdID, 2.3, 4.2, -1, VXD::SensorInfoBase::SVD);
498 vector<const SVDCluster*> clusters2d = { &clusterU1, &clusterV1 };
502 vector<const SVDCluster*> clustersU = { &clusterU1 };
506 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.
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.
double sqrt(double a)
sqrt for double
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.