Skip to content

Commit 7f0f877

Browse files
committed
Fixes in ITS/MFT BuildTopologyDictionary class:
Save under the ccdb_object name. In absence of MC info assign as an error Pitch/sqrt(12*min(10, span)) in each dimension, also for the grouped topologies (even in case of MC) but increment the pith by the factor of the group pattens step in span (RowClassSpan and ColClassSpan = 4). Prevent dictionary size exceeding InvalidPatternID=2048.
1 parent 84ad624 commit 7f0f877

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
///
1515
/// \author Luca Barioglio, University and INFN of Torino
1616

17+
#include "DataFormatsITSMFT/CompCluster.h"
1718
#include "ITSMFTReconstruction/BuildTopologyDictionary.h"
1819
#include "ITSMFTReconstruction/LookUp.h"
20+
#include "ITSMFTBase/SegmentationAlpide.h"
1921
#include <cmath>
2022
#include <TFile.h>
2123

@@ -51,9 +53,11 @@ void BuildTopologyDictionary::accountTopology(const ClusterTopology& cluster, fl
5153
topInf.mXmean = dX;
5254
topInf.mZmean = dZ;
5355
topoStat.countsWithBias = 1;
56+
} else { // assign expected sigmas from the pixel X, Z sizes
57+
topInf.mXsigma2 = SegmentationAlpide::PitchRow * SegmentationAlpide::PitchRow / 12. / std::min(10, topInf.mSizeX);
58+
topInf.mZsigma2 = SegmentationAlpide::PitchCol * SegmentationAlpide::PitchCol / 12. / std::min(10, topInf.mSizeZ);
5459
}
5560
mMapInfo.insert(std::make_pair(cluster.getHash(), topInf));
56-
5761
} else {
5862
if (useDf) {
5963
auto num = topoStat.countsWithBias++;
@@ -90,10 +94,19 @@ void BuildTopologyDictionary::setThreshold(double thr)
9094
break;
9195
}
9296
}
97+
if (mNCommonTopologies >= CompCluster::InvalidPatternID) {
98+
mFrequencyThreshold = ((double)mTopologyFrequency[CompCluster::InvalidPatternID - 1].first) / mTotClusters;
99+
LOGP(warning, "Redefining prob. threshould from {} to {} to be below InvalidPatternID (was {})", thr, mFrequencyThreshold, mNCommonTopologies);
100+
mNCommonTopologies = CompCluster::InvalidPatternID - 1;
101+
}
93102
}
94103

