Skip to content

Commit fbb036e

Browse files
mconcassawenzel
authored andcommitted
Improve dbg mode
1 parent b106ba3 commit fbb036e

13 files changed

Lines changed: 344 additions & 66 deletions

Detectors/ITSMFT/ITS/tracking/cuda/include/ITStrackingCUDA/DeviceStoreVertexerGPU.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ inline std::vector<Tracklet> DeviceStoreVertexerGPU::getDupletsFromGPU(const Ord
193193
mDuplets12.copyIntoSizedVector(tmpDuplets);
194194
mNFoundDuplets[1].copyIntoSizedVector(nFoundDuplets);
195195
}
196-
197196
for (int iCluster{0}; iCluster < sizes[1]; ++iCluster) {
198197
const int stride{iCluster * mGPUConf.maxTrackletsPerCluster};
199198
for (int iDuplet{0}; iDuplet < nFoundDuplets[iCluster]; ++iDuplet) {
@@ -236,7 +235,6 @@ inline std::vector<int> DeviceStoreVertexerGPU::getHistogramZFromGPU()
236235
{
237236
std::vector<int> histoZ;
238237
histoZ.resize(mGPUConf.nBinsXYZ[2] - 1);
239-
std::cout << "Size of dest vector to be refined" << std::endl;
240238
mHistogramXYZ[2].copyIntoSizedVector(histoZ);
241239

242240
return histoZ;

Detectors/ITSMFT/ITS/tracking/cuda/src/DeviceStoreVertexerGPU.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ UniquePointer<DeviceStoreVertexerGPU> DeviceStoreVertexerGPU::initialise(const s
7171
const std::array<std::array<int, constants::index_table::ZBins * constants::index_table::PhiBins + 1>,
7272
constants::its::LayersNumberVertexer>& indexTables)
7373
{
74+
#ifdef _ALLOW_DEBUG_TREES_ITS_
7475
std::array<int, constants::its::LayersNumberVertexer> tmpSizes = {static_cast<int>(clusters[0].size()),
7576
static_cast<int>(clusters[1].size()),
7677
static_cast<int>(clusters[2].size())};
78+
mSizes.reset(tmpSizes.data(), static_cast<int>(3));
79+
#endif
7780
for (int iLayer{0}; iLayer < constants::its::LayersNumberVertexer; ++iLayer) {
7881
mClusters[iLayer].reset(clusters[iLayer].data(), static_cast<int>(clusters[iLayer].size()));
7982
}

Detectors/ITSMFT/ITS/tracking/cuda/src/VertexerTraitsGPU.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ GPUg() void trackleterKernel(
144144
const size_t stride{currentClusterIndex * store.getConfig().maxTrackletsPerCluster};
145145
const Cluster& currentCluster = store.getClusters()[1][currentClusterIndex]; // assign-constructor may be a problem, check
146146
const VertexerLayerName adjacentLayerIndex{layerOrder == TrackletingLayerOrder::fromInnermostToMiddleLayer ? VertexerLayerName::innermostLayer : VertexerLayerName::outerLayer};
147-
const int4 selectedBinsRect{VertexerTraits::getBinsRect(currentCluster, static_cast<int>(adjacentLayerIndex), 0.f, 50.f, phiCut)};
147+
const int4 selectedBinsRect{VertexerTraits::getBinsRect(currentCluster, static_cast<int>(adjacentLayerIndex), 0.f, 50.f, phiCut / 2)};
148148
if (selectedBinsRect.x != 0 || selectedBinsRect.y != 0 || selectedBinsRect.z != 0 || selectedBinsRect.w != 0) {
149149
int phiBinsNum{selectedBinsRect.w - selectedBinsRect.y + 1};
150150
if (phiBinsNum < 0) {
@@ -253,7 +253,6 @@ GPUg() void computeZCentroidsKernel(DeviceStoreVertexerGPU& store,
253253
{
254254
const int nLines = store.getNExclusiveFoundLines()[store.getClusters()[1].size() - 1] + store.getNFoundLines()[store.getClusters()[1].size() - 1];
255255
for (size_t currentThreadIndex = blockIdx.x * blockDim.x + threadIdx.x; currentThreadIndex < nLines; currentThreadIndex += blockDim.x * gridDim.x) {
256-
// printOnThread(0, "Max X: %d Max Y %d \n", store.getTmpVertexPositionBins()[0].value, store.getTmpVertexPositionBins()[1].value);
257256
if (store.getTmpVertexPositionBins()[0].value || store.getTmpVertexPositionBins()[1].value) {
258257
float tmpX{store.getConfig().lowHistBoundariesXYZ[0] + store.getTmpVertexPositionBins()[0].key * store.getConfig().binSizeHistX + store.getConfig().binSizeHistX / 2};
259258
int sumWX{store.getTmpVertexPositionBins()[0].value};
@@ -292,7 +291,7 @@ GPUg() void computeVertexKernel(DeviceStoreVertexerGPU& store, const int vertInd
292291
{
293292
for (size_t currentThreadIndex = blockIdx.x * blockDim.x + threadIdx.x; currentThreadIndex < binOpeningZ; currentThreadIndex += blockDim.x * gridDim.x) {
294293
if (currentThreadIndex == 0) {
295-
if (store.getTmpVertexPositionBins()[2].value > 1) {
294+
if (store.getTmpVertexPositionBins()[2].value > 1 && (store.getTmpVertexPositionBins()[0].value || store.getTmpVertexPositionBins()[1].value)) {
296295
float z{store.getConfig().lowHistBoundariesXYZ[2] + store.getTmpVertexPositionBins()[2].key * store.getConfig().binSizeHistZ + store.getConfig().binSizeHistZ / 2};
297296
float ex{0.f};
298297
float ey{0.f};

Detectors/ITSMFT/ITS/tracking/hip/src/DeviceStoreVertexerHIP.hip.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ UniquePointer<DeviceStoreVertexerHIP> DeviceStoreVertexerHIP::initialise(const s
7171
const std::array<std::array<int, constants::index_table::ZBins * constants::index_table::PhiBins + 1>,
7272
constants::its::LayersNumberVertexer>& indexTables)
7373
{
74+
#ifdef _ALLOW_DEBUG_TREES_ITS_
75+
std::array<int, constants::its::LayersNumberVertexer> tmpSizes = {static_cast<int>(clusters[0].size()),
76+
static_cast<int>(clusters[1].size()),
77+
static_cast<int>(clusters[2].size())};
78+
79+
mSizes.reset(tmpSizes.data(), static_cast<int>(3));
80+
#endif
7481
for (int iLayer{0}; iLayer < constants::its::LayersNumberVertexer; ++iLayer) {
7582
mClusters[iLayer].reset(clusters[iLayer].data(), static_cast<int>(clusters[iLayer].size()));
7683
}

Detectors/ITSMFT/ITS/tracking/hip/src/VertexerTraitsHIP.hip.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ GPUg() void trackleterKernel(
145145
const unsigned int stride{currentClusterIndex * store->getConfig().maxTrackletsPerCluster};
146146
const Cluster& currentCluster = store->getClusters()[1][currentClusterIndex]; // assign-constructor may be a problem, check
147147
const VertexerLayerName adjacentLayerIndex{layerOrder == TrackletingLayerOrder::fromInnermostToMiddleLayer ? VertexerLayerName::innermostLayer : VertexerLayerName::outerLayer};
148-
const int4 selectedBinsRect{VertexerTraits::getBinsRect(currentCluster, static_cast<int>(adjacentLayerIndex), 0.f, 50.f, phiCut)};
148+
const int4 selectedBinsRect{VertexerTraits::getBinsRect(currentCluster, static_cast<int>(adjacentLayerIndex), 0.f, 50.f, phiCut / 2)};
149149
if (selectedBinsRect.x != 0 || selectedBinsRect.y != 0 || selectedBinsRect.z != 0 || selectedBinsRect.w != 0) {
150150
int phiBinsNum{selectedBinsRect.w - selectedBinsRect.y + 1};
151151
if (phiBinsNum < 0) {
@@ -293,7 +293,7 @@ GPUg() void computeVertexKernel(DeviceStoreVertexerHIP* store, const int vertInd
293293
{
294294
for (unsigned int currentThreadIndex = blockIdx.x * blockDim.x + threadIdx.x; (int)currentThreadIndex < binOpeningZ; currentThreadIndex += blockDim.x * gridDim.x) {
295295
if (currentThreadIndex == 0) {
296-
if (store->getTmpVertexPositionBins()[2].value > 1) {
296+
if (store->getTmpVertexPositionBins()[2].value > 1 && (store->getTmpVertexPositionBins()[0].value || store->getTmpVertexPositionBins()[1].value)) {
297297
float z{store->getConfig().lowHistBoundariesXYZ[2] + store->getTmpVertexPositionBins()[2].key * store->getConfig().binSizeHistZ + store->getConfig().binSizeHistZ / 2};
298298
float ex{0.f};
299299
float ey{0.f};

Detectors/ITSMFT/ITS/tracking/include/ITStracking/ClusterLines.h

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include "ITStracking/Tracklet.h"
1919
#include "GPUCommonMath.h"
2020

21+
#ifdef _ALLOW_DEBUG_TREES_ITS_
22+
#include <unordered_map>
23+
#endif
24+
2125
namespace o2
2226
{
2327
namespace its
@@ -30,6 +34,10 @@ struct Line final {
3034
GPUhd() Line(const float firstPoint[3], const float secondPoint[3]);
3135
GPUhd() Line(const Tracklet&, const Cluster*, const Cluster*);
3236

37+
#ifdef _ALLOW_DEBUG_TREES_ITS_
38+
Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters, const int evId);
39+
#endif
40+
3341
inline static float getDistanceFromPoint(const Line& line, const std::array<float, 3>& point);
3442
GPUhd() static float getDistanceFromPoint(const Line& line, const float point[3]);
3543
static std::array<float, 6> getDCAComponents(const Line& line, const std::array<float, 3> point);
@@ -47,6 +55,10 @@ struct Line final {
4755
// 3 --> 1,1
4856
// 4 --> 1,2
4957
// 5 --> 2,2
58+
// Debug quantities
59+
#ifdef _ALLOW_DEBUG_TREES_ITS_
60+
int evtId; // -1 if fake
61+
#endif
5062
};
5163

5264
inline Line::Line() : weightMatrix{1., 0., 0., 1., 0., 1.}
@@ -64,6 +76,9 @@ inline Line::Line(const Line& other)
6476
for (int i{0}; i < 6; ++i) {
6577
weightMatrix[i] = other.weightMatrix[i];
6678
}
79+
#ifdef _ALLOW_DEBUG_TREES_ITS_
80+
evtId = other.evtId;
81+
#endif
6782
}
6883

6984
inline Line::Line(const float firstPoint[3], const float secondPoint[3])
@@ -97,6 +112,25 @@ inline Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const
97112
cosinesDirector[index] *= inverseNorm;
98113
}
99114

115+
#ifdef _ALLOW_DEBUG_TREES_ITS_
116+
inline Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters, const int evId) : evtId{evId}
117+
{
118+
originPoint[0] = innerClusters[tracklet.firstClusterIndex].xCoordinate;
119+
originPoint[1] = innerClusters[tracklet.firstClusterIndex].yCoordinate;
120+
originPoint[2] = innerClusters[tracklet.firstClusterIndex].zCoordinate;
121+
122+
cosinesDirector[0] = outerClusters[tracklet.secondClusterIndex].xCoordinate - innerClusters[tracklet.firstClusterIndex].xCoordinate;
123+
cosinesDirector[1] = outerClusters[tracklet.secondClusterIndex].yCoordinate - innerClusters[tracklet.firstClusterIndex].yCoordinate;
124+
cosinesDirector[2] = outerClusters[tracklet.secondClusterIndex].zCoordinate - innerClusters[tracklet.firstClusterIndex].zCoordinate;
125+
126+
float inverseNorm{1.f / gpu::CAMath::Sqrt(cosinesDirector[0] * cosinesDirector[0] + cosinesDirector[1] * cosinesDirector[1] +
127+
cosinesDirector[2] * cosinesDirector[2])};
128+
129+
for (int index{0}; index < 3; ++index)
130+
cosinesDirector[index] *= inverseNorm;
131+
}
132+
#endif
133+
100134
// static functions
101135
inline float Line::getDistanceFromPoint(const Line& line, const std::array<float, 3>& point)
102136
{
@@ -179,7 +213,10 @@ class ClusterLines final
179213
ClusterLines(const Line& firstLine, const Line& secondLine);
180214
void add(const int& lineLabel, const Line& line, const bool& weight = false);
181215
void computeClusterCentroid();
182-
inline std::vector<int>& getLabels() { return mLabels; }
216+
inline std::vector<int>& getLabels()
217+
{
218+
return mLabels;
219+
}
183220
inline int getSize() const { return mLabels.size(); }
184221
inline std::array<float, 3> getVertex() const { return mVertex; }
185222
inline std::array<float, 6> getRMS2() const { return mRMS2; }
@@ -190,6 +227,15 @@ class ClusterLines final
190227
{
191228
return mLines;
192229
}
230+
void vote(const Line& line);
231+
inline int getEventId() const { return mPoll; }
232+
inline float getPurity()
233+
{
234+
auto id = getEventId();
235+
auto it = mMap.find(id);
236+
assert(it != mMap.end());
237+
return (float)it->second / (float)mLabels.size();
238+
}
193239
#endif
194240

195241
protected:
@@ -198,11 +244,15 @@ class ClusterLines final
198244
std::vector<int> mLabels; // labels
199245
std::array<float, 3> mVertexCandidate; // vertex candidate
200246
std::array<float, 9> mWeightMatrix; // weight matrix
201-
std::array<float, 3> mVertex; // cluster centroid posdtion
247+
std::array<float, 3> mVertex; // cluster centroid position
202248
std::array<float, 6> mRMS2; // symmetric matrix: diagonal is RMS2
203249
float mAvgDistance2; // substitute for chi2
204250
#ifdef _ALLOW_DEBUG_TREES_ITS_
205251
std::vector<Line> mLines;
252+
int mPoll;
253+
int mNVotes;
254+
std::unordered_map<int, int> mMap;
255+
int mSwitches;
206256
#endif
207257
};
208258

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Configuration.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct VertexingParameters {
115115
float phiCut = 0.005f; //0.005f
116116
float pairCut = 0.04f;
117117
float clusterCut = 0.8f;
118-
float histPairCut = 0.01f;
118+
float histPairCut = 0.04f;
119119
float tanLambdaCut = 0.002f; // tanLambda = deltaZ/deltaR
120120
int clusterContributorsCut = 16;
121121
int phiSpan = -1;
@@ -132,9 +132,9 @@ struct VertexerStoreConfigurationGPU {
132132
int maxTrackletCapacity = 2e4;
133133
int maxCentroidsXYCapacity = std::ceil(maxTrackletCapacity * (maxTrackletCapacity - 1) / 2);
134134
int nMaxVertices = 10;
135-
int nBinsXYZ[3] = {402, 402, 2002};
135+
int nBinsXYZ[3] = {402, 402, 4002};
136136
// int nBinsXYZ[3] = {5, 5, 2002};
137-
int binSpanXYZ[3] = {1, 1, 1};
137+
int binSpanXYZ[3] = {2, 2, 4};
138138
float lowHistBoundariesXYZ[3] = {-1.98f, -1.98f, -40.f};
139139
float highHistBoundariesXYZ[3] = {1.98f, 1.98f, 40.f};
140140
float binSizeHistX = (highHistBoundariesXYZ[0] - lowHistBoundariesXYZ[0]) / (nBinsXYZ[0] - 1);
@@ -143,8 +143,8 @@ struct VertexerStoreConfigurationGPU {
143143
};
144144

145145
struct VertexerHistogramsConfiguration {
146-
int nBinsXYZ[3] = {402, 402, 2002};
147-
int binSpanXYZ[3] = {2, 2, 1};
146+
int nBinsXYZ[3] = {402, 402, 4002};
147+
int binSpanXYZ[3] = {2, 2, 4};
148148
float lowHistBoundariesXYZ[3] = {-1.98f, -1.98f, -40.f};
149149
float highHistBoundariesXYZ[3] = {1.98f, 1.98f, 40.f};
150150
float binSizeHistX = (highHistBoundariesXYZ[0] - lowHistBoundariesXYZ[0]) / (nBinsXYZ[0] - 1);

Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class StandaloneDebugger
3737
explicit StandaloneDebugger(const std::string debugTreeFileName = "dbg_ITS.root");
3838
~StandaloneDebugger();
3939
void setDebugTreeFileName(std::string);
40-
const std::string& getDebugTreeFileName() const { return mDebugTreeFileName; }
4140

41+
// Monte carlo oracle
42+
int getEventId(const int firstClusterId, const int secondClusterId, ROframe* frame);
43+
44+
// Tree part
45+
const std::string& getDebugTreeFileName() const { return mDebugTreeFileName; }
4246
void fillCombinatoricsTree(std::array<std::vector<Cluster>, constants::its::LayersNumberVertexer>&,
4347
std::vector<Tracklet>,
4448
std::vector<Tracklet>,
@@ -51,7 +55,11 @@ class StandaloneDebugger
5155
const ROframe*);
5256
void fillLinesSummaryTree(std::vector<Line>, const ROframe*);
5357
void fillPairsInfoTree(std::vector<Line>, const ROframe*);
58+
void fillLineClustersTree(std::vector<ClusterLines> clusters, const ROframe* event);
5459
void fillXYZHistogramTree(std::array<std::vector<int>, 3>, const std::array<int, 3>);
60+
void fillVerticesInfoTree(float x, float y, float z, int size, int rId, int eId, float pur);
61+
62+
static int getBinIndex(const float, const int, const float, const float);
5563

5664
private:
5765
std::string mDebugTreeFileName = "dbg_ITS.root"; // output filename

Detectors/ITSMFT/ITS/tracking/include/ITStracking/VertexerTraits.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,20 @@ using constants::its::LayersNumberVertexer;
5151

5252
struct lightVertex {
5353
lightVertex(float x, float y, float z, std::array<float, 6> rms2, int cont, float avgdis2, int stamp);
54+
#ifdef _ALLOW_DEBUG_TREES_ITS_
55+
lightVertex(float x, float y, float z, std::array<float, 6> rms2, int cont, float avgdis2, int stamp, int eId, float pur);
56+
#endif
5457
float mX;
5558
float mY;
5659
float mZ;
5760
std::array<float, 6> mRMS2;
5861
float mAvgDistance2;
5962
int mContributors;
6063
int mTimeStamp;
64+
#ifdef _ALLOW_DEBUG_TREES_ITS_
65+
float mPurity;
66+
int mEventId;
67+
#endif
6168
};
6269

6370
struct ClusterMCLabelInfo {
@@ -75,9 +82,14 @@ enum class VertexerDebug : unsigned int {
7582
HistCentroids = 0x1 << 5
7683
};
7784

78-
inline lightVertex::lightVertex(float x, float y, float z, std::array<float, 6> rms2, int cont, float avgdis2, int stamp) : mX(x), mY(y), mZ(z), mRMS2(rms2), mAvgDistance2(avgdis2), mContributors(cont), mTimeStamp(stamp)
85+
inline lightVertex::lightVertex(float x, float y, float z, std::array<float, 6> rms2, int cont, float avgdis2, int stamp) : mX{x}, mY{y}, mZ{z}, mRMS2{rms2}, mAvgDistance2{avgdis2}, mContributors{cont}, mTimeStamp{stamp}
7986
{
8087
}
88+
#ifdef _ALLOW_DEBUG_TREES_ITS_
89+
inline lightVertex::lightVertex(float x, float y, float z, std::array<float, 6> rms2, int cont, float avgdis2, int stamp, int eId, float pur) : mX{x}, mY{y}, mZ{z}, mRMS2{rms2}, mAvgDistance2{avgdis2}, mContributors{cont}, mTimeStamp{stamp}, mEventId{eId}, mPurity{pur}
90+
{
91+
}
92+
#endif
8193

8294
class VertexerTraits
8395
{

Detectors/ITSMFT/ITS/tracking/src/ClusterLines.cxx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ std::array<float, 6> Line::getDCAComponents(const Line& line, const std::array<f
7676

7777
ClusterLines::ClusterLines(const int firstLabel, const Line& firstLine, const int secondLabel, const Line& secondLine,
7878
const bool weight)
79+
7980
{
8081
mLabels.push_back(firstLabel);
8182
mLabels.push_back(secondLabel);
@@ -171,6 +172,13 @@ ClusterLines::ClusterLines(const int firstLabel, const Line& firstLine, const in
171172
// AvgDistance2
172173
mAvgDistance2 = std::move(Line::getDistanceFromPoint(firstLine, mVertex) * Line::getDistanceFromPoint(firstLine, mVertex));
173174
mAvgDistance2 += (Line::getDistanceFromPoint(secondLine, mVertex) * Line::getDistanceFromPoint(secondLine, mVertex) - mAvgDistance2) / mLabels.size();
175+
176+
#ifdef _ALLOW_DEBUG_TREES_ITS_
177+
mNVotes = 1;
178+
mPoll = firstLine.evtId;
179+
mMap.emplace(firstLine.evtId, 1);
180+
vote(secondLine);
181+
#endif
174182
}
175183

176184
ClusterLines::ClusterLines(const Line& firstLine, const Line& secondLine)
@@ -258,13 +266,19 @@ ClusterLines::ClusterLines(const Line& firstLine, const Line& secondLine)
258266
determinantSecond;
259267

260268
computeClusterCentroid();
269+
#ifdef _ALLOW_DEBUG_TREES_ITS_
270+
mNVotes = 1;
271+
mPoll = firstLine.evtId;
272+
mMap.emplace(firstLine.evtId, 1);
273+
vote(secondLine);
274+
#endif
261275
}
262276

263277
void ClusterLines::add(const int& lineLabel, const Line& line, const bool& weight)
264278
{
265279
mLabels.push_back(lineLabel);
266280
#ifdef _ALLOW_DEBUG_TREES_ITS_
267-
// mLines.push_back(line);
281+
vote(line);
268282
#endif
269283
std::array<float, 3> covariance{1., 1., 1.};
270284

@@ -334,5 +348,28 @@ void ClusterLines::computeClusterCentroid()
334348
determinant;
335349
}
336350

351+
#ifdef _ALLOW_DEBUG_TREES_ITS_
352+
void ClusterLines::vote(const Line& line)
353+
{
354+
if (mNVotes == 0) {
355+
mPoll = line.evtId;
356+
++mNVotes;
357+
} else {
358+
if (line.evtId == mPoll) {
359+
++mNVotes;
360+
} else {
361+
++mSwitches;
362+
--mNVotes;
363+
}
364+
}
365+
auto it = mMap.find(line.evtId);
366+
if (it == mMap.end()) {
367+
mMap.emplace(line.evtId, 1);
368+
} else {
369+
it->second += 1;
370+
}
371+
}
372+
#endif
373+
337374
} // namespace its
338375
} // namespace o2

0 commit comments

Comments
 (0)