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