15#include "Acts/Definitions/Units.hpp"
22using namespace Acts::UnitLiterals;
33 constexpr int overlapSector(
const int sec1 ,
const int sec2) {
35 if (sec2 > sec1)
return overlapSector(sec2, sec1);
36 if (sec1 == 1 && sec2 == nSec)
return 0;
45 int secMax{-1}, secMin{100};
47 if (matchedSegs.empty()) {
51 secMax = std::max(secMax, seg->sector());
52 secMin = std::min(secMin, seg->sector());
54 const int orSec = overlapSector(secMax, secMin);
64 const auto [barrelLength, barrelTheta] =
calcSeedLength(gctx, barrelSeed);
65 const auto [endcapLength, endcapTheta] =
calcSeedLength(gctx, endcapSeed);
66 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Constructed new seed from truth muon wih pT:"
67 <<(truthMuon.pt()/ Gaudi::Units::GeV)<<
" [GeV], eta: "<<truthMuon.eta()
68 <<
", phi: "<<(truthMuon.phi() / 1._degree)<<
", q: "<<truthMuon.charge()
69 <<
", matchedSeg: "<<matchedSegs.size()<<
" barrel (L/theta): "<<barrelLength
70 <<
"/"<<(barrelTheta / 1._degree)<<
" - endcap (L/theta): "
71 <<endcapLength<<
"/"<<(endcapTheta / 1._degree)<<
"\n"<<barrelSeed);
72 if (barrelLength < 0 && endcapLength < 0) {
76 return barrelLength < 0 || std::abs(endcapLength) < barrelLength
77 ? endcapSeed : barrelSeed;
82 double maxL{-1.*Gaudi::Units::km}, minL{1.*Gaudi::Units::km},
85 const auto secProj =
m_seeder->projectorFromSeed(*seg, seed);
87 if (!
m_seeder->withinBounds(projPos, seed.location())) {
90 const double projected = projPos[seed.location()==Location::Barrel];
91 const double theta = seg->direction().theta();
92 minL = std::min(minL, projected);
93 maxL = std::max(maxL, projected);
94 minTheta = std::min(minTheta,
theta);
95 maxTheta = std::max(maxTheta,
theta);
97 return std::make_pair(maxL - minL, maxTheta - minTheta);
116 m_seeder = std::make_unique<MuonR4::MsTrackSeeder>(name(), std::move(seederCfg));
124 return m_segSelector->passSeedingQuality(Gaudi::Hive::currentContext(),
129 return m_segSelector->passTrackQuality(Gaudi::Hive::currentContext(),
138 const unsigned linkIdx = truthS ?
m_truthSegs->push_back(*truthS) : -1;
158 unsigned short linkIdx =
m_truthTrks->find(truthP);
167 for (
const auto proj : {leftOverlap, center, rightOverlap}) {
169 if (
m_seeder->withinBounds(projPos, Location::Barrel)) {
182 for (
const auto proj : {leftOverlap, center, rightOverlap}) {
184 if (
m_seeder->withinBounds(projPos, Location::Endcap)) {
200 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, evOpts));
210 for (
const auto& summary :{
212 "innerSmallHits",
"innerLargeHits",
"innerSmallHoles",
"innerLargeHoles",
214 "middleSmallHits",
"middleLargeHits",
"middleSmallHoles",
217 "outerSmallHits",
"outerLargeHits",
"outerSmallHoles",
"outerLargeHoles",
219 "extendedSmallHits",
"extendedLargeHits",
"extendedSmallHoles",
220 "extendedLargeHoles",
221 "etaLayer1Hits",
"phiLayer1Hits",
"etaLayer2Hits",
"phiLayer2Hits",
222 "etaLayer3Hits",
"phiLayer3Hits",
"etaLayer4Hits",
"phiLayer4Hits",
223 "etaLayer1Holes",
"phiLayer1Holes",
"etaLayer2Holes",
"phiLayer2Holes",
224 "etaLayer3Holes",
"phiLayer3Holes",
"etaLayer4Holes",
"phiLayer4Holes" }) {
239 return StatusCode::SUCCESS;
242 const EventContext& ctx{Gaudi::Hive::currentContext()};
256 if (recoSegments->
empty()){
257 return StatusCode::SUCCESS;
266 std::map<const xAOD::TruthParticle*, std::vector<unsigned>> truthToSeedMatchCounter{};
270 m_seedType+= Acts::toUnderlying(seed.location());
276 truthSeg !=
nullptr) {
278 if (seedIdx >= matchCounter.size()) {
279 matchCounter.resize(seedIdx +1);
281 ++matchCounter[seedIdx];
287 m_seedQP +=
m_seeder->estimateQtimesP(*gctx, *magCache, seed) / Gaudi::Units::GeV;
297 ATH_MSG_VERBOSE(std::format(
"Dump truth segment {:} @{:}, eta: {:.2f}, phi {:.2f}",
299 seg->direction().eta(), seg->direction().phi() / 1._degree));
302 if (truthSegs->size()) {
309 if (truthMuons && truthMuons->
size()) {
317 ATH_MSG_DEBUG(
"Truth muon: pT: "<<(truth->pt() *MeVtoGeV)<<
", eta: "<<truth->eta()
318 <<
", phi: "<<(truth->phi() / 1._degree)<<
", q: "<<truth->charge());
322 std::vector<unsigned>& matchCounter = truthToSeedMatchCounter[truth];
323 std::vector<unsigned>::iterator maxSeed = matchCounter.begin();
325 while ( (maxSeed = std::ranges::max_element(matchCounter))!=matchCounter.end() && (*maxSeed) > 0) {
332 const std::vector<const xAOD::MuonSegment*> truthSegs =
getTruthSegments(*truth);
335 truthSegLinks.push_back(
m_truthSegs->push_back(*truthSeg));
347 m_truthMuonQP[truthIdx] =
m_seeder->estimateQtimesP(*gctx, *magCache, *truthSeed) / Gaudi::Units::GeV;
354 for (
const auto trk : *msTracks) {
359 return StatusCode::SUCCESS;
363 return StatusCode::SUCCESS;
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
void addSegment(const xAOD::MuonSegment *seg)
Append a segment to the seed.
void setPosition(Amg::Vector3D &&pos)
set the seed's position
MsTrackSeed::Location Location
Enum toggling whether the segment is in the endcap or barrel.
SectorProjector
Enumeration to select the sector projection.
const MuonGMR4::MuonDetectorManager * m_detMgr
std::optional< MuonR4::MsTrackSeed > makeSeedFromTruth(const ActsTrk::GeometryContext &gctx, const xAOD::TruthParticle &truthMuon) const
Construct MS track seed from the truth associated segments.
ToolHandle< MuonR4::ITrackSummaryTool > m_summaryTool
Hit summary tool.
ParticleBranchPtr_t m_truthTrks
std::unique_ptr< MuonR4::MsTrackSeeder > m_seeder
MuonVal::VectorBranch< float > & m_seedThetaCone
Maximum angular difference between the segments part of the seed.
ParticleBranchPtr_t m_legacyTrks
Output branches of the legacy MS tracks.
SegmentBranchPtr_t m_truthSegs
MuonVal::MatrixBranch< unsigned short > & m_truthMuRecoSegLinks
Links from the truth muon to the segments.
MuonVal::MatrixBranch< unsigned short > & m_truthMuToSeedIdx
Links to all MsTrkSeeds that could be matched to the truthMuon, i.e.
StatusCode execute() override final
MuonVal::VectorBranch< float > & m_truthMuonQP
Estimated Q x P from the seeder algorithm class.
MuonVal::VectorBranch< float > & m_truthMuonsSeedLength
MuonVal::VectorBranch< char > & m_seedType
Is the seed in the encap or in the barrel chambers.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_legacyTrackKey
Legacy track reconstruction chain.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
Key to the truth particle collection.
Gaudi::Property< bool > m_isMC
MuonVal::MatrixBranch< unsigned short > & m_truthSegToRecoLink
Link of the truth segments to the matchin reco segments.
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheKey
Dependency on the magnetic field.
SegmentBranchPtr_t m_recoSegs
SG::ReadHandleKey< MuonR4::MsTrackSeedContainer > m_msTrkSeedKey
Temporary container write handle to push the seeds to store gate for later efficiency analysis.
SG::ReadDecorHandleKeyArray< SG::AuxVectorBase > m_trkTruthLinks
Decoration dependency to the MS truth track links.
MuonVal::MatrixBranch< unsigned short > & m_truthMuTruthSegLinks
Links from the truth muon to the segments.
MuonVal::VectorBranch< float > & m_truthMuonsSeedCone
Angular deviation of the true segment seed.
StatusCode initialize() override final
MuonVal::MatrixBranch< unsigned short > & m_seedRecoSegMatch
Link of the track seed to the building segment.
MuonVal::VectorBranch< float > & m_seedQP
Estimated momentum times charge from the track seed.
MuonVal::MatrixBranch< unsigned short > & m_truthMuToSeedCounter
Corresponding matching counter of reconstructed segments.
MuonVal::VectorBranch< unsigned short > & m_truthMuTruthNSegs
Number of associated truth muon segments.
MuonVal::ThreeVectorBranch m_seedPos
Simple seed information.
MuonVal::VectorBranch< float > & m_seedLength
Maximum separation between the segments on the reference plane.
SG::ReadHandleKey< ActsTrk::TrackContainer > m_trackKey
Dependency on the R4 MS track container.
ToolHandle< MuonR4::ISegmentSelectionTool > m_segSelector
Segment selection tool to pick the good quality segments.
SegmentKey_t m_recoSegmentKey
Primary segment container.
MuonVal::MuonTesterTree m_tree
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
Dependency on the geometry alignment.
SegmentKey_t m_truthSegmentKey
Segment from the truth hits.
std::shared_ptr< TrackSummaryModule > m_trackSummary
Hit summary on the reconstructed track.
StatusCode finalize() override final
std::shared_ptr< TrackSummaryModule > m_seedSummary
Hit summary on the track seed.
std::pair< double, double > calcSeedLength(const ActsTrk::GeometryContext &gctx, const MuonR4::MsTrackSeed &seed) const
static bool connectCollections(ParticleBranch_ptr primColl, ParticleBranch_ptr secondColl, Linker_t fromPrimToSec, const std::string &altPrimName="", const std::string &altSecName="")
@ isMC
Flag determining whether the branch is simulation.
Generic branch object where the information is evaluated by a std::function instead reading it from t...
Base class for elements of a container that can have aux data.
Helper class to provide constant type-safe access to aux data.
Class providing the definition of the 4-vector interface.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 2, 1 > Vector2D
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.
std::vector< MsTrackSeed > MsTrackSeedContainer
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
std::vector< const xAOD::MuonSegment * > getTruthSegments(const xAOD::TruthParticle &truthMuon)
Returns the segments associated to the truth muon.
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
std::vector< SegLink_t > SegLinkVec_t
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...
Class to store array like branches into the n-tuples.
constexpr unsigned numberOfSectors()
return total number of sectors
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
double endcapDiscRadius
Radius of the endcap discs.
const MuonGMR4::MuonDetectorManager * detMgr
Detector manager to fetch the sector enevelope transforms.
double seedHalfLength
Maximum separation of point on the cylinder to be picked up onto a seed.