13 using namespace MuonR4;
14 using namespace MuonVal;
16 using simHitSet = std::unordered_set<const xAOD::MuonSimHit*>;
22 for (
const auto& [tp, truthHitSets] : truthHits) {
23 for (
const simHitSet& truthHitSet : truthHitSets) {
24 if (truthHitSet.count(hit)) {
26 else return truthHits.size();
37 for (
const SpacePoint* hit : pattern.hitsInStation(station)) {
38 if (hit ==
sp)
return true;
48 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
86 return StatusCode::SUCCESS;
91 return StatusCode::SUCCESS;
95 const EventContext& ctx = Gaudi::Hive::currentContext();
113 ATH_MSG_DEBUG(
"Succesfully retrieved input collections. Global Patterns: "<<globPatterns->
size()
114 <<
", truth segments: "<<(readTruthSegments? readTruthSegments->
size() : -1)<<
".");
126 std::vector<const MuonR4::SpacePointContainer*>{spContainer, NSWspContainer});
129 return StatusCode::SUCCESS;
136 if (!truth)
continue;
145 if (!
m_isMC || truthHits.empty())
return;
147 for (
const auto& [tp, _] : truthHits) {
154 m_gen_Q.push_back(tp->charge());
161 for (
const auto& segment : *truthSegments) {
162 if (!segment)
continue;
164 const auto StIdx {Acts::toUnderlying(
toStationIndex(segment->chamberIndex()))};
180 for (
const auto&
sp : *bucket) {
183 if (
const auto tpIdx {
isTruthMatched(
sp.get(), truthHits)}; tpIdx.has_value()) {
185 spMatchedToTruthBranch[tpIdx.value()].
push_back(treeIdx);
189 std::size_t patternIdx{0};
191 for (
const StIndex station : pattern->getStations()) {
192 for (
const SpacePoint*
sp : pattern->hitsInStation(station)) {
194 spMatchedToPatternBranch[patternIdx].
push_back(treeIdx);
202 const std::vector<const MuonR4::SpacePointContainer*>& spContainers) {
206 const bool isTriggerEta = !isPrec &&
sp->measuresEta();
207 hitCount[Acts::toUnderlying(
ePrec)] += isPrec;
208 hitCount[Acts::toUnderlying(
eTriggerEta)] += isTriggerEta;
209 hitCount[Acts::toUnderlying(
ePhi)] +=
sp->measuresPhi();
212 std::size_t patternIdx{0};
215 const std::vector<StIndex> stations {pattern->getStations()};
216 for (
const StIndex station : stations) {
217 for (
const SpacePoint*
sp : pattern->hitsInStation(station)) {
224 if (std::ranges::find(matchedTPs, tpIdx.value()) == matchedTPs.end()) {
225 matchedTPs.push_back(tpIdx.value());
231 if (!spContainer)
continue;
233 bool bucketInPattern{
false};
235 std::vector<const SpacePoint*> allHits{};
237 for (
const auto&
sp : *bucket) {
239 bucketInPattern =
true;
241 allHits.push_back(
sp.get());
243 if (bucketInPattern) {
258 m_pat_Eta.push_back(-std::log(std::tan(pattern->theta()/2.)));
264 m_pat_side.push_back(pattern->hitsInStation(stations.front()).front()->msSector()->side());
278 [&truthHits](
unsigned char tpIdx){
return tpIdx < truthHits.size(); }));
#define ATH_CHECK
Evaluate an expression and check for errors.
size_type size() const noexcept
Returns the number of elements in the collection.
Data class to represent an eta maximum in hough space.
: The muon space point bucket represents a collection of points that will bre processed together in t...
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
MuonVal::VectorBranch< float > & m_gen_Phi
MuonVal::VectorBranch< unsigned char > & m_spType
Type of spacepoints: 1 for trigger eta, 2 for precision, 3 for only-phi.
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_NSWspKey
SG::ReadHandleKey< MuonR4::GlobalPatternContainer > m_patternKey
MuonVal::ScalarBranch< unsigned > & m_pat_n
====== Global Pattern block ===========
void fillTruthInfo(const TruthParticleMap &truthHits, const xAOD::MuonSegmentContainer *truthSegments)
Fill the truth particleinformation into the tree.
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToPattern
Branch indicating which space points in the tree are associated to the i-th pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nPileupNonPrecSpacePoints
Number of pileup trigger eta space points in the pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nAllPrecSpacePoints
Number of precision space points in the buckets crossed by the pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nStations
Number of stations.
MuonVal::MatrixBranch< unsigned char > & m_NSWspMatchedToTruth
MuonVal::VectorBranch< uint16_t > & m_pat_sector2
MuonVal::VectorBranch< float > & m_gen_Eta
MuonVal::VectorBranch< unsigned char > & m_pat_nAllPhiSpacePoints
Number of phi space points in the buckets crossed by the pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nPhiSpacePoints
Number of phi measurements in the pattern.
Gaudi::Property< bool > m_writeSpacePoints
MuonVal::VectorBranch< float > & m_pat_phi
MuonVal::VectorBranch< float > & m_pat_normalizedResidual
pattern normalized residual
MuonVal::VectorBranch< unsigned char > & m_pat_nTrueNonPrecSpacePoints
Number of truth trigger eta space points in the pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nPileupPhiSpacePoints
Number of pileup phi space points in the pattern.
virtual StatusCode execute() override
std::map< const xAOD::TruthParticle *, std::vector< simHitSet > > TruthParticleMap
MuonVal::VectorBranch< unsigned char > & m_pat_nTruePrecSpacePoints
Number of truth precision space points in the pattern.
MuonVal::VectorBranch< short > & m_gen_Q
====== Truth particle block ===========
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
MuonVal::MatrixBranch< unsigned char > & m_gen_nNonPrecSpacePointsPerStation
Number of trigger eta measurements per station.
virtual StatusCode finalize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
MuonVal::VectorBranch< unsigned char > & m_pat_nPileupPrecSpacePoints
Number of pileup precision space points in the pattern.
MuonVal::MatrixBranch< unsigned char > & m_gen_nPhiSpacePointsPerStation
Number of phi measurements per station.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_truthSegmentKey
std::shared_ptr< SpacePointTesterModule > m_NSWspTester
std::shared_ptr< SpacePointTesterModule > m_spTester
====== Spacepoint block ===========
virtual StatusCode initialize() override
MuonVal::VectorBranch< unsigned char > & m_pat_nNonPrecSpacePoints
Number of trigger eta space points in the pattern.
Gaudi::Property< bool > m_isMC
MuonVal::VectorBranch< unsigned char > & m_pat_nTruthparticles
number of matched truth particles
MuonVal::VectorBranch< float > & m_gen_Pt
void fillSpacePointInfo(const MuonR4::SpacePointContainer *spc, const MuonR4::GlobalPatternContainer *patternCont, const TruthParticleMap &truthHits, SpacePointTesterModule &spTester, MuonVal::VectorBranch< unsigned char > &spTypeBranch, MuonVal::MatrixBranch< unsigned char > &spMatchedToPatternBranch, MuonVal::MatrixBranch< unsigned char > &spMatchedToTruthBranch) const
Fill the space point information into the tree.
MuonVal::VectorBranch< unsigned char > & m_NSWspType
void fillGlobPatternInfo(const MuonR4::GlobalPatternContainer *patternCont, const TruthParticleMap &truthHits, const std::vector< const MuonR4::SpacePointContainer * > &spContainers)
Fill the info associated to the global patterns into the tree.
MuonVal::VectorBranch< uint16_t > & m_pat_sector1
pattern primary & secondary sectors (different if the pattern is in the sector overlap)
MuonVal::MatrixBranch< unsigned char > & m_NSWspMatchedToPattern
MuonVal::VectorBranch< float > & m_pat_residual
pattern residual
MuonVal::MuonTesterTree m_tree
MuonVal::VectorBranch< unsigned char > & m_pat_nAllNonPrecSpacePoints
Number of trigger eta space points in the buckets crossed by the pattern.
MuonVal::VectorBranch< short > & m_pat_side
+1 for A-, -1 of C-side
MuonVal::MatrixBranch< unsigned char > & m_pat_MatchedToTruth
Branch indicating which truth particles in the tree are associated to the i-th pattern.
MuonVal::VectorBranch< unsigned char > & m_pat_nPrecSpacePoints
Number of precision measurements in the pattern.
MuonVal::MatrixBranch< unsigned char > & m_gen_nPrecSpacePointsPerStation
Number of precision measurements per station.
TruthParticleMap fillTruthMap(const xAOD::MuonSegmentContainer *truthSegments) const
Fill the truth particle map.
std::array< unsigned int, Acts::toUnderlying(eHitType::nTypes)> HitCounts
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToTruth
Branch indicating which space points in the tree are associated to the i-th truth particle.
MuonVal::VectorBranch< float > & m_pat_Eta
pattern average theta & phi
MuonVal::VectorBranch< unsigned char > & m_pat_nTruePhiSpacePoints
Number of truth phi space points in the pattern.
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_spKey
unsigned int push_back(const MuonR4::SpacePointBucket &bucket)
@ isMC
Flag determining whether the branch is simulation.
void push_back(size_t i, const T &value)
void push_back(const T &value)
Adds a new element at the end of the vector.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
DataVector< GlobalPattern > GlobalPatternContainer
Abrivation of the GlobalPattern container type.
bool isPrecisionHit(const SpacePoint &hit)
Returns whether the uncalibrated spacepoint is a precision hit (Mdt, micromegas, stgc strips)
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
std::optional< std::size_t > isTruthMatched(const SpacePoint *sp, const TruthParticleMap &truthHits)
bool isInPattern(const SpacePoint *sp, const StIndex station, const GlobalPattern &pattern)
std::map< const xAOD::TruthParticle *, std::vector< simHitSet > > TruthParticleMap
std::unordered_set< const xAOD::MuonSimHit * > simHitSet
StIndex
enum to classify the different station layers in the muon spectrometer
StIndex toStationIndex(ChIndex index)
convert ChIndex into StIndex
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.
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
HitCounts pileupHitCounts