Belle II Software development
CompactSecID.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
9#include <tracking/trackFindingVXD/filterMap/map/CompactSecIDs.h>
10#include "tracking/dataobjects/FullSecID.h"
11
12#include <gtest/gtest.h>
13#include <iostream>
14#include <vector>
15
16using namespace std;
17using namespace Belle2;
18
19
20TEST(CompactSecIDs, basicCheck)
21{
22 CompactSecIDs compactSecIds;
23
24 vector< double > uSup = { .25, .5, .75 };
25 vector< double > vSup = { .25, .5, .75, .8};
26
27 vector< vector< FullSecID > > sectors;
28
29 sectors.resize(uSup.size() + 1);
30
31 int counter = 0;
32 for (unsigned int i = 0; i < uSup.size() + 1 ; i++) {
33 sectors[i].resize(vSup.size() + 1);
34 for (unsigned int j = 0; j < vSup.size() + 1; j++) {
35 sectors[i][j] = FullSecID(VxdID(6, 3, 2), false, 12 + counter);
36 counter ++;
37 }
38 }
39 // succesfully insert
40 EXPECT_EQ(sectors.size()*sectors[0].size(),
41 compactSecIds.addSectors(uSup, vSup, sectors)) ;
42
43 // succesfully retrieve
44 EXPECT_EQ(1, compactSecIds.getCompactID(sectors[0][0]));
45 EXPECT_EQ(2, compactSecIds.getCompactIDFastAndDangerous(sectors[0][1]));
46
47 // unsuccesfully retrieve
48 EXPECT_EQ(0, compactSecIds.getCompactID(FullSecID(VxdID(6, 3, 2), false, 1)));
49 EXPECT_EQ(0, compactSecIds.getCompactID(FullSecID(VxdID(7, 3, 2), false, 1)));
50 EXPECT_EQ(0, compactSecIds.getCompactID(FullSecID(VxdID(5, 3, 2), false, 1)));
51
52 // cannot insert twice
53 EXPECT_EQ(0, compactSecIds.addSectors(uSup, vSup, sectors));
54
55
56
57}
58
59
60TEST(CompactSecIDs, stressTest)
61{
62
63 CompactSecIDs compactSecIds;
64 vector<int> layers = { 1, 2, 3, 4, 5, 6};
65 vector<int> ladders = { 8, 12, 7, 10, 12, 16};
66 vector<int> sensors = { 2, 2, 2, 3, 4, 5};
67
68
69 vector< double > uSup = { .25, .5, .75 };
70 vector< double > vSup = { .2, .4, .6, .8};
71
72
73 vector< vector< FullSecID > > sectors;
74
75 sectors.resize(uSup.size() + 1);
76
77
78 for (auto layer : layers)
79 for (int ladder = 1 ; ladder <= ladders[layer - 1] ; ladder++)
80 for (int sensor = 1 ; sensor <= sensors[layer - 1] ; sensor++) {
81 int counter = 0;
82 for (unsigned int i = 0; i < uSup.size() + 1; i++) {
83 sectors[i].resize(vSup.size() + 1);
84 for (unsigned int j = 0; j < vSup.size() + 1 ; j++) {
85 sectors[i][j] = FullSecID(VxdID(layer, ladder, sensor),
86 sensor % 2 == 0 ? false : true, counter);
87 counter ++;
88 }
89 }
90
91 // succesfully insert
92 EXPECT_EQ(sectors.size()*sectors[0].size(), compactSecIds.addSectors(uSup, vSup, sectors));
93 }
94
95 for (auto layer : layers)
96 for (int ladder = 1 ; ladder <= ladders[layer - 1] ; ladder++)
97 for (int sensor = 1 ; sensor <= sensors[layer - 1] ; sensor++) {
98 int counter = 0;
99 for (unsigned int i = 0; i < uSup.size() + 1 ; i++) {
100 sectors[i].resize(vSup.size() + 1);
101 for (unsigned int j = 0; j < vSup.size() + 1; j++) {
102 sectors[i][j] = FullSecID(VxdID(layer, ladder, sensor),
103 sensor % 2 == 0 ? false : true, counter);
104 counter ++;
105 }
106 }
107
108 // un succesfully insert because the sectors are already in compactSecIds
109 EXPECT_EQ(0, compactSecIds.addSectors(uSup, vSup, sectors));
110 }
111
112 int expected = 0;
113
114 for (auto layer : layers)
115 for (int ladder = 1 ; ladder <= ladders[layer - 1] ; ladder++)
116 for (int sensor = 1 ; sensor <= sensors[layer - 1] ; sensor++)
117 for (unsigned int sector = 0 ; sector < (uSup.size() + 1) * (vSup.size() + 1) ; sector ++) {
118 FullSecID aSector(VxdID(layer, ladder, sensor),
119 sensor % 2 == 0 ? false : true
120 , sector);
121 // succesfully retrieve
122 EXPECT_EQ(++ expected, compactSecIds.getCompactID(aSector));
123
124 }
125
126 // list< pair< float, float> >;
127
128 for (double u = 0. ; u < 1.; u += .25) {
129 for (double v = 0.; v < 1.; v += .2)
130 cout << compactSecIds.getFullSecID(VxdID(1, 1, 1), u, v) << "\t";
131 cout << endl;
132 }
133
134 // the compactsecids dont throw exceptions anymore
148 for (double u = .25 ; u < 1.25; u += .25) {
149 for (double v = 0.2; v < 1.2; v += .2) {
150 if (u < 0. or u > 1. or v < 0. or v >1.) {
151 EXPECT_ANY_THROW(compactSecIds.getFullSecID(VxdID(1, 1, 1), u, v));
152 } else {
153 cout << compactSecIds.getFullSecID(VxdID(1, 1, 1), u, v) << "\t";
154 }
155 }
156 cout << endl;
157 }
158
159}
This class provides a computer convenient numbering scheme for the sectors in the sector map and for ...
Definition: CompactSecIDs.h:28
FullSecID getFullSecID(VxdID aSensorID, double normalizedU, double normalizedV) const
Returns a fullSecID for given sensor and pair of coordinates.
sectorID_t getCompactID(const FullSecID &fullID) const
Returns the compact id of the FullSecID It does not throw exceptions (at least it should not).
sectorID_t getCompactIDFastAndDangerous(const FullSecID &fullID) const
Fast (and potentially dangerous) equivalent of getCompactID.
int addSectors(const std::vector< double > &normalizedUsup, const std::vector< double > &normalizedVsup, const std::vector< std::vector< FullSecID > > &fullSecIDs)
This method defines all the sectors on a given sensor.
Definition: CompactSecIDs.h:69
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:33
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.
STL namespace.