95104
void BuildTopologyDictionary::setNCommon(unsigned int nCommon)
96105
{
106+
if (nCommon >= CompCluster::InvalidPatternID) {
107+
LOGP(warning, "Redefining nCommon from {} to {} to be below InvalidPatternID", nCommon, CompCluster::InvalidPatternID - 1);
108+
nCommon = CompCluster::InvalidPatternID - 1;
109+
}
97110
mTopologyFrequency.clear();
98111
for (auto&& p : mTopologyMap) { // p os pair<ulong,TopoStat>
99112
mTopologyFrequency.emplace_back(std::make_pair(p.second.countsTotal, p.first));
@@ -127,6 +140,11 @@ void BuildTopologyDictionary::setThresholdCumulative(double cumulative)
127140
totFreq += ((double)(q.first)) / mTotClusters;
128141
if (totFreq < cumulative) {
129142
mNCommonTopologies++;
143+
if (mNCommonTopologies >= CompCluster::InvalidPatternID) {
144+
totFreq -= ((double)(q.first)) / mTotClusters;
145+
mNCommonTopologies--;
146+
LOGP(warning, "Redefining cumulative threshould from {} to {} to be below InvalidPatternID)", cumulative, totFreq);
147+
}
130148
} else {
131149
break;
132150
}
@@ -148,17 +166,24 @@ void BuildTopologyDictionary::groupRareTopologies()
148166
GroupStruct gr;
149167
gr.mHash = mTopologyFrequency[j].second;
150168
gr.mFrequency = ((double)(mTopologyFrequency[j].first)) / mTotClusters;
169+
totFreq += gr.mFrequency;
151170
// rough estimation for the error considering a8 uniform distribution
152171
gr.mErrX = std::sqrt(mMapInfo.find(gr.mHash)->second.mXsigma2);
153172
gr.mErrZ = std::sqrt(mMapInfo.find(gr.mHash)->second.mZsigma2);
154-
gr.mErr2X = gr.mErrX * gr.mErrX;
155-
gr.mErr2Z = gr.mErrZ * gr.mErrZ;
173+
gr.mErr2X = mMapInfo.find(gr.mHash)->second.mXsigma2;
174+
gr.mErr2Z = mMapInfo.find(gr.mHash)->second.mZsigma2;
156175
gr.mXCOG = -1 * mMapInfo.find(gr.mHash)->second.mCOGx * o2::itsmft::SegmentationAlpide::PitchRow;
157176
gr.mZCOG = mMapInfo.find(gr.mHash)->second.mCOGz * o2::itsmft::SegmentationAlpide::PitchCol;
158177
gr.mNpixels = mMapInfo.find(gr.mHash)->second.mNpixels;
159178
gr.mPattern = mMapInfo.find(gr.mHash)->second.mPattern;
160179
gr.mIsGroup = false;
161180
mDictionary.mVectorOfIDs.push_back(gr);
181+
if (j == int(CompCluster::InvalidPatternID - 1)) {
182+
LOGP(warning, "Limiting N unique topologies to {}, threshold freq. to {}, cumulative freq. to {} to be below InvalidPatternID", j, gr.mFrequency, totFreq);
183+
mNCommonTopologies = j;
184+
mFrequencyThreshold = gr.mFrequency;
185+
break;
186+
}
162187
}
163188
// groupRareTopologies based on binning over number of rows and columns (TopologyDictionary::NumberOfRowClasses *
164189
// NumberOfColClasses)
@@ -176,8 +201,8 @@ void BuildTopologyDictionary::groupRareTopologies()
176201
// Create a structure for a group of rare topologies
177202
GroupStruct gr;
178203
gr.mHash = (((unsigned long)(grNum)) << 32) & 0xffffffff00000000;
179-
gr.mErrX = (rowBinEdge)*o2::itsmft::SegmentationAlpide::PitchRow / std::sqrt(12);
180-
gr.mErrZ = (colBinEdge)*o2::itsmft::SegmentationAlpide::PitchCol / std::sqrt(12);
204+
gr.mErrX = TopologyDictionary::RowClassSpan * o2::itsmft::SegmentationAlpide::PitchRow / std::sqrt(12 * std::min(10, rowBinEdge));
205+
gr.mErrZ = TopologyDictionary::ColClassSpan * o2::itsmft::SegmentationAlpide::PitchCol / std::sqrt(12 * std::min(10, colBinEdge));
181206
gr.mErr2X = gr.mErrX * gr.mErrX;
182207
gr.mErr2Z = gr.mErrZ * gr.mErrZ;
183208
gr.mXCOG = 0;
@@ -227,8 +252,16 @@ void BuildTopologyDictionary::groupRareTopologies()
227252
mDictionary.mVectorOfIDs.push_back(group);
228253
}
229254

230-
// Sorting the dictionary
231-
std::sort(mDictionary.mVectorOfIDs.begin(), mDictionary.mVectorOfIDs.end(), [](const GroupStruct& a, const GroupStruct& b) { return (a.mFrequency > b.mFrequency); });
255+
// Sorting the dictionary preserving all unique topologies
256+
std::sort(mDictionary.mVectorOfIDs.begin(), mDictionary.mVectorOfIDs.end(), [](const GroupStruct& a, const GroupStruct& b) {
257+
return (!a.mIsGroup) && b.mIsGroup ? true : (a.mIsGroup && (!b.mIsGroup) ? false : (a.mFrequency > b.mFrequency));
258+
});
259+
if (mDictionary.mVectorOfIDs.size() >= CompCluster::InvalidPatternID - 1) {
260+
LOGP(warning, "Max allowed {} patterns is reached, stopping", CompCluster::InvalidPatternID - 1);
261+
mDictionary.mVectorOfIDs.resize(CompCluster::InvalidPatternID - 1);
262+
}
263+
// Sorting the dictionary to final form
264+
std::sort(mDictionary.mVectorOfIDs.begin(), mDictionary.mVectorOfIDs.end(), [](const GroupStruct& a, const GroupStruct& b) { return a.mFrequency > b.mFrequency; });
232265
// Creating the map for common topologies
233266
for (int iKey = 0; iKey < mDictionary.getSize(); iKey++) {
234267
GroupStruct& gr = mDictionary.mVectorOfIDs[iKey];
@@ -283,7 +316,7 @@ void BuildTopologyDictionary::saveDictionaryRoot(const std::string& fname)
283316
{
284317
std::cout << "Saving the the dictionary in a ROOT file: ";
285318
TFile output(fname.c_str(), "recreate");
286-
output.WriteObjectAny(&mDictionary, mDictionary.Class(), "TopologyDictionary");
319+
output.WriteObjectAny(&mDictionary, mDictionary.Class(), "ccdb_object");
287320
output.Close();
288321
std::cout << "done!" << std::endl;
289322
}

0 commit comments

Comments
 (0)