Skip to content

Commit 9091544

Browse files
lbarioglshahor02
authored andcommitted
Fix grouping of rare topologies
1 parent ac62bbd commit 9091544

7 files changed

Lines changed: 55 additions & 54 deletions

File tree

DataFormats/Detectors/ITSMFT/common/include/DataFormatsITSMFT/TopologyDictionary.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ class TopologyDictionary
7373

7474
/// constexpr for the definition of the groups of rare topologies.
7575
/// The attritbution of the group ID is stringly dependent on the following parameters: it must be a power of 2.
76-
static constexpr int RowClassSpan = 4; ///< Row span of the classes of rare topologies
77-
static constexpr int ColClassSpan = 4; ///< Column span of the classes of rare topologies
78-
static constexpr int MinimumClassArea = RowClassSpan * ColClassSpan; ///< Area of the smallest class of rare topologies (used as reference)
79-
static constexpr int MaxNumberOfClasses = ClusterPattern::MaxPatternBits / MinimumClassArea; ///< Maximum number of row/column classes for the groups of rare topologies
80-
static constexpr int NumberOfRareGroups = MaxNumberOfClasses * MaxNumberOfClasses; ///< Number of entries corresponding to groups of rare topologies (those whos matrix exceed the max number of bytes are empty).
76+
static constexpr int RowClassSpan = 4; ///< Row span of the classes of rare topologies
77+
static constexpr int ColClassSpan = 4; ///< Column span of the classes of rare topologies
78+
static constexpr int MaxNumberOfRowClasses = 1 + (ClusterPattern::MaxRowSpan - 1) / RowClassSpan; ///< Maximum number of row classes for the groups of rare topologies
79+
static constexpr int MaxNumberOfColClasses = 1 + (ClusterPattern::MaxColSpan - 1) / ColClassSpan; ///< Maximum number of col classes for the groups of rare topologies
80+
static constexpr int NumberOfRareGroups = MaxNumberOfRowClasses * MaxNumberOfColClasses; ///< Number of entries corresponding to groups of rare topologies (those whos matrix exceed the max number of bytes are empty).
8181
/// Prints the dictionary
8282
friend std::ostream& operator<<(std::ostream& os, const TopologyDictionary& dictionary);
8383
/// Prints the dictionary in a binary file
@@ -169,7 +169,7 @@ class TopologyDictionary
169169
int mSmallTopologiesLUT[8 * 255 + 1]; ///< Look-Up Table for the topologies with 1-byte linearised matrix
170170
std::vector<GroupStruct> mVectorOfIDs; ///< Vector of topologies and groups
171171

172-
ClassDefNV(TopologyDictionary, 3);
172+
ClassDefNV(TopologyDictionary, 4);
173173
}; // namespace itsmft
174174
} // namespace itsmft
175175
} // namespace o2

DataFormats/Detectors/ITSMFT/common/src/TopologyDictionary.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ TopologyDictionary::TopologyDictionary(std::string fileName)
4040

4141
std::ostream& operator<<(std::ostream& os, const TopologyDictionary& dict)
4242
{
43+
int ID = 0;
4344
for (auto& p : dict.mVectorOfIDs) {
44-
os << "Hash: " << p.mHash << " ErrX: " << p.mErrX << " ErrZ : " << p.mErrZ << " xCOG: " << p.mXCOG << " zCOG: " << p.mZCOG << " Npixels: " << p.mNpixels << " Frequency: " << p.mFrequency << " isGroup : " << std::boolalpha << p.mIsGroup << std::endl
45+
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
4546
<< p.mPattern << std::endl
4647
<< "*********************************************************" << std::endl
4748
<< std::endl;

Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/BuildTopologyDictionary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BuildTopologyDictionary
8282

8383
std::unordered_map<long unsigned, TopologyInfo> mMapInfo;
8484

85-
ClassDefNV(BuildTopologyDictionary, 3);
85+
ClassDefNV(BuildTopologyDictionary, 4);
8686
};
8787
} // namespace itsmft
8888
} // namespace o2

Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/LookUp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LookUp
4545
TopologyDictionary mDictionary;
4646
int mTopologiesOverThreshold;
4747

