Belle II Software development
SectorsOnSensor.h
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#pragma once
10
11#include "tracking/dataobjects/FullSecID.h"
12#include <map>
13#include <vector>
14#include <cfloat>
15
16namespace Belle2 {
25 template< class sectorID >
27
29 typedef unsigned char index_t;
30
32 std::map<double, index_t> m_normalizedUsup;
33
35 std::map<double, index_t> m_normalizedVsup;
36
39 std::vector< std::vector < FullSecID > > m_fullSecIDs;
40
43 std::vector< sectorID > m_compactSecIDs;
44
45 public:
46
49
52 const std::vector< double >& normalizedUsup,
53 const std::vector< double >& normalizedVsup,
54 const std::vector< std::vector< FullSecID > >& fullSecIDs)
55 {
56 index_t index = 0;
57
58 for (auto Vsup : normalizedVsup)
59 m_normalizedVsup.insert({Vsup, index++});
60 m_normalizedVsup.insert({FLT_MAX, index++});
61
62 index = 0;
63 for (auto Usup : normalizedUsup)
64 m_normalizedUsup.insert({Usup, index++});
65 // cppcheck-suppress unreadVariable
66 m_normalizedUsup.insert({FLT_MAX, index++});
67
68 m_fullSecIDs = fullSecIDs;
69
70 }
71
74
77 FullSecID operator()(double normalizedU, double normalizedV) const
78 {
79
80 if (normalizedU < 0. or normalizedU > 1.)
81 return FullSecID(0);
82 if (normalizedV < 0. or normalizedV > 1.)
83 return FullSecID(0);
84
85 auto uKeyVal = m_normalizedUsup.upper_bound(normalizedU);
86 if (uKeyVal == m_normalizedUsup.end())
87 return FullSecID(0);
88
89 auto vKeyVal = m_normalizedVsup.upper_bound(normalizedV);
90 if (vKeyVal == m_normalizedVsup.end())
91 return FullSecID(0);
92
93
94 auto uIndex = uKeyVal->second;
95 auto vIndex = vKeyVal->second;
96
97 return m_fullSecIDs[ uIndex ][ vIndex ];
98 }
99
100
101
102
107 void get(std::vector< double >* normalizedUsup,
108 std::vector< double >* normalizedVsup,
109 std::vector< std::vector< unsigned int > >* secID) const
110 {
111 // let us copy the sorted map Usup
112 for (auto uIndexPair : m_normalizedUsup)
113 if (uIndexPair.first != FLT_MAX)
114 normalizedUsup->push_back(uIndexPair.first);
115
116 // let us copy the sorted map Vsup
117 for (auto vIndexPair : m_normalizedVsup)
118 if (vIndexPair.first != FLT_MAX)
119 normalizedVsup->push_back(vIndexPair.first);
120
121 // and finally we copy the array of full sec ids
122 for (auto col : m_fullSecIDs) {
123 std::vector< unsigned int > tmp_col;
124 for (auto id : col)
125 tmp_col.push_back(id);
126 secID->push_back(tmp_col);
127 }
128 }
129
131 bool areCoordinatesValid(double normalizedU, double normalizedV) const
132 {
133 // check u and v
134 if ((normalizedU < 0.) or (normalizedU > 1.)) return false;
135 if ((normalizedV < 0.) or (normalizedV > 1.)) return false;
136 // check internal map for problems:
137 if (m_normalizedUsup.upper_bound(normalizedU) == m_normalizedUsup.end())
138 return false;
139
140 if (m_normalizedVsup.upper_bound(normalizedV) == m_normalizedVsup.end())
141 return false;
142
143 return true;
144 }
145
146
149 sectorID& operator[](int index) { return m_compactSecIDs[index] ;};
150
152 const sectorID& operator[](int index) const { return m_compactSecIDs[index] ;};
153
155 size_t size() const { return m_compactSecIDs.size(); };
156
158 void resize(size_t n) { m_compactSecIDs.resize(n); };
159
160
164 bool updateSubLayerID(FullSecID sector, int sublayer)
165 {
166 for (auto& v : m_fullSecIDs) {
167 for (FullSecID& thisSecID : v) {
169 if (sector.equalIgnoreSubLayerID(thisSecID)) {
170 thisSecID = FullSecID(thisSecID.getVxdID(), (bool)sublayer, thisSecID.getSecID());
171 return true;
172 }
173 }
174 }
175 return false;
176 }
177
179 const std::vector< sectorID >& getCompactSecIDs() const { return m_compactSecIDs; }
180
181 };
182
184}
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:33
This class associates to an ordered pairs of normalized local coordinates a compact sector id.
std::map< double, index_t > m_normalizedVsup
Upper limits of the sectors in normalized V coordinates.
std::vector< std::vector< FullSecID > > m_fullSecIDs
The 2D array of the full sec ID is stored in this member.
size_t size() const
minimal vector semantics to get the size of the compactSecIDs vector
sectorID & operator[](int index)
minimal vector semantics to access the compactSecIDs vector using the sector
bool areCoordinatesValid(double normalizedU, double normalizedV) const
check if using operator() would be safe (true if it is safe):
SectorsOnSensor()
Default constructor needed for the vector traits.
unsigned char index_t
Typedef for the internal numbering of rows and columns of the sectors.
void resize(size_t n)
minimal vector semantics to resize the compactSecIDs vector
FullSecID operator()(double normalizedU, double normalizedV) const
Returns the Full Sector ID of the sector on this sensor that contains the point at normalized coordin...
std::map< double, index_t > m_normalizedUsup
Upper limits of the sectors in normalized U coordinates.
SectorsOnSensor(const std::vector< double > &normalizedUsup, const std::vector< double > &normalizedVsup, const std::vector< std::vector< FullSecID > > &fullSecIDs)
Useful constructor.
~SectorsOnSensor()
Destructor of the object.
const std::vector< sectorID > & getCompactSecIDs() const
JKL: for testing - get all compactSecIDs:
std::vector< sectorID > m_compactSecIDs
The 1D array of the compact ID is stored in this member.
bool updateSubLayerID(FullSecID sector, int sublayer)
update the sublayer id for the sector with the given FullSecID, the sublayer id is ignored when searc...
const sectorID & operator[](int index) const
minimal vector semantics to access the compactSecIDs vector
void get(std::vector< double > *normalizedUsup, std::vector< double > *normalizedVsup, std::vector< std::vector< unsigned int > > *secID) const
copy the vector members on the vector pointed from the arguments.
Abstract base class for different kinds of events.