ATLAS Offline Software
Loading...
Searching...
No Matches
MuonML::BucketGraphUtils Namespace Reference

Classes

struct  NodeAux

Functions

double bucket_size_mm (const MuonR4::SpacePointBucket &b)
bool keepBucketAsTrainingNode (const MuonR4::SpacePointBucket &b)
 bucket_size == 0, where bucket_size is bucket_max - bucket_min.
void buildNodesAndFeatures (const MuonR4::SpacePointContainer &buckets, const ActsTrk::GeometryContext &gctx, std::vector< NodeAux > &nodes, std::vector< float > &featuresLeaves, std::vector< int64_t > &spInBucket)
 Build nodes + flat features (N,6) and number of SPs per kept bucket.
void buildSparseEdges (const std::vector< NodeAux > &nodes, int minLayers, int maxChamberDelta, int maxSectorDelta, double maxDistXY, double maxAbsDz, std::vector< int64_t > &srcEdges, std::vector< int64_t > &dstEdges)
size_t packEdgeIndex (const std::vector< int64_t > &srcEdges, const std::vector< int64_t > &dstEdges, std::vector< int64_t > &edgeIndexPacked)

Function Documentation

◆ bucket_size_mm()

double MuonML::BucketGraphUtils::bucket_size_mm ( const MuonR4::SpacePointBucket & b)
inline

Definition at line 32 of file BucketGraphUtils.h.

32 {
33 return b.coveredMax() - b.coveredMin();
34}

◆ buildNodesAndFeatures()

void MuonML::BucketGraphUtils::buildNodesAndFeatures ( const MuonR4::SpacePointContainer & buckets,
const ActsTrk::GeometryContext & gctx,
std::vector< NodeAux > & nodes,
std::vector< float > & featuresLeaves,
std::vector< int64_t > & spInBucket )
inline

Build nodes + flat features (N,6) and number of SPs per kept bucket.

  • Features: [x, y, z, layers, nSp, bucketSize]

In cas that the data vectors have been used by an earlier ML algorithm ensure that the vectors remain clean

Definition at line 47 of file BucketGraphUtils.h.

52{
54 nodes.clear();
55 featuresLeaves.clear();
56 spInBucket.clear();
57 nodes.reserve(buckets.size());
58 featuresLeaves.reserve(6u * buckets.size()); // preallocate
59 spInBucket.reserve(buckets.size());
60
62
63 for (const MuonR4::SpacePointBucket* bucket : buckets) {
64 const double bsize = bucket_size_mm(*bucket);
65
66 if (!keepBucketAsTrainingNode(*bucket)) {
67 continue;
68 }
69
70 NodeAux n;
71
72 const double midY = 0.5 * (bucket->coveredMin() + bucket->coveredMax());
73 const Amg::Vector3D glob = bucket->msSector()->localToGlobalTransform(gctx) * (midY * Amg::Vector3D::UnitY());
74 n.x = glob.x();
75 n.y = glob.y();
76 n.z = glob.z();
77
78 std::unordered_set<unsigned int> laySet;
79 laySet.reserve(bucket->size());
80 for (const auto& spPtr : *bucket) {
81 laySet.insert(layerSorter.sectorLayerNum(*spPtr));
82 }
83 n.layers = static_cast<int>(laySet.size());
84 n.nSp = static_cast<int>(bucket->size());
85 n.bucketSize = bsize;
86 n.sector = bucket->msSector()->sector();
87 n.chamber = Acts::toUnderlying(bucket->msSector()->chamberIndex());
88
89 nodes.push_back(n);
90
91 featuresLeaves.push_back(static_cast<float>(n.x));
92 featuresLeaves.push_back(static_cast<float>(n.y));
93 featuresLeaves.push_back(static_cast<float>(n.z));
94 featuresLeaves.push_back(static_cast<float>(n.layers));
95 featuresLeaves.push_back(static_cast<float>(n.nSp));
96 featuresLeaves.push_back(static_cast<float>(n.bucketSize));
97
98 spInBucket.emplace_back(static_cast<int64_t>(n.nSp)); // store as int64_t
99 }
100}
size_type size() const noexcept
Returns the number of elements in the collection.
: The muon space point bucket represents a collection of points that will bre processed together in t...
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
unsigned int sectorLayerNum(const SpacePoint &sp) const
method returning the logic layer number
Eigen::Matrix< double, 3, 1 > Vector3D
bool keepBucketAsTrainingNode(const MuonR4::SpacePointBucket &b)
bucket_size == 0, where bucket_size is bucket_max - bucket_min.
double bucket_size_mm(const MuonR4::SpacePointBucket &b)

