6#include "GaudiKernel/SystemOfUnits.h"
16#include "Acts/Utilities/Enumerate.hpp"
17#include "GaudiKernel/PhysicalConstants.h"
23 #include "Acts/Utilities/AlgebraHelpers.hpp"
24 #include "Acts/Definitions/Units.hpp"
27 constexpr double c_inv = 1. /Gaudi::Units::c_light;
32 (hit.
type() == sTgcStripType &&
48 using namespace MuonR4;
49 using namespace MuonVal;
50 using namespace Muon::MuonStationIndex;
51 using namespace Acts::UnitLiterals;
62 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
86 for (std::size_t cov = 0 ; cov <
m_segmentCov.size(); ++cov){
88 const auto [i, j] = Acts::symMatIndices<Acts::toUnderlying(ParamDefs::nPars)>(cov);
89 ParamDefs pI{
static_cast<std::uint8_t
>(i)},
90 pJ{
static_cast<std::uint8_t
>(j)};
91 std::string brName = (pI!= pJ) ? std::format(
"segment_cov_{:}_{:}", pI, pJ)
92 : std::format(
"segment_cov_{:}", pI);
103 return StatusCode::SUCCESS;
109 unsigned int same{0};
114 const std::vector<int> truthSigns = SeedingAux::strawSigns(truePos, trueDir, detailSeg->
measurements());
115 const std::vector<int> recoSigns = SeedingAux::strawSigns(recoPos, recoDir, detailSeg->
measurements());
116 for (
unsigned int s = 0 ; s < truthSigns.size(); ++s) {
117 same += (truthSigns[s] != 0) && truthSigns[s] == recoSigns[s];
121 std::vector<ObjectMatching>
125 std::vector<ObjectMatching> allAssociations{};
126 std::unordered_set<const SegmentSeed*> usedSeeds{};
131 assert(segment !=
nullptr);
132 std::vector<ObjectMatching>::iterator assoc_itr = allAssociations.end();
136 assoc_itr = std::ranges::find_if(allAssociations, [truthSeg](
const ObjectMatching& obj){
137 return obj.truthSegment == truthSeg;
141 if (assoc_itr == allAssociations.end()) {
145 recoSeg->etaIndex());
147 assoc_itr = allAssociations.end() -1;
153 usedSeeds.insert(segment->
parent());
159 if (!assocObj.truthSegment) {
162 std::ranges::sort(assocObj.matchedSegments,
165 return countOnSameSide(*assocObj.truthSegment, *a) >
166 countOnSameSide(*assocObj.truthSegment, *b);
173 if (usedSeeds.count(seed)) {
177 std::vector<std::pair<const xAOD::MuonSegment*, std::size_t>> segCounts{};
184 auto count_itr = std::ranges::find_if(segCounts, [truthSeg](
const auto& segCounter){
185 return segCounter.first == truthSeg;
187 if (count_itr != segCounts.end()) {
188 ++(count_itr->second);
190 segCounts.emplace_back(std::make_pair(truthSeg, 1ul));
194 std::ranges::sort(segCounts, [](
const auto&
a,
const auto& b){
195 return a.second > b.second;
199 ? segCounts.front().first :
nullptr;
201 auto assoc_itr = std::ranges::find_if(allAssociations,
203 return obj.truthSegment == truthSeg;
205 if (assoc_itr == allAssociations.end()) {
207 newObj.
chamber = seed->msSector();
209 assoc_itr = allAssociations.end() -1;
211 assoc_itr->matchedSeeds.push_back(seed);
212 assoc_itr->matchedSeedFoundSegment.push_back(0);
215 newObj.
chamber = seed->msSector();
224 if (std::ranges::any_of(allAssociations, [truthSeg](
const auto& assocObj){
225 return assocObj.truthSegment == truthSeg;
232 truthSeg->etaIndex());
236 return allAssociations;
241 return StatusCode::SUCCESS;
253 segmentSeeds.
insert(segmentSeeds.
end(), readSegmentSeeds->
begin(), readSegmentSeeds->
end());
262 ATH_MSG_DEBUG(
"Succesfully retrieved input collections. Seeds: "<<segmentSeeds.size()
263 <<
", segments: "<<recoSegments->
size()
264 <<
", truth segments: "<<(truthSegments? truthSegments->
size() : -1)
267 *recoSegments, truthSegments);
275 return StatusCode::SUCCESS;
305 unsigned nMmEtaHits{0}, nMmStereoHits{0}, nStgcHits{0};
315 const bool isStereo =
m_idHelperSvc->mmIdHelper().isStereo(simHit->identify());
316 nMmEtaHits += (!isStereo);
317 nMmStereoHits += isStereo;
329 double minYhit = std::numeric_limits<double>::max();
330 double maxYhit = -1 * std::numeric_limits<double>::max();
338 minYhit = std::min(chamberPos.y(), minYhit);
339 maxYhit = std::max(chamberPos.y(), maxYhit);
359 std::vector<const MuonR4::SpacePoint*> etaHits{};
360 etaHits.reserve(bucket.size());
361 for (
const auto&
sp : bucket) {
362 if (
sp->measuresEta()) {
363 etaHits.push_back(
sp.get());
368 return a->localPosition().y() < b->localPosition().y();
372 double maxEtaHitGap{-1.f};
373 for (std::size_t i = 1; i < etaHits.size(); ++i) {
374 maxEtaHitGap = std::max(maxEtaHitGap,
375 std::abs(etaHits[i]->localPosition().
y()
376 - etaHits[i - 1]->localPosition().
y()));
383 return isPrecision(*
sp);
386 return sp->measuresPhi();
404 for (
const auto [iseed, seed] : Acts::enumerate(obj.matchedSeeds)){
410 for (
const SpacePoint* hit : seed->getHitsInMax()){
420 if (seed->hasPhiExtension()){
432 auto hitCounter = [seed](
auto lambda) {
433 return std::count_if(seed->getHitsInMax().begin(),
434 seed->getHitsInMax().end(), lambda);
438 return isPrecision(*
sp);
441 return !isPrecision(*
sp) &&
sp->measuresEta();
444 return sp->measuresPhi();
448 return isPrecision(*
sp) &&
452 return !isPrecision(*
sp) &&
sp->measuresEta() &&
456 return sp->measuresPhi() &&
520 std::vector<unsigned char> treeIdxs{};
521 for (
const HoughHitType & houghSP: seed->getHitsInMax()){
523 unsigned treeIdx =
m_spTester->push_back(*houghSP);
524 treeIdxs.push_back(treeIdx);
549 for (std::size_t i =0; i < Acts::toUnderlying(ParamDefs::nPars); ++i) {
550 for (std::size_t j = 0; j <=i; ++j) {
551 const std::size_t vecIdx = Acts::vecIdxFromSymMat<Acts::toUnderlying(ParamDefs::nPars)>(i,j);
564 auto hitCounter = [detailSeg](
auto lambda) {
568 const unsigned nAuxilliary = hitCounter([](
const auto& m){
584 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
590 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
591 !isPrecision(*meas) && meas->measuresEta() &&
592 meas->spacePoint() &&
597 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
598 !isPrecision(*meas) && meas->measuresPhi() &&
599 meas->spacePoint() &&
604 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
610 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
611 !isPrecision(*meas) && meas->measuresEta() &&
612 meas->spacePoint() &&
617 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
618 !isPrecision(*meas) && meas->measuresPhi() &&
619 meas->spacePoint() &&
627 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
629 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
632 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
634 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
637 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
639 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
642 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
644 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
648 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
653 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
655 meas->measuresPhi() &&
656 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
660 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
662 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
666 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
671 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
673 meas->measuresPhi() &&
674 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
678 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
680 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
685 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
688 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
691 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
694 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
697 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
700 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
703 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
706 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
709 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
715 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
718 meas->measuresPhi() &&
719 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
723 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
726 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
730 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
736 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
739 meas->measuresPhi() &&
740 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
744 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
747 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
751 double minYhit = 1._km;
752 double maxYhit = -1._km;
753 double minYTruehit = 1._km;
754 double maxYTruehit = -1._km;
756 std::vector<unsigned char> matched{};
763 minYhit = std::min(meas->localPosition().y(),minYhit);
764 maxYhit = std::max(meas->localPosition().y(),maxYhit);
766 minYTruehit = std::min(meas->localPosition().y(), minYTruehit);
767 maxYTruehit = std::max(meas->localPosition().y(), maxYTruehit);
770 unsigned treeIdx =
m_spTester->push_back(*meas->spacePoint());
771 if (treeIdx >= matched.size()){
772 matched.resize(treeIdx +1);
774 matched[treeIdx] =
true;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
DataVector adapter that acts like it holds const pointers.
const ServiceHandle< StoreGateSvc > & detStore() const
hash_t hash(const std::string &histName) const
Method to calculate a 32-bit hash from a string.
DataVector adapter that acts like it holds const pointers.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
virtual IdentifierHash measurementHash(const Identifier &measId) const =0
The measurement hash is a continous numbering schema of all readout channels described by the specifi...
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &ctx) const override final
Returns the transformation from the local coordinate system of the readout element into the global AT...
virtual IdentifierHash layerHash(const Identifier &measId) const =0
The layer hash removes the bits from the IdentifierHash corresponding to the measurement's channel nu...
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.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
int stationPhi() const
: Returns the station phi of the sector
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index scheme.
The calibrated Space point is created during the calibration process.
const SpacePoint * spacePoint() const
The pointer to the space point out of which this space point has been built.
xAOD::UncalibMeasType type() const
Returns the space point type.
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Placeholder for what will later be the muon segment EDM representation.
unsigned int nFitIterations() const
Returns how many iterations the fitter needed to make the segment converge.
const SegmentSeed * parent() const
Returns the seed out of which the segment was built.
const MeasVec & measurements() const
Returns the associated measurements.
bool hasTimeFit() const
has the time been fitted
: The muon space point bucket represents a collection of points that will bre processed together in t...
double coveredMin() const
lower interval value covered by the bucket
double coveredMax() const
upper interval value covered by the bucket
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
const Identifier & identify() const
: Identifier of the primary measurement
xAOD::UncalibMeasType type() const
const xAOD::MuonMeasurement * primaryMeasurement() const
const Amg::Vector3D & localPosition() const
@ isMC
Flag determining whether the branch is simulation.
Helper class to provide constant type-safe access to aux data.
Property holding a SG store/key/clid from which a ReadHandle is made.
std::uint8_t nTrigEtaLayers() const
Returns the number of trigger eta hits.
std::uint8_t nTriggerPhiHoles() const
Returns the number of trigger phi holes.
float numberDoF() const
Returns the numberDoF.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
std::uint8_t nPrecisionOutliers() const
Returns the number of precision outliers.
std::uint8_t nTriggerPhiOutliers() const
Returns the number of trigger phi outliers.
std::uint8_t nPrecisionHits() const
Returns the number of precision hits.
std::uint8_t nPrecisionHoles() const
Returns the number of precision holes.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
std::uint8_t nTriggerEtaHoles() const
Returns the number of trigger eta holes.
std::uint8_t nPhiLayers() const
Returns the number of trigger phi hits.
std::uint8_t nTriggerEtaOutliers() const
Returns the number of trigger eta outliers.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
std::optional< Covariance > localSegmentCov(const xAOD::MuonSegment &seg)
Returns the localCovariance decoration from a xAOD::MuonSegment.
SeedingAux::FitParIndex ParamDefs
Use the same parameter indices as used by the CompSpacePointAuxiliaries.
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
double houghTanBeta(const Amg::Vector3D &v)
Returns the hough tanBeta [y] / [z].
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
DataVector< SegmentSeed > SegmentSeedContainer
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
const SpacePoint * HoughHitType
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
MuonHoughTransformTester::ObjectMatching ObjectMatching
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Dedicated namespace for the helper functions.
int getParticleTruthType(const xAOD::IParticle &p)
Return the particle's truth type (as defined by the MC Truth Classifier).
int getParticleTruthOrigin(const xAOD::IParticle &p)
Return the particle's truth origin (as defined by the MC Truth Classifier).
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
TruthParticle_v1 TruthParticle
Typedef to implementation.
UncalibMeasType
Define the type of the uncalibrated measurement.
sTgcMeasurement_v1 sTgcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version: