ATLAS Offline Software
TrackFindingMeasurements.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 namespace ActsTrk::detail {
8 
9  TrackFindingMeasurements::TrackFindingMeasurements(std::size_t nMeasurementContainerMax)
10  : m_measurementOffsets(nMeasurementContainerMax, 0ul)
11  {}
12 
13  // NB. all addDetectorElements() must have been done before calling first addMeasurements().
14  void TrackFindingMeasurements::addMeasurements(std::size_t typeIndex,
15  const xAOD::UncalibratedMeasurementContainer &clusterContainer,
16  const DetectorElementToActsGeometryIdMap &detectorElementToGeoid)
17  {
18  if (typeIndex >= m_measurementOffsets.size()) {
19  throw std::runtime_error("Adding collection with too big a typeIndex");
20  }
22 
23  if (m_measurementRanges.empty()) {
24  // try to reserve needed space,
25  // this however will reserve more than necessary not just the space needed for the surfaces of
26  // all the measurements that are going to be added (e.g. pixel+strips).
27  m_measurementRanges.reserve(detectorElementToGeoid.size());
28  }
29  m_measurementRanges.setContainer(typeIndex, &clusterContainer);
30 
33  MeasurementRange *currentRange = nullptr;
34 
35  std::size_t n_elements = clusterContainer.size();;
36  std::size_t sl_idx = 0;
37  for( ; sl_idx < n_elements; ++sl_idx) {
38  const auto *measurement = clusterContainer[sl_idx];
39  if (measurement->identifierHash() != lastIdHash or
40  measurement->type() != lastMeasurementType)
41  {
42  if (currentRange) {
43  currentRange->updateEnd(typeIndex, sl_idx);
44  }
45  lastIdHash = measurement->identifierHash();
46  lastMeasurementType = measurement->type();
47 
48  Acts::GeometryIdentifier measurementSurfaceId = ActsTrk::getSurfaceGeometryIdOfMeasurement(detectorElementToGeoid,
49  *measurement);
50  if (measurementSurfaceId.value() == 0u) {
51  // @TODO improve error message.
52  throw std::domain_error("No Acts surface associated to measurement");
53  }
54 
55  // start with en empty range which is updated later.
56  auto ret = m_measurementRanges.insert( std::make_pair( measurementSurfaceId.value(),
57  MeasurementRange( typeIndex, sl_idx, sl_idx) ));
58  if (!ret.second) {
59  std::stringstream msg;
60  msg << "Measurement not clustered by identifierHash / geometryId. New measurement "
61  << sl_idx << " with geo Id " << measurementSurfaceId
62  << " type = " << static_cast<unsigned int>(measurement->type())
63  << " idHash=" << measurement->identifierHash()
64  << " but already recorded for this geo ID the range : [" << ret.first->second.containerIndex() << "]"
65  << ret.first->second.elementBeginIndex()
66  << " .. " << ret.first->second.elementEndIndex()
67  << (ret.first->second.isConsistentRange() ? "" : " !Container index inconsistent or not in increasing order!");
68  throw std::runtime_error(msg.str());
69  }
70  currentRange = &ret.first->second;
71  }
72  }
73 
74  if (currentRange) {
75  currentRange->updateEnd(typeIndex, sl_idx);
76  }
77 
78  m_measurementsTotal += clusterContainer.size();
79  }
80 
81  std::vector<std::pair<const xAOD::UncalibratedMeasurementContainer *, std::size_t>>
83  {
84  std::vector<std::pair<const xAOD::UncalibratedMeasurementContainer *, std::size_t>> offsets;
85  if (m_measurementRanges.numContainers() == 0) return offsets;
86  offsets.reserve(m_measurementRanges.numContainers() - 1); // first one usually 0
87 
88  for (std::size_t typeIndex = 0; typeIndex < m_measurementRanges.numContainers(); ++typeIndex)
89  {
90  const xAOD::UncalibratedMeasurementContainer *theContainer
91  = std::visit( [] (const auto &a) -> const xAOD::UncalibratedMeasurementContainer *
92  { return a.containerPtr(); },
93  m_measurementRanges.container(typeIndex));
94 
95  if (measurementOffset(typeIndex) > 0 and theContainer != nullptr)
96  {
97  offsets.emplace_back(theContainer, measurementOffset(typeIndex));
98  }
99  }
100 
101  return offsets;
102  }
103 
104 } // namespace ActsTrk::detail
105 
ActsTrk::getSurfaceGeometryIdOfMeasurement
Acts::GeometryIdentifier getSurfaceGeometryIdOfMeasurement(const DetectorElementToActsGeometryIdMap &detector_element_to_geoid, const xAOD::UncalibratedMeasurement &measurement)
Definition: SurfaceOfMeasurementUtil.h:24
ActsTrk::DetectorElementToActsGeometryIdMap
Definition: DetectorElementToActsGeometryIdMap.h:31
ActsTrk::detail::MeasurementRange::updateEnd
void updateEnd(std::size_t container_idx, unsigned int end_element_idx)
Definition: AtlasUncalibSourceLinkAccessor.h:51
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
ActsTrk::detail::TrackFindingMeasurements::TrackFindingMeasurements
TrackFindingMeasurements(std::size_t nMeasurementContainerMax)
Definition: TrackFindingMeasurements.cxx:9
ActsTrk::detail::MeasurementRange
Definition: AtlasUncalibSourceLinkAccessor.h:24
TrackFindingMeasurements.h
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
ActsTrk::detail::GenMeasurementRangeList::numContainers
std::size_t numContainers() const
Definition: AtlasUncalibSourceLinkAccessor.h:94
ActsTrk::detail::TrackFindingMeasurements::measurementContainerOffsets
std::vector< std::pair< const xAOD::UncalibratedMeasurementContainer *, std::size_t > > measurementContainerOffsets() const
Definition: TrackFindingMeasurements.cxx:82
xAOD::Other
@ Other
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
ActsTrk::detail::TrackFindingMeasurements::m_measurementsTotal
std::size_t m_measurementsTotal
Definition: TrackFindingMeasurements.h:43
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsTrk::detail::TrackFindingMeasurements::addMeasurements
void addMeasurements(std::size_t typeIndex, const xAOD::UncalibratedMeasurementContainer &clusterContainer, const DetectorElementToActsGeometryIdMap &detectorElementToGeoid)
Definition: TrackFindingMeasurements.cxx:14
ActsTrk::detail::TrackFindingMeasurements::m_measurementRanges
ActsTrk::detail::MeasurementRangeList m_measurementRanges
Definition: TrackFindingMeasurements.h:42
xAOD::DetectorIDHashType
unsigned int DetectorIDHashType
@ detector ID element hash
Definition: MeasurementDefs.h:42
ActsTrk::detail::GenMeasurementRangeList::setContainer
void setContainer(unsigned int container_index, const xAOD::UncalibratedMeasurementContainer *container)
Definition: AtlasUncalibSourceLinkAccessor.h:88
ActsTrk::detail::TrackFindingMeasurements::m_measurementOffsets
std::vector< std::size_t > m_measurementOffsets
Definition: TrackFindingMeasurements.h:40
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:24
ActsTrk::detail::GenMeasurementRangeList::container
const MeasurementContainer & container(unsigned index) const
Definition: AtlasUncalibSourceLinkAccessor.h:96
ActsTrk::detail::TrackFindingMeasurements::measurementOffset
std::size_t measurementOffset(std::size_t typeIndex) const
ActsTrk::detail
Definition: Decoration.h:15
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7