ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DoubleHitSpacePointBuilderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DoubleHitSpacePointBuilderTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
18 
19 namespace bdata = boost::unit_test::data;
20 namespace tt = boost::test_tools;
21 using namespace Acts::UnitLiterals;
22 
23 namespace Acts {
24 namespace Test {
25 
26 // Create a test context
28 
32 BOOST_DATA_TEST_CASE(DoubleHitsSpacePointBuilder_basic, bdata::xrange(1),
33  index) {
34  (void)index;
35 
36  std::cout << "Create first hit" << std::endl;
37 
38  // Build Bounds
39  std::shared_ptr<const RectangleBounds> recBounds(
40  new RectangleBounds(35_um, 25_mm));
41 
42  // Build binning and segmentation
43  std::vector<float> boundariesX, boundariesY;
44  boundariesX.push_back(-35_um);
45  boundariesX.push_back(35_um);
46  boundariesY.push_back(-25_mm);
47  boundariesY.push_back(25_mm);
48 
49  BinningData binDataX(BinningOption::open, BinningValue::binX, boundariesX);
50  std::shared_ptr<BinUtility> buX(new BinUtility(binDataX));
51  BinningData binDataY(BinningOption::open, BinningValue::binY, boundariesY);
52  std::shared_ptr<BinUtility> buY(new BinUtility(binDataY));
53  (*buX) += (*buY);
54 
55  std::shared_ptr<const Segmentation> segmentation(
56  new CartesianSegmentation(buX, recBounds));
57 
58  // Build translation
59 
60  double rotation = 0.026;
61  RotationMatrix3D rotationPos;
62  Vector3D xPos(cos(rotation), sin(rotation), 0.);
63  Vector3D yPos(-sin(rotation), cos(rotation), 0.);
64  Vector3D zPos(0., 0., 1.);
65  rotationPos.col(0) = xPos;
66  rotationPos.col(1) = yPos;
67  rotationPos.col(2) = zPos;
68  Transform3D t3d(Transform3D::Identity() * rotationPos);
69  t3d.translation() = Vector3D(0., 0., 10_m);
70 
71  // Build Digitization
72  const DigitizationModule digMod(segmentation, 1., 1., 0.);
73  DetectorElementStub detElem(std::make_shared<const Transform3D>(t3d));
74  auto pSur = Surface::makeShared<PlaneSurface>(recBounds, detElem);
76  cov << 0., 0., 0., 0., 0., 0., 0., 0., 0.;
77  Vector2D local = {0.1, -0.1};
78 
79  // Build PlanarModuleCluster
80  PlanarModuleCluster* pmc =
81  new PlanarModuleCluster(pSur, {}, cov, local[0], local[1], 0.,
82  {DigitizationCell(0, 0, 1.)}, &digMod);
83 
84  std::cout << "Create second hit" << std::endl;
85 
86  // Build second PlanarModuleCluster
87 
88  double rotation2 = -0.026;
89  RotationMatrix3D rotationNeg;
90  Vector3D xNeg(cos(rotation2), sin(rotation2), 0.);
91  Vector3D yNeg(-sin(rotation2), cos(rotation2), 0.);
92  Vector3D zNeg(0., 0., 1.);
93  rotationNeg.col(0) = xNeg;
94  rotationNeg.col(1) = yNeg;
95  rotationNeg.col(2) = zNeg;
96  Transform3D t3d2(Transform3D::Identity() * rotationNeg);
97  t3d2.translation() = Vector3D(0., 0., 10.005_m);
98 
99  DetectorElementStub detElem2(std::make_shared<const Transform3D>(t3d2));
100 
101  auto pSur2 = Surface::makeShared<PlaneSurface>(recBounds, detElem2);
102 
103  PlanarModuleCluster* pmc2 =
104  new PlanarModuleCluster(pSur2, {}, cov, local[0], local[1], 0.,
105  {DigitizationCell(0, 0, 1.)}, &digMod);
106 
107  std::cout << "Store both hits" << std::endl;
108 
109  std::vector<SpacePoint<PlanarModuleCluster>> resultSP;
110  std::vector<std::pair<PlanarModuleCluster const*, PlanarModuleCluster const*>>
111  clusterPairs;
112  DoubleHitSpacePointConfig dhsp_cfg;
113 
114  // Combine two PlanarModuleClusters
116  dhsp.makeClusterPairs(tgContext, {pmc}, {pmc2}, clusterPairs);
117 
118  BOOST_CHECK_EQUAL(clusterPairs.size(), 1u);
119  BOOST_CHECK_EQUAL(*(clusterPairs[0].first), *pmc);
120  BOOST_CHECK_EQUAL(*(clusterPairs[0].second), *pmc2);
121 
122  std::cout << "Calculate space point" << std::endl;
123 
124  dhsp.calculateSpacePoints(tgContext, clusterPairs, resultSP);
125 
126  BOOST_CHECK_EQUAL(resultSP.size(), 1u);
127 
128  std::cout << "Create third hit" << std::endl;
129 
130  // Build third PlanarModuleCluster
131  Transform3D t3d3(Transform3D::Identity() * rotationNeg);
132  t3d3.translation() = Vector3D(0., 0., 10.005_m);
133 
134  DetectorElementStub detElem3(std::make_shared<const Transform3D>(t3d3));
135  auto pSur3 = Surface::makeShared<PlaneSurface>(recBounds, detElem3);
136 
137  PlanarModuleCluster* pmc3 =
138  new PlanarModuleCluster(pSur3, {}, cov, local[0], local[1], 0.,
139  {DigitizationCell(0, 0, 1.)}, &digMod);
140 
141  std::cout << "Try to store hits" << std::endl;
142 
143  // Combine points
144  dhsp.makeClusterPairs(tgContext, {pmc}, {pmc3}, clusterPairs);
145 
146  // Test for rejecting unconnected hits
147  BOOST_CHECK_EQUAL(resultSP.size(), 1u);
148 }
149 
150 } // end of namespace Test
151 } // end of namespace Acts