29 LOG(info) <<
"Number of common topologies: " <<
mCommonMap.size();
30 LOG(info) <<
"Number of groups of rare topologies: " <<
mGroupMap.size();
45 LOG(info) <<
"ITS3 TopologyDictionary";
46 LOG(info) <<
"InnerBarrel";
48 LOG(info) <<
"OuterBarrel";
62 auto&
data = (IB) ? mDataIB : mDataOB;
63 data.mCommonMap.clear();
64 data.mGroupMap.clear();
70 os <<
"--- InnerBarrel:\n";
72 os <<
"ID: " <<
ID++ <<
" Hash: " << p.mHash <<
" ErrX: " << p.mErrX <<
" ErrZ : " << p.mErrZ <<
" xCOG: " << p.mXCOG <<
" zCOG: " << p.mZCOG <<
" Npixles: " << p.mNpixels <<
" Frequency: " << p.mFrequency <<
" isGroup : " << std::boolalpha << p.mIsGroup <<
'\n'
74 <<
"*********************************************************" <<
'\n'
78 os <<
"--- OuterBarrel:\n";
80 os <<
"ID: " <<
ID++ <<
" Hash: " << p.mHash <<
" ErrX: " << p.mErrX <<
" ErrZ : " << p.mErrZ <<
" xCOG: " << p.mXCOG <<
" zCOG: " << p.mZCOG <<
" Npixles: " << p.mNpixels <<
" Frequency: " << p.mFrequency <<
" isGroup : " << std::boolalpha << p.mIsGroup <<
'\n'
82 <<
"*********************************************************" <<
'\n'
90 std::ofstream file_output(outputfile, std::ios::out | std::ios::binary);
92 throw std::runtime_error(fmt::format(
"Cannot open output file %s!", outputfile));
95 auto writeData = [](
auto& file_output,
auto&
data) {
96 auto size =
data.mVectorOfIDs.size();
97 file_output.write(
reinterpret_cast<char*
>(&
size),
sizeof(
size));
98 for (
auto& p :
data.mVectorOfIDs) {
99 file_output.write(
reinterpret_cast<char*
>(&p.mHash),
sizeof(
unsigned long));
100 file_output.write(
reinterpret_cast<char*
>(&p.mErrX),
sizeof(float));
101 file_output.write(
reinterpret_cast<char*
>(&p.mErrZ),
sizeof(float));
102 file_output.write(
reinterpret_cast<char*
>(&p.mErr2X),
sizeof(float));
103 file_output.write(
reinterpret_cast<char*
>(&p.mErr2Z),
sizeof(float));
104 file_output.write(
reinterpret_cast<char*
>(&p.mXCOG),
sizeof(float));
105 file_output.write(
reinterpret_cast<char*
>(&p.mZCOG),
sizeof(float));
106 file_output.write(
reinterpret_cast<char*
>(&p.mNpixels),
sizeof(
int));
107 file_output.write(
reinterpret_cast<char*
>(&p.mFrequency),
sizeof(double));
108 file_output.write(
reinterpret_cast<char*
>(&p.mIsGroup),
sizeof(bool));
109 file_output.write(
const_cast<char*
>(
reinterpret_cast<const char*
>(&p.mPattern.getPattern())),
114 writeData(file_output, mDataIB);
115 writeData(file_output, mDataOB);
122 LOGP(info,
"Reading TopologyDictionary from File '{}'", fname);
124 std::unique_ptr<TopologyDictionary> d{
loadFrom(fname)};
129 throw std::runtime_error(fmt::format(
"Unrecognized format {}", fname));
137 std::ifstream in(fname.data(), std::ios::in | std::ios::binary);
139 LOG(error) <<
"The file " << fname <<
" coud not be opened";
140 throw std::runtime_error(
"The file coud not be opened");
145 std::size_t
size{}, cur{};
147 in.read(
reinterpret_cast<char*
>(&
size),
sizeof(std::size_t));
148 while (cur++ !=
size) {
149 in.read(
reinterpret_cast<char*
>(&gr.
mHash),
sizeof(
unsigned long));
150 in.read(
reinterpret_cast<char*
>(&gr.
mErrX),
sizeof(float));
151 in.read(
reinterpret_cast<char*
>(&gr.
mErrZ),
sizeof(float));
152 in.read(
reinterpret_cast<char*
>(&gr.
mErr2X),
sizeof(float));
153 in.read(
reinterpret_cast<char*
>(&gr.
mErr2Z),
sizeof(float));
154 in.read(
reinterpret_cast<char*
>(&gr.
mXCOG),
sizeof(float));
155 in.read(
reinterpret_cast<char*
>(&gr.
mZCOG),
sizeof(float));
156 in.read(
reinterpret_cast<char*
>(&gr.
mNpixels),
sizeof(
int));
157 in.read(
reinterpret_cast<char*
>(&gr.
mFrequency),
sizeof(double));
158 in.read(
reinterpret_cast<char*
>(&gr.
mIsGroup),
sizeof(bool));
160 data.mVectorOfIDs.push_back(gr);
162 data.mCommonMap.insert(std::make_pair(gr.
mHash, groupID));
167 data.mGroupMap.insert(std::make_pair((
int)(gr.
mHash >> 32) & 0x00000000ffffffff, groupID));
182 auto* histo =
new TH1F(hname.data(), Form(
"%s;Topology ID;Frequency", (IB) ?
"InnerBarrel" :
"OuterBarrel"), dictSize, -0.5, dictSize - 0.5);
183 histo->SetFillColor(kRed);
184 histo->SetFillStyle(3005);
185 histo->SetDrawOption(
"histo");
186 for (
int i = 0;
i < dictSize;
i++) {
195 static std::array<o2::its3::SegmentationMosaix, 3> mIBSegmentations{0, 1, 2};
203 mIBSegmentations[
layer].detectorToLocalUnchecked(cl.
getRow(), cl.
getCol(), locCl);
206 float xCurved{0.f}, yCurved{0.f};
207 mIBSegmentations[
layer].flatToCurved(locCl.X(), locCl.Y(), xCurved, yCurved);
208 locCl.SetXYZ(xCurved, yCurved, locCl.Z());
216 static std::array<o2::its3::SegmentationMosaix, 3> mIBSegmentations{0, 1, 2};
217 auto refRow = cl.
getRow();
218 auto refCol = cl.
getCol();
219 float xCOG = 0, zCOG = 0;
222 refRow -= round(xCOG);
223 refCol -= round(zCOG);
230 mIBSegmentations[
layer].detectorToLocalUnchecked(refRow + xCOG, refCol + zCOG, locCl);
231 float xCurved{0.f}, yCurved{0.f};
232 mIBSegmentations[
layer].flatToCurved(locCl.X(), locCl.Y(), xCurved, yCurved);
233 locCl.SetXYZ(xCurved, yCurved, locCl.Z());
240 LOGP(info,
"Loading TopologyDictionary from {} with name {}", fname, objName);
242 TFile fl(fname.c_str(),
"READ");
243 if (fl.IsZombie() || !fl.IsOpen()) {
244 throw std::runtime_error(fmt::format(
"Failed to open {} file", fname));
247 if (dict ==
nullptr) {
248 throw std::runtime_error(fmt::format(
"Failed to load {} from {}", objName, fname));
Definition of the BuildTopologyDictionary class for ITS3.
ClassImp(o2::its3::TopologyDictionary)
Definition of the SegmentationAlpide class.
Definition of the SegmentationMosaix class.
static constexpr float PitchCol
static constexpr float PitchRow
void readFromFile(const std::string &fileName)
math_utils::Point3D< T > getClusterCoordinates(const itsmft::CompClusterExt &cl) const
Returns the local position of a compact cluster.
static TopologyDictionary * loadFrom(const std::string &fileName="", const std::string &objName="ccdb_object")
void reset() noexcept
Resets internal structures.
void readBinaryFile(const std::string &fileName)
Reads the dictionary from a binary file.
void print() const noexcept
double getFrequency(int n, bool IB=true) const
Returns the frequency of the n_th element;.
void writeBinaryFile(const std::string &outputFile)
Prints the dictionary in a binary file.
int getSize(bool IB) const
Returns the number of elements in the dicionary;.
bool isGroup(int n, bool IB=true) const
Returns true if the element corresponds to a group of rare topologies.
void resetMaps(bool IB=true) noexcept
TH1F * getTopologyDistribution(const std::string_view hname, bool IB=true) const
Fills a hostogram with the distribution of the IDs.
int getColumnSpan() const
Returns the number of columns.
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
static constexpr int kExtendedPatternBytes
Maximum number of bytes for the cluster puttern + 2 bytes respectively for the number of rows and col...
unsigned char getByte(int n) const
Returns a specific byte of the pattern.
const std::array< unsigned char, kExtendedPatternBytes > & getPattern() const
Returns the pattern.
int getUsedBytes() const
Returns the number of bytes used for the pattern.
UShort_t getSensorID() const
UShort_t getPatternID() const
static void detectorToLocalUnchecked(L row, L col, T &xRow, T &zCol)
static constexpr float PitchCol
static constexpr float PitchRow
GLenum GLuint GLint GLint layer
T getDetID2Layer(T detID)
std::ostream & operator<<(std::ostream &os, const BuildTopologyDictionary &DB)
void readData(o2::tpc::GBTFrameContainer &container, std::vector< std::ofstream * > &outfiles, int &run, int &done)
std::unordered_map< unsigned long, int > mCommonMap
Map of pair <hash, position in mVectorOfIDs>
void print() const noexcept
std::vector< itsmft::GroupStruct > mVectorOfIDs
Vector of topologies and groups.
std::unordered_map< int, int > mGroupMap
Map of pair <groudID, position in mVectorOfIDs>
std::array< int, STopoSize > mSmallTopologiesLUT
Look-Up Table for the topologies with 1-byte linearised matrix.
Structure containing the most relevant pieces of information of a topology.
float mErrX
Error associated to the hit point in the x direction.
float mErr2X
Squared Error associated to the hit point in the x direction.
float mErrZ
Error associated to the hit point in the z direction.
unsigned long mHash
Hashcode.
float mXCOG
x position of the COG wrt the bottom left corner of the bounding box
int mNpixels
Number of fired pixels.
double mFrequency
Frequency of the topology.
bool mIsGroup
false: common topology; true: group of rare topologies
float mErr2Z
Squared Error associated to the hit point in the z direction.
float mZCOG
z position of the COG wrt the bottom left corner of the bounding box
static bool endsWith(const std::string &s, const std::string &ending)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"