6#include "GaudiKernel/SystemOfUnits.h"
16#include "Acts/Utilities/Enumerate.hpp"
17#include "GaudiKernel/PhysicalConstants.h"
25 constexpr double c_inv = 1. /Gaudi::Units::c_light;
27 template <
typename SegObj>
31 return truthSeg !=
nullptr ?
40 using namespace MuonR4;
41 using namespace MuonVal;
51 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
80 return StatusCode::SUCCESS;
91 const std::vector<int> truthSigns = SeedingAux::strawSigns(truePos, trueDir, recoSeg.
measurements());
92 const std::vector<int> recoSigns = SeedingAux::strawSigns(recoPos, recoDir, recoSeg.
measurements());
93 for (
unsigned int s = 0 ; s < truthSigns.size(); ++s) {
94 same += (truthSigns[s] != 0) && truthSigns[s] == recoSigns[s];
98 std::vector<ObjectMatching>
103 std::vector<ObjectMatching> allAssociations{};
104 std::unordered_set<const SegmentSeed*> usedSeeds{};
109 assert(segment !=
nullptr);
110 std::vector<ObjectMatching>::iterator assoc_itr = allAssociations.end();
113 assoc_itr = std::ranges::find_if(allAssociations, [truthSeg](
const ObjectMatching& obj){
114 return obj.truthSegment == truthSeg;
117 if (assoc_itr == allAssociations.end()) {
121 recoSeg->etaIndex());
123 assoc_itr = allAssociations.end() -1;
131 usedSeeds.insert(segment->
parent());
136 if (!assocObj.truthSegment) {
139 std::ranges::sort(assocObj.matchedSegments,
141 return countOnSameSide(gctx,*assocObj.truthSegment, *a) >
142 countOnSameSide(gctx,*assocObj.truthSegment, *b);
144 std::ranges::transform(assocObj.matchedSegments, std::back_inserter(assocObj.matchedSeeds),
152 if (usedSeeds.count(seed)) {
156 std::vector<std::pair<const xAOD::MuonSegment*, std::size_t>> segCounts{};
163 auto count_itr = std::ranges::find_if(segCounts, [truthSeg](
const auto& segCounter){
164 return segCounter.first == truthSeg;
166 if (count_itr != segCounts.end()) {
167 ++(count_itr->second);
169 segCounts.emplace_back(std::make_pair(truthSeg, 1ul));
173 std::ranges::sort(segCounts, [](
const auto&
a,
const auto& b){
174 return a.second > b.second;
178 ? segCounts.front().first :
nullptr;
180 auto assoc_itr = std::ranges::find_if(allAssociations,
182 return obj.truthSegment == truthSeg;
184 if (assoc_itr == allAssociations.end()) {
186 newObj.
chamber = seed->msSector();
188 assoc_itr = allAssociations.end() -1;
190 assoc_itr->matchedSeeds.push_back(seed);
191 assoc_itr->matchedSeedFoundSegment.push_back(0);
194 newObj.
chamber = seed->msSector();
203 if (std::ranges::any_of(allAssociations, [truthSeg](
const auto& assocObj){
204 return assocObj.truthSegment == truthSeg;
215 return allAssociations;
220 return StatusCode::SUCCESS;
224 const EventContext & ctx = Gaudi::Hive::currentContext();
234 segmentSeeds.
insert(segmentSeeds.
end(), readSegmentSeeds->
begin(), readSegmentSeeds->
end());
243 ATH_MSG_DEBUG(
"Succesfully retrieved input collections. Seeds: "<<segmentSeeds.size()
244 <<
", segments: "<<recoSegments->
size()
245 <<
", truth segments: "<<(truthSegments? truthSegments->
size() : -1)
248 *recoSegments, truthSegments);
256 return StatusCode::SUCCESS;
287 unsigned nMMHits{0}, nSTGHits{0};
302 double minYhit = std::numeric_limits<double>::max();
303 double maxYhit = -1 * std::numeric_limits<double>::max();
310 const Amg::Vector3D chamberPos = localToChamber * xAOD::toEigen(hit->localPosition());
311 minYhit = std::min(chamberPos.y(), minYhit);
312 maxYhit = std::max(chamberPos.y(), maxYhit);
336 return sp->measuresPhi();
354 for (
const auto [iseed, seed] : Acts::enumerate(obj.matchedSeeds)){
360 for (
const SpacePoint* hit : seed->getHitsInMax()){
361 minYhit = std::min(hit->localPosition().y(),minYhit);
362 maxYhit = std::max(hit->localPosition().y(),maxYhit);
371 if (seed->hasPhiExtension()){
380 unsigned nMdtSeed{0}, nRpcSeed{0}, nTgcSeed{0}, nMmEtaSeed{0}, nMmStereoSeed{0},
381 nsTgcStripSeed{0}, nsTgcWireSeed{0}, nsTgcPadSeed{0};
382 unsigned nPrecHits{0}, nEtaHits{0}, nPhiHits{0}, nTrueHits{0}, nTruePrecHits{0}, nTrueEtaHits{0}, nTruePhiHits{0};
383 std::vector<unsigned char> treeIdxs{};
385 for (
const HoughHitType & houghSP: seed->getHitsInMax()){
387 unsigned treeIdx =
m_spTester->push_back(*houghSP);
388 treeIdxs.push_back(treeIdx);
391 nPhiHits += houghSP->measuresPhi();
392 nEtaHits += houghSP->measuresEta();
397 nTruePhiHits +=
m_visionTool->isLabeled(*houghSP) && houghSP->measuresPhi();
398 nTrueEtaHits +=
m_visionTool->isLabeled(*houghSP) && houghSP->measuresEta();
400 switch (houghSP->type()) {
405 nRpcSeed+=houghSP->measuresEta();
406 nRpcSeed+=houghSP->measuresPhi();
409 nTgcSeed+=houghSP->measuresEta();
410 nTgcSeed+=houghSP->measuresPhi();
413 const Identifier sTgc = houghSP->primaryMeasurement()->identify();
414 const Identifier sTgc2 = houghSP->secondaryMeasurement() ?
415 houghSP->secondaryMeasurement()->identify() :
Identifier{};
428 if (
m_idHelperSvc->mmIdHelper().isStereo(houghSP->identify())) {
435 ATH_MSG_WARNING(
"Technology "<<houghSP->identify() <<
" not yet implemented");
471 for (
const Segment* segment : obj.matchedSegments) {
473 [](
const auto& meas){ return meas->measuresPhi();}));
492 unsigned nMdtHits{0}, nRpcEtaHits{0}, nRpcPhiHits{0}, nTgcEtaHits{0}, nTgcPhiHits{0},
493 nMmEtaHits{0}, nMmStereoHits{0}, nStgcStripHits{0},nStgcWireHits{0}, nStgcPadHits{0};
494 unsigned nTrueHits{0}, nTruePrecHits{0}, nTrueEtaHits{0}, nTruePhiHits{0};
496 double minYhit = std::numeric_limits<double>::max();
497 double maxYhit = -1 * std::numeric_limits<double>::max();
499 std::vector<unsigned char> matched;
506 minYhit = std::min(meas->localPosition().y(),minYhit);
507 maxYhit = std::max(meas->localPosition().y(),maxYhit);
509 unsigned treeIdx =
m_spTester->push_back(*meas->spacePoint());
510 if (treeIdx >= matched.size()){
511 matched.resize(treeIdx +1);
513 matched[treeIdx] =
true;
516 nTrueHits +=
m_visionTool->isLabeled(*meas->spacePoint());
518 nTrueEtaHits += meas->measuresEta() &&
m_visionTool->isLabeled(*meas->spacePoint());
519 nTruePhiHits += meas->measuresPhi() &&
m_visionTool->isLabeled(*meas->spacePoint());
521 switch (meas->type()) {
526 nRpcEtaHits += meas->measuresEta();
527 nRpcPhiHits += meas->measuresPhi();
530 nTgcEtaHits += meas->measuresEta();
531 nTgcPhiHits += meas->measuresPhi();
535 nMmEtaHits += !idHelper.
isStereo(meas->spacePoint()->identify());
536 nMmStereoHits += !idHelper.
isStereo(meas->spacePoint()->identify());
539 const auto* prd =
static_cast<const xAOD::sTgcMeasurement*
>(meas->spacePoint()->primaryMeasurement());
540 const int primType = prd->channelType();
542 const int secType = (prd !=
nullptr ? prd->channelType() : -1);
#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.
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
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the local coordinate system of the readout element into the global AT...
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...
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.
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.
double segementT0() const
Returns the fitted segment time, if there's any.
unsigned int nDoF() const
Returns the number of degrees of freedom.
unsigned int nFitIterations() const
Returns how many iterations the fitter needed to make the segment converge.
const SegmentFit::Covariance & covariance() const
Returns the uncertainties of the defining parameters.
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
double chi2() const
Returns the chi2 of the segment fit.
const Amg::Vector3D & position() const
Returns the global segment position.
: 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.
int channelType(const Identifier &id) const
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.
int etaIndex() const
Returns the eta index, which corresponds to stationEta in the offline identifiers (and the ).
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.
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.
bool isPrecisionHit(const SpacePoint &hit)
Returns whether the uncalibrated spacepoint is a precision hit (Mdt, micromegas, stgc strips).
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
TechnologyIndex
enum to classify the different layers in the muon spectrometer
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.
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.
sTgcMeasurement_v1 sTgcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version: