17#include "CLHEP/Random/RandFlat.h"
20 struct LocalSegSorter{
25 if (
a->chamberIndex() !=
b->chamberIndex()) {
26 return a->chamberIndex() <
b->chamberIndex();
28 if (
a->sector() !=
b->sector()) {
29 return a->sector() <
b->sector();
31 if (
a->etaIndex() !=
b->etaIndex()) {
32 return a->etaIndex() <
b->etaIndex();
34 using namespace MuonR4::SegmentFit;
37 return locParsA < locParsB;
54 m_tree.addBranch(std::make_shared<MuonVal::EventHashBranch>(
m_tree.tree()));
63 return StatusCode::SUCCESS;
68 return StatusCode::SUCCESS;
72 const EventContext& ctx{Gaudi::Hive::currentContext()};
79 return StatusCode::SUCCESS;
86 std::set<const xAOD::MuonSegment*, LocalSegSorter>>;
88 SegmentsPerBucket_t segmentMap{};
111 CLHEP::RandFlat::shoot(rndEngine,0.,1.) >
m_fracToKeep) {
124 const Amg::Vector3D bucketPos = bucket->msSector()->localToGlobalTrans(*gctx) *
125 (0.5*(bucket->coveredMin() + bucket->coveredMax()) * Amg::Vector3D::UnitY());
131 m_bucket_truthHit = std::ranges::any_of(*bucket,[
this](
const SpacePointBucket::value_type &
sp){
140 std::unordered_map<const SpacePoint*, std::vector<int16_t>> spacePointToSegment{};
141 std::set<const xAOD::MuonSegment*, LocalSegSorter> truthSegments{};
143 auto match_itr = segmentMap.find(bucket);
144 if (match_itr != segmentMap.end()) {
147 if (meas->fitState() == CalibratedSpacePoint::State::Valid) {
148 spacePointToSegment[meas->spacePoint()].push_back(segment->
index());
159 unsigned truthLink = -1;
161 truthLink = truthPart->index();
165 truthSegments.insert(truthSeg);
175 std::vector<unsigned int> layNumbers{};
176 std::unordered_map<const SpacePoint*, std::vector<const xAOD::MuonSegment*>> spToTrueSeg{};
178 using SegLinkVec_t = std::vector<ElementLink<xAOD::MuonSegmentContainer>>;
180 for (
const auto&
sp : *bucket){
181 for (
const auto& link : segAcc(*
sp->primaryMeasurement())) {
182 spToTrueSeg[
sp.get()].push_back(*link);
183 truthSegments.insert(*link);
188 for(
const SpacePointBucket::value_type&
sp : *bucket) {
191 if (std::find(layNumbers.begin(), layNumbers.end(), layNum) == layNumbers.end()) {
192 layNumbers.push_back(layNum);
194 const unsigned layer = layNumbers.size()-1;
200 if (dc->status() != Muon::MdtDriftCircleStatus::MdtStatusDriftTime){
218 const std::vector<int16_t>& segIdxs = spacePointToSegment[
sp.get()];
222 trueSegLinks.push_back(std::distance(truthSegments.begin(), truthSegments.find(matchedSeg)));
229 m_spoint_covX.push_back(
sp->covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
230 m_spoint_covY.push_back(
sp->covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
242 Amg::Vector3D globalPos =
sp->msSector()->localToGlobalTrans(*gctx) *
sp->localPosition();
258 return StatusCode::FAILURE;
262 return StatusCode::SUCCESS;
269 rngWrapper->
setSeed(rngName, ctx);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
Handle class for reading from StoreGate.
static const Attributes_t empty
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
ToolHandle< MuonValR4::IPatternVisualizationTool > m_visionTool
Pattern visualization tool.
MuonVal::ScalarBranch< Char_t > & m_bucket_side
MuonVal::ThreeVectorBranch m_spoint_localPosition
MuonVal::VectorBranch< unsigned short > & m_spoint_measuresEta
MuonVal::ScalarBranch< uint8_t > & m_bucket_sector
MuonVal::VectorBranch< float > & m_truthSegLocTheta
MuonVal::VectorBranch< float > & m_segment_numberDoF
SG::ReadHandleKeyArray< SpacePointContainer > m_spacePointKeys
StatusCode dumpContainer(const EventContext &ctx, const SG::ReadHandleKey< SpacePointContainer > &spacePointKey, const SG::ReadHandleKey< xAOD::MuonSegmentContainer > &segmentKey)
Dumps the space point container with the associated muon segment container.
MuonVal::ScalarBranch< float > & m_bucket_min
MuonVal::VectorBranch< uint16_t > & m_spoint_layer
MuonVal::ThreeVectorBranch m_segmentPos
MuonVal::VectorBranch< float > & m_spoint_covX
MuonVal::VectorBranch< float > & m_segmentLocTheta
MuonVal::VectorBranch< float > & m_truthSegLocY
MuonVal::VectorBranch< float > & m_segment_chiSquared
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
MuonVal::MatrixBranch< int16_t > & m_spoint_mat
MuonVal::ScalarBranch< float > & m_bucket_posZ
MuonVal::ScalarBranch< uint16_t > & m_bucket_layers
MuonVal::VectorBranch< float > & m_truthSegLocPhi
MuonVal::VectorBranch< float > & m_segmentLocY
MuonVal::VectorBranch< uint16_t > & m_segmentTruthIdx
virtual StatusCode initialize() override final
MuonVal::MuonTesterTree m_tree
MuonVal::VectorBranch< float > & m_segmentLocX
Gaudi::Property< double > m_fracToKeep
MuonVal::ScalarBranch< float > & m_bucket_max
virtual StatusCode execute() override final
MuonVal::VectorBranch< uint16_t > & m_spoint_nSegments
SG::ReadDecorHandleKeyArray< xAOD::MuonSegmentContainer > m_truthDecorKeys
Gaudi::Property< bool > m_isMC
MuonVal::VectorBranch< unsigned int > & m_spoint_nPhiInstances
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
MuonVal::ScalarBranch< uint8_t > & m_bucket_truthHit
Gaudi::Property< std::string > m_streamName
MuonVal::ThreeVectorBranch m_segmentDir
MuonVal::VectorBranch< uint16_t > & m_spoint_tdc
MuonVal::VectorBranch< float > & m_spoint_driftR
MuonVal::ScalarBranch< float > & m_bucket_posY
MuonVal::VectorBranch< float > & m_segmentLocPhi
MuonVal::ScalarBranch< float > & m_bucket_posX
MuonVal::VectorBranch< uint16_t > & m_spoint_adc
MuonVal::MuonIdentifierBranch m_spoint_id
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
MuonVal::ScalarBranch< uint16_t > & m_bucket_segments
MuonVal::VectorBranch< unsigned int > & m_spoint_dimension
SG::ReadHandleKeyArray< xAOD::MuonSegmentContainer > m_inSegmentKeys
MuonVal::ScalarBranch< uint8_t > & m_bucket_chamberIdx
MuonVal::VectorBranch< float > & m_spoint_covY
MuonVal::MatrixBranch< int16_t > & m_spoint_trueSeg
MuonVal::VectorBranch< unsigned short > & m_spoint_isStrip
MuonVal::VectorBranch< unsigned int > & m_spoint_nEtaInstances
MuonVal::VectorBranch< float > & m_truthSegLocX
MuonVal::VectorBranch< unsigned short > & m_spoint_trueLabel
ServiceHandle< IAthRNGSvc > m_rndmSvc
MuonVal::ScalarBranch< uint16_t > & m_bucket_spacePoints
MuonVal::VectorBranch< unsigned short > & m_spoint_isMdt
virtual StatusCode finalize() override final
MuonVal::ThreeVectorBranch m_spoint_globalPosition
MuonVal::VectorBranch< unsigned short > & m_spoint_measuresPhi
const SpacePointBucket * parentBucket() const
Returns the bucket out of which the seed was formed.
const SegmentSeed * parent() const
Returns the seed out of which the segment was built.
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...
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
unsigned int sectorLayerNum(const SpacePoint &sp) const
method returning the logic layer number
size_t index() const
Return the index of this element within its container.
Helper class to provide constant type-safe access to aux data.
Property holding a SG store/key/clid from which a ReadHandle is made.
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
float numberDoF() const
Returns the numberDoF.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
Eigen::Matrix< double, 3, 1 > Vector3D
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
This header ties the generic definitions in this package.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
std::vector< SegLink_t > SegLinkVec_t
SpacePoint::CovIdx CovIdx
########################################## SpacePointMakerAlg #######################################...
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MdtDriftCircle_v1 MdtDriftCircle
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonSegment_v1 MuonSegment
Reference the current persistent version: