20#include "Acts/Utilities/Enumerate.hpp"
21#include "Acts/Surfaces/StrawSurface.hpp"
22#include "Acts/Surfaces/LineBounds.hpp"
23#include "Acts/Geometry/TrackingGeometry.hpp"
27using namespace Acts::UnitLiterals;
31 const Acts::TrackingVolume* highestAlignable(
const Acts::TrackingVolume* volume){
32 return !volume || !volume->motherVolume() || !volume->motherVolume()->isAlignable()
33 ? volume : highestAlignable(volume->motherVolume());
62 return StatusCode::SUCCESS;
86 unsigned recoSegIdx{0};
87 outContainer->reserve(outContainer->size() + segmentContainer->
size());
88 for (
const Segment* inSegment : *segmentContainer) {
91 xAOD::MuonSegment* convertedSeg = outContainer->push_back(std::make_unique<xAOD::MuonSegment>());
92 dec_parentLink(*convertedSeg) =
SegLink_t{segmentContainer, recoSegIdx};
97 convertedSeg->
setPosition(pos.x(), pos.y(), pos.z());
101 sector->
side(), inSegment->technology());
102 convertedSeg->
setFitQuality(inSegment->chi2(), inSegment->nDoF());
105 convertedSeg->
setT0Error(inSegment->segementT0(),
106 Amg::error(inSegment->covariance(), Acts::toUnderlying(
t0)));
108 SegPars_t& localPars{dec_locPars(*convertedSeg)};
113 localPars[Acts::toUnderlying(x0)] = locPos.x();
114 localPars[Acts::toUnderlying(y0)] = locPos.y();
115 localPars[Acts::toUnderlying(
theta)] = locDir.theta();
116 localPars[Acts::toUnderlying(
phi)] = locDir.phi();
117 localPars[Acts::toUnderlying(
t0)] = inSegment->segementT0();
119 SegCov_t& localCov{dec_locCov(*convertedSeg)};
120 constexpr std::size_t n = Acts::toUnderlying(ParamDefs::nPars);
121 for (std::size_t p = 1; p < n; ++p) {
122 for (std::size_t p1 = 0 ; p1 <=p;++p1) {
123 localCov[Acts::vecIdxFromSymMat<n>(p,p1)] = inSegment->covariance()(p, p1);
130 return StatusCode::SUCCESS;
139 std::vector< std::tuple<const xAOD::MuonMeasurement*, State, std::size_t>> combineMap{};
140 std::vector< std::tuple<const xAOD::UncalibratedMeasurement*, State, std::size_t>> linkMap{};
144 std::vector<char>& linkStates = ship.
dec_prdStates(copySegment);
152 auto cmbMeas = ship.
prdCombContainer->push_back(std::make_unique<xAOD::CombinedMuonStrip>());
154 cmbMeas->setPrimaryStrip(m1);
155 cmbMeas->setSecondaryStrip(m2);
159 const Identifier id1{m1->identify()}, id2{m2->identify()};
172 for (
const auto [segIdx, meas] : Acts::enumerate(inSegment.
measurements())) {
182 return StatusCode::FAILURE;
186 meas->localPosition();
190 covariance(0,0) = meas->covariance()[Acts::toUnderlying(CovIdx::etaCov)];
191 covariance(1,1) = meas->covariance()[Acts::toUnderlying(CovIdx::phiCov)];
194 std::make_shared<Acts::LineBounds>(std::sqrt(covariance(0,0)), 20._m));
197 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Created beamspot measurement "<<(*meas)<<
", "
198 <<surf->toString(gctx.
context()));
200 linkMap.emplace_back(ship.
beamSpot, meas->fitState(), segIdx);
203 switch (
sp->type()) {
206 case MdtDriftCircleType:
207 case MMClusterType: {
208 linkMap.emplace_back(
sp->primaryMeasurement(), meas->fitState(), segIdx);
212 case sTgcStripType: {
213 if (
sp->primaryMeasurement() &&
sp->secondaryMeasurement()) {
214 if (
sp->primaryMeasurement() !=
sp->secondaryMeasurement()) {
215 linkMap.emplace_back(combine(
sp->primaryMeasurement(),
216 sp->secondaryMeasurement()),
217 meas->fitState(), segIdx);
219 linkMap.emplace_back(
sp->primaryMeasurement(), meas->fitState(), segIdx);
224 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Append for later combination "<<(*meas));
225 combineMap.emplace_back(
sp->primaryMeasurement(), meas->fitState(), segIdx);
234 for (std::size_t cmbIdx = 0; cmbIdx < combineMap.size(); ++cmbIdx){
236 const State s1{std::get<1>(combineMap[cmbIdx])};
237 const std::size_t segIdx1{std::get<2>(combineMap[cmbIdx])};
238 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Find another measurement to combine with "
240 if (cmbIdx +1 < combineMap.size()) {
242 const State s2{std::get<1>(combineMap[cmbIdx+1])};
244 <<
" is a good candidate");
247 if (m1->type() == m2->type() && m1->identifierHash() == m2->identifierHash() &&
248 m1->layerHash() == m2->layerHash() && s1 == s2) {
251 if (m1->measuresPhi()) {
252 linkMap.emplace_back(combine(m2, m1), s2, segIdx1);
254 linkMap.emplace_back(combine(m1, m2), s1, segIdx1);
261 linkMap.emplace_back(m1, s1, segIdx1);
264 std::ranges::sort(linkMap, [](
const auto&
a,
const auto& b){
265 return std::get<2>(
a) < std::get<2>(b);
268 for (
const auto& [prd, state, segIdx]: linkMap) {
271 linkStates.emplace_back(Acts::toUnderlying(state));
273 return StatusCode::SUCCESS;
281 Counter hits{}, outliers{}, holes{};
283 std::unordered_set<Identifier> crossedSurfaces{};
286 const Acts::Surface* startSurface{}, *lastSurface{};
289 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Loop over "<<nMeas<<
" measurements.");
290 for (std::size_t m = 0 ; m < nMeas; ++m) {
292 Counter& increment = {isOutlier ? outliers: hits};
295 <<
", outlier: "<<isOutlier);
298 increment.
triggerPhi += (!muonMeas|| muonMeas->measuresPhi());
305 if (!muonMeas->measuresPhi() &&
re->nPhiStrips()) {
307 }
else if (muonMeas->measuresPhi()) {
313 if (!muonMeas->measuresPhi() &&
re->numStrips(muonMeas->layerHash())) {
315 }
else if (muonMeas->measuresPhi() &&
re->numWireGangs(muonMeas->layerHash())) {
337 muonMeas->identify());
338 const auto* volume = highestAlignable(trackingGeo->findVolume(
volumeId(surface)));
339 assert(volume !=
nullptr);
342 }
else if (m +1 == nMeas) {
348 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
349 auto atSurface = startSurface->intersect(tgContext, segment.
position(), segment.
direction(),
350 Acts::BoundaryTolerance::Infinite()).closest();
352 auto startPars = Acts::BoundTrackParameters::create(tgContext, startSurface->getSharedPtr(),
354 segment.
direction(), 1./ 5._TeV, std::nullopt,
355 Acts::ParticleHypothesis::muon());
356 if (startPars.ok()) {
357 findHoles(ctx, *startPars, lastSurface, crossedSurfaces, holes);
359 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Start parameters not defined.");
362 segment.
setNHits(hits.precision, hits.triggerPhi, hits.triggerEta);
363 segment.
setNOutliers(outliers.precision, outliers.triggerPhi, outliers.triggerEta);
364 segment.
setNHoles(holes.precision, holes.triggerPhi, holes.triggerEta);
367 const Acts::BoundTrackParameters& startPars,
368 const Acts::Surface* target,
369 const std::unordered_set<Identifier>& layersWithHits,
376 propOpts.recordPassive =
false;
377 propOpts.recordSensitive =
true;
381 if (!propResult.ok()) {
386 for (Acts::BoundTrackParameters& record : (*propResult)) {
388 assert(placement !=
nullptr);
392 if (layersWithHits.count(placement->identify())) {
399 if(std::ranges::none_of(layersWithHits,[&](
const Identifier& recorded){
400 return m_idHelperSvc->chamberIndex(recorded) == detEl->chamberIndex() &&
404 <<
m_idHelperSvc->toStringGasGap(placement->identify())<<
" is not in the same sector");
407 switch (placement->detectorType()) {
410 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Precision hole detected "
417 <<
m_idHelperSvc->toStringGasGap(placement->identify())<<
".");
423 holeCounter.
triggerEta += (
re->numWireGangs(placement->hash())>0);
424 holeCounter.
triggerPhi += (
re->numStrips(placement->hash())>0);
426 <<
m_idHelperSvc->toStringGasGap(placement->identify())<<
".");
429 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Precision hole detected "
436 <<placement->detectorType());
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
Acts::GeometryContext context() const
: Helper class to assign a @ActsSurfacePlacementBase to the Acts::Surfaces in order to make them alig...
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink implementation for ROOT usage.
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
int8_t side() const
Returns the side of the MS-sector 1 -> A side ; -1 -> C side.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the local -> global tarnsformation from the sector.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
int sector() const
Returns the sector of the MS-sector.
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index scheme.
State
State flag to distinguish different space point states.
Placeholder for what will later be the muon segment EDM representation.
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
const MeasVec & measurements() const
Returns the associated measurements.
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
void evaluateSummary(const EventContext &ctx, xAOD::MuonSegment &segment) const
Calculate the number of hits, outliers and holes on the segment and set the hit summary fields of the...
DecorKey_t m_prdStateKey
Decoration to the PrdLink state (I.e.
DecorKey_t m_localSegParKey
Decoration of the local segment parameters.
void findHoles(const EventContext &ctx, const Acts::BoundTrackParameters &startPars, const Acts::Surface *target, const std::unordered_set< Identifier > &geoIdsWithHits, Counter &holeCounter) const
Find potential sensitive surfaces crossed by the segment but without contributing measurements.
DecorKey_t m_localSegCovKey
Decoration of the local fit covariance parameters.
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
Tracking geometry tool to search for holes.
DecorKey_t m_parentSegKey
Decoration of the original segment.
SG::WriteHandleKey< xAOD::MuonSegmentContainer > m_writeKey
Output segment container key.
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Acts extrapolation tool to search for holes.
StatusCode linkMeasurements(const ActsTrk::GeometryContext &gctx, const Segment &inSegment, xAOD::MuonSegment &targetSegment, PrepDataCollectorShip &ship) const
Decorate the prd links onto the output muon segment.
std::vector< PrdLink_t > PrdLinkVec_t
Abrivation of a collection of Prd links.
SG::WriteHandleKey< xAOD::CombinedMuonStripContainer > m_combMeasKey
Auxiliary container to model two measurements in the same gas gap as a single track state.
Gaudi::Property< double > m_extraHolePath
Extra path length for the propagation after the last surface was crossed.
DecorKey_t m_prdLinkKey
Decoration to the links to the associated Uncalibrated measurements.
virtual StatusCode execute(const EventContext &ctx) const override final
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc for Identifier printing & manipulation.
virtual StatusCode initialize() override final
Gaudi::Property< bool > m_convertBeamSpot
Flag to convert the beamspot constaint as well.
ActsTrk::AuxiliaryMeasurementHandler m_auxMeasProv
Handler to parse the auxiliary beam spot constaint.
ActsTrk::ContextUtility m_ctxProvider
Context provider for geometry, magnetic field and calibration contexts.
SG::ReadHandleKeyArray< SegmentContainer > m_readKeys
Input segment container key.
ActsTrk::GeoContextReadKey_t m_geoCtxKey
Alignment container key.
Gaudi::Property< bool > m_estimateHoles
Flag to tell whether the hole summary shall be written.
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for adding a decoration to an object.
ActsTrk::detail::MeasurementCalibratorBase::ProjectorType ProjectorType
Use the calibration projector.
void setDirection(float px, float py, float pz)
Sets the direction.
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
void setT0Error(float t0, float t0Error)
Sets the time error.
void setNHits(const std::uint8_t nPrecisionHits, const std::uint8_t nPhiLayers, const std::uint8_t nTrigEtaLayers)
Assign the segment hit summary.
void setNOutliers(const std::uint8_t nPrecOutliers, const std::uint8_t nTrigPhiOutliers, const std::uint8_t nTrigEtaOutliers)
Assign the number of hits with a large pull per hit category.
void setNHoles(const std::uint8_t nPrecHoles, const std::uint8_t nTrigPhiHoles, const std::uint8_t nTrigEtaHoles)
Assign the number of expected but missing hits.
void setPosition(float x, float y, float z)
Sets the global position.
void setIdentifier(const std::uint8_t sector, const ::Muon::MuonStationIndex::ChIndex chamberIndex, const std::int8_t etaIndex, const ::Muon::MuonStationIndex::TechnologyIndex technology)
Set the Identifier fields of the Segment.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
virtual unsigned int numDimensions() const =0
Returns the number of dimensions of the measurement.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
Acts::Vector4 convertPosToActs(const Amg::Vector3D &athenaPos, const double athenaTime=0.)
Converts a position vector & time from Athena units into Acts units.
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
const Acts::Surface * bottomBoundary(const Acts::TrackingVolume &volume)
Returns the boundary surface parallel to the x-y plane at negative local z.
const Acts::Surface * topBoundary(const Acts::TrackingVolume &volume)
Returns the boundary surface parallel to the x-y plane at positive local z.
SeedingAux::FitParIndex ParamDefs
Use the same parameter indices as used by the CompSpacePointAuxiliaries.
This header ties the generic definitions in this package.
const xAOD::UncalibratedMeasurement * getMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns the n-th uncalibrated measurement.
CalibratedSpacePoint::State State
std::size_t nMeasurements(const xAOD::MuonSegment &segment)
Returns the number of associated Uncalibrated measurements.
Acts::GeometryIdentifier volumeId(const Acts::Surface &surface)
Returns the identifier of the volume in which the surface is embedded.
bool isOutlierMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns whether the n-the uncalibrated measurement is an outlier.
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
DataVector< Segment > SegmentContainer
xAOD::PosAccessor< Acts::sumUpToN(Acts::toUnderlying(ParamDefs::nPars))>::element_type SegCov_t
Abrivation of the decorated local segment covariance.
xAOD::PosAccessor< Acts::toUnderlying(ParamDefs::nPars)>::element_type SegPars_t
Abrivation of the decorated local segment parameters.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
SG::AuxElement::Accessor< std::array< float, N > > PosAccessor
xAOD Accessor to the position
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonMeasurement_v1 MuonMeasurement
MeasVector< N > toStorage(const AmgVector(N)&amgVec)
Converts the double precision of the AmgVector into the floating point storage precision of the MeasV...
UncalibMeasType
Define the type of the uncalibrated measurement.
bool isPrecisionHit(const UncalibratedMeasurement *meas)
Returns whether the measurement is a precision hit.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
std::pair< Amg::Vector2D, AmgSymMatrix(2)> positionAndCovariance(const MuonMeasurement *oneDimMeas)
Returns the 1D position of the uncalibrated measurement expressed in the coordinate system of the mea...
MuonSegmentAuxContainer_v1 MuonSegmentAuxContainer
Definition of the current Muon auxiliary container.
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
Helper struct to keep track of the number of precision, trigger phi and trigger eta hits.
Auxiliary struct to ship the WriteDecorHandle and writeHandles needed to link the uncalibrated meausr...
SG::WriteDecorHandle< xAOD::MuonSegmentContainer, PrdLinkVec_t > dec_prdLinks
List of element links to the associated measurements.
xAOD::FillContainer< xAOD::CombinedMuonStripContainer, xAOD::CombinedMuonStripAuxContainer > prdCombContainer
Container handle to create the combined measurements of Rpc/Tgc/sTgc.
Acts::Result< ActsTrk::AuxiliaryMeasurementHandler::MeasurementProvider, ActsTrk::AuxiliaryMeasurementHandler::HandleStatus > beamSpotMeasCreator
Container handle to create the beamspot measurement, if needed.
const xAOD::UncalibratedMeasurement * beamSpot
Pointer to the commonly shared beamspot measurement.
SG::WriteDecorHandle< xAOD::MuonSegmentContainer, std::vector< char > > dec_prdStates
Flag indicating whether each measurement is valid or an outlier.
#define THROW_EXCEPTION(MESSAGE)