101 {
102 auto track_association = std::make_unique<TrackToTruthParticleAssociation>();
103
104 const ActsTrk::TrackContainer* tracksContainer{};
106
107 track_association->resize( tracksContainer->size() );
108 track_association->setSourceContainer(DataLink<ActsTrk::TrackContainer>(*tracksContainer,ctx));
109 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
110
111 std::array<std::vector<const ActsTrk::MeasurementToTruthParticleAssociation*>,
113
115 const MeasurementToTruthParticleAssociation* measAssocMap{};
117 if (measAssocMap->sourceContainer()->empty()) {
118 continue;
119 }
121 prdToTruthMaps[Acts::toUnderlying(measType)].push_back(measAssocMap);
122 }
123 std::array<unsigned int,s_NCounterForAssociatedTruth> tracks_with_associated_truth{};
124 std::pair<unsigned int, unsigned int> compatible_assoc_container_counts{};
126
128 ++compatible_assoc_container_counts.second;
129 }
130
131 std::vector<unsigned int> counted_truth_particles;
132 counted_truth_particles.reserve(10);
133
134 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
135 const unsigned track_i =
track.index();
136 unsigned int n_measurements=0
u;
137
138 HitCounterArray &reco_hits = track_association->at(track_i).totalCounts();
139 HitCounterArray &noise_hits = track_association->at(track_i).noiseCounts();
141 for (
const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state :
track.trackStatesReversed()) {
142 if (state.typeFlags().isOutlier() || !state.hasUncalibratedSourceLink()) {
143 continue;
144 }
146 const auto typeIdx = Acts::toUnderlying(uncalibMeas->type());
147
148 ++n_measurements;
149
150 const ActsTrk::MeasurementToTruthParticleAssociation* association_map{};
151 if (auto map_itr = std::ranges::find_if(prdToTruthMaps.at(typeIdx),
152 [uncalibMeas](const auto* map){
153 return uncalibMeas->container() == map->sourceContainer();
154 }); map_itr != prdToTruthMaps.at(typeIdx).end()) {
155 association_map = (*map_itr);
156 } else {
157 continue;
158 }
159 ++compatible_assoc_container_counts.second;
161 if (association_map->at(uncalibMeas->index()).empty()) {
162 ++noise_hits.at(typeIdx);
163 }
164 counted_truth_particles.clear();
166 for (
const xAOD::TruthParticle *truth_particle : association_map->at(uncalibMeas->index()) ) {
168 ATH_MSG_VERBOSE(
"Fill truth counts for "<<uncalibMeas->type()<<
" hit with particle "<<(mother_particle->
pt()*1.e-3)<<
" [GeV], eta:"
169 <<mother_particle->
eta()<<
", " <<
", phi: "<<mother_particle->
phi()<<
", pdgId: "<<mother_particle->
pdgId()<<
", index: "<<mother_particle->index()
170 <<", "<<mother_particle->container());
171
172 if (!Acts::rangeContainsValue(counted_truth_particles, mother_particle->index())) {
173 counted_truth_particles.push_back(mother_particle->index());
174
175 ActsTrk::HitCountsPerTrack::container::iterator
176 hit_count_iter = std::ranges::find_if(truth_particle_counts,
177 [mother_particle](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a) {
178 return a.first == mother_particle;
179 });
180 if (hit_count_iter == truth_particle_counts.end()) {
181 truth_particle_counts.push_back( std::make_pair(mother_particle,
HitCounterArray{}));
182 hit_count_iter = truth_particle_counts.end()-1;
183 }
184 ++(hit_count_iter->second.at(typeIdx));
185 }
186 }
187 ++reco_hits.at(typeIdx);
188 }
189 std::ranges::stable_sort(truth_particle_counts,
190 [](
const std::pair<const xAOD::TruthParticle*, HitCounterArray>&
a,
191 const std::pair<const xAOD::TruthParticle*, HitCounterArray>& b) {
192 return std::accumulate(
a.second.begin(),
a.second.end(),0u) >
193 std::accumulate(
b.second.begin(),
b.second.end(),0u);
194 });
196 ++(tracks_with_associated_truth[std::min(truth_particle_counts.size(),
197 tracks_with_associated_truth.size()-1u)]);
198 }
199 for (const auto[idx, elem] : Acts::enumerate(tracks_with_associated_truth)) {
200 m_nTracksWithAssociatedTruth[
idx] +=
elem;
201
202 }
205
208 return StatusCode::SUCCESS;
209 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x,...)
boost::container::small_vector< std::pair< const xAOD::TruthParticle *, HitCounterArray >, NTruthParticlesPerTrack > container
Gaudi::Property< float > m_maxEnergyLoss
std::atomic< std::size_t > m_nCcompatibleMeasurementContainer
AssociationCounter< TrackToTruthParticleAssociationDebugHists > m_associationCounter
SG::WriteHandleKey< TrackToTruthParticleAssociation > m_trackToTruthOut
std::atomic< std::size_t > m_nIncompatibleMeasurementContainer
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksContainerKey
ContextUtility m_ctxProvider
Context provider for geometry, magnetic field and calibration contexts.
SG::ReadHandleKeyArray< MeasurementToTruthParticleAssociation > m_measAssocKeys
ElasticDecayUtil< TrackToTruthParticleAssociationDebugHists > m_elasticDecayUtil
static const xAOD::UncalibratedMeasurement * unpack(const Acts::SourceLink &sl)
Helper method to unpack an Acts source link to an uncalibrated measurement.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
int pdgId() const
PDG ID code.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
std::array< uint8_t, NHitCounter > HitCounterArray
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
@ u
Enums for curvilinear frames.
TruthParticle_v1 TruthParticle
Typedef to implementation.
UncalibMeasType
Define the type of the uncalibrated measurement.