102 auto track_association = std::make_unique<TrackToTruthParticleAssociation>();
107 track_association->resize( tracksContainer->size() );
109 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
111 std::array<std::vector<const ActsTrk::MeasurementToTruthParticleAssociation*>,
121 prdToTruthMaps[Acts::toUnderlying(measType)].push_back(measAssocMap);
123 std::array<unsigned int,s_NCounterForAssociatedTruth> tracks_with_associated_truth{};
124 std::pair<unsigned int, unsigned int> compatible_assoc_container_counts{};
128 ++compatible_assoc_container_counts.second;
131 std::vector<unsigned int> counted_truth_particles;
132 counted_truth_particles.reserve(10);
134 for (
const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
135 const unsigned track_i = track.index();
136 unsigned int n_measurements=0u;
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()) {
146 const auto typeIdx = Acts::toUnderlying(uncalibMeas->type());
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);
159 ++compatible_assoc_container_counts.second;
161 if (association_map->at(uncalibMeas->index()).empty()) {
162 ++noise_hits.at(typeIdx);
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());
172 if (!Acts::rangeContainsValue(counted_truth_particles, mother_particle->index())) {
173 counted_truth_particles.push_back(mother_particle->index());
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;
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;
184 ++(hit_count_iter->second.at(typeIdx));
187 ++reco_hits.at(typeIdx);
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);
196 ++(tracks_with_associated_truth[std::min(truth_particle_counts.size(),
197 tracks_with_associated_truth.size()-1u)]);
199 for (
const auto[idx, elem] : Acts::enumerate(tracks_with_associated_truth)) {
200 m_nTracksWithAssociatedTruth[idx] += elem;
208 return StatusCode::SUCCESS;