26using std::unordered_map;
38 memset(mSmallTopologiesLUT, -1, STopoSize *
sizeof(
int));
49 for (
auto& p : dict.mVectorOfIDs) {
50 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 << std::endl
51 << p.mPattern << std::endl
52 <<
"*********************************************************" << std::endl
60 std::ofstream file_output(outputfile, std::ios::out | std::ios::binary);
61 for (
auto& p : mVectorOfIDs) {
62 file_output.write(
reinterpret_cast<char*
>(&p.mHash),
sizeof(
unsigned long));
63 file_output.write(
reinterpret_cast<char*
>(&p.mErrX),
sizeof(float));
64 file_output.write(
reinterpret_cast<char*
>(&p.mErrZ),
sizeof(float));
65 file_output.write(
reinterpret_cast<char*
>(&p.mErr2X),
sizeof(float));
66 file_output.write(
reinterpret_cast<char*
>(&p.mErr2Z),
sizeof(float));
67 file_output.write(
reinterpret_cast<char*
>(&p.mXCOG),
sizeof(float));
68 file_output.write(
reinterpret_cast<char*
>(&p.mZCOG),
sizeof(float));
69 file_output.write(
reinterpret_cast<char*
>(&p.mNpixels),
sizeof(
int));
70 file_output.write(
reinterpret_cast<char*
>(&p.mFrequency),
sizeof(double));
71 file_output.write(
reinterpret_cast<char*
>(&p.mIsGroup),
sizeof(bool));
72 file_output.write(
reinterpret_cast<char*
>(&p.mPattern.mBitmap),
81 std::unique_ptr<TopologyDictionary> d{
loadFrom(fname)};
86 throw std::runtime_error(fmt::format(
"Unrecognized format {}", fname));
95 for (
auto& p : mSmallTopologiesLUT) {
98 std::ifstream in(fname.data(), std::ios::in | std::ios::binary);
102 LOG(error) <<
"The file " << fname <<
" coud not be opened";
103 throw std::runtime_error(
"The file coud not be opened");
105 while (in.read(
reinterpret_cast<char*
>(&gr.
mHash),
sizeof(
unsigned long))) {
106 in.read(
reinterpret_cast<char*
>(&gr.
mErrX),
sizeof(
float));
107 in.read(
reinterpret_cast<char*
>(&gr.
mErrZ),
sizeof(
float));
108 in.read(
reinterpret_cast<char*
>(&gr.
mErr2X),
sizeof(
float));
109 in.read(
reinterpret_cast<char*
>(&gr.
mErr2Z),
sizeof(
float));
110 in.read(
reinterpret_cast<char*
>(&gr.
mXCOG),
sizeof(
float));
111 in.read(
reinterpret_cast<char*
>(&gr.
mZCOG),
sizeof(
float));
112 in.read(
reinterpret_cast<char*
>(&gr.
mNpixels),
sizeof(
int));
113 in.read(
reinterpret_cast<char*
>(&gr.
mFrequency),
sizeof(
double));
114 in.read(
reinterpret_cast<char*
>(&gr.
mIsGroup),
sizeof(
bool));
116 mVectorOfIDs.push_back(gr);
118 mCommonMap.insert(std::make_pair(gr.
mHash, groupID));
123 mGroupMap.insert(std::make_pair((
int)(gr.
mHash >> 32) & 0x00000000ffffffff, groupID));
138 histo =
new TH1F(histName,
";Topology ID;Frequency", dictSize, -0.5, dictSize - 0.5);
139 histo->SetFillColor(kRed);
140 histo->SetFillStyle(3005);
141 histo->SetDrawOption(
"histo");
142 for (
int i = 0;
i < dictSize;
i++) {
150 std::array<T, 3> locCl;
162 locCl.SetX(locCl.X() + this->getXCOG(cl.
getPatternID()));
163 locCl.SetZ(locCl.Z() + this->getZCOG(cl.
getPatternID()));
170 auto refRow = cl.
getRow();
171 auto refCol = cl.
getCol();
172 float xCOG = 0, zCOG = 0;
175 refRow -= round(xCOG);
176 refCol -= round(zCOG);
186 auto refRow = cl.
getRow();
187 auto refCol = cl.
getCol();
188 float xCOG = 0, zCOG = 0;
191 refRow -= round(xCOG);
192 refCol -= round(zCOG);
194 std::array<T, 3> locCl;
203 TFile fl(fname.c_str());
205 throw std::runtime_error(fmt::format(
"Failed to open {} file", fname));
209 throw std::runtime_error(fmt::format(
"Failed to load {} from {}", objName, fname));
219template std::array<float, 3> TopologyDictionary::getClusterCoordinatesA<float>(
const CompCluster& cl)
const;
220template std::array<double, 3> TopologyDictionary::getClusterCoordinatesA<double>(
const CompCluster& cl)
const;
221template std::array<float, 3> TopologyDictionary::getClusterCoordinatesA<float>(
const CompCluster& cl,
const ClusterPattern& patt,
bool isGroup);
222template std::array<double, 3> TopologyDictionary::getClusterCoordinatesA<double>(
const CompCluster& cl,
const ClusterPattern& patt,
bool isGroup);
Definition of the ClusterTopology class.
Definition of the SegmentationAlpide class.
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...
int getUsedBytes() const
Returns the number of bytes used for the pattern.
UShort_t getPatternID() const
static void detectorToLocalUnchecked(L row, L col, T &xRow, T &zCol)
TopologyDictionary()
Default constructor.
int readBinaryFile(const std::string &fileName)
Reads the dictionary from a binary file.
std::array< T, 3 > getClusterCoordinatesA(const CompCluster &cl) const
Returns the local position of a compact cluster.
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
int getSize() const
Returns the number of elements in the dicionary;.
int readFromFile(const std::string &fileName)
static TopologyDictionary * loadFrom(const std::string &fileName="", const std::string &objName="ccdb_object")
void writeBinaryFile(const std::string &outputFile)
Prints the dictionary in a binary file.
double getFrequency(int n) const
Returns the frequency of the n_th element;.
static void getTopologyDistribution(const TopologyDictionary &dict, TH1F *&histo, const char *histName)
Fills a hostogram with the distribution of the IDs.
float getXCOG(int n) const
Returns the x position of the COG for the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getZCOG(int n) const
Returns the z position of the COG for the n_th element.
std::ostream & operator<<(std::ostream &os, const ClusterPattern &pattern)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
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"