Belle II Software development
CompactSecIDs.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#pragma once
9
10#include "tracking/dataobjects/FullSecID.h"
11#include <tracking/trackFindingVXD/filterMap/map/SectorsOnSensor.h>
12#include <framework/core/FrameworkExceptions.h>
13#include <framework/logging/Logger.h>
14#include <cstdint>
15#include <vector>
16
17namespace Belle2 {
29
30 public:
31
32 // uint_16_t upper limit is UINT16_MAX
33
35 typedef uint16_t sectorID_t ;
36
38 typedef uint32_t secPairID_t ;
39
41 typedef uint64_t secTripletID_t ;
42
44 typedef uint64_t secQuadrupletID_t;
45
48
51
53 int getSize() const {return (int)m_sectorCounter ; }
54
56 unsigned int getAvailableSlots() const
57 {
58 return UINT16_MAX - (getSize());
59 }
60
61
69 int addSectors(const std::vector< double>& normalizedUsup,
70 const std::vector< double>& normalizedVsup,
71 const std::vector< std::vector< FullSecID >>& fullSecIDs)
72 {
73 // First let us check that there is space to store all the sectors
74 if (getAvailableSlots() < (normalizedUsup.size() + 1) *
75 (normalizedVsup.size() + 1))
76 return 0;
77
78 // Second let us check that the array of fullSecIDs is rectangular
79 // and that its size matches the size of the coordinates.
80 if (fullSecIDs.size() != normalizedUsup.size() + 1 ||
81 fullSecIDs[0].size() != normalizedVsup.size() + 1)
82 return 0;
83
84 // Further sanity checks
85
86 auto layer = fullSecIDs[0][0].getLayerID();
87 auto ladder = fullSecIDs[0][0].getLadderID();
88 auto sensor = fullSecIDs[0][0].getVxdID().getSensorNumber();
89
90 for (auto fullSecIDrow : fullSecIDs) {
91 // Check that the fullSecIDs vector of vector is rectangular
92 if (fullSecIDrow.size() != normalizedVsup.size() + 1)
93 return 0;
94
95 // Check that all the fullSectorIDs are on the same physical sensor
96 for (auto fullSecID : fullSecIDrow)
97 if (layer != fullSecID.getLayerID() ||
98 ladder != fullSecID.getLadderID() ||
99 sensor != fullSecID.getVxdID().getSensorNumber())
100 return 0;
101 }
102
104 normalizedUsup, normalizedVsup,
105 fullSecIDs,
106 layer, ladder, sensor);
107
108 }
109
110
116 sectorID_t getCompactID(const FullSecID& fullID) const
117 {
118
120 fullID.getLayerID(),
121 fullID.getLadderID(),
122 fullID.getVxdID().getSensorNumber(),
123 fullID.getSecID());
124 }
125
133 getSectorsOnSensor(unsigned layer, unsigned ladder, unsigned sensor)
134 const
135 {
136 try {
137 return m_compactSectorsIDMap.at(layer).at(ladder).at(sensor);
138 } catch (...)
139 { return SectorsOnSensor<sectorID_t>(); }
140
141 }
142
144 BELLE2_DEFINE_EXCEPTION(unboundedNormalizedU,
145 "On layer:%1% ladder:%2% sensor:%3% abnormal U=%4$");
146
148 BELLE2_DEFINE_EXCEPTION(unboundedNormalizedV,
149 "On layer:%1% ladder:%2% sensor:%3% abnormal V=%4$");
150
154 double normalizedU, double normalizedV) const
155 {
156
157 auto layer = aSensorID.getLayerNumber() ;
158 auto ladder = aSensorID.getLadderNumber();
159 auto sensor = aSensorID.getSensorNumber();
160
161 auto sectorsOnSensor =
162 m_compactSectorsIDMap.at(layer).at(ladder).at(sensor);
163
164
165 if (normalizedU < 0. || 1. < normalizedU)
166 B2WARNING("CompactSecIDs: U not normalized! This may lead to undefined behavior!");
167 if (normalizedV < 0. || 1. < normalizedV)
168 B2WARNING("CompactSecIDs: V not normalized! This may lead to undefined behavior!");
169
170 return sectorsOnSensor(normalizedU, normalizedV);
171
172
173 }
174
179 sectorID_t operator [](const FullSecID& fullID) const
180 {
181 return getCompactID(fullID);
182 }
183
188 secPairID_t getCompactID(const FullSecID& id1, const FullSecID& id2) const
189 {
190
191 auto i1 = (secPairID_t)getCompactID(id1);
192 if (i1 == 0)
193 return 0;
194
195 auto i2 = (secPairID_t)getCompactID(id2);
196 if (i2 == 0)
197 return 0;
198
199 return i1 + (i2 << 16);
200
201 }
202
208 static void extractCompactID(secPairID_t pair_id, sectorID_t& id1, sectorID_t& id2)
209 {
210 id1 = pair_id & 0xffff;
211 id2 = (pair_id >> 16) & 0xffff;
212 }
213
214
215
222 const FullSecID& id3) const
223 {
224
225 auto i1 = (secTripletID_t)getCompactID(id1);
226 if (i1 == 0)
227 return 0;
228
229 auto i2 = (secTripletID_t)getCompactID(id2);
230 if (i2 == 0)
231 return 0;
232
233 auto i3 = (secTripletID_t)getCompactID(id3);
234 if (i3 == 0)
235 return 0;
236
237 return i1 + (i2 << 16) + (i3 << 32);
238
239 }
240
246 static void extractCompactID(secTripletID_t triplet_id, sectorID_t& id1, sectorID_t& id2, sectorID_t& id3)
247 {
248 id1 = triplet_id & 0xffff;
249 id2 = (triplet_id >> 16) & 0xffff;
250 id3 = (triplet_id >> 32) & 0xffff;
251 }
252
256 const FullSecID& id3, const FullSecID& id4)
257 const
258 {
259
260 auto i1 = (secQuadrupletID_t)getCompactID(id1);
261 if (i1 == 0)
262 return 0;
263
264 auto i2 = (secQuadrupletID_t)getCompactID(id2);
265 if (i2 == 0)
266 return 0;
267
268 auto i3 = (secQuadrupletID_t)getCompactID(id3);
269 if (i3 == 0)
270 return 0;
271
272 auto i4 = (secQuadrupletID_t)getCompactID(id4);
273 if (i4 == 0)
274 return 0;
275
276 return i1 + (i2 << 16) + (i3 << 32) + (i4 << 48) ;
277
278 }
279
283 {
284
285 auto layer = fullID.getLayerID();
286 auto ladder = fullID.getLadderID();
287 auto sensor = fullID.getVxdID().getSensorNumber();
288 auto sector = fullID.getSecID();
289
290 return m_compactSectorsIDMap[layer][ladder][sensor][sector];
291
292 }
293
294
295
297 bool areCoordinatesValid(VxdID aSensorID, double normalizedU, double normalizedV) const
298 {
299 auto layer = aSensorID.getLayerNumber() ;
300 auto ladder = aSensorID.getLadderNumber();
301 auto sensor = aSensorID.getSensorNumber();
302
303 // check sensor:
304 if (!(layer < m_compactSectorsIDMap.size())) return false;
305 if (!(ladder < m_compactSectorsIDMap[layer].size())) return false;
306 if (!(sensor < m_compactSectorsIDMap[layer][ladder].size())) return false;
307
308 // check u and v:
309 return m_compactSectorsIDMap[layer][ladder][sensor].areCoordinatesValid(normalizedU, normalizedV);
310 }
311
313 typedef std::vector<SectorsOnSensor<sectorID_t> > SensorsOnLadder_t;
315 typedef std::vector<SensorsOnLadder_t> LaddersOnLayer_t;
317 typedef std::vector<LaddersOnLayer_t> LayersLookUpTable_t;
318
319
322
324 int nOfLayers(void) const
325 { return m_compactSectorsIDMap.size(); }
326
331 int nOfLadders(int layer) const
332 {
333 if (layer < 0 || layer >= nOfLayers())
334 return 0;
335 return m_compactSectorsIDMap[layer].size();
336 }
337
343 int nOfSensors(int layer, int ladder) const
344 {
345 if (ladder < 0 || ladder >= nOfLadders(layer))
346 return 0; // Note: the check on the layer is implicitly made
347
348 return m_compactSectorsIDMap[layer][ladder].size();
349 }
350
355 bool setSubLayerID(FullSecID& sector, int sublayer)
356 {
357 // cross check if sector is registered in the map, compactID will be 0 if not
358 sectorID_t compactID = getCompactID(sector);
359 if (compactID == 0) return false;
360
361 // now update the SectorsOnSensor object
362 return m_compactSectorsIDMap[sector.getLayerID()][sector.getLadderID()]
363 [sector.getVxdID().getSensorNumber()].updateSubLayerID(sector, sublayer);
364 }
365
366
367 private:
370
373
377 template< class TContainer,
378 class ... Indexes >
379 int privateAddSectors(TContainer& container,
380 const std::vector< double >& normalizedUsup,
381 const std::vector< double >& normalizedVsup,
382 const std::vector< std::vector< FullSecID > >& fullSecIDs,
383 short unsigned int index, Indexes ... indexes)
384 {
385 try {
386 if ((int) container.size() < (int)index + 1)
387 container.resize(index + 1);
388 } catch (...) { return 0; }
389 return privateAddSectors(container[ index ],
390 normalizedUsup, normalizedVsup,
391 fullSecIDs, indexes...);
392 }
393
394
399 const std::vector< double>& normalizedUsup,
400 const std::vector< double>& normalizedVsup,
401 const std::vector< std::vector< FullSecID > >& fullSecIDs)
402 {
403 if (sectors.size() != 0)
404 return 0;
405
406 sectors = SectorsOnSensor< sectorID_t >(normalizedUsup,
407 normalizedVsup, fullSecIDs);
408
409 int addedSectors = 0;
410
411 for (auto sectorRow : fullSecIDs)
412 for (auto sector : sectorRow) {
413 auto secID = sector.getSecID();
414 try {
415 if ((int) sectors.size() < (int) secID + 1)
416 sectors.resize(secID + 1);
417 } catch (...) { return addedSectors; }
418
419 sectors[ secID ] = ++m_sectorCounter ;
420 addedSectors++;
421 }
422 return addedSectors;
423
424 }
425
430 template< class TContainer,
431 class ... Indexes >
432 sectorID_t privateGetCompactID(const TContainer& container,
433 short unsigned int index, Indexes ... indexes) const
434 {
435 if ((int) container.size() < (int) index + 1)
436 return 0;
437
438 return privateGetCompactID(container[ index ], indexes...);
439 }
440
441
445 template< class TContainer >
446 sectorID_t privateGetCompactID(const TContainer& container,
447 short unsigned int index) const
448 {
449 if ((int) container.size() < (int) index + 1)
450 return 0;
451
452 return container[ index ];
453 }
454
455 };
456
458}
This class provides a computer convenient numbering scheme for the sectors in the sector map and for ...
Definition: CompactSecIDs.h:28
int nOfSensors(int layer, int ladder) const
get the number of sensors on
sectorID_t operator[](const FullSecID &fullID) const
Returns the compact id of the FullSecID fullID.
secTripletID_t getCompactID(const FullSecID &id1, const FullSecID &id2, const FullSecID &id3) const
Returns the compact id of the triplet of FullSecID id1 id2 id3.
std::vector< SensorsOnLadder_t > LaddersOnLayer_t
Typedef for vector of vector of IDs of sectors on a Ladder.
FullSecID getFullSecID(VxdID aSensorID, double normalizedU, double normalizedV) const
Returns a fullSecID for given sensor and pair of coordinates.
bool areCoordinatesValid(VxdID aSensorID, double normalizedU, double normalizedV) const
JKL: returns true if operator() will not throw an exception.
uint32_t secPairID_t
Typedef of the compact Id for a 2 sectors combination.
Definition: CompactSecIDs.h:38
int nOfLadders(int layer) const
get the number of ladders on
BELLE2_DEFINE_EXCEPTION(unboundedNormalizedU, "On layer:%1% ladder:%2% sensor:%3% abnormal U=%4$")
Exception for normalized coordinate U out of bound [0,1].
~CompactSecIDs()
The destructor is quite trivial: nothing special to delete.
Definition: CompactSecIDs.h:50
int privateAddSectors(TContainer &container, const std::vector< double > &normalizedUsup, const std::vector< double > &normalizedVsup, const std::vector< std::vector< FullSecID > > &fullSecIDs, short unsigned int index, Indexes ... indexes)
The hidden private method that recursively manage the size of everything.
uint64_t secTripletID_t
Typedef of the compact Id for a 3 sectors combination.
Definition: CompactSecIDs.h:41
sectorID_t privateGetCompactID(const TContainer &container, short unsigned int index, Indexes ... indexes) const
The hidden private method that recursively descend the layer, ladder, sensor stack and returns the co...
uint16_t sectorID_t
Typedef of the compact Id for a single sector.
Definition: CompactSecIDs.h:35
sectorID_t getCompactID(const FullSecID &fullID) const
Returns the compact id of the FullSecID It does not throw exceptions (at least it should not).
static void extractCompactID(secPairID_t pair_id, sectorID_t &id1, sectorID_t &id2)
Uses the values coded by the Sector Pair ID pair_id and sets the two compact Sector ids id1 and id2.
sectorID_t m_sectorCounter
Counter for sectors.
std::vector< LaddersOnLayer_t > LayersLookUpTable_t
Typedef for vector of vector of vector of IDs of sectors on a layer.
const LayersLookUpTable_t & getCompactSectorsIDMap() const
Get access to the whole map.
int getSize() const
Returns the number of sectors defined so far.
Definition: CompactSecIDs.h:53
CompactSecIDs()
The constructor have just to set the internal counter to 0.
Definition: CompactSecIDs.h:47
bool setSubLayerID(FullSecID &sector, int sublayer)
set the SublayerID of the sector
std::vector< SectorsOnSensor< sectorID_t > > SensorsOnLadder_t
Typedef for vector of IDs of sectors on a sensors.
LayersLookUpTable_t m_compactSectorsIDMap
Lookup table containing all sectorIDs.
int nOfLayers(void) const
get the number of layers in this CompactSecIDs
secPairID_t getCompactID(const FullSecID &id1, const FullSecID &id2) const
Returns the compact id of the pair of FullSecID id1 id2.
static void extractCompactID(secTripletID_t triplet_id, sectorID_t &id1, sectorID_t &id2, sectorID_t &id3)
Uses the values coded by the Sector Pair ID to set the three compact sector ids.
sectorID_t getCompactIDFastAndDangerous(const FullSecID &fullID) const
Fast (and potentially dangerous) equivalent of getCompactID.
SectorsOnSensor< sectorID_t > getSectorsOnSensor(unsigned layer, unsigned ladder, unsigned sensor) const
Getter for IDs of all sectors on a sensor.
unsigned int getAvailableSlots() const
Returns the available number of sector that can be defined now.
Definition: CompactSecIDs.h:56
secQuadrupletID_t getCompactID(const FullSecID &id1, const FullSecID &id2, const FullSecID &id3, const FullSecID &id4) const
Returns the compact id of the quadruplet of FullSecID id1 id2 id3 id4 If any of the id1,...
sectorID_t privateGetCompactID(const TContainer &container, short unsigned int index) const
The hidden private method that close the recursion.
uint64_t secQuadrupletID_t
Typedef of the compact Id for a 4 sectors combination.
Definition: CompactSecIDs.h:44
BELLE2_DEFINE_EXCEPTION(unboundedNormalizedV, "On layer:%1% ladder:%2% sensor:%3% abnormal V=%4$")
Exception for normalized coordinate V out of bound [0,1].
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
int privateAddSectors(SectorsOnSensor< sectorID_t > &sectors, const std::vector< double > &normalizedUsup, const std::vector< double > &normalizedVsup, const std::vector< std::vector< FullSecID > > &fullSecIDs)
The hidden private method that end the recursion.
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:33
int getLadderID() const
returns LadderID compatible with basf2 standards
Definition: FullSecID.h:126
VxdID getVxdID() const
returns VxdID of sensor.
Definition: FullSecID.h:138
short int getLayerID() const
returns LayerID compatible with basf2 standards.
Definition: FullSecID.h:118
short int getSecID() const
returns SecID of current FullSecID (only unique for each sensor).
Definition: FullSecID.h:146
This class associates to an ordered pairs of normalized local coordinates a compact sector id.
size_t size() const
minimal vector semantics to get the size of the compactSecIDs vector
void resize(size_t n)
minimal vector semantics to resize the compactSecIDs vector
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:100
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:98
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
Abstract base class for different kinds of events.