Belle II Software  release-05-01-25
topology.test.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost <oliver.frost@desy.de> *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <gtest/gtest.h>
11 #include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
12 
13 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCBFieldUtil.h>
14 #include <tracking/trackFindingCDC/testFixtures/TrackFindingCDCTestWithTopology.h>
15 #include <cdc/geometry/CDCGeometryPar.h>
16 #include <framework/logging/Logger.h>
17 
18 using namespace Belle2;
19 using namespace TrackFindingCDC;
20 
21 class SecondaryWireNeighborhoodTest : public TrackFindingCDCTestWithTopology,
22  public ::testing::WithParamInterface<int> {
23 };
24 
25 TEST_P(SecondaryWireNeighborhoodTest, IsSymmetric)
26 {
27  WireNeighborKind testNeighborKind(2, GetParam());
28  short oClockDirection = testNeighborKind.getOClockDirection();
29  short reverseOClockDirection = modulo(testNeighborKind.getOClockDirection() + 6, 12);
30 
31  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
32 
33  for (const CDCWire& wire : theWireTopology.getWires()) {
34  MayBePtr<const CDCWire> neighbor = wire.getSecondaryNeighbor(oClockDirection);
35  if (neighbor != nullptr) {
36  MayBePtr<const CDCWire> neighbor_of_neighbor =
37  neighbor->getSecondaryNeighbor(reverseOClockDirection);
38 
39  EXPECT_EQ(*neighbor_of_neighbor, wire);
40 
41  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
42  EXPECT_TRUE(neighborKind.isValid());
43  EXPECT_EQ(testNeighborKind.getCellDistance(), neighborKind.getCellDistance());
44  EXPECT_EQ(oClockDirection, neighborKind.getOClockDirection());
45  EXPECT_EQ(neighbor->getILayer() - wire.getILayer(), neighborKind.getILayerDifference());
46  }
47  }
48 }
49 
50 INSTANTIATE_TEST_CASE_P(SecondaryWireNeighborhoodTest_IsSymmetric,
52  ::testing::Range(0, 12));
53 
54 
55 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CWInwards)
56 {
57 
58  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
59 
60  for (const CDCWire& wire : theWireTopology.getWires()) {
61  MayBePtr<const CDCWire> neighbor = wire.getNeighborCWInwards();
62  if (neighbor != nullptr) {
63  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCCWOutwards();
64  EXPECT_EQ(*neighbor_of_neighbor, wire);
65 
66  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
67  EXPECT_EQ(1, neighborKind.getCellDistance());
68  EXPECT_EQ(5, neighborKind.getOClockDirection());
69  EXPECT_EQ(-1, neighborKind.getILayerDifference());
70  }
71  }
72 }
73 
74 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CCWInwards)
75 {
76 
77  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
78 
79  for (const CDCWire& wire : theWireTopology.getWires()) {
80  MayBePtr<const CDCWire> neighbor = wire.getNeighborCCWInwards();
81  if (neighbor != nullptr) {
82  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCWOutwards();
83  EXPECT_EQ(*neighbor_of_neighbor, wire);
84 
85  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
86  EXPECT_EQ(1, neighborKind.getCellDistance());
87  EXPECT_EQ(7, neighborKind.getOClockDirection());
88  EXPECT_EQ(-1, neighborKind.getILayerDifference());
89  }
90  }
91 }
92 
93 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CWOutwards)
94 {
95 
96  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
97 
98  for (const CDCWire& wire : theWireTopology.getWires()) {
99  MayBePtr<const CDCWire> neighbor = wire.getNeighborCWOutwards();
100  if (neighbor != nullptr) {
101  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCCWInwards();
102  EXPECT_EQ(*neighbor_of_neighbor, wire);
103 
104  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
105  EXPECT_EQ(1, neighborKind.getCellDistance());
106  EXPECT_EQ(1, neighborKind.getOClockDirection());
107  EXPECT_EQ(1, neighborKind.getILayerDifference());
108  }
109  }
110 }
111 
112 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CCWOutwards)
113 {
114 
115  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
116 
117  for (const CDCWire& wire : theWireTopology.getWires()) {
118  MayBePtr<const CDCWire> neighbor = wire.getNeighborCCWOutwards();
119  if (neighbor != nullptr) {
120  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCWInwards();
121  EXPECT_EQ(*neighbor_of_neighbor, wire);
122 
123  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
124  EXPECT_EQ(1, neighborKind.getCellDistance());
125  EXPECT_EQ(11, neighborKind.getOClockDirection());
126  EXPECT_EQ(1, neighborKind.getILayerDifference());
127  }
128  }
129 }
130 
131 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CCW)
132 {
133 
134  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
135 
136  for (const CDCWire& wire : theWireTopology.getWires()) {
137  MayBePtr<const CDCWire> neighbor = wire.getNeighborCCW();
138  if (neighbor != nullptr) {
139  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCW();
140  EXPECT_EQ(*neighbor_of_neighbor, wire);
141 
142  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
143  EXPECT_EQ(1, neighborKind.getCellDistance());
144  EXPECT_EQ(9, neighborKind.getOClockDirection());
145  EXPECT_EQ(0, neighborKind.getILayerDifference());
146  }
147  }
148 }
149 
150 TEST_F(TrackFindingCDCTestWithTopology, topology_WireNeighborSymmetry_CW)
151 {
152 
153  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
154 
155  for (const CDCWire& wire : theWireTopology.getWires()) {
156  MayBePtr<const CDCWire> neighbor = wire.getNeighborCW();
157  if (neighbor != nullptr) {
158  MayBePtr<const CDCWire> neighbor_of_neighbor = neighbor->getNeighborCCW();
159  EXPECT_EQ(*neighbor_of_neighbor, wire);
160 
161  WireNeighborKind neighborKind = wire.getNeighborKind(*neighbor);
162  EXPECT_EQ(1, neighborKind.getCellDistance());
163  EXPECT_EQ(3, neighborKind.getOClockDirection());
164  EXPECT_EQ(0, neighborKind.getILayerDifference());
165  }
166  }
167 }
168 
169 TEST_F(TrackFindingCDCTestWithTopology, topology_CDCWire_stereoAngle)
170 {
171  // Test if the all wires in the same superlayer have similar skew parameters.
172 
173  double tanThetaByICLayer[CDCWireTopology::c_NLayers];
174  double stereoAngleByICLayer[CDCWireTopology::c_NLayers];
175  double refCylindricalRByICLayer[CDCWireTopology::c_NLayers];
176 
177  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
178  for (const CDCWireLayer& wireLayer : theWireTopology.getWireLayers()) {
179  const ILayer iCLayer = wireLayer.getICLayer();
180 
181  const CDCWire& firstWire = wireLayer.front();
182  tanThetaByICLayer[iCLayer] = firstWire.getTanStereoAngle();
183  stereoAngleByICLayer[iCLayer] = firstWire.getStereoAngle();
184  refCylindricalRByICLayer[iCLayer] = firstWire.getRefCylindricalR();
185 
186  for (const CDCWire& wire : wireLayer) {
187  // this limits can change when a per-wire alignment is done using CDC dat
188  // therefore, this test might fail in the future, if new aligments for the CDC
189  // are created.
190  EXPECT_NEAR(tanThetaByICLayer[iCLayer], wire.getTanStereoAngle(), 10e-2);
191  EXPECT_NEAR(stereoAngleByICLayer[iCLayer], wire.getStereoAngle(), 10e-2);
192  EXPECT_NEAR(refCylindricalRByICLayer[iCLayer], wire.getRefCylindricalR(), 10e-2);
193  }
194 
195  B2INFO("ICLayer : " << iCLayer);
196  B2INFO(" Tan Theta : " << tanThetaByICLayer[iCLayer]);
197  B2INFO(" Stereo angle : " << stereoAngleByICLayer[iCLayer]);
198  B2INFO(" Z range : " << wireLayer.getBackwardZ() << " to " << wireLayer.getForwardZ());
199  B2INFO(" Ref. cylindricalR : " << refCylindricalRByICLayer[iCLayer]);
200  B2INFO(" Max abs displacement : " << wireLayer.getWire(0).getWireVector().xy().norm());
201  }
202 
203 }
204 
205 
206 
207 TEST_F(TrackFindingCDCTestWithTopology, topology_RefCylindricalRVersusZInSuperLayers)
208 {
209  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
210  for (const CDCWireSuperLayer& wireSuperLayer : theWireTopology.getWireSuperLayers()) {
211  if (wireSuperLayer.getStereoKind() == EStereoKind::c_Axial) {
212  EXPECT_EQ(0.0, wireSuperLayer.getRefTanLambda());
213  }
214 
215  B2INFO("ISuperLayer : " << wireSuperLayer.getISuperLayer() <<
216  " Inner ref. z : " << wireSuperLayer.getInnerRefZ() <<
217  " Outer ref. z : " << wireSuperLayer.getOuterRefZ() <<
218  " CylindricalR Z slope : " << wireSuperLayer.getRefTanLambda()
219  );
220 
221  }
222 }
223 
224 TEST_F(TrackFindingCDCTestWithTopology, topology_ShowCurlCurv)
225 {
226  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
227 
228  double outerR = theWireTopology.getOuterCylindricalR();
229  double innerR = theWireTopology.getInnerCylindricalR();
230 
231  double innerOriginCurv = 1 / (innerR / 2);
232  double outerOriginCurv = 1 / (outerR / 2);
233 
234  double innerCurlCurv = 1 / innerR;
235  double outerCurlCurv = 1 / outerR;
236 
237  B2INFO("Maximal curvature still reaching the CDC from IP : " << innerOriginCurv);
238  B2INFO("Minimal momentum still reaching the CDC from IP : " << CDCBFieldUtil::curvatureToAbsMom2D(innerOriginCurv, 1.5) << " GeV");
239 
240  B2INFO("Maximal curvature still leaving the CDC from IP : " << outerOriginCurv);
241  B2INFO("Minimal momentum still leaving the CDC from IP : " << CDCBFieldUtil::curvatureToAbsMom2D(outerOriginCurv, 1.5) << " GeV");
242 
243 
244  B2INFO("Minimal curvature not reaching the CDC from VXD : " << innerCurlCurv);
245  B2INFO("Maximal momentum not reaching the CDC from VXD : " << CDCBFieldUtil::curvatureToAbsMom2D(innerCurlCurv, 1.5) << " GeV");
246 
247  B2INFO("Minimal curvature not leaving the CDC from inside the CDC : " << outerCurlCurv);
248  B2INFO("Maximal momentum not leaving the CDC from inside the CDC : " << CDCBFieldUtil::curvatureToAbsMom2D(outerCurlCurv,
249  1.5) << " GeV");
250 
251  for (const CDCWireSuperLayer& wireSuperLayer : theWireTopology.getWireSuperLayers()) {
252  double innerSLCurv = 1 / wireSuperLayer.getInnerCylindricalR();
253  B2INFO("Maximal curvature still reaching SL " << wireSuperLayer.getISuperLayer() << " from IP : " << innerSLCurv);
254  B2INFO("Minimal momentum still reaching SL " << wireSuperLayer.getISuperLayer() << " from IP : " <<
255  CDCBFieldUtil::curvatureToAbsMom2D(innerSLCurv, 1.5) << " GeV");
256  }
257 }
258 
259 TEST_F(TrackFindingCDCTestWithTopology, topology_ShowLayerLimits)
260 {
261  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
262  ISuperLayer iL = -1;
263  for (const CDCWireLayer& wireLayer : theWireTopology.getWireLayers()) {
264  ++iL;
265  B2INFO("Layer " << iL << ":");
266  B2INFO("z in " << wireLayer.getForwardZ() << ", " << wireLayer.getBackwardZ());
267  B2INFO("r in " << wireLayer.getInnerCylindricalR() << ", " << wireLayer.getOuterCylindricalR());
268  }
269 }
270 
271 TEST_F(TrackFindingCDCTestWithTopology, topology_CDCGeometryPar_cellId)
272 {
273  // Testing for a discrepancy in the cellId method of CDCGeometryPar
274  // Example in layer four
275  unsigned iCLayer = 4;
276 
277  // Middle of the layer four
278  TVector3 posInMiddle(0, 0, 20.8);
279 
280  unsigned iWireInFourthLayer = CDC::CDCGeometryPar::Instance().cellId(iCLayer, posInMiddle);
281  EXPECT_TRUE(iWireInFourthLayer < 160);
282  EXPECT_LT(iWireInFourthLayer, 160);
283 }
284 
285 TEST_F(TrackFindingCDCTestWithTopology, topology_sag)
286 {
287  const CDCWireTopology& theWireTopology = CDCWireTopology::getInstance();
288  for (const CDCWire& wire : theWireTopology.getWires()) {
289  const WireLine& wireLine = wire.getWireLine();
290  const double forwardZ = wireLine.forwardZ();
291  const double backwardZ = wireLine.backwardZ();
292  const double centerZ = (forwardZ + backwardZ) / 2;
293 
294  EXPECT_LE(0, wireLine.sagCoeff());
295 
296  EXPECT_EQ(wireLine.nominalPos2DAtZ(forwardZ).y(), wireLine.sagPos2DAtZ(forwardZ).y());
297  EXPECT_EQ(wireLine.nominalPos2DAtZ(backwardZ).y(), wireLine.sagPos2DAtZ(backwardZ).y());
298  EXPECT_GE(wireLine.nominalPos2DAtZ(centerZ).y(), wireLine.sagPos2DAtZ(centerZ).y());
299 
300  EXPECT_LE(wireLine.nominalMovePerZ().y(), wireLine.sagMovePerZ(forwardZ).y());
301  EXPECT_GE(wireLine.nominalMovePerZ().y(), wireLine.sagMovePerZ(backwardZ).y());
302  EXPECT_EQ(wireLine.nominalMovePerZ().y(), wireLine.sagMovePerZ(centerZ).y());
303  }
304 }
Belle2::TrackFindingCDC::CDCWireTopology::getInstance
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Definition: CDCWireTopology.cc:22
Belle2::TrackFindingCDC::CDCWireTopology::c_NLayers
static const ILayer c_NLayers
Total number of layers.
Definition: CDCWireTopology.h:76
SecondaryWireNeighborhoodTest
Definition: topology.test.cc:21
Belle2::TrackFindingCDC::CDCBFieldUtil::curvatureToAbsMom2D
static double curvatureToAbsMom2D(double curvature, double bZ)
Conversion helper for two dimensional curvature to momenta.
Definition: CDCBFieldUtil.cc:132
Belle2::CDC::CDCGeometryPar::Instance
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Definition: CDCGeometryPar.cc:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST_F
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:65
Belle2::CDC::CDCGeometryPar::cellId
unsigned cellId(unsigned layerId, const TVector3 &position) const
The method to get cell id based on given layer id and the position.
Definition: CDCGeometryPar.cc:1733