Belle II Software  release-05-02-19
FullSecID.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include "tracking/dataobjects/FullSecID.h"
12 #include <framework/logging/Logger.h>
13 #include <limits> // needed for numeric_limits<t>::max()
14 #include <assert.h> // testing purposes
15 #include <boost/format.hpp> // needed for xml-data-compatibility
16 // #include <sstream> // stringstream, needed for xml-data-compatibility
17 #include <vector> // needed for xml-data-compatibility
18 #include <boost/algorithm/string.hpp> // needed for xml-data-compatibility
19 #include <bitset>
20 
21 
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 
27 const int FullSecID::LayerBits = 4;
28 const int FullSecID::SubLayerBits = 1;
29 const int FullSecID::VxdIDBits = 16;
30 const int FullSecID::SectorBits = 11;
31 const int FullSecID::Bits = LayerBits + SubLayerBits + VxdIDBits + SectorBits;
32 const int FullSecID::MaxLayer = (1 << LayerBits) - 1;
33 const int FullSecID::MaxSubLayer = (1 << SubLayerBits) - 1;
34 const int FullSecID::MaxVxdID = (1 << VxdIDBits) - 1;
35 const int FullSecID::MaxSector = (1 << SectorBits) - 1;
36 const int FullSecID::MaxID = std::numeric_limits<unsigned int>::max();
37 const int FullSecID::LayerBitShift = SubLayerBits + VxdIDBits + SectorBits;
38 const int FullSecID::SubLayerBitShift = VxdIDBits + SectorBits;
39 const int FullSecID::VxdIDBitShift = SectorBits;
40 const int FullSecID::SubLayerMask = MaxSubLayer << SubLayerBitShift;
41 const int FullSecID::VxdIDMask = MaxVxdID << VxdIDBitShift;
42 const int FullSecID::SectorMask = MaxSector;
43 
44 
45 
46 FullSecID::FullSecID(std::string sid)
47 {
48  vector<string> stringSegments;
49  boost::split(stringSegments, sid, boost::is_any_of("_"));
50 
51  unsigned int LayerID = stringSegments[0][0] -
52  '0'; // since chars are (compared to strings) very problematic to convert to ints, this solution is very dirty but at least it's short and easy to read.
53  unsigned int SubLayerID = 0;
54  if (stringSegments[0].size() > 1) {
55  SubLayerID = stringSegments[0][1] - '0';
56  }
57 // unsigned int SubLayerID = stringSegments[0][1] - '0';
58  unsigned int UniID = std::stoi(stringSegments[1]); // C++03: atoi(stringSegments[1].c_str());
59  unsigned int sectorNumber = std::stoi(stringSegments[2]); // atoi(stringSegments[2].c_str());
60  B2DEBUG(1000, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID <<
61  ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
62  assert(LayerID < MaxLayer + 1);
63  assert(SubLayerID < MaxSubLayer + 1);
64  assert(UniID < MaxVxdID + 1);
65  assert(sectorNumber < MaxSector + 1);
66 
67  LayerID <<= LayerBitShift;
68  SubLayerID <<= SubLayerBitShift;
69  UniID <<= VxdIDBitShift;
70  m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
71 }
72 
73 
74 
75 FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
76  m_fullSecID(0) // setting to 0 to be sure that value is 0 when using it within the brackets
77 {
78  unsigned int LayerID = vxdID.getLayerNumber();
79  unsigned int SubLayerID = subLayerID; // converting to int
80  unsigned int UniID = vxdID;
81 
82  B2DEBUG(175, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID <<
83  ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
84  ", MaxSector " << MaxSector);
85  assert(LayerID < MaxLayer + 1);
86  assert(SubLayerID < MaxSubLayer + 1);
87  assert(UniID < MaxVxdID + 1);
88  assert(sectorNumber < MaxSector + 1);
89 
90  LayerID <<= LayerBitShift;
91  SubLayerID <<= SubLayerBitShift;
92  UniID <<= VxdIDBitShift;
93  m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
94 // m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
95 }
96 
97 
98 
99 FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
100 {
101  unsigned int SubLayerID = subLayerID; // converting to int
102  B2DEBUG(175, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID <<
103  ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
104  ", MaxSector " << MaxSector);
105  assert(layerID < MaxLayer + 1);
106  assert(SubLayerID < MaxSubLayer + 1);
107  assert(sensorID < MaxVxdID + 1);
108  assert(sectorNumber < MaxSector + 1);
109 
110  layerID <<= LayerBitShift;
111  SubLayerID <<= SubLayerBitShift;
112  sensorID <<= VxdIDBitShift;
113  m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber;
114  B2DEBUG(175, " m_fullSecID/binary: " << m_fullSecID << "/" << std::bitset<32>(m_fullSecID) << "\n, secID/binary: " << sectorNumber
115  << "/" << std::bitset<32>(sectorNumber) << ", layerID-binary: " << std::bitset<32>(layerID) << "\n, SubLayerID-binary: " <<
116  std::bitset<32>(SubLayerID) << ", sensorID-binary: " << std::bitset<32>(sensorID));
117 }
118 
119 std::string FullSecID::getFullSecString() const
120 {
121  if (getLayerID() == 0) {
122  return (boost::format("0%1%_000_%2%") % getLayerID() % getSecID()).str();
123  }
124  return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() %
125  getSecID()).str(); // WARNING this bypasses the following code - intended?
126 // if (getLayerID() == 0) {
127 // return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
128 // }
129 // return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
130 }
131 
132 
133 
134 
135 // FullSecID::FullSecID(std::string sid)
136 // {
137 // vector<string> stringSegments;
138 // boost::split(stringSegments, sid, boost::is_any_of("_"));
139 //
140 // unsigned int LayerID = stringSegments[0][0] - '0'; // since chars are (compared to strings) very problematic to convert to ints, this solution is very dirty but at least it's short and easy to read.
141 // unsigned int SubLayerID = stringSegments[0][1] - '0';
142 // unsigned int UniID = atoi(stringSegments[1].c_str()); // C++ 11: std::stoi( stringSegments[1] )
143 // unsigned int sectorNumber = atoi(stringSegments[2].c_str());
144 // B2DEBUG(1000, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID << ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
145 // assert(LayerID < MaxLayer + 1);
146 // assert(SubLayerID < MaxSubLayer + 1);
147 // assert(UniID < MaxVxdID + 1);
148 // assert(sectorNumber < MaxSector + 1);
149 //
150 // LayerID <<= LayerBitShift;
151 // SubLayerID <<= SubLayerBitShift;
152 // UniID <<= VxdIDBitShift;
153 // m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
154 // }
155 //
156 //
157 // FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
158 // m_fullSecID(0) // setting to 0 to be shure that value is 0 when using it within the brackets
159 // {
160 // unsigned int LayerID = vxdID.getLayerNumber();
161 // unsigned int SubLayerID = subLayerID; // converting to int
162 // unsigned int UniID = vxdID;
163 //
164 // B2DEBUG(175, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
165 // assert(LayerID < MaxLayer + 1);
166 // assert(SubLayerID < MaxSubLayer + 1);
167 // assert(UniID < MaxVxdID + 1);
168 // assert(sectorNumber < MaxSector + 1);
169 //
170 // LayerID <<= LayerBitShift;
171 // SubLayerID <<= SubLayerBitShift;
172 // UniID <<= VxdIDBitShift;
173 // m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
174 // // m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
175 // }
176 //
177 // FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
178 // {
179 // unsigned int SubLayerID = subLayerID; // converting to int
180 // B2DEBUG(175, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
181 // assert(layerID < MaxLayer + 1);
182 // assert(SubLayerID < MaxSubLayer + 1);
183 // assert(sensorID < MaxVxdID + 1);
184 // assert(sectorNumber < MaxSector + 1);
185 //
186 // layerID <<= LayerBitShift;
187 // SubLayerID <<= SubLayerBitShift;
188 // sensorID <<= VxdIDBitShift;
189 // m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber; // should be the same as below
190 // B2DEBUG(175, " m_fullSecID/binary: " << m_fullSecID << "/" << std::bitset<32>(m_fullSecID) << "\n, secID/binary: " << sectorNumber << "/" << std::bitset<32>(sectorNumber) << ", layerID-binary: " << std::bitset<32>(layerID) << "\n, SubLayerID-binary: " << std::bitset<32>(SubLayerID) << ", sensorID-binary: " << std::bitset<32>(sensorID))
191 // }
192 //
193 // std::string FullSecID::getFullSecString() const
194 // {
195 // return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() % getSecID()).str(); // WARNING this bypasses the following code - intended?
196 // if (getLayerID() == 0) {
197 // return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
198 // }
199 // return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
200 // }
201 
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::FullSecID::getUniID
unsigned short int getUniID() const
returns uniID of sensor (basically the same as VxdID (can simply converted to vxdID(uniID)) but a tri...
Definition: FullSecID.h:152
Belle2::FullSecID::getSubLayerID
bool getSubLayerID() const
returns SubLayerID which tells you whether it is useful to search for compatible sectors in the same ...
Definition: FullSecID.h:144
Belle2::FullSecID::MaxSubLayer
const static int MaxSubLayer
Maximum valid Ladder ID.
Definition: FullSecID.h:192
Belle2::FullSecID::LayerBitShift
const static int LayerBitShift
Number of bits to shift for storing a LayerID.
Definition: FullSecID.h:208
Belle2::FullSecID::m_fullSecID
BaseType m_fullSecID
contains full info of current SecID.
Definition: FullSecID.h:231
Belle2::FullSecID::VxdIDBitShift
const static int VxdIDBitShift
Number of bits shift for storing a full vxdID.
Definition: FullSecID.h:216
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::FullSecID::SubLayerBitShift
const static int SubLayerBitShift
Number of bits to shift for storing a SubLayerID.
Definition: FullSecID.h:212
Belle2::FullSecID::getSecID
short int getSecID() const
returns SecID of current FullSecID (only unique for each sensor).
Definition: FullSecID.h:156
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::FullSecID::FullSecID
FullSecID(const FullSecID &secID)
Copy constructor.
Definition: FullSecID.h:83
Belle2::FullSecID::getLayerID
short int getLayerID() const
returns LayerID compatible with basf2 standards.
Definition: FullSecID.h:128
Belle2::FullSecID::MaxSector
const static int MaxSector
Maximum valid Segment ID.
Definition: FullSecID.h:200
Belle2::FullSecID::MaxVxdID
const static int MaxVxdID
Maximum valid Sensor ID.
Definition: FullSecID.h:196
Belle2::FullSecID::getFullSecString
std::string getFullSecString() const
returns the FullSecID coded as string compatible to secIDs stored in the xml-sectormaps
Definition: FullSecID.cc:119
Belle2::FullSecID::MaxLayer
const static int MaxLayer
Maximum valid Layer ID.
Definition: FullSecID.h:188