◆ buildSparseEdges()

void MuonML::BucketGraphUtils::buildSparseEdges ( const std::vector< NodeAux > & nodes,
int minLayers,
int maxChamberDelta,
int maxSectorDelta,
double maxDistXY,
double maxAbsDz,
std::vector< int64_t > & srcEdges,
std::vector< int64_t > & dstEdges )
inline

Ensure that previously built graphs don't leak memory

Definition at line 102 of file BucketGraphUtils.h.

110{
112 srcEdges.clear();
113 dstEdges.clear();
114
115 std::vector<size_t> validIdx;
116 validIdx.reserve(nodes.size());
117 for (size_t i = 0; i < nodes.size(); ++i) {
118 if (nodes[i].layers >= minLayers) validIdx.push_back(i);
119 }
120
121 if (validIdx.size() < 2) {
122 if (!nodes.empty()) {
123 srcEdges.push_back(0);
124 dstEdges.push_back(0);
125 }
126 return;
127 }
128
129 const unsigned int secMax = Muon::MuonStationIndex::numberOfSectors();
130
131 for (size_t a = 0; a < validIdx.size(); ++a) {
132 const size_t i = validIdx[a];
133 const auto& ni = nodes[i];
134 for (size_t b = a + 1; b < validIdx.size(); ++b) {
135 const size_t j = validIdx[b];
136 const auto& nj = nodes[j];
137
138 const double dx = static_cast<double>(ni.x) - static_cast<double>(nj.x);
139 const double dy = static_cast<double>(ni.y) - static_cast<double>(nj.y);
140 const double dz = static_cast<double>(ni.z) - static_cast<double>(nj.z);
141
142 const double distXY = Acts::fastHypot(dx, dy);
143 const int secDiffLin = std::abs(ni.sector - nj.sector) % static_cast<int>(secMax);
144 const int d_sec = std::min(secDiffLin, static_cast<int>(secMax) - secDiffLin);
145 const int d_ch = std::abs(ni.chamber - nj.chamber);
146
147 const bool mask =
148 (d_ch > 0) &&
149 (d_sec <= maxSectorDelta) &&
150 (distXY < maxDistXY) &&
151 (std::abs(dz) < maxAbsDz) &&
152 (d_ch <= maxChamberDelta);
153
154 if (mask) {
155 srcEdges.push_back(static_cast<int64_t>(i));
156 dstEdges.push_back(static_cast<int64_t>(j));
157 srcEdges.push_back(static_cast<int64_t>(j));
158 dstEdges.push_back(static_cast<int64_t>(i));
159 }
160 }
161 }
162
163 if (srcEdges.empty() && !nodes.empty()) {
164 srcEdges.push_back(0);
165 dstEdges.push_back(0);
166 }
167}
static Double_t a
constexpr unsigned numberOfSectors()
return total number of sectors
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ keepBucketAsTrainingNode()

bool MuonML::BucketGraphUtils::keepBucketAsTrainingNode ( const MuonR4::SpacePointBucket & b)
inline

bucket_size == 0, where bucket_size is bucket_max - bucket_min.

Definition at line 39 of file BucketGraphUtils.h.

39 {
40 return bucket_size_mm(b) != 0.0;
41}

◆ packEdgeIndex()

size_t MuonML::BucketGraphUtils::packEdgeIndex ( const std::vector< int64_t > & srcEdges,
const std::vector< int64_t > & dstEdges,
std::vector< int64_t > & edgeIndexPacked )
inline

Definition at line 169 of file BucketGraphUtils.h.

172{
173 const size_t E = srcEdges.size();
174 edgeIndexPacked = srcEdges;
175 edgeIndexPacked.insert(edgeIndexPacked.end(), dstEdges.begin(), dstEdges.end());
176 return E;
177}