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"
29 constexpr double c_inv = 1. /Gaudi::Units::c_light;
34 (
hit.type() == sTgcStripType &&
43 return isPrecision(*
hit.spacePoint());
50 using namespace MuonR4;
51 using namespace MuonVal;
52 using namespace Muon::MuonStationIndex;
53 using namespace Acts::UnitLiterals;
64 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
88 for (std::size_t cov = 0 ; cov <
m_segmentCov.size(); ++cov){
90 const auto [i, j] = Acts::symMatIndices<Acts::toUnderlying(ParamDefs::nPars)>(cov);
91 ParamDefs pI{
static_cast<std::uint8_t
>(i)},
92 pJ{
static_cast<std::uint8_t
>(j)};
93 std::string brName = (pI!= pJ) ? std::format(
"segment_cov_{:}_{:}", pI, pJ)
94 : std::format(
"segment_cov_{:}", pI);
105 return StatusCode::SUCCESS;
111 unsigned int same{0};
116 const std::vector<int> truthSigns = SeedingAux::strawSigns(truePos, trueDir, detailSeg->
measurements());
117 const std::vector<int> recoSigns = SeedingAux::strawSigns(recoPos, recoDir, detailSeg->
measurements());
118 for (
unsigned int s = 0 ; s < truthSigns.size(); ++s) {
119 same += (truthSigns[s] != 0) && truthSigns[s] == recoSigns[s];
123 std::vector<ObjectMatching>
127 std::vector<ObjectMatching> allAssociations{};
128 std::unordered_set<const SegmentSeed*> usedSeeds{};
133 assert(segment !=
nullptr);
134 std::vector<ObjectMatching>::iterator assoc_itr = allAssociations.end();
138 assoc_itr = std::ranges::find_if(allAssociations, [truthSeg](
const ObjectMatching& obj){
139 return obj.truthSegment == truthSeg;
143 if (assoc_itr == allAssociations.end()) {
147 recoSeg->etaIndex());
149 assoc_itr = allAssociations.end() -1;
155 usedSeeds.insert(segment->
parent());
161 if (!assocObj.truthSegment) {
164 std::ranges::sort(assocObj.matchedSegments,
167 return countOnSameSide(*assocObj.truthSegment, *a) >
168 countOnSameSide(*assocObj.truthSegment, *b);
175 if (usedSeeds.count(seed)) {
179 std::vector<std::pair<const xAOD::MuonSegment*, std::size_t>> segCounts{};
186 auto count_itr = std::ranges::find_if(segCounts, [truthSeg](
const auto& segCounter){
187 return segCounter.first == truthSeg;
189 if (count_itr != segCounts.end()) {
190 ++(count_itr->second);
192 segCounts.emplace_back(std::make_pair(truthSeg, 1ul));
196 std::ranges::sort(segCounts, [](
const auto&
a,
const auto& b){
197 return a.second > b.second;
201 ? segCounts.front().first :
nullptr;
203 auto assoc_itr = std::ranges::find_if(allAssociations,
205 return obj.truthSegment == truthSeg;
207 if (assoc_itr == allAssociations.end()) {
209 newObj.
chamber = seed->msSector();
211 assoc_itr = allAssociations.end() -1;
213 assoc_itr->matchedSeeds.push_back(seed);
214 assoc_itr->matchedSeedFoundSegment.push_back(0);
217 newObj.
chamber = seed->msSector();
226 if (std::ranges::any_of(allAssociations, [truthSeg](
const auto& assocObj){
227 return assocObj.truthSegment == truthSeg;
234 truthSeg->etaIndex());
238 return allAssociations;
243 return StatusCode::SUCCESS;
255 segmentSeeds.
insert(segmentSeeds.
end(), readSegmentSeeds->
begin(), readSegmentSeeds->
end());
264 ATH_MSG_DEBUG(
"Succesfully retrieved input collections. Seeds: "<<segmentSeeds.size()
265 <<
", segments: "<<recoSegments->
size()
266 <<
", truth segments: "<<(truthSegments? truthSegments->
size() : -1)
269 *recoSegments, truthSegments);
277 return StatusCode::SUCCESS;
318 using namespace Acts::detail::LineHelper;
319 const Acts::Intersection3D bsExtp = lineIntersect<3>(Amg::Vector3D::Zero(),
320 Amg::Vector3D::UnitZ(),
327 unsigned nMmEtaHits{0}, nMmStereoHits{0}, nStgcHits{0};
337 const bool isStereo =
m_idHelperSvc->mmIdHelper().isStereo(simHit->identify());
338 nMmEtaHits += (!isStereo);
339 nMmStereoHits += isStereo;
351 double minYhit = std::numeric_limits<double>::max();
352 double maxYhit = -1 * std::numeric_limits<double>::max();
362 const Amg::Vector3D chamberPos = localToChamber * xAOD::toEigen(
hit->localPosition());
363 minYhit = std::min(chamberPos.y(), minYhit);
364 maxYhit = std::max(chamberPos.y(), maxYhit);
384 std::vector<const MuonR4::SpacePoint*> etaHits{};
385 etaHits.reserve(bucket.size());
386 for (
const auto&
sp : bucket) {
387 if (
sp->measuresEta()) {
388 etaHits.push_back(
sp.get());
393 return a->localPosition().y() < b->localPosition().y();
397 double maxEtaHitGap{-1.f};
398 for (std::size_t i = 1; i < etaHits.size(); ++i) {
399 maxEtaHitGap = std::max(maxEtaHitGap,
400 std::abs(etaHits[i]->localPosition().
y()
401 - etaHits[i - 1]->localPosition().
y()));
408 return isPrecision(*
sp);
411 return sp->measuresPhi();
429 for (
const auto [iseed, seed] : Acts::enumerate(obj.matchedSeeds)){
436 minYhit = std::min(
hit->localPosition().y(),minYhit);
437 maxYhit = std::max(
hit->localPosition().y(),maxYhit);
445 if (seed->hasPhiExtension()){
457 auto hitCounter = [seed](
auto lambda) {
458 return std::count_if(seed->getHitsInMax().begin(),
459 seed->getHitsInMax().end(), lambda);
463 return isPrecision(*
sp);
466 return !isPrecision(*
sp) &&
sp->measuresEta();
469 return sp->measuresPhi();
473 return isPrecision(*
sp) &&
477 return !isPrecision(*
sp) &&
sp->measuresEta() &&
481 return sp->measuresPhi() &&
545 std::vector<unsigned char> treeIdxs{};
546 for (
const HoughHitType & houghSP: seed->getHitsInMax()){
548 unsigned treeIdx =
m_spTester->push_back(*houghSP);
549 treeIdxs.push_back(treeIdx);
574 for (std::size_t i =0; i < Acts::toUnderlying(ParamDefs::nPars); ++i) {
575 for (std::size_t j = 0; j <=i; ++j) {
576 const std::size_t vecIdx = Acts::vecIdxFromSymMat<Acts::toUnderlying(ParamDefs::nPars)>(i,j);
589 auto hitCounter = [detailSeg](
auto lambda) {
607 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
613 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
614 !isPrecision(*meas) && meas->measuresEta() &&
615 meas->spacePoint() &&
620 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
621 !isPrecision(*meas) && meas->measuresPhi() &&
622 meas->spacePoint() &&
627 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
633 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
634 !isPrecision(*meas) && meas->measuresEta() &&
635 meas->spacePoint() &&
640 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
641 !isPrecision(*meas) && meas->measuresPhi() &&
642 meas->spacePoint() &&
650 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
652 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
655 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
657 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
660 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
662 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
665 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
667 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
671 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
676 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
678 meas->measuresPhi() &&
679 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
683 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
685 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
689 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
694 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
696 meas->measuresPhi() &&
697 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
701 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
703 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
708 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
711 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
714 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
717 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
720 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
723 !
m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
726 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
729 m_idHelperSvc->mmIdHelper().isStereo(meas->spacePoint()->identify());
732 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
738 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
741 meas->measuresPhi() &&
742 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
746 return meas->fitState() == CalibratedSpacePoint::State::Valid &&
749 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
753 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
759 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
762 meas->measuresPhi() &&
763 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) !=
767 return meas->fitState() != CalibratedSpacePoint::State::Valid &&
770 m_idHelperSvc->stgcIdHelper().channelType(meas->spacePoint()->identify()) ==
774 double minYhit = 1._km;
775 double maxYhit = -1._km;
776 double minYTruehit = 1._km;
777 double maxYTruehit = -1._km;
779 std::vector<unsigned char> matched{};
786 minYhit = std::min(meas->localPosition().y(),minYhit);
787 maxYhit = std::max(meas->localPosition().y(),maxYhit);
789 minYTruehit = std::min(meas->localPosition().y(), minYTruehit);
790 maxYTruehit = std::max(meas->localPosition().y(), maxYTruehit);
793 unsigned treeIdx =
m_spTester->push_back(*meas->spacePoint());
794 if (treeIdx >= matched.size()){
795 matched.resize(treeIdx +1);
797 matched[treeIdx] =
true;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
DataVector adapter that acts like it holds const pointers.
const ServiceHandle< StoreGateSvc > & detStore() const
hash_t hash(std::string_view 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.
const Acts::Transform3 & 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 measurementHash(const Identifier &measId) const =0
The measurement hash is a continous numbering schema of all readout channels described by the specifi...
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.
const Acts::Transform3 & 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.
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...
@ 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.
double angle(const Amg::Vector3D &v1, const Amg::Vector3D &v2)
calculates the opening angle between two vectors
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:
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP