17 void resize_all (
const std::size_t nEle,
const std::size_t
size,
auto&&... vecs) {
18 for (std::size_t idx = 0;
idx < nEle; ++
idx) {
25 using namespace MuonR4;
26 using namespace MuonVal;
28 constexpr std::size_t
s_nStations {Acts::toUnderlying(StIndex::StIndexMax)};
29 using simHitSet = std::unordered_set<const xAOD::MuonSimHit*>;
34 if (!hit)
return std::nullopt;
36 for (
const auto& [tp, truthHitSets] : truthHits) {
37 for (
const simHitSet& truthHitSet : truthHitSets) {
38 if (truthHitSet.count(hit)) {
40 else return truthHits.size();
50 for (
const SpacePoint* hit : pattern.hitsInStation(station)) {
51 if (hit ==
sp)
return true;
61 m_tree.addBranch(std::make_unique<EventInfoBranch>(
m_tree, infoOpts));
107 return StatusCode::SUCCESS;
112 return StatusCode::SUCCESS;
116 const EventContext& ctx = Gaudi::Hive::currentContext();
138 ATH_MSG_DEBUG(
"Succesfully retrieved input collections: Global Patterns: "<<globPatterns->
size()
139 <<
", truth segments: "<<(readTruthSegments? readTruthSegments->
size() : -1)
140 <<
", Rois: "<<(roiCollection ? roiCollection->
size() : -1));
153 std::vector<const MuonR4::SpacePointContainer*>{spContainer, NSWspContainer});
156 return StatusCode::SUCCESS;
166 if (tp->eta() < roi->etaMinus() || tp->eta() > roi->etaPlus())
continue;
170 if (dPhiPlus >= 0. && dPhiMinus <= 0.)
return true;
186 const std::vector<const MuonR4::SpacePointContainer*>& spContainers) {
187 if (!
m_isMC || truthHits.empty())
return;
191 using LayerBookeeper = std::unordered_map<const MuonGMR4::SpectrometerSector*, std::set<unsigned>>;
192 using MeasBookeeper = std::array<std::vector<const SpacePoint*>, Acts::toUnderlying(
nTypes)>;
194 MeasBookeeper measInStation{};
195 LayerBookeeper seenEtaLayers{};
196 LayerBookeeper seenPhiLayers{};
198 auto processMeas = [&truthHits, &measInStation, &seenEtaLayers, &seenPhiLayers,
this]
203 (
type ==
NonPrec && (isPrec || !
sp->measuresEta())) || (
type == Phi &&
sp->measuresEta())) {
207 std::vector<const SpacePoint*>& outCont {measInStation[Acts::toUnderlying(
type)]};
208 if (std::ranges::find_if(outCont, [
sp](
const SpacePoint* s) {
209 return s->primaryMeasurement() ==
sp->primaryMeasurement(); }) != outCont.end()) {
215 const bool isDoubleMatched {
sp->dimension() == 2u &&
sp->secondaryMeasurement() &&
isTruthMatched(*
sp->secondaryMeasurement(), truthHits) == tpIdx};
216 if (process2Dmeas && !isDoubleMatched)
return;
220 ATH_MSG_VERBOSE(
"---> "<<(isPrec ?
"Prec" : (
type ==
NonPrec ?
"Trig" :
"Phi "))<<
" " << *
sp <<
" in sector "<<
sp->msSector()->identString() <<
" lay "<<layNum);
221 if (
sp->measuresEta()) {
222 const bool isSeenLayer {seenEtaLayers[
sp->msSector()].count(layNum) > 0};
223 if (isSeenLayer && !
sp->isStraw())
return;
224 if (!isSeenLayer) seenEtaLayers[
sp->msSector()].insert(layNum);
227 ++measCounter[tpIdx][stIdx];
230 if (
sp->measuresPhi() && isDoubleMatched) {
231 seenPhiLayers[
sp->msSector()].insert(layNum);
233 measInStation[Acts::toUnderlying(Phi)].push_back(
sp);
236 if (seenPhiLayers[
sp->msSector()].count(layNum) > 0)
return;
237 seenPhiLayers[
sp->msSector()].insert(layNum);
240 outCont.push_back(
sp);
244 for (
const auto& [tp, _] : truthHits) {
249 m_gen_Q.push_back(tp->charge());
252 std::vector<int> sectors{};
254 const int side {tp->eta() > 0 ? 1 : -1};
257 ATH_MSG_VERBOSE(
"tp: " << tpIdx <<
", Eta: " << tp->eta() <<
", Phi: " << tp->phi() <<
", Pt [GeV]: " << tp->pt() * 1e-3 <<
", Q: " << tp->charge());
258 for (std::size_t stIdx = 0; stIdx <
s_nStations; ++stIdx) {
261 for (
auto&
vec : measInStation)
vec.clear();
262 seenEtaLayers.clear();
263 seenPhiLayers.clear();
267 for (
const bool process2Dmeas : {
true,
false}) {
268 for (
const auto& spContainer : spContainers) {
269 if (!spContainer)
continue;
272 if (
static_cast<std::size_t
>(
m_idHelperSvc->stationIndex(bucket->front()->identify())) != stIdx)
continue;
274 if (bucket->msSector()->side() != side ||
275 std::ranges::none_of(sectors, [&](
int s){ return bucket->msSector()->sector() == s; })) {
278 for (
const auto&
sp : *bucket) {
280 processMeas(
sp.get(),
type, process2Dmeas, tpIdx, stIdx);
313 for (
const auto&
sp : *bucket) {
317 if (
const auto tpIdx {
isTruthMatched(*
sp->primaryMeasurement(), truthHits)}; tpIdx.has_value()) {
319 spMatchedToTruthBranch[tpIdx.value()].
push_back(treeIdx);
323 std::size_t patternIdx{0};
325 for (
const StIndex station : pattern->getStations()) {
326 for (
const SpacePoint*
sp : pattern->hitsInStation(station)) {
328 spMatchedToPatternBranch[patternIdx].
push_back(treeIdx);
336 const std::vector<const MuonR4::SpacePointContainer*>& spContainers) {
348 auto isSecondaryMatched = [&truthHits](
const SpacePoint*
sp, std::size_t tpIdx) {
349 return sp->secondaryMeasurement() &&
isTruthMatched(*
sp->secondaryMeasurement(), truthHits) == tpIdx;
351 std::size_t patternIdx{0};
354 std::unordered_map<std::size_t, std::vector<const SpacePoint*>> patternTruthHits{};
356 const std::vector<StIndex> stations {pattern->getStations()};
357 for (
const StIndex station : stations) {
358 for (
const SpacePoint*
sp : pattern->hitsInStation(station)) {
362 if (
const auto tpIdx {
isTruthMatched(*
sp->primaryMeasurement(), truthHits)}; tpIdx.has_value()) {
364 if (*tpIdx >= truthHits.size() ) {
367 patternTruthHits[*tpIdx].push_back(
sp);
372 if (!patternTruthHits.empty()) {
374 std::vector<std::size_t> sortedTPs {};
375 std::ranges::transform(patternTruthHits, std::back_inserter(sortedTPs), [](
const auto&
pair){
return pair.first; });
376 std::ranges::sort(sortedTPs, [&patternTruthHits](
const auto&
a,
const auto& b){
377 return patternTruthHits.at(
a).size() > patternTruthHits.at(b).size();
379 const auto mainTP = sortedTPs.front();
385 for (
const auto& [tpIdx, hits] : patternTruthHits) {
386 if (tpIdx == mainTP)
continue;
393 std::ranges::transform(sortedTPs, std::back_inserter(
m_pat_MatchedToTruth[patternIdx]), [](
const auto& tp){
return tp; });
397 if (!spContainer)
continue;
399 bool bucketInPattern{
false};
401 std::vector<const SpacePoint*> allHits{};
403 for (
const auto&
sp : *bucket) {
405 bucketInPattern =
true;
407 allHits.push_back(
sp.get());
409 if (bucketInPattern) {
416 m_pat_Eta.push_back(-std::log(std::tan(pattern->theta()/2.)));
421 m_pat_side.push_back(pattern->hitsInStation(stations.front()).front()->msSector()->side());
424 if (msgLevel(MSG::VERBOSE)) {
426 unsigned nPrecHits{0}, nNonPrecHits{0}, nPhiHits{0};
427 unsigned gen_nPrecHits{0}, gen_nNonPrecHits{0}, gen_nPhiHits{0};
428 for (std::size_t stIdx = 0; stIdx <
s_nStations; ++stIdx) {
432 if (mainTP < 0)
continue;
433 gen_nPrecHits +=
static_cast<unsigned>(
m_gen_nPrecMeas[mainTP][stIdx]);
435 gen_nPhiHits +=
static_cast<unsigned>(
m_gen_nPhiMeas[mainTP][stIdx]);
437 ATH_MSG_VERBOSE(
"Pat #" << patternIdx<<
": " << *pattern <<
"mainTP: "<<std::to_string(mainTP)
438 <<
", nTruthMatchedHits Trig: "<<nNonPrecHits<<
" / "<<gen_nNonPrecHits<<
", Prec: "<<nPrecHits<<
" / "<<gen_nPrecHits<<
", Phi: "<<nPhiHits<<
" / "<<gen_nPhiHits);
446 const std::size_t patIdx,
449 const bool isSecondaryMatched) {
452 const auto updateCounts = [&](
unsigned char& nonPrecCount,
453 unsigned char& precCount,
454 unsigned char& phiCount) {
455 if (
sp->measuresEta()) {
462 if (
sp->measuresPhi() && (!isTruthInfo || isSecondaryMatched)) {
469 const auto stIdx = Acts::toUnderlying(hitSt);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
std::vector< size_t > vec
size_t size() const
Number of registered mappings.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
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...
void fillTruthInfo(const TruthParticleMap &truthHits, const std::vector< const MuonR4::SpacePointContainer * > &spContainers)
Fill the truth particle information into the tree.
MuonVal::VectorBranch< float > & m_gen_Phi
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllNonPrecMeas
Number of trigger eta measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::VectorBranch< unsigned char > & m_spType
Type of spacepoints: 1 for trigger eta, 2 for precision, 3 for only-phi.
MuonVal::VectorBranch< float > & m_roi_ZMax
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_NSWspKey
MuonVal::MatrixBranch< unsigned char > & m_pat_nNonPrecMeas
Number of trigger eta measurements per station.
measType
Enum for measurement types.
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllPhiMeas
Number of phi measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthPrecMeas
Number of truth precision measurements per station.
SG::ReadHandleKey< MuonR4::GlobalPatternContainer > m_patternKey
MuonVal::ScalarBranch< unsigned > & m_pat_n
====== Global Pattern block ===========
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToPattern
Branch indicating which space points in the tree are associated to the i-th pattern.
BooleanProperty m_isSeededReco
MuonVal::MatrixBranch< unsigned char > & m_pat_nMisTruthPhiMeas
Number of mismatched truth phi measurements per station.
MuonVal::VectorBranch< unsigned char > & m_pat_nStations
Number of stations.
MuonVal::MatrixBranch< unsigned char > & m_NSWspMatchedToTruth
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupPhiMeas
Number of pileup phi measurements per station.
void fillRoIInfo(const TrigRoiDescriptorCollection *roiCollection)
Fill the RoI information into the tree.
MuonVal::VectorBranch< uint16_t > & m_pat_sector2
MuonVal::VectorBranch< float > & m_gen_Eta
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllPrecMeas
Number of precision measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupPrecMeas
Number of pileup precision measurements per station.
MuonVal::VectorBranch< float > & m_pat_phi
virtual StatusCode execute() override
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
std::map< const xAOD::TruthParticle *, std::vector< simHitSet > > TruthParticleMap
MuonVal::VectorBranch< short > & m_gen_Q
====== Truth particle block ===========
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
virtual StatusCode finalize() override
MuonVal::MatrixBranch< unsigned char > & m_gen_nPrecMeas
Number of precision measurements per station.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
void updatePatHitInfo(const ePatBranchType type, const std::size_t patIdx, const Muon::MuonStationIndex::StIndex hitSt, const MuonR4::SpacePoint *sp, const bool isSecondaryMatched=false)
Update the hit counts for a given pattern branch type.
ePatBranchType
Enum for different types of pattern hit content branches.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_truthSegmentKey
MuonVal::VectorBranch< float > & m_roi_EtaMin
====== RoI info ===========
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthPhiMeas
Number of truth phi measurements per station.
std::shared_ptr< SpacePointTesterModule > m_NSWspTester
MuonVal::VectorBranch< float > & m_roi_PhiMin
MuonVal::VectorBranch< float > & m_roi_PhiMax
std::shared_ptr< SpacePointTesterModule > m_spTester
====== Spacepoint block ===========
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthNonPrecMeas
Number of truth trigger eta measurements per station.
virtual StatusCode initialize() override
MuonVal::MatrixBranch< unsigned char > & m_pat_nPhiMeas
Number of phi measurements per station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPrecMeas
Number of precision measurements per station.
MuonVal::VectorBranch< float > & m_roi_EtaMax
MuonVal::VectorBranch< float > & m_pat_meanNormResidual2
mean square normalized pattern residual
BooleanProperty m_writeSpacePoints
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::MatrixBranch< unsigned char > & m_pat_nMisTruthNonPrecMeas
Number of mismatched truth trigger eta measurements per station.
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::MatrixBranch< unsigned char > & m_pat_nMisTruthPrecMeas
Number of mismatched truth precision measurements per station.
MuonVal::MuonTesterTree m_tree
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.
MuonR4::SpacePointPerLayerSorter m_spSorter
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToTruth
Branch indicating which space points in the tree are associated to the i-th truth particle.
MuonVal::MatrixBranch< unsigned char > & m_gen_nPhiMeas
Number of phi measurements per station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupNonPrecMeas
Number of pileup trigger eta measurements per station.
MuonVal::VectorBranch< float > & m_pat_Eta
pattern average theta & phi
MuonVal::MatrixBranch< unsigned char > & m_gen_nNonPrecMeas
Number of trigger eta measurements per station.
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_spKey
TruthParticleMap fillTruthMap(const xAOD::MuonSegmentContainer *truthSegments, const TrigRoiDescriptorCollection *roiCollection) const
Fill the truth particle map.
MuonVal::VectorBranch< float > & m_roi_ZMin
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.
void getSectors(double phi, std::vector< int > §ors) const
returns the main sector plus neighboring if the phi position is in an overlap region
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
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
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
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::unordered_set< const xAOD::MuonSimHit * > simHitSet
bool isInPattern(const SpacePoint *sp, const StIndex station, const GlobalPattern &pattern)
std::map< const xAOD::TruthParticle *, std::vector< simHitSet > > TruthParticleMap
constexpr std::size_t s_nStations
std::optional< std::size_t > isTruthMatched(const xAOD::MuonMeasurement &meas, const TruthParticleMap &truthHits)
StIndex
enum to classify the different station layers in the muon spectrometer
const std::string & stName(StIndex index)
convert StIndex into a string
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".
MuonMeasurement_v1 MuonMeasurement
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Helper for azimuthal angle calculations.