Belle II Software  release-05-02-19
SectorsOnSensor.h
1 /********************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Eugenio Paoloni *
7  * *
8  * This software is provided "as is" without any warranty. *
9  *******************************************************************************/
10 
11 #pragma once
12 
13 #include "tracking/dataobjects/FullSecID.h"
14 #include <map>
15 #include <vector>
16 #include <cfloat>
17 
18 namespace Belle2 {
25  template< class sectorID >
28  class SectorsOnSensor {
29 
31  typedef unsigned char index_t;
32 
34  std::map<double , index_t> m_normalizedUsup;
35 
37  std::map<double , index_t> m_normalizedVsup;
38 
41  std::vector< std::vector < FullSecID > > m_fullSecIDs;
42 
45  std::vector< sectorID > m_compactSecIDs;
46 
47  public:
48 
50  SectorsOnSensor() {}
51 
54  const std::vector< double >& normalizedUsup,
55  const std::vector< double >& normalizedVsup,
56  const std::vector< std::vector< FullSecID > >& fullSecIDs)
57  {
58  index_t index = 0;
59 
60  for (auto Vsup : normalizedVsup)
61  m_normalizedVsup.insert({Vsup, index++});
62  m_normalizedVsup.insert({FLT_MAX, index++});
63 
64  index = 0;
65  for (auto Usup : normalizedUsup)
66  m_normalizedUsup.insert({Usup, index++});
67  // cppcheck-suppress unreadVariable
68  m_normalizedUsup.insert({FLT_MAX, index++});
69 
70  m_fullSecIDs = fullSecIDs;
71 
72  }
73 
75  ~SectorsOnSensor() {};
76 
79  FullSecID operator()(double normalizedU, double normalizedV) const
80  {
81 
82  if (normalizedU < 0. or normalizedU > 1.)
83  return FullSecID(0);
84  if (normalizedV < 0. or normalizedV > 1.)
85  return FullSecID(0);
86 
87  auto uKeyVal = m_normalizedUsup.upper_bound(normalizedU);
88  if (uKeyVal == m_normalizedUsup.end())
89  return FullSecID(0);
90 
91  auto vKeyVal = m_normalizedVsup.upper_bound(normalizedV);
92  if (vKeyVal == m_normalizedVsup.end())
93  return FullSecID(0);
94 
95 
96  auto uIndex = uKeyVal->second;
97  auto vIndex = vKeyVal->second;
98 
99  return m_fullSecIDs[ uIndex ][ vIndex ];
100  }
101 
102 
103 
104 
109  void get(std::vector< double >* normalizedUsup,
110  std::vector< double >* normalizedVsup,
111  std::vector< std::vector< unsigned int > >* secID) const
112  {
113  // let us copy the sorted map Usup
114  for (auto uIndexPair : m_normalizedUsup)
115  if (uIndexPair.first != FLT_MAX)
116  normalizedUsup->push_back(uIndexPair.first);
117 
118  // let us copy the sorted map Vsup
119  for (auto vIndexPair : m_normalizedVsup)
120  if (vIndexPair.first != FLT_MAX)
121  normalizedVsup->push_back(vIndexPair.first);
122 
123  // and finally we copy the array of full sec ids
124  for (auto col : m_fullSecIDs) {
125  std::vector< unsigned int > tmp_col;
126  for (auto id : col)
127  tmp_col.push_back(id);
128  secID->push_back(tmp_col);
129  }
130  }
131 
133  bool areCoordinatesValid(double normalizedU, double normalizedV) const
134  {
135  // check u and v
136  if ((normalizedU < 0.) or (normalizedU > 1.)) return false;
137  if ((normalizedV < 0.) or (normalizedV > 1.)) return false;
138  // check internal map for problems:
139  if (m_normalizedUsup.upper_bound(normalizedU) == m_normalizedUsup.end())
140  return false;
141 
142  if (m_normalizedVsup.upper_bound(normalizedV) == m_normalizedVsup.end())
143  return false;
144 
145  return true;
146  }
147 
148 
151  sectorID& operator[](int index) { return m_compactSecIDs[index] ;};
152 
154  const sectorID& operator[](int index) const { return m_compactSecIDs[index] ;};
155 
157  size_t size() const { return m_compactSecIDs.size(); };
158 
160  void resize(size_t n) { m_compactSecIDs.resize(n); };
161 
162 
166  bool updateSubLayerID(FullSecID sector, int sublayer)
167  {
168  for (auto& v : m_fullSecIDs) {
169  for (FullSecID& thisSecID : v) {
171  if (sector.equalIgnoreSubLayerID(thisSecID)) {
172  thisSecID = FullSecID(thisSecID.getVxdID(), (bool)sublayer, thisSecID.getSecID());
173  return true;
174  }
175  }
176  }
177  return false;
178  }
179 
181  const std::vector< sectorID >& getCompactSecIDs() const { return m_compactSecIDs; }
182 
183  };
184 
186 }
Belle2::SectorsOnSensor::size
size_t size() const
minimal vector semantics to get the size of the compactSecIDs vector
Definition: SectorsOnSensor.h:165
Belle2::SectorsOnSensor::m_compactSecIDs
std::vector< sectorID > m_compactSecIDs
The 1D array of the compact ID is stored in this member.
Definition: SectorsOnSensor.h:53
Belle2::SectorsOnSensor::getCompactSecIDs
const std::vector< sectorID > & getCompactSecIDs() const
JKL: for testing - get all compactSecIDs:
Definition: SectorsOnSensor.h:189
Belle2::SectorsOnSensor::operator()
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...
Definition: SectorsOnSensor.h:87
Belle2::SectorsOnSensor::get
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.
Definition: SectorsOnSensor.h:117
Belle2::SectorsOnSensor::m_fullSecIDs
std::vector< std::vector< FullSecID > > m_fullSecIDs
The 2D array of the full sec ID is stored in this member.
Definition: SectorsOnSensor.h:49
Belle2::SectorsOnSensor::~SectorsOnSensor
~SectorsOnSensor()
Destructor of the object.
Definition: SectorsOnSensor.h:83
Belle2::SectorsOnSensor::areCoordinatesValid
bool areCoordinatesValid(double normalizedU, double normalizedV) const
check if using operator() would be safe (true if it is safe):
Definition: SectorsOnSensor.h:141
Belle2::FullSecID
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:43
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SectorsOnSensor::index_t
unsigned char index_t
Typedef for the internal numbering of rows and columns of the sectors.
Definition: SectorsOnSensor.h:39
Belle2::SectorsOnSensor::m_normalizedVsup
std::map< double, index_t > m_normalizedVsup
Upper limits of the sectors in normalized V coordinates.
Definition: SectorsOnSensor.h:45
Belle2::SectorsOnSensor::updateSubLayerID
bool updateSubLayerID(FullSecID sector, int sublayer)
update the sublayer id for the sector with the given FullSecID, the sublayer id is ignored when searc...
Definition: SectorsOnSensor.h:174
Belle2::SectorsOnSensor::m_normalizedUsup
std::map< double, index_t > m_normalizedUsup
Upper limits of the sectors in normalized U coordinates.
Definition: SectorsOnSensor.h:42
Belle2::SectorsOnSensor::operator[]
sectorID & operator[](int index)
minimal vector semantics to access the compactSecIDs vector using the sector
Definition: SectorsOnSensor.h:159
Belle2::SectorsOnSensor::resize
void resize(size_t n)
minimal vector semantics to resize the compactSecIDs vector
Definition: SectorsOnSensor.h:168
Belle2::SectorsOnSensor::SectorsOnSensor
SectorsOnSensor()
Default constructor needed for the vector traits.
Definition: SectorsOnSensor.h:58