48-
ClassDefNV(LookUp, 2);
48+
ClassDefNV(LookUp, 3);
4949
};
5050
} // namespace itsmft
5151
} // namespace o2

Detectors/ITSMFT/common/reconstruction/src/BuildTopologyDictionary.cxx

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -156,56 +156,53 @@ void BuildTopologyDictionary::groupRareTopologies()
156156
mDictionary.mVectorOfIDs.push_back(gr);
157157
}
158158
// groupRareTopologies based on binning over number of rows and columns (TopologyDictionary::NumberOfRowClasses *
159-
// NumberOfColClasse)
159+
// NumberOfColClasses)
160160

161161
std::unordered_map<int, std::pair<GroupStruct, unsigned long>> tmp_GroupMap; //<group ID, <Group struct, counts>>
162162

163163
int grNum = 0;
164164
int rowBinEdge = 0;
165165
int colBinEdge = 0;
166-
for (int iRowClass = 0; iRowClass < TopologyDictionary::MaxNumberOfClasses; iRowClass++) {
167-
for (int iColClass = 0; iColClass < TopologyDictionary::MaxNumberOfClasses; iColClass++) {
168-
if ((iRowClass + 1) * (iColClass + 1) <= TopologyDictionary::MaxNumberOfClasses) {
169-
rowBinEdge = (iRowClass + 1) * TopologyDictionary::RowClassSpan;
170-
colBinEdge = (iColClass + 1) * TopologyDictionary::ColClassSpan;
171-
grNum = LookUp::groupFinder(rowBinEdge, colBinEdge);
172-
// Create a structure for a group of rare topologies
173-
GroupStruct gr;
174-
gr.mHash = (((unsigned long)(grNum)) << 32) & 0xffffffff00000000;
175-
gr.mErrX = (rowBinEdge)*o2::itsmft::SegmentationAlpide::PitchRow / std::sqrt(12);
176-
gr.mErrZ = (colBinEdge)*o2::itsmft::SegmentationAlpide::PitchCol / std::sqrt(12);
177-
gr.mErr2X = gr.mErrX * gr.mErrX;
178-
gr.mErr2Z = gr.mErrZ * gr.mErrZ;
179-
gr.mXCOG = 0;
180-
gr.mZCOG = 0;
181-
gr.mNpixels = rowBinEdge * colBinEdge;
182-
gr.mIsGroup = true;
183-
gr.mFrequency = 0.;
184-
/// A dummy pattern with all fired pixels in the bounding box is assigned to groups of rare topologies.
185-
unsigned char dummyPattern[ClusterPattern::kExtendedPatternBytes] = {0};
186-
dummyPattern[0] = (unsigned char)rowBinEdge;
187-
dummyPattern[1] = (unsigned char)colBinEdge;
188-
int nBits = rowBinEdge * colBinEdge;
189-
int nBytes = nBits / 8;
190-
for (int iB = 2; iB < nBytes + 2; iB++) {
191-
dummyPattern[iB] = (unsigned char)255;
192-
}
193-
int residualBits = nBits % 8;
194-
if (residualBits) {
195-
unsigned char tempChar = 0;
196-
while (residualBits > 0) {
197-
residualBits--;
198-
tempChar |= 1 << (7 - residualBits);
199-
}
200-
dummyPattern[nBytes + 2] = tempChar;
166+
for (int iRowClass = 0; iRowClass < TopologyDictionary::MaxNumberOfRowClasses; iRowClass++) {
167+
for (int iColClass = 0; iColClass < TopologyDictionary::MaxNumberOfColClasses; iColClass++) {
168+
rowBinEdge = (iRowClass + 1) * TopologyDictionary::RowClassSpan;
169+
colBinEdge = (iColClass + 1) * TopologyDictionary::ColClassSpan;
170+
grNum = LookUp::groupFinder(rowBinEdge, colBinEdge);
171+
// Create a structure for a group of rare topologies
172+
GroupStruct gr;
173+
gr.mHash = (((unsigned long)(grNum)) << 32) & 0xffffffff00000000;
174+
gr.mErrX = (rowBinEdge)*o2::itsmft::SegmentationAlpide::PitchRow / std::sqrt(12);
175+
gr.mErrZ = (colBinEdge)*o2::itsmft::SegmentationAlpide::PitchCol / std::sqrt(12);
176+
gr.mErr2X = gr.mErrX * gr.mErrX;
177+
gr.mErr2Z = gr.mErrZ * gr.mErrZ;
178+
gr.mXCOG = 0;
179+
gr.mZCOG = 0;
180+
gr.mNpixels = rowBinEdge * colBinEdge;
181+
gr.mIsGroup = true;
182+
gr.mFrequency = 0.;
183+
/// A dummy pattern with all fired pixels in the bounding box is assigned to groups of rare topologies.
184+
unsigned char dummyPattern[ClusterPattern::kExtendedPatternBytes] = {0};
185+
dummyPattern[0] = (unsigned char)rowBinEdge;
186+
dummyPattern[1] = (unsigned char)colBinEdge;
187+
int nBits = rowBinEdge * colBinEdge;
188+
int nBytes = nBits / 8;
189+
for (int iB = 2; iB < nBytes + 2; iB++) {
190+
dummyPattern[iB] = (unsigned char)255;
191+
}
192+
int residualBits = nBits % 8;
193+
if (residualBits) {
194+
unsigned char tempChar = 0;
195+
while (residualBits > 0) {
196+
residualBits--;
197+
tempChar |= 1 << (7 - residualBits);
201198
}
202-
gr.mPattern.setPattern(dummyPattern);
203-
// Filling the map for groups
204-
tmp_GroupMap[grNum] = std::make_pair(gr, 0);
199+
dummyPattern[nBytes + 2] = tempChar;
205200
}
201+
gr.mPattern.setPattern(dummyPattern);
202+
// Filling the map for groups
203+
tmp_GroupMap[grNum] = std::make_pair(gr, 0);
206204
}
207205
}
208-
209206
int rs;
210207
int cs;
211208
int index;

Detectors/ITSMFT/common/reconstruction/src/LookUp.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ int LookUp::groupFinder(int nRow, int nCol)
4747
if (nCol % TopologyDictionary::RowClassSpan == 0) {
4848
col_index--;
4949
}
50-
if (row_index > TopologyDictionary::MaxNumberOfClasses || col_index > TopologyDictionary::MaxNumberOfClasses) {
51-
return TopologyDictionary::NumberOfRareGroups - 1;
50+
int grNum = -1;
51+
if (row_index > TopologyDictionary::MaxNumberOfRowClasses || col_index > TopologyDictionary::MaxNumberOfColClasses) {
52+
grNum = TopologyDictionary::NumberOfRareGroups - 1;
5253
} else {
53-
return row_index * TopologyDictionary::MaxNumberOfClasses + col_index;
54+
grNum = row_index * TopologyDictionary::MaxNumberOfColClasses + col_index;
5455
}
56+
return grNum;
5557
}
5658

5759
int LookUp::findGroupID(int nRow, int nCol, const unsigned char patt[ClusterPattern::MaxPatternBytes])

macro/compareTopologyDistributions.C

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ void compareTopologyDistributions(
2424
string output_file_name = "comparison.root")
2525
{
2626
if (dictionary_file_name.empty()) {
27-
dictionary_file_name = o2::base::NameConf::getDictionaryFileName(o2::detectors::DetID::ITS, "", ".root");
27+
dictionary_file_name = o2::base::NameConf::getDictionaryFileName(o2::detectors::DetID::ITS, "", ".bin");
2828
}
29-
TFile dictionary_file(dictionary_file_name.c_str());
3029
o2::itsmft::TopologyDictionary dict;
3130
dict.readBinaryFile(dictionary_file_name.c_str());
3231
int dict_size = dict.getSize();
@@ -49,6 +48,8 @@ void compareTopologyDistributions(
4948
hRec->Scale(1 / hRec->Integral());
5049

5150
TFile output_file(output_file_name.c_str(), "RECREATE");
51+
hRec->Write();
52+
hDictio->Write();
5253
TCanvas* cOut = new TCanvas("cOut", "cOut", 800, 600);
5354
cOut->SetLogy();
5455
hDictio->GetYaxis()->SetRangeUser(1.e-8, 1.2);

0 commit comments

Comments
 (0)