EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProtoLayerHelperTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProtoLayerHelperTests.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 
21 
22 #include <cmath>
23 
24 namespace Acts {
25 
26 namespace Test {
27 namespace Layers {
28 BOOST_AUTO_TEST_SUITE(Geometry)
29 
30 BOOST_AUTO_TEST_CASE(ProtoLayerHelperTests) {
31  ProtoLayerHelper::Config plhConfig;
32  ProtoLayerHelper plHelper(
33  plhConfig, getDefaultLogger("ProtoLayerHelper", Logging::VERBOSE));
34 
36 
37  ObjVisualization3D objVis;
38 
39  CylindricalTrackingGeometry ctGeometry(tgContext);
41 
43  std::vector<double> layerRadii = {32., 72., 116., 172.};
44  std::vector<std::pair<int, int>> layerBinning = {
45  {16, 14}, {32, 14}, {52, 14}, {78, 14}};
46  std::vector<double> moduleTiltPhi = {0.145, 0.145, 0.145, 0.145};
47  std::vector<double> moduleHalfX = {8.4, 8.4, 8.4, 8.4};
48  std::vector<double> moduleHalfY = {36., 36., 36., 36.};
49  std::vector<double> moduleThickness = {0.15, 0.15, 0.15, 0.15};
50 
51  std::vector<const Surface*> cylinderSurfaces;
52  for (size_t ilp = 0; ilp < layerRadii.size(); ++ilp) {
53  std::vector<const Surface*> layerSurfaces = ctGeometry.surfacesCylinder(
54  dStore, moduleHalfX[ilp], moduleHalfY[ilp], moduleThickness[ilp],
55  moduleTiltPhi[ilp], layerRadii[ilp], 2., 5., layerBinning[ilp]);
56  cylinderSurfaces.insert(cylinderSurfaces.begin(), layerSurfaces.begin(),
57  layerSurfaces.end());
58  }
59 
60  ViewConfig unsorted({252, 160, 0});
61  for (auto& sf : cylinderSurfaces) {
62  GeometryView3D::drawSurface(objVis, *sf, tgContext, Transform3D::Identity(),
63  unsorted);
64  }
65  // Draw the all surfaces
66  objVis.write("ProtoLayerHelper_CylinderLayers_unsorted");
67  objVis.clear();
68 
69  // Sort into ProtoLayers
70  auto radialLayers = plHelper.protoLayers(
71  tgContext, cylinderSurfaces, ProtoLayerHelper::SortingConfig(binR, 5.));
72 
73  BOOST_CHECK(radialLayers.size() == 4);
74 
75  std::vector<ColorRGB> sortedColors = {{102, 204, 255},
76  {102, 255, 153},
77  {255, 204, 102},
78  {204, 102, 0},
79  {278, 123, 55}};
80 
81  size_t il = 0;
82  for (auto& layer : radialLayers) {
83  for (auto& sf : layer.surfaces()) {
84  ViewConfig sorted(sortedColors[il]);
85  GeometryView3D::drawSurface(objVis, *sf, tgContext,
86  Transform3D::Identity(), sorted);
87  }
88  ++il;
89  }
90 
91  // Draw the sorted surfaces
92  objVis.write("ProtoLayerHelper_CylinderLayers_radially");
93  objVis.clear();
94 
96  std::vector<const Surface*> discSurfaces;
97 
98  std::vector<double> discZ = {-350., -250., -150., -100.};
99  std::vector<double> discRadii = {55., 55., 55., 55.};
100  std::vector<int> discModules = {22, 22, 22, 22};
101 
102  std::vector<double> dModuleHalfXMinY = {6.4, 6.4, 6.4, 6.4};
103  std::vector<double> dModuleHalfXMaxY = {12.4, 12.4, 12.4, 12.4};
104  std::vector<double> dModuleHalfY = {36., 36., 36., 36.};
105  std::vector<double> dModuleTilt = {0.075, 0.075, 0.075, 0.075};
106  std::vector<double> dModuleThickness = {0.15, 0.15, 0.15, 0.15};
107 
108  for (size_t ilp = 0; ilp < discZ.size(); ++ilp) {
109  std::vector<const Surface*> layerSurfaces = ctGeometry.surfacesRing(
110  dStore, dModuleHalfXMinY[ilp], dModuleHalfXMaxY[ilp], dModuleHalfY[ilp],
111  dModuleThickness[ilp], dModuleTilt[ilp], discRadii[ilp], discZ[ilp], 2.,
112  discModules[ilp]);
113  discSurfaces.insert(discSurfaces.begin(), layerSurfaces.begin(),
114  layerSurfaces.end());
115  }
116 
117  for (auto& sf : discSurfaces) {
118  GeometryView3D::drawSurface(objVis, *sf, tgContext);
119  }
120  // Draw the all surfaces
121  objVis.write("ProtoLayerHelper_DiscLayers_unsorted");
122  objVis.clear();
123 
124  // Sort into ProtoLayers
125  auto discLayersZ = plHelper.protoLayers(tgContext, discSurfaces, {binZ, 5.});
126 
127  BOOST_CHECK(discLayersZ.size() == 4);
128 
129  il = 0;
130  for (auto& layer : discLayersZ) {
131  for (auto& sf : layer.surfaces()) {
132  ViewConfig ViewConfig(sortedColors[il]);
133  GeometryView3D::drawSurface(objVis, *sf, tgContext,
134  Transform3D::Identity(), ViewConfig);
135  }
136  ++il;
137  }
138 
139  // Draw the sorted surfaces
140  objVis.write("ProtoLayerHelper_DiscLayers_longitudinally");
141  objVis.clear();
142 
144  std::vector<const Surface*> ringSurfaces;
145 
146  std::vector<double> ringZ = {-350., -250., -150., -100., -360., -255.,
147  -120., -330., -260., -150., -95.};
148  std::vector<double> ringRadii = {32., 32., 32., 32., 58., 58.,
149  58., 84., 84., 84., 84.};
150  std::vector<int> ringModules = {22, 22, 22, 22, 32, 32, 32, 44, 44, 44, 44};
151 
152  std::vector<double> rModuleHalfXMinY(11, 6.4);
153  std::vector<double> rModuleHalfXMaxY(11, 6.4);
154  std::vector<double> rModuleHalfY(11, 10.);
155  std::vector<double> rModuleTilt(11, 0.075);
156  std::vector<double> rModuleThickness(11, 0.15);
157 
158  for (size_t ilp = 0; ilp < ringZ.size(); ++ilp) {
159  std::vector<const Surface*> layerSurfaces = ctGeometry.surfacesRing(
160  dStore, rModuleHalfXMinY[ilp], rModuleHalfXMaxY[ilp], rModuleHalfY[ilp],
161  rModuleThickness[ilp], rModuleTilt[ilp], ringRadii[ilp], ringZ[ilp], 2.,
162  ringModules[ilp]);
163  ringSurfaces.insert(ringSurfaces.begin(), layerSurfaces.begin(),
164  layerSurfaces.end());
165  }
166 
167  for (auto& sf : ringSurfaces) {
168  GeometryView3D::drawSurface(objVis, *sf, tgContext);
169  }
170  // Draw the all surfaces
171  objVis.write("ProtoLayerHelper_RingLayers_unsorted");
172  objVis.clear();
173 
174  // First: Sort into ProtoLayers radially
175  auto rSorted = plHelper.protoLayers(
176  tgContext, ringSurfaces, ProtoLayerHelper::SortingConfig(binR, 1.));
177  BOOST_CHECK(rSorted.size() == 3);
178 
179  ColorRGB dColor = {0, 0, 0};
180 
181  int ir = 0;
182  for (auto& rBatch : rSorted) {
183  auto lSorted =
184  plHelper.protoLayers(tgContext, rBatch.surfaces(),
186  il = 0;
187  dColor[ir] = 256;
188  for (auto& layer : lSorted) {
189  dColor[ir] -= il * 50;
190  for (auto& sf : layer.surfaces()) {
191  GeometryView3D::drawSurface(objVis, *sf, tgContext);
192  }
193  ++il;
194  }
195  ++ir;
196  }
197  // Draw the all surfaces
198  objVis.write("ProtoLayerHelper_RingLayers_sorted");
199 
200  // Perform the split at once
201  auto rzSorted =
202  plHelper.protoLayers(tgContext, ringSurfaces, {{binR, 1.}, {binZ, 5}});
203 
204  size_t irz = 0;
205  for (auto& layer : rzSorted) {
206  for (auto& sf : layer.surfaces()) {
207  GeometryView3D::drawSurface(objVis, *sf, tgContext);
208  }
209  objVis.write("ProtoLayerHelper_RingLayers_rz_sorted" +
210  std::to_string(irz++));
211  objVis.clear();
212  }
213 }
214 
215 BOOST_AUTO_TEST_SUITE_END()
216 } // namespace Layers
217 } // namespace Test
218 
219 } // namespace Acts