Project
Loading...
Searching...
No Matches
VertexUtils.h
Go to the documentation of this file.
1// Copyright 2019-2026 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.
11
14
15#ifndef O2_ITS_TRACKING_VERTEXUTILS_H_
16#define O2_ITS_TRACKING_VERTEXUTILS_H_
17
21
22#include "Framework/Logger.h"
23
24#include <algorithm>
25#include <cmath>
26#include <limits>
27#include <unordered_map>
28#include <utility>
29#include <vector>
30
31namespace o2::its
32{
33
36template <typename Container>
37VertexLabel computeMainVertexLabel(const Container& elements)
38{
39 // we only care about the source&event of the tracks, not the trackId
40 auto composeVtxLabel = [](const o2::MCCompLabel& lbl) -> o2::MCCompLabel {
41 return {o2::MCCompLabel::maxTrackID(), lbl.getEventID(), lbl.getSourceID(), lbl.isFake()};
42 };
43 std::unordered_map<o2::MCCompLabel, size_t> frequency;
44 for (const auto& element : elements) {
45 ++frequency[composeVtxLabel(element)];
46 }
47 o2::MCCompLabel elem{};
48 size_t maxCount = 0;
49 for (const auto& [key, count] : frequency) {
50 if (count > maxCount) {
52 elem = key;
53 }
54 }
55 if (maxCount <= 1) { // need >50%
56 elem.setFakeFlag();
57 }
58 return std::make_pair(elem, static_cast<float>(maxCount) / static_cast<float>(elements.size()));
59}
60
62{
63 Vertex diamond(trkParam.Diamond, trkParam.DiamondCov, 1, 1.f);
64 diamond.setTimeStamp({0u, std::numeric_limits<TimeStampErrorType>::max()});
65 return diamond;
66}
67
70inline float getDebrisThreshold(const float goodSig, const double rofLoad, const int suppressLowMultDebris)
71{
72 const float threshold = goodSig * std::sqrt(static_cast<float>(std::max(rofLoad, 1.)));
73 if (suppressLowMultDebris < constants::VtxMinGoodThreshold) {
74 return threshold;
75 }
76 return std::clamp(threshold, constants::VtxMinGoodThreshold, static_cast<float>(suppressLowMultDebris));
77}
78
80template <typename VtxVec, typename LabVec>
81void pruneOverpopulatedRofs(std::vector<VtxVec>& rofVertices, std::vector<LabVec>& rofLabels, const float nSigma, const int minContributors)
82{
83 const int nRofs = static_cast<int>(rofVertices.size());
84 if (nSigma <= 0.f || nRofs == 0) {
85 return;
86 }
87 std::vector<int> counts(nRofs);
88 for (int r = 0; r < nRofs; ++r) {
89 counts[r] = static_cast<int>(rofVertices[r].size());
90 }
91 std::vector<int> sorted(counts);
92 std::sort(sorted.begin(), sorted.end());
93 const int nUsed = std::max(1, nRofs - std::max(1, static_cast<int>(constants::VtxOverpopulatedRofTrimFraction * nRofs)));
94 double sum = 0.;
95 for (int i = 0; i < nUsed; ++i) {
96 sum += sorted[i];
97 }
98 const double mean = sum / nUsed;
99 const double threshold = mean + nSigma * std::sqrt(mean + 1.);
100 for (int r = 0; r < nRofs; ++r) {
101 if (counts[r] <= threshold) {
102 continue;
103 }
104 auto& vtx = rofVertices[r];
105 const bool withLabels = static_cast<int>(rofLabels.size()) == nRofs && rofLabels[r].size() == vtx.size();
106 size_t out = 1; // the largest vertex always stays
107 for (size_t i = 1; i < vtx.size(); ++i) {
108 if (vtx[i].getNContributors() >= minContributors) {
109 vtx[out] = vtx[i];
110 if (withLabels) {
111 rofLabels[r][out] = rofLabels[r][i];
112 }
113 ++out;
114 }
115 }
116 LOGP(info, "Seeding vertexer: overpopulated ROF {} pruned {} -> {} vertices (threshold {:.1f}, mean {:.2f} per ROF)", r, vtx.size(), out, threshold, mean);
117 vtx.erase(vtx.begin() + out, vtx.end());
118 if (withLabels) {
119 rofLabels[r].erase(rofLabels[r].begin() + out, rofLabels[r].end());
120 }
121 }
122}
123
124} // namespace o2::its
125
126#endif /* O2_ITS_TRACKING_VERTEXUTILS_H_ */
atype::type element
std::vector< double > sum
int32_t i
StringRef key
static constexpr int maxTrackID()
void setFakeFlag(bool v=true)
int getEventID() const
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLsizei maxCount
Definition glcorearb.h:792
GLboolean r
Definition glcorearb.h:1233
constexpr float VtxOverpopulatedRofTrimFraction
Definition Constants.h:47
constexpr float VtxMinGoodThreshold
Definition Constants.h:46
std::pair< o2::MCCompLabel, float > VertexLabel
Definition Vertex.h:27
const int end
void pruneOverpopulatedRofs(std::vector< VtxVec > &rofVertices, std::vector< LabVec > &rofLabels, const float nSigma, const int minContributors)
Caps ROFs whose vertex count is an outlier of the TF.
Definition VertexUtils.h:81
float getDebrisThreshold(const float goodSig, const double rofLoad, const int suppressLowMultDebris)
Definition VertexUtils.h:70
VertexLabel computeMainVertexLabel(const Container &elements)
Definition VertexUtils.h:37
Vertex makeDiamondVertex(const TrackingParameters &trkParam)
Definition VertexUtils.h:61