Project
Loading...
Searching...
No Matches
TimeFrame.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
16#include <numeric>
17#include <sstream>
18
19#include "Framework/Logger.h"
30
31namespace
32{
33struct ClusterHelper {
34 float phi;
35 float r;
36 int bin;
37 int ind;
38};
39} // namespace
40
41namespace o2::its
42{
43
48
49template <int nLayers>
51{
52 resetVectors();
53}
54
55template <int nLayers>
57{
58 wipe();
59}
60
61template <int nLayers>
63{
64 for (const auto& vertex : vertices) {
65 mPrimaryVertices.emplace_back(vertex);
66 if (!isBeamPositionOverridden) {
67 const float w = vertex.getNContributors();
68 mBeamPos[0] = (mBeamPos[0] * mBeamPosWeight + vertex.getX() * w) / (mBeamPosWeight + w);
69 mBeamPos[1] = (mBeamPos[1] * mBeamPosWeight + vertex.getY() * w) / (mBeamPosWeight + w);
70 mBeamPosWeight += w;
71 }
72 }
73 mROFramesPV.push_back(mPrimaryVertices.size());
74}
75
76template <int nLayers>
77void TimeFrame<nLayers>::addPrimaryVertices(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration)
78{
79 addPrimaryVertices(gsl::span<const Vertex>(vertices), rofId, iteration);
82template <int nLayers>
83void TimeFrame<nLayers>::addPrimaryVerticesLabels(bounded_vector<std::pair<MCCompLabel, float>>& labels)
85 mVerticesMCRecInfo.insert(mVerticesMCRecInfo.end(), labels.begin(), labels.end());
86}
87
88template <int nLayers>
89void TimeFrame<nLayers>::addPrimaryVerticesInROF(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration)
90{
91 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId], vertices.begin(), vertices.end());
92 for (int i = rofId + 1; i < mROFramesPV.size(); ++i) {
93 mROFramesPV[i] += vertices.size();
94 }
95 mTotVertPerIteration[iteration] += vertices.size();
96}
97
98template <int nLayers>
99void TimeFrame<nLayers>::addPrimaryVerticesLabelsInROF(const bounded_vector<std::pair<MCCompLabel, float>>& labels, const int rofId)
100{
101 mVerticesMCRecInfo.insert(mVerticesMCRecInfo.begin() + mROFramesPV[rofId], labels.begin(), labels.end());
102}
103
104template <int nLayers>
105void TimeFrame<nLayers>::addPrimaryVertices(const gsl::span<const Vertex>& vertices, const int rofId, const int iteration)
106{
107 bounded_vector<Vertex> futureVertices(mMemoryPool.get());
108 for (const auto& vertex : vertices) {
109 if (vertex.getTimeStamp().getTimeStamp() < rofId) { // put a copy in the past
110 insertPastVertex(vertex, iteration);
111 } else {
112 if (vertex.getTimeStamp().getTimeStamp() > rofId) { // or put a copy in the future
113 futureVertices.emplace_back(vertex);
114 }
115 }
116 mPrimaryVertices.emplace_back(vertex); // put a copy in the present
117 mTotVertPerIteration[iteration]++;
118 if (!isBeamPositionOverridden) { // beam position is updated only at first occurrence of the vertex. A bit sketchy if we have past/future vertices, it should not impact too much.
119 const float w = vertex.getNContributors();
120 mBeamPos[0] = (mBeamPos[0] * mBeamPosWeight + vertex.getX() * w) / (mBeamPosWeight + w);
121 mBeamPos[1] = (mBeamPos[1] * mBeamPosWeight + vertex.getY() * w) / (mBeamPosWeight + w);
122 mBeamPosWeight += w;
123 }
124 }
125 mROFramesPV.push_back(mPrimaryVertices.size()); // current rof must have number of vertices up to present
126 for (auto& vertex : futureVertices) {
127 mPrimaryVertices.emplace_back(vertex);
128 mTotVertPerIteration[iteration]++;
129 }
130}
131
132template <int nLayers>
133int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
134 gsl::span<const itsmft::CompClusterExt> clusters,
135 gsl::span<const unsigned char>::iterator& pattIt,
136 const itsmft::TopologyDictionary* dict,
138{
139 resetROFrameData();
140
143
144 mNrof = 0;
145 clearResizeBoundedVector(mClusterSize, clusters.size(), mMemoryPool.get());
146 for (auto& rof : rofs) {
147 for (int clusterId{rof.getFirstEntry()}; clusterId < rof.getFirstEntry() + rof.getNEntries(); ++clusterId) {
148 const auto& c = clusters[clusterId];
149
150 int layer = geom->getLayer(c.getSensorID());
151
152 auto pattID = c.getPatternID();
154 float sigmaY2 = DefClusError2Row, sigmaZ2 = DefClusError2Col, sigmaYZ = 0; // Dummy COG errors (about half pixel size)
155 unsigned int clusterSize{0};
157 sigmaY2 = dict->getErr2X(pattID);
158 sigmaZ2 = dict->getErr2Z(pattID);
159 if (!dict->isGroup(pattID)) {
160 locXYZ = dict->getClusterCoordinates(c);
161 clusterSize = dict->getNpixels(pattID);
162 } else {
163 o2::itsmft::ClusterPattern patt(pattIt);
164 locXYZ = dict->getClusterCoordinates(c, patt);
165 clusterSize = patt.getNPixels();
166 }
167 } else {
168 o2::itsmft::ClusterPattern patt(pattIt);
169 locXYZ = dict->getClusterCoordinates(c, patt, false);
170 clusterSize = patt.getNPixels();
171 }
172 mClusterSize[clusterId] = std::clamp(clusterSize, 0u, 255u);
173 auto sensorID = c.getSensorID();
174 // Inverse transformation to the local --> tracking
175 auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
176 // Transformation to the local --> global
177 auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
178
179 addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
180 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
181 std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
182
184 addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), mUnsortedClusters[layer].size());
185 addClusterExternalIndexToLayer(layer, clusterId);
186 }
187 for (unsigned int iL{0}; iL < mUnsortedClusters.size(); ++iL) {
188 mROFramesClusters[iL].push_back(mUnsortedClusters[iL].size());
189 }
190 mNrof++;
192
193 for (auto i = 0; i < mNTrackletsPerCluster.size(); ++i) {
194 mNTrackletsPerCluster[i].resize(mUnsortedClusters[1].size());
195 mNTrackletsPerClusterSum[i].resize(mUnsortedClusters[1].size() + 1); // Exc sum "prepends" a 0
196 }
197
198 if (mcLabels != nullptr) {
199 mClusterLabels = mcLabels;
200 }
201
202 return mNrof;
203}
204
205template <int nLayers>
207{
208 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
209 deepVectorClear(mUnsortedClusters[iLayer], mMemoryPool.get());
210 deepVectorClear(mTrackingFrameInfo[iLayer], mMemoryPool.get());
211 deepVectorClear(mClusterExternalIndices[iLayer], mMemoryPool.get());
212 clearResizeBoundedVector(mROFramesClusters[iLayer], 1, mMemoryPool.get(), 0);
213
214 if (iLayer < 2) {
215 deepVectorClear(mTrackletsIndexROF[iLayer], mMemoryPool.get());
216 deepVectorClear(mNTrackletsPerCluster[iLayer], mMemoryPool.get());
217 deepVectorClear(mNTrackletsPerClusterSum[iLayer], mMemoryPool.get());
218 }
219 }
220}
221
222template <int nLayers>
223void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, const int maxLayers)
224{
225 const int numBins{trkParam.PhiBins * trkParam.ZBins};
226 const int stride{numBins + 1};
227 bounded_vector<ClusterHelper> cHelper(mMemoryPool.get());
228 bounded_vector<int> clsPerBin(numBins, 0, mMemoryPool.get());
229 bounded_vector<int> lutPerBin(numBins, 0, mMemoryPool.get());
230 for (int rof{0}; rof < mNrof; ++rof) {
231 if ((int)mMultiplicityCutMask.size() == mNrof && !mMultiplicityCutMask[rof]) {
232 continue;
233 }
234 for (int iLayer{0}, stopLayer = std::min(trkParam.NLayers, maxLayers); iLayer < stopLayer; ++iLayer) {
235 const auto& unsortedClusters{getUnsortedClustersOnLayer(rof, iLayer)};
236 const int clustersNum{static_cast<int>(unsortedClusters.size())};
237 auto* tableBase = mIndexTables[iLayer].data() + rof * stride;
238
239 cHelper.resize(clustersNum);
240
241 for (int iCluster{0}; iCluster < clustersNum; ++iCluster) {
242 const Cluster& c = unsortedClusters[iCluster];
243 ClusterHelper& h = cHelper[iCluster];
244
245 const float x = c.xCoordinate - mBeamPos[0];
246 const float y = c.yCoordinate - mBeamPos[1];
247 const float z = c.zCoordinate;
248
249 float phi = math_utils::computePhi(x, y);
250 int zBin{mIndexTableUtils.getZBinIndex(iLayer, z)};
251 if (zBin < 0 || zBin >= trkParam.ZBins) {
252 zBin = std::clamp(zBin, 0, trkParam.ZBins - 1);
253 mBogusClusters[iLayer]++;
254 }
255 int bin = mIndexTableUtils.getBinIndex(zBin, mIndexTableUtils.getPhiBinIndex(phi));
256 h.phi = phi;
257 h.r = math_utils::hypot(x, y);
258 mMinR[iLayer] = o2::gpu::GPUCommonMath::Min(h.r, mMinR[iLayer]);
259 mMaxR[iLayer] = o2::gpu::GPUCommonMath::Max(h.r, mMaxR[iLayer]);
260 h.bin = bin;
261 h.ind = clsPerBin[bin]++;
262 }
263 std::exclusive_scan(clsPerBin.begin(), clsPerBin.end(), lutPerBin.begin(), 0);
265 auto clusters2beSorted{getClustersOnLayer(rof, iLayer)};
266 for (int iCluster{0}; iCluster < clustersNum; ++iCluster) {
267 const ClusterHelper& h = cHelper[iCluster];
268 Cluster& c = clusters2beSorted[lutPerBin[h.bin] + h.ind];
270 c = unsortedClusters[iCluster];
271 c.phi = h.phi;
272 c.radius = h.r;
273 c.indexTableBinIndex = h.bin;
274 }
275 std::copy_n(lutPerBin.data(), clsPerBin.size(), tableBase);
276 std::fill_n(tableBase + clsPerBin.size(), stride - clsPerBin.size(), clustersNum);
277
278 std::fill(clsPerBin.begin(), clsPerBin.end(), 0);
279 cHelper.clear();
280 }
281 }
282}
283
284template <int nLayers>
285void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameters& trkParam, const int maxLayers, bool resetVertices)
286{
287 if (iteration == 0) {
288 if (maxLayers < trkParam.NLayers && resetVertices) {
289 resetRofPV();
290 deepVectorClear(mTotVertPerIteration);
291 }
292 deepVectorClear(mTracks);
293 deepVectorClear(mTracksLabel);
294 deepVectorClear(mLines);
295 deepVectorClear(mLinesLabels);
296 if (resetVertices) {
297 deepVectorClear(mVerticesMCRecInfo);
298 }
299 clearResizeBoundedVector(mTracks, mNrof, mMemoryPool.get());
300 clearResizeBoundedVector(mTracksLabel, mNrof, mMemoryPool.get());
301 clearResizeBoundedVector(mLinesLabels, mNrof, mMemoryPool.get());
302 clearResizeBoundedVector(mCells, trkParam.CellsPerRoad(), mMemoryPool.get());
303 clearResizeBoundedVector(mCellsLookupTable, trkParam.CellsPerRoad() - 1, mMemoryPool.get());
304 clearResizeBoundedVector(mCellsNeighbours, trkParam.CellsPerRoad() - 1, mMemoryPool.get());
305 clearResizeBoundedVector(mCellsNeighboursLUT, trkParam.CellsPerRoad() - 1, mMemoryPool.get());
306 clearResizeBoundedVector(mCellLabels, trkParam.CellsPerRoad(), mMemoryPool.get());
307 clearResizeBoundedVector(mTracklets, std::min(trkParam.TrackletsPerRoad(), maxLayers - 1), mMemoryPool.get());
308 clearResizeBoundedVector(mTrackletLabels, trkParam.TrackletsPerRoad(), mMemoryPool.get());
309 clearResizeBoundedVector(mTrackletsLookupTable, trkParam.TrackletsPerRoad(), mMemoryPool.get());
310 mIndexTableUtils.setTrackingParameters(trkParam);
311 clearResizeBoundedVector(mPositionResolution, trkParam.NLayers, mMemoryPool.get());
312 clearResizeBoundedVector(mBogusClusters, trkParam.NLayers, mMemoryPool.get());
313 deepVectorClear(mTrackletClusters);
314 for (unsigned int iLayer{0}; iLayer < std::min((int)mClusters.size(), maxLayers); ++iLayer) {
315 clearResizeBoundedVector(mClusters[iLayer], mUnsortedClusters[iLayer].size(), mMemoryPool.get());
316 clearResizeBoundedVector(mUsedClusters[iLayer], mUnsortedClusters[iLayer].size(), mMemoryPool.get());
317 mPositionResolution[iLayer] = o2::gpu::CAMath::Sqrt(0.5f * (trkParam.SystErrorZ2[iLayer] + trkParam.SystErrorY2[iLayer]) + trkParam.LayerResolution[iLayer] * trkParam.LayerResolution[iLayer]);
318 }
319 clearResizeBoundedArray(mIndexTables, mNrof * (trkParam.ZBins * trkParam.PhiBins + 1), mMemoryPool.get());
320 clearResizeBoundedVector(mLines, mNrof, mMemoryPool.get());
321 clearResizeBoundedVector(mTrackletClusters, mNrof, mMemoryPool.get());
322
323 for (int iLayer{0}; iLayer < trkParam.NLayers; ++iLayer) {
324 if (trkParam.SystErrorY2[iLayer] > 0.f || trkParam.SystErrorZ2[iLayer] > 0.f) {
325 for (auto& tfInfo : mTrackingFrameInfo[iLayer]) {
327 tfInfo.covarianceTrackingFrame[0] += trkParam.SystErrorY2[iLayer];
328 tfInfo.covarianceTrackingFrame[2] += trkParam.SystErrorZ2[iLayer];
329 }
330 }
331 }
332 }
333 mNTrackletsPerROF.resize(2);
334 for (auto& v : mNTrackletsPerROF) {
335 v = bounded_vector<int>(mNrof + 1, 0, mMemoryPool.get());
336 }
337 if (iteration == 0 || iteration == 3) {
338 prepareClusters(trkParam, maxLayers);
339 }
340 mTotalTracklets = {0, 0};
341 if (maxLayers < trkParam.NLayers) { // Vertexer only, but in both iterations
342 for (size_t iLayer{0}; iLayer < maxLayers; ++iLayer) {
343 deepVectorClear(mUsedClusters[iLayer]);
344 clearResizeBoundedVector(mUsedClusters[iLayer], mUnsortedClusters[iLayer].size(), mMemoryPool.get());
345 }
346 }
347
348 mTotVertPerIteration.resize(1 + iteration);
349 mNoVertexROF = 0;
350 deepVectorClear(mRoads);
351 deepVectorClear(mRoadLabels);
352
353 mMSangles.resize(trkParam.NLayers);
354 mPhiCuts.resize(mClusters.size() - 1, 0.f);
355
356 float oneOverR{0.001f * 0.3f * std::abs(mBz) / trkParam.TrackletMinPt};
357 for (unsigned int iLayer{0}; iLayer < nLayers; ++iLayer) {
358 mMSangles[iLayer] = math_utils::MSangle(0.14f, trkParam.TrackletMinPt, trkParam.LayerxX0[iLayer]);
359 mPositionResolution[iLayer] = o2::gpu::CAMath::Sqrt(0.5f * (trkParam.SystErrorZ2[iLayer] + trkParam.SystErrorY2[iLayer]) + trkParam.LayerResolution[iLayer] * trkParam.LayerResolution[iLayer]);
360 if (iLayer < mClusters.size() - 1) {
361 const float& r1 = trkParam.LayerRadii[iLayer];
362 const float& r2 = trkParam.LayerRadii[iLayer + 1];
363 const float res1 = o2::gpu::CAMath::Hypot(trkParam.PVres, mPositionResolution[iLayer]);
364 const float res2 = o2::gpu::CAMath::Hypot(trkParam.PVres, mPositionResolution[iLayer + 1]);
365 const float cosTheta1half = o2::gpu::CAMath::Sqrt(1.f - math_utils::Sq(0.5f * r1 * oneOverR));
366 const float cosTheta2half = o2::gpu::CAMath::Sqrt(1.f - math_utils::Sq(0.5f * r2 * oneOverR));
367 float x = r2 * cosTheta1half - r1 * cosTheta2half;
368 float delta = o2::gpu::CAMath::Sqrt(1.f / (1.f - 0.25f * math_utils::Sq(x * oneOverR)) * (math_utils::Sq(0.25f * r1 * r2 * math_utils::Sq(oneOverR) / cosTheta2half + cosTheta1half) * math_utils::Sq(res1) + math_utils::Sq(0.25f * r1 * r2 * math_utils::Sq(oneOverR) / cosTheta1half + cosTheta2half) * math_utils::Sq(res2)));
369 mPhiCuts[iLayer] = std::min(o2::gpu::CAMath::ASin(0.5f * x * oneOverR) + 2.f * mMSangles[iLayer] + delta, o2::constants::math::PI * 0.5f);
370 }
371 }
372
373 for (int iLayer{0}; iLayer < std::min((int)mTracklets.size(), maxLayers); ++iLayer) {
374 deepVectorClear(mTracklets[iLayer]);
375 deepVectorClear(mTrackletLabels[iLayer]);
376 if (iLayer < (int)mCells.size()) {
377 deepVectorClear(mCells[iLayer]);
378 deepVectorClear(mTrackletsLookupTable[iLayer]);
379 mTrackletsLookupTable[iLayer].resize(mClusters[iLayer + 1].size(), 0);
380 deepVectorClear(mCellLabels[iLayer]);
381 }
382
383 if (iLayer < (int)mCells.size() - 1) {
384 deepVectorClear(mCellsLookupTable[iLayer]);
385 deepVectorClear(mCellsNeighbours[iLayer]);
386 deepVectorClear(mCellsNeighboursLUT[iLayer]);
387 }
388 }
389}
390
391template <int nLayers>
393{
394 unsigned long size{0};
395 for (const auto& trkl : mTracklets) {
396 size += sizeof(Tracklet) * trkl.size();
397 }
398 for (const auto& cells : mCells) {
399 size += sizeof(CellSeed) * cells.size();
400 }
401 for (const auto& cellsN : mCellsNeighbours) {
402 size += sizeof(int) * cellsN.size();
403 }
404 return size + sizeof(Road<nLayers - 2>) * mRoads.size();
405}
406
407template <int nLayers>
409{
410 LOGP(info, "TimeFrame: Artefacts occupy {:.2f} MB", getArtefactsMemory() / constants::MB);
411}
412
413template <int nLayers>
415{
416 deepVectorClear(mPValphaX);
417 mPValphaX.reserve(mPrimaryVertices.size());
418 for (auto& pv : mPrimaryVertices) {
419 mPValphaX.emplace_back(std::array<float, 2>{o2::gpu::CAMath::Hypot(pv.getX(), pv.getY()), math_utils::computePhi(pv.getX(), pv.getY())});
420 }
421}
422
423template <int nLayers>
425{
426 for (ushort iLayer = 0; iLayer < 2; ++iLayer) {
427 for (unsigned int iRof{0}; iRof < mNrof; ++iRof) {
428 if (mMultiplicityCutMask[iRof]) {
429 mTotalTracklets[iLayer] += mNTrackletsPerROF[iLayer][iRof];
430 }
431 }
432 std::exclusive_scan(mNTrackletsPerROF[iLayer].begin(), mNTrackletsPerROF[iLayer].end(), mNTrackletsPerROF[iLayer].begin(), 0);
433 std::exclusive_scan(mNTrackletsPerCluster[iLayer].begin(), mNTrackletsPerCluster[iLayer].end(), mNTrackletsPerClusterSum[iLayer].begin(), 0);
434 }
435}
436
437template <int nLayers>
439{
440 for (uint32_t iLayer{0}; iLayer < getTracklets().size(); ++iLayer) {
441 int prev{-1};
442 int count{0};
443 for (uint32_t iTracklet{0}; iTracklet < getTracklets()[iLayer].size(); ++iTracklet) {
444 auto& trk = getTracklets()[iLayer][iTracklet];
445 int currentId{trk.firstClusterIndex};
446 if (currentId < prev) {
447 LOG(info) << "First Cluster Index not increasing monotonically on L:T:ID:Prev " << iLayer << "\t" << iTracklet << "\t" << currentId << "\t" << prev;
448 } else if (currentId == prev) {
449 count++;
450 } else {
451 if (iLayer > 0) {
452 auto& lut{getTrackletsLookupTable()[iLayer - 1]};
453 if (count != lut[prev + 1] - lut[prev]) {
454 LOG(info) << "LUT count broken " << iLayer - 1 << "\t" << prev << "\t" << count << "\t" << lut[prev + 1] << "\t" << lut[prev];
455 }
456 }
457 count = 1;
458 }
459 prev = currentId;
460 if (iLayer > 0) {
461 auto& lut{getTrackletsLookupTable()[iLayer - 1]};
462 if (iTracklet >= (uint32_t)(lut[currentId + 1]) || iTracklet < (uint32_t)(lut[currentId])) {
463 LOG(info) << "LUT broken: " << iLayer - 1 << "\t" << currentId << "\t" << iTracklet;
464 }
465 }
466 }
467 }
468}
469
470template <int nLayers>
472{
473 mMinR.fill(10000.);
474 mMaxR.fill(-1.);
475 for (int iLayers{nLayers}; iLayers--;) {
476 mClusters[iLayers].clear();
477 mUnsortedClusters[iLayers].clear();
478 mTrackingFrameInfo[iLayers].clear();
479 mClusterExternalIndices[iLayers].clear();
480 mUsedClusters[iLayers].clear();
481 mROFramesClusters[iLayers].clear();
482 mNClustersPerROF[iLayers].clear();
483 }
484 for (int i{2}; i--;) {
485 mTrackletsIndexROF[i].clear();
486 }
487}
488
489template <int nLayers>
491{
492 for (auto& trkl : mTracklets) {
493 deepVectorClear(trkl);
494 }
495 deepVectorClear(mTrackletsLookupTable);
496}
497
498template <int nLayers>
500{
501 LOG(info) << "-------- Tracklet LUT " << i;
502 std::stringstream s;
503 for (int j : mTrackletsLookupTable[i]) {
504 s << j << "\t";
505 }
506 LOG(info) << s.str();
507 LOG(info) << "--------";
508}
509
510template <int nLayers>
512{
513 LOG(info) << "-------- Cell LUT " << i;
514 std::stringstream s;
515 for (int j : mCellsLookupTable[i]) {
516 s << j << "\t";
517 }
518 LOG(info) << s.str();
519 LOG(info) << "--------";
520}
521
522template <int nLayers>
524{
525 for (unsigned int i{0}; i < mTrackletsLookupTable.size(); ++i) {
526 printTrackletLUTonLayer(i);
527 }
528}
529
530template <int nLayers>
532{
533 for (unsigned int i{0}; i < mCellsLookupTable.size(); ++i) {
534 printCellLUTonLayer(i);
535 }
536}
537
538template <int nLayers>
540{
541 LOG(info) << "Vertices in ROF (nROF = " << mNrof << ", lut size = " << mROFramesPV.size() << ")";
542 for (unsigned int iR{0}; iR < mROFramesPV.size(); ++iR) {
543 LOG(info) << mROFramesPV[iR] << "\t";
544 }
545 LOG(info) << "\n\n Vertices:";
546 for (unsigned int iV{0}; iV < mPrimaryVertices.size(); ++iV) {
547 LOG(info) << mPrimaryVertices[iV].getX() << "\t" << mPrimaryVertices[iV].getY() << "\t" << mPrimaryVertices[iV].getZ();
548 }
549 LOG(info) << "--------";
550}
551
552template <int nLayers>
554{
555 LOG(info) << "--------";
556 for (unsigned int iLayer{0}; iLayer < mROFramesClusters.size(); ++iLayer) {
557 LOG(info) << "Layer " << iLayer;
558 std::stringstream s;
559 for (auto value : mROFramesClusters[iLayer]) {
560 s << value << "\t";
561 }
562 LOG(info) << s.str();
563 }
564}
565
566template <int nLayers>
568{
569 LOG(info) << "--------";
570 for (unsigned int iLayer{0}; iLayer < mNClustersPerROF.size(); ++iLayer) {
571 LOG(info) << "Layer " << iLayer;
572 std::stringstream s;
573 for (auto& value : mNClustersPerROF[iLayer]) {
574 s << value << "\t";
575 }
576 LOG(info) << s.str();
577 }
578}
579
580template <int nLayers>
581void TimeFrame<nLayers>::printSliceInfo(const int startROF, const int sliceSize)
582{
583 LOG(info) << "Dumping slice of " << sliceSize << " rofs:";
584 for (int iROF{startROF}; iROF < startROF + sliceSize; ++iROF) {
585 LOG(info) << "ROF " << iROF << " dump:";
586 for (unsigned int iLayer{0}; iLayer < mClusters.size(); ++iLayer) {
587 LOG(info) << "Layer " << iLayer << " has: " << getClustersOnLayer(iROF, iLayer).size() << " clusters.";
588 }
589 LOG(info) << "Number of seeding vertices: " << getPrimaryVertices(iROF).size();
590 int iVertex{0};
591 for (auto& v : getPrimaryVertices(iROF)) {
592 LOG(info) << "\t vertex " << iVertex++ << ": x=" << v.getX() << " " << " y=" << v.getY() << " z=" << v.getZ() << " has " << v.getNContributors() << " contributors.";
593 }
594 }
595}
596
597template <int nLayers>
598void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool)
599{
600 wipe();
601 mMemoryPool = pool;
602
603 auto initVector = [&]<typename T>(bounded_vector<T>& vec) {
604 auto alloc = vec.get_allocator().resource();
605 if (alloc != mMemoryPool.get()) {
606 vec = bounded_vector<T>(mMemoryPool.get());
607 }
608 };
609 auto initArrays = [&]<typename T, size_t S>(std::array<bounded_vector<T>, S>& arr) {
610 for (size_t i{0}; i < S; ++i) {
611 auto alloc = arr[i].get_allocator().resource();
612 if (alloc != mMemoryPool.get()) {
613 arr[i] = bounded_vector<T>(mMemoryPool.get());
614 }
615 }
616 };
617 auto initVectors = [&]<typename T>(std::vector<bounded_vector<T>>& vec) {
618 for (size_t i{0}; i < vec.size(); ++i) {
619 auto alloc = vec[i].get_allocator().resource();
620 if (alloc != mMemoryPool.get()) {
621 vec[i] = bounded_vector<T>(mMemoryPool.get());
622 }
623 }
624 };
625
626 initVector(mTotVertPerIteration);
627 initVector(mPrimaryVertices);
628 initVector(mROFramesPV);
629 initArrays(mClusters);
630 initArrays(mTrackingFrameInfo);
631 initArrays(mClusterExternalIndices);
632 initArrays(mROFramesClusters);
633 initArrays(mNTrackletsPerCluster);
634 initArrays(mNTrackletsPerClusterSum);
635 initArrays(mNClustersPerROF);
636 initArrays(mIndexTables);
637 initArrays(mUsedClusters);
638 initArrays(mUnsortedClusters);
639 initVector(mROFramesPV);
640 initVector(mPrimaryVertices);
641 initVector(mRoads);
642 initVector(mRoadLabels);
643 initVector(mMSangles);
644 initVector(mPhiCuts);
645 initVector(mPositionResolution);
646 initVector(mClusterSize);
647 initVector(mPValphaX);
648 initVector(mBogusClusters);
649 initArrays(mTrackletsIndexROF);
650 initVectors(mTracks);
651 initVectors(mTracklets);
652 initVectors(mCells);
653 initVectors(mCellsNeighbours);
654 initVectors(mCellsLookupTable);
655}
656
657template <int nLayers>
659{
660 deepVectorClear(mUnsortedClusters);
661 deepVectorClear(mTracks);
662 deepVectorClear(mTracklets);
663 deepVectorClear(mCells);
664 deepVectorClear(mRoads);
665 deepVectorClear(mCellsNeighbours);
666 deepVectorClear(mCellsLookupTable);
667 deepVectorClear(mTotVertPerIteration);
668 deepVectorClear(mPrimaryVertices);
669 deepVectorClear(mROFramesPV);
670 deepVectorClear(mClusters);
671 deepVectorClear(mTrackingFrameInfo);
672 deepVectorClear(mClusterExternalIndices);
673 deepVectorClear(mROFramesClusters);
674 deepVectorClear(mNTrackletsPerCluster);
675 deepVectorClear(mNTrackletsPerClusterSum);
676 deepVectorClear(mNClustersPerROF);
677 deepVectorClear(mIndexTables);
678 deepVectorClear(mUsedClusters);
679 deepVectorClear(mUnsortedClusters);
680 deepVectorClear(mROFramesPV);
681 deepVectorClear(mPrimaryVertices);
682 deepVectorClear(mRoads);
683 deepVectorClear(mRoadLabels);
684 deepVectorClear(mMSangles);
685 deepVectorClear(mPhiCuts);
686 deepVectorClear(mPositionResolution);
687 deepVectorClear(mClusterSize);
688 deepVectorClear(mPValphaX);
689 deepVectorClear(mBogusClusters);
690 deepVectorClear(mTrackletsIndexROF);
691 deepVectorClear(mPrimaryVertices);
692}
693
694template class TimeFrame<7>;
695
696} // namespace o2::its
Definition of the ITSMFT compact cluster.
Definition of the ITSMFT cluster.
Definition of the ClusterTopology class.
uint64_t vertex
Definition RawEventData.h:9
int32_t i
Definition of the GeometryTGeo class.
Definition of the ITSMFT ROFrame (trigger) record.
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Definition of the SegmentationAlpide class.
int clusterSize
Class for time synchronization of RawReader instances.
A container to hold and manage MC truth information/labels.
const Mat3D & getMatrixL2G(int sensID) const
HMPID cluster implementation.
Definition Cluster.h:27
const Mat3D & getMatrixT2L(int lay, int hba, int sta, int det) const
int getLayer(int index) const
Get chip layer, from 0.
float getSensorRefAlpha(int isn) const
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
static constexpr float PitchCol
static constexpr float PitchRow
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
float getErr2X(int n) const
Returns the error^2 on the x position of the COG for the n_th element.
int getNpixels(int n) const
Returns the number of fired pixels of the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getErr2Z(int n) const
Returns the error^2 on the z position of the COG for the n_th element.
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLenum GLboolean GLsizei stride
Definition glcorearb.h:867
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLboolean r
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr float PI
constexpr unsigned int nLayers
Definition SpecsV2.h:127
constexpr float MB
Definition Constants.h:23
void deepVectorClear(std::vector< T > &vec)
std::pmr::vector< T > bounded_vector
void clearResizeBoundedArray(std::array< bounded_vector< T >, S > &arr, size_t size, BoundedMemoryResource *bmr, T def=T())
constexpr float DefClusError2Col
Definition TimeFrame.cxx:47
constexpr float DefClusError2Row
Definition TimeFrame.cxx:46
void clearResizeBoundedVector(bounded_vector< T > &vec, size_t size, BoundedMemoryResource *bmr, T def=T())
constexpr float DefClusErrorRow
Definition TimeFrame.cxx:44
constexpr float DefClusErrorCol
Definition TimeFrame.cxx:45
void checkTrackletLUTs()
Debug and printing.
void printTrackletLUTonLayer(int i)
void initialise(const int iteration, const TrackingParameters &trkParam, const int maxLayers=7, bool resetVertices=true)
virtual ~TimeFrame()
Definition TimeFrame.cxx:56
void addPrimaryVerticesInROF(const bounded_vector< Vertex > &vertices, const int rofId, const int iteration)
Definition TimeFrame.cxx:89
void printSliceInfo(const int, const int)
void computeTrackletsPerROFScans()
void addPrimaryVerticesLabelsInROF(const bounded_vector< std::pair< MCCompLabel, float > > &labels, const int rofId)
Definition TimeFrame.cxx:99
void addPrimaryVerticesLabels(bounded_vector< std::pair< MCCompLabel, float > > &labels)
Definition TimeFrame.cxx:83
int loadROFrameData(const o2::itsmft::ROFRecord &rof, gsl::span< const itsmft::Cluster > clusters, const dataformats::MCTruthContainer< MCCompLabel > *mcLabels=nullptr)
void fillPrimaryVerticesXandAlpha()
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
memory management
unsigned long getArtefactsMemory() const
void printCellLUTonLayer(int i)
void printArtefactsMemory() const
void addPrimaryVertices(const bounded_vector< Vertex > &vertices)
Definition TimeFrame.cxx:62
std::vector< float > LayerRadii
std::vector< float > SystErrorY2
std::vector< float > SystErrorZ2
float TrackletMinPt
Trackleting cuts.
std::vector< float > LayerResolution
std::vector< float > LayerxX0
int CellsPerRoad() const noexcept
int TrackletsPerRoad() const noexcept
static constexpr int L2G
Definition Cartesian.h:54
static constexpr int T2L
Definition Cartesian.h:55
std::vector< o2::ctf::BufferType > vec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< Cell > cells