Belle II Software  release-08-01-10
SensorInfo.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <vxd/geometry/SensorInfoBase.h>
9 #include <vxd/geometry/SensorPlane.h>
10 #include <framework/utilities/TestHelpers.h>
11 #include <gtest/gtest.h>
12 #include <iostream>
13 #include <string>
14 #include <cmath>
15 
16 using namespace std;
17 
18 namespace Belle2 {
23  namespace VXD {
24 
29  TEST(SensorInfoBase, Rectangular)
30  {
31  SensorInfoBase rect(SensorInfoBase::PXD, VxdID(1, 2, 3), 1.0, 2.0, 3.0, 2, 4);
32  EXPECT_EQ(rect.getType(), SensorInfoBase::PXD);
33  EXPECT_EQ(rect.getID(), VxdID(1, 2, 3));
34  EXPECT_EQ(rect.getWidth(), 1.0);
35  EXPECT_EQ(rect.getLength(), 2.0);
36  EXPECT_EQ(rect.getThickness(), 3.0);
37  EXPECT_EQ(rect.getWidth(), rect.getUSize());
38  EXPECT_EQ(rect.getLength(), rect.getVSize());
39  EXPECT_EQ(rect.getThickness(), rect.getWSize());
40  EXPECT_EQ(rect.getUPitch(), 0.5);
41  EXPECT_EQ(rect.getVPitch(), 0.5);
42  EXPECT_EQ(rect.getUCellPosition(0), -0.25);
43  EXPECT_EQ(rect.getUCellPosition(1), 0.25);
44  EXPECT_EQ(rect.getVCellPosition(0), -0.75);
45  EXPECT_EQ(rect.getVCellPosition(1), -0.25);
46  EXPECT_EQ(rect.getVCellPosition(2), 0.25);
47  EXPECT_EQ(rect.getVCellPosition(3), 0.75);
48  for (double u = -1.0 + 0.05; u <= 1.0; u += 0.1) {
49  EXPECT_EQ(rect.getUCellID(u), (int)((u / 1.0 + 0.5) * 2));
50  if (u < -0.5) {EXPECT_EQ(rect.getUCellID(u, 0, true), 0); }
51  if (u > 0.5) {EXPECT_EQ(rect.getUCellID(u, 0, true), rect.getUCells() - 1);}
52  for (double v = -2.0 + 0.11; v <= 2.0; v += 0.2) {
53  EXPECT_EQ(rect.getVCellID(v), (int)((v / 2.0 + 0.5) * 4));
54  if (v < -1.0) {EXPECT_EQ(rect.getVCellID(v, true), 0);}
55  if (v > 1.0) {EXPECT_EQ(rect.getVCellID(v, true), rect.getVCells() - 1);}
56  EXPECT_EQ(rect.inside(u, v), fabs(u) <= 0.5 && fabs(v) <= 1.0);
57  }
58  }
59  EXPECT_EQ(rect.getUCells(), 2);
60  EXPECT_EQ(rect.getVCells(), 4);
61  }
62 
67  TEST(SensorInfoBase, Trapezoidal)
68  {
69  SensorInfoBase rect(SensorInfoBase::PXD, VxdID(3, 2, 1), 2.0, 2.0, 1.0, 2, 4, 1.0);
70  EXPECT_EQ(rect.getType(), SensorInfoBase::PXD);
71  EXPECT_EQ(rect.getID(), VxdID(3, 2, 1));
72  for (double v = -1.0; v < 1.0; v += 0.1) {
73  EXPECT_DOUBLE_EQ(rect.getWidth(v), 2.0 - (v / 2.0 + 0.5) * 1.0);
74  EXPECT_EQ(rect.getWidth(), rect.getUSize());
75  }
76  EXPECT_EQ(rect.getLength(), 2.0);
77  EXPECT_EQ(rect.getThickness(), 1.0);
78  EXPECT_EQ(rect.getLength(), rect.getVSize());
79  EXPECT_EQ(rect.getThickness(), rect.getWSize());
80  EXPECT_EQ(rect.getUPitch(-1.0), 1.0);
81  EXPECT_EQ(rect.getUPitch(0.0), 0.75);
82  EXPECT_EQ(rect.getUPitch(1.0), 0.5);
83  EXPECT_EQ(rect.getVPitch(), 0.5);
84  for (double u = -2.0 + 0.1; u <= 2.0; u += 0.2) {
85  for (double v = -2.0 + 0.11; v <= 2.0; v += 0.2) {
86  EXPECT_EQ(rect.getUCellID(u, v), (int)((u / rect.getWidth(v) + 0.5) * 2));
87  EXPECT_EQ(rect.getVCellID(v), (int)((v / 2.0 + 0.5) * 4));
88  EXPECT_EQ(rect.inside(u, v), fabs(u) <= rect.getWidth(v) / 2.0 && fabs(v) <= 1.0);
89  }
90  }
91  EXPECT_EQ(rect.getUCells(), 2);
92  EXPECT_EQ(rect.getVCells(), 4);
93  }
94 
99  TEST(SensorInfoBase, Segmented)
100  {
101  SensorInfoBase rect(SensorInfoBase::PXD, VxdID(3, 2, 1), 2.0, 2.0, 1.0, 2, 2, 1.0, 1.0, 4);
102  for (double v = -1.0; v < 1.0; v += 0.1) {
103  EXPECT_DOUBLE_EQ(rect.getWidth(v), 2.0 - (v / 2.0 + 0.5) * 1.0);
104  EXPECT_EQ(rect.getWidth(), rect.getUSize());
105  EXPECT_EQ(rect.getVPitch(v), v >= 0 ? 0.25 : 0.5);
106  }
107  EXPECT_EQ(rect.getLength(), 2.0);
108  EXPECT_EQ(rect.getThickness(), 1.0);
109  EXPECT_EQ(rect.getLength(), rect.getVSize());
110  EXPECT_EQ(rect.getThickness(), rect.getWSize());
111  EXPECT_EQ(rect.getUPitch(-1.0), 1.0);
112  EXPECT_EQ(rect.getUPitch(0.0), 0.75);
113  EXPECT_EQ(rect.getUPitch(1.0), 0.5);
114  EXPECT_EQ(rect.getVCellPosition(0), -0.75);
115  EXPECT_EQ(rect.getVCellPosition(1), -0.25);
116  EXPECT_EQ(rect.getVCellPosition(2), 0.125);
117  EXPECT_EQ(rect.getVCellPosition(3), 0.375);
118  EXPECT_EQ(rect.getVCellPosition(4), 0.625);
119  EXPECT_EQ(rect.getVCellPosition(5), 0.875);
120  for (double u = -2.0 + 0.1; u <= 2.0; u += 0.2) {
121  for (double v = -2.0 + 0.11; v <= 2.0; v += 0.2) {
122  EXPECT_EQ(rect.getUCellID(u, v), (int)((u / rect.getWidth(v) + 0.5) * 2));
123  if (v <= 0) {
124  EXPECT_EQ(rect.getVCellID(v), (int)((v / 2.0 + 0.5) * 4));
125  } else {
126  EXPECT_EQ(rect.getVCellID(v), (int)((v / 2.0 + 0.5) * 8) - 2);
127  }
128  EXPECT_EQ(rect.inside(u, v), fabs(u) <= rect.getWidth(v) / 2.0 && fabs(v) <= 1.0);
129  double iu(u), iv(v);
130  rect.forceInside(iu, iv);
131  EXPECT_TRUE(rect.inside(iu, iv));
132  }
133  }
134  EXPECT_EQ(rect.getUCells(), 2);
135  EXPECT_EQ(rect.getVCells(), 6);
136  }
137 
143  TEST(SensorPlane, DISABLED_NotFound)
144  {
145  SensorPlane plane(VxdID(1, 1, 1));
146  EXPECT_B2FATAL(plane.isInActive(0, 0));
147  }
148 
149  } // vxd namespace
151 } // Belle2 namespace
Base class to provide Sensor Information for PXD and SVD.
double getVCellPosition(int vID) const
Return the position of a specific strip/pixel in v direction.
double getUPitch(double v=0) const
Return the pitch of the sensor.
double getVSize() const
Return the length of the sensor.
double getUCellPosition(int uID, int vID=-1) const
Return the position of a specific strip/pixel in u direction.
double getWSize() const
Return the thickness of the sensor.
SensorType getType() const
Return the Type of the Sensor.
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
bool inside(double u, double v, double uTolerance=DBL_EPSILON, double vTolerance=DBL_EPSILON) const
Check wether a given point is inside the active area.
double getWidth(double v=0) const
Return the width of the sensor.
VxdID getID() const
Return the ID of the Sensor.
double getVPitch(double v=0) const
Return the pitch of the sensor.
double getThickness() const
Return the thickness of the sensor.
double getUSize(double v=0) const
Return the width of the sensor.
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
double getLength() const
Return the length of the sensor.
void forceInside(double &u, double &v) const
Force a position to be inside the active area.
A Finite plane of one VXD Sensor.
Definition: SensorPlane.h:34
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.