ATLAS Offline Software
Classes | Functions
MuonML::BucketGraphUtils Namespace Reference

Classes

struct  NodeAux
 

Functions

double bucket_size_mm (const MuonR4::SpacePointBucket &b)
 
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. More...
 
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 40 of file BucketGraphUtils.h.

45 {
47  nodes.clear();
48  featuresLeaves.clear();
49  spInBucket.clear();
50  nodes.reserve(buckets.size());
51  featuresLeaves.reserve(6u * buckets.size()); // preallocate
52  spInBucket.reserve(buckets.size());
53 
55 
56  for (const MuonR4::SpacePointBucket* bucket : buckets) {
57  const double bsize = bucket_size_mm(*bucket);
58  // Don't skip buckets with 0 size - this was causing 0 nodes with new gctx implementation
59  // The new gctx may result in buckets with exactly 0.0 size that should still be processed
60 
61  NodeAux n;
62 
63  if (bucket->msSector()) {
64  const double midY = 0.5 * (bucket->coveredMin() + bucket->coveredMax());
65  const Amg::Vector3D glob = bucket->msSector()->localToGlobalTrans(gctx) * (midY * Amg::Vector3D::UnitY());
66  n.x = glob.x();
67  n.y = glob.y();
68  n.z = glob.z();
69  }
70 
71  std::unordered_set<unsigned int> laySet;
72  laySet.reserve(bucket->size());
73  for (const auto& spPtr : *bucket) {
74  laySet.insert(layerSorter.sectorLayerNum(*spPtr));
75  }
76  n.layers = static_cast<int>(laySet.size());
77  n.nSp = static_cast<int>(bucket->size());
78  n.bucketSize = bsize;
79  n.sector = bucket->msSector()->sector();
80  n.chamber = Acts::toUnderlying(bucket->msSector()->chamberIndex());
81 
82  nodes.push_back(n);
83 
84  featuresLeaves.push_back(static_cast<float>(n.x));
85  featuresLeaves.push_back(static_cast<float>(n.y));
86  featuresLeaves.push_back(static_cast<float>(n.z));
87  featuresLeaves.push_back(static_cast<float>(n.layers));
88  featuresLeaves.push_back(static_cast<float>(n.nSp));
89  featuresLeaves.push_back(static_cast<float>(n.bucketSize));
90 
91  spInBucket.emplace_back(static_cast<int64_t>(n.nSp)); // store as int64_t
92  }
93 }

◆ 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 95 of file BucketGraphUtils.h.

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

◆ 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 162 of file BucketGraphUtils.h.

165 {
166  const size_t E = srcEdges.size();
167  edgeIndexPacked = srcEdges;
168  edgeIndexPacked.insert(edgeIndexPacked.end(), dstEdges.begin(), dstEdges.end());
169  return E;
170 }
MuonR4::minLayers
constexpr unsigned int minLayers
Definition: NswSegmentFinderAlg.cxx:58
MuonR4::SpacePointBucket
: The muon space point bucket represents a collection of points that will bre processed together in t...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePointContainer.h:21
MuonR4::SpacePointPerLayerSorter
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
Definition: SpacePointPerLayerSorter.h:15
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
module_driven_slicing.layers
layers
Definition: module_driven_slicing.py:113
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Muon::MuonStationIndex::numberOfSectors
constexpr unsigned numberOfSectors()
return total number of sectors
Definition: MuonStationIndex.h:118
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:459
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:727
MuonML::BucketGraphUtils::bucket_size_mm
double bucket_size_mm(const MuonR4::SpacePointBucket &b)
Definition: BucketGraphUtils.h:32
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
a
TList * a
Definition: liststreamerinfos.cxx:10
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.