6#include "GaudiKernel/SystemOfUnits.h"
14#include "Acts/Utilities/Enumerate.hpp"
15#include "GaudiKernel/PhysicalConstants.h"
21 constexpr double c_inv = 1. /Gaudi::Units::c_light;
26 using namespace MuonR4;
27 using namespace MuonVal;
29 using simHitSet = std::unordered_set<const xAOD::MuonSimHit*>;
32 unsigned int matched{0};
34 matched += truthHits.count(reco);
47 template <
class SpType>
60 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
81 return StatusCode::SUCCESS;
92 const std::vector<int> truthSigns = SeedingAux::strawSigns(truePos, trueDir, recoSeg.
measurements());
93 const std::vector<int> recoSigns = SeedingAux::strawSigns(recoPos, recoDir, recoSeg.
measurements());
94 for (
unsigned int s = 0 ; s < truthSigns.size(); ++s) {
95 same += (truthSigns[s] != 0) && truthSigns[s] == recoSigns[s];
99 std::vector<ObjectMatching>
104 std::vector<ObjectMatching> allAssociations{};
105 std::unordered_set<const SegmentSeed*> usedSeeds{};
106 std::unordered_set<const Segment*> usedSegs{};
112 std::vector<simHitSet> truthHitsVec{}, seedSimHitVec{}, segmentSimHitVec{};
116 for (
const Segment* segment: *segmentContainer){
124 ObjectMatching & matchedWithTruth = allAssociations.emplace_back();
126 matchedWithTruth.
chamber =
m_detMgr->getSectorEnvelope((*truthHits.begin())->identify());
128 std::vector<std::pair<const SegmentSeed*, unsigned>> matchedSeeds{};
135 if (seed->msSector() != matchedWithTruth.
chamber) {
138 const simHitSet& seedHits{seedSimHitVec[seedIdx]};
139 unsigned int matchedHits =
countMatched(truthHits, seedHits);
143 matchedSeeds.emplace_back(std::make_pair(seed, matchedHits));
146 std::vector<std::pair<const Segment*, unsigned>> matchedSegs{};
148 for (
const Segment* segment : *segmentContainer) {
150 if (segment->msSector() != matchedWithTruth.
chamber) {
153 const simHitSet& segmentHits{segmentSimHitVec[segmentIdx]};
154 unsigned int matchedHits =
countMatched(truthHits, segmentHits);
158 matchedSegs.emplace_back(std::make_pair(segment,matchedHits));
164 std::ranges::sort(matchedSegs,
165 [
this, &truth, &gctx](
const std::pair<const Segment*, unsigned>& segA,
166 const std::pair<const Segment*, unsigned>& segB){
167 if (segA.second != segB.second)
return segA.second > segB.second;
171 std::ranges::sort(matchedSeeds, [](
const std::pair<const SegmentSeed*, unsigned>& seedA,
172 const std::pair<const SegmentSeed*, unsigned>& seedB) {
173 return seedA.second > seedB.second;
180 for (
const auto& [matched, nMatchedHits] : matchedSegs) {
184 usedSeeds.insert(matched->parent());
185 usedSegs.insert(matched);
189 for (
const auto& [seed ,
nHits] : matchedSeeds) {
194 usedSeeds.insert(seed);
204 for (
const Segment* seg: *segmentContainer) {
206 if (usedSegs.count(seg)) {
210 match.chamber = seg->msSector();
211 match.matchedSegments = {seg};
212 match.matchedSeeds = {seg->parent()};
214 usedSeeds.insert(seg->parent());
215 match.matchedSeedFoundSegment.push_back(1);
219 if (usedSeeds.count(seed)) {
223 match.chamber = seed->msSector();
224 match.matchedSeeds = {seed};
225 match.matchedSeedFoundSegment.push_back(0);
227 return allAssociations;
232 return StatusCode::SUCCESS;
236 const EventContext & ctx = Gaudi::Hive::currentContext();
248 segmentSeeds.
insert(segmentSeeds.
end(),readSegmentSeeds->
begin(), readSegmentSeeds->
end());
261 ATH_MSG_DEBUG(
"Succesfully retrieved input collections. Seeds: "<<segmentSeeds.size()
262 <<
", segments: "<<segments.size() <<
", truth segments: "<<(readTruthSegments? readTruthSegments->
size() : -1)<<
".");
272 return StatusCode::SUCCESS;
281 if (!segment)
return;
307 double minYhit = std::numeric_limits<double>::max();
308 double maxYhit = -1 * std::numeric_limits<double>::max();
315 const Amg::Vector3D chamberPos = localToChamber * xAOD::toEigen(hit->localPosition());
316 minYhit = std::min(chamberPos.y(), minYhit);
317 maxYhit = std::max(chamberPos.y(), maxYhit);
334 return sp->measuresPhi();
352 for (
const auto [iseed, seed] : Acts::enumerate(obj.matchedSeeds)){
358 for (
const SpacePoint* hit : seed->getHitsInMax()){
359 minYhit = std::min(hit->localPosition().y(),minYhit);
360 maxYhit = std::max(hit->localPosition().y(),maxYhit);
369 if (seed->hasPhiExtension()){
378 unsigned nMdtSeed{0}, nRpcSeed{0}, nTgcSeed{0}, nMmSeed{0}, nsTgcSeed{0};
379 unsigned nPrecHits{0}, nEtaHits{0}, nPhiHits{0}, nTrueHits{0}, nTruePrecHits{0}, nTrueEtaHits{0}, nTruePhiHits{0};
380 std::vector<unsigned char> treeIdxs{};
382 for (
const HoughHitType & houghSP: seed->getHitsInMax()){
384 unsigned treeIdx =
m_spTester->push_back(*houghSP);
385 treeIdxs.push_back(treeIdx);
388 nPhiHits += houghSP->measuresPhi();
389 nEtaHits += houghSP->measuresEta();
394 nTruePhiHits +=
m_visionTool->isLabeled(*houghSP) && houghSP->measuresPhi();
395 nTrueEtaHits +=
m_visionTool->isLabeled(*houghSP) && houghSP->measuresEta();
397 switch (houghSP->type()) {
402 nRpcSeed+=houghSP->measuresEta();
403 nRpcSeed+=houghSP->measuresPhi();
406 nTgcSeed+=houghSP->measuresEta();
407 nTgcSeed+=houghSP->measuresPhi();
410 nsTgcSeed += houghSP->measuresEta();
411 nsTgcSeed += houghSP->measuresPhi();
417 ATH_MSG_WARNING(
"Technology "<<houghSP->identify() <<
" not yet implemented");
448 for (
auto & segment : obj.matchedSegments){
449 m_out_segment_hasPhi.push_back(std::ranges::find_if(segment->measurements(), [](
const auto& meas){ return meas->measuresPhi();})
450 !=segment->measurements().end());
457 m_out_segment_err_x0.push_back(segment->covariance()(Acts::toUnderlying(ParamDefs::x0), Acts::toUnderlying(ParamDefs::x0)));
458 m_out_segment_err_y0.push_back(segment->covariance()(Acts::toUnderlying(ParamDefs::y0), Acts::toUnderlying(ParamDefs::y0)));
459 m_out_segment_err_tantheta.push_back(segment->covariance()(Acts::toUnderlying(ParamDefs::theta), Acts::toUnderlying(ParamDefs::theta)));
460 m_out_segment_err_tanphi.push_back(segment->covariance()(Acts::toUnderlying(ParamDefs::phi), Acts::toUnderlying(ParamDefs::phi)));
461 m_out_segment_err_time.push_back(segment->covariance()(Acts::toUnderlying(ParamDefs::t0), Acts::toUnderlying(ParamDefs::t0)));
467 m_out_segment_time.push_back(segment->segementT0() + segment->position().mag() * c_inv);
469 unsigned nMdtHits{0}, nRpcEtaHits{0}, nRpcPhiHits{0}, nTgcEtaHits{0}, nTgcPhiHits{0},
470 nMmEtaHits{0}, nMmStereoHits{0}, nStgcStripHits{0},nStgcWireHits{0}, nStgcPadHits{0};
471 unsigned nTrueHits{0}, nTruePrecHits{0}, nTrueEtaHits{0}, nTruePhiHits{0};
473 double minYhit = std::numeric_limits<double>::max();
474 double maxYhit = -1 * std::numeric_limits<double>::max();
476 std::vector<unsigned char> matched;
477 for (
const auto & meas : segment->measurements()){
480 minYhit = std::min(meas->localPosition().y(),minYhit);
481 maxYhit = std::max(meas->localPosition().y(),maxYhit);
483 unsigned treeIdx =
m_spTester->push_back(*meas->spacePoint());
484 if (treeIdx >= matched.size()){
485 matched.resize(treeIdx +1);
487 matched[treeIdx] =
true;
490 nTrueHits +=
m_visionTool->isLabeled(*meas->spacePoint());
492 nTrueEtaHits += meas->measuresEta() &&
m_visionTool->isLabeled(*meas->spacePoint());
493 nTruePhiHits += meas->measuresPhi() &&
m_visionTool->isLabeled(*meas->spacePoint());
495 switch (meas->type()) {
500 nRpcEtaHits += meas->measuresEta();
501 nRpcPhiHits += meas->measuresPhi();
504 nTgcEtaHits += meas->measuresEta();
505 nTgcPhiHits += meas->measuresPhi();
509 nMmEtaHits += !idHelper.
isStereo(meas->spacePoint()->identify());
510 nMmStereoHits += !idHelper.
isStereo(meas->spacePoint()->identify());
513 const auto* prd =
static_cast<const xAOD::sTgcMeasurement*
>(meas->spacePoint()->primaryMeasurement());
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
DataVector adapter that acts like it holds const pointers.
static const uint32_t nHits
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.
bool isStereo(const Identifier &id) const
The MuonReadoutElement is an abstract class representing the geometry representing the muon detector.
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
const Amg::Transform3D & localToGlobalTrans(const ActsTrk::GeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
virtual IdentifierHash measurementHash(const Identifier &measId) const =0
Constructs the identifier hash from the full measurement Identifier.
virtual IdentifierHash layerHash(const Identifier &measId) const =0
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 globalToLocalTrans(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.
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.
const MeasVec & measurements() const
Returns the associated measurements.
: 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 type-safe access to aux data.
Property holding a SG store/key/clid from which a ReadHandle is made.
int nTrigEtaLayers() const
Returns the number of trigger eta layers.
int nPrecisionHits() const
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
::Muon::MuonStationIndex::TechnologyIndex technology() const
Returns the main technology of the segment.
::Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index.
int nPhiLayers() const
Returns the number of phi layers.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
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.
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
DataVector< SegmentSeed > SegmentSeedContainer
DataVector< Segment > SegmentContainer
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
const SpacePoint * HoughHitType
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
std::unordered_set< const xAOD::MuonSimHit * > simHitSet
bool isPrecHit(const SpType &sp)
Define a spacepoint as precision hit if it's a Mdt or NSW eta hit.
MuonHoughTransformTester::ObjectMatching ObjectMatching
unsigned int countMatched(const simHitSet &truthHits, const simHitSet &recoHits)
bool isBarrel(const ChIndex index)
Returns true if the chamber index points to a barrel chamber.
@ 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.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
sTgcMeasurement_v1 sTgcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version: