108 {
109 std::unique_ptr<TrackToTruthParticleAssociation>
110 track_association( std::make_unique<TrackToTruthParticleAssociation>() );
111
113 if (!pixelClustersToTruthAssociation.
isValid()) {
115 return StatusCode::FAILURE;
116 }
118 if (!stripClustersToTruthAssociation.
isValid()) {
120 return StatusCode::FAILURE;
121 }
122
124 if (!tracksContainer.
isValid()) {
126 return StatusCode::FAILURE;
127 }
128 track_association->resize( tracksContainer->size() );
129 track_association->setSourceContainer(DataLink<ActsTrk::TrackContainer>(*tracksContainer,ctx));
131
132 std::array<const ActsTrk::MeasurementToTruthParticleAssociation *,
134 measurement_to_truth_association_maps{};
135
138
141 if (!hgtdClustersToTruthAssociation.
isValid()) {
143 }
145 }
146
148 const ActsTrk::MeasurementToTruthParticleAssociation *assoc = measurement_to_truth_association_maps[Acts::toUnderlying(type)];
149 return assoc ? assoc->size() : 0
ul;
150 };
151
155 );
156 unsigned int track_i=0;
157 std::array<unsigned int,s_NCounterForAssociatedTruth> tracks_with_associated_truth{};
158 std::pair<unsigned int, unsigned int> compatible_assoc_container_counts{};
160
162 ++compatible_assoc_container_counts.second;
163 }
164
165 std::vector<unsigned int> counted_truth_particles;
166 counted_truth_particles.reserve(10);
167
168 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
169 const auto lastMeasurementIndex =
track.tipIndex();
170
171 unsigned int n_measurements=0
u;
172
173 HitCounterArray &reco_hits = track_association->at(track_i).totalCounts();
174 HitCounterArray &noise_hits = track_association->at(track_i).noiseCounts();
176 tracksContainer->trackStateContainer().visitBackwards(
177 lastMeasurementIndex,
178 [this,
179 &n_measurements,
180 &measurement_to_truth_association_maps,
181 &truth_particle_counts,
182 &reco_hits,
183 &noise_hits,
184 &counted_truth_particles,
185 &compatible_assoc_container_counts
186 ](const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
187 {
188 if (!state.typeFlags().isOutlier() && state.hasUncalibratedSourceLink()) {
190
191 const ActsTrk::MeasurementToTruthParticleAssociation *association_map = measurement_to_truth_association_maps.at(Acts::toUnderlying(uncalibMeas->type()));
192 if (association_map) {
194 if (compatible_assoc_container_counts.second==0) {
195 ATH_MSG_ERROR(
"MeasurementToTruthParticleAssociation for measurement type " << uncalibMeas->type()
196 << " is not compatible with the measurement on track.");
197 }
198 ++compatible_assoc_container_counts.second;
199 return;
200 }
201 else {
202 ++compatible_assoc_container_counts.first;
203 }
204 ++n_measurements;
205 counted_truth_particles.clear();
206 for (
const xAOD::TruthParticle *truth_particle : association_map->at(uncalibMeas->index()) ) {
208
209
210 if (std::find(counted_truth_particles.begin(), counted_truth_particles.end(), mother_particle->index())
211 ==counted_truth_particles.end()) {
212 counted_truth_particles.push_back(mother_particle->index());
213
214 ActsTrk::HitCountsPerTrack::container::iterator
215 hit_count_iter = std::find_if(truth_particle_counts.begin(),
216 truth_particle_counts.end(),
217 [mother_particle](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a) {
218 return a.first == mother_particle;
219 });
220 if (hit_count_iter == truth_particle_counts.end()) {
221 truth_particle_counts.push_back( std::make_pair(mother_particle, HitCounterArray{}));
222 hit_count_iter = truth_particle_counts.end()-1;
223 }
224 ++(hit_count_iter->second.at( Acts::toUnderlying(uncalibMeas->type())));
225 }
226 }
227 if (association_map->at(uncalibMeas->index()).empty()) {
228 ++noise_hits.at( Acts::toUnderlying(uncalibMeas->type()));
229 }
230 }
231 ++reco_hits.at( Acts::toUnderlying(uncalibMeas->type()));
232 }
233
234 });
235 std::sort( truth_particle_counts.begin(),
236 truth_particle_counts.end(),
237 [](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a,
238 const std::pair<const xAOD::TruthParticle *, HitCounterArray > &b) {
239 return std::accumulate(a.second.begin(),a.second.end(),0u) > std::accumulate(b.second.begin(),b.second.end(),0u);
240 });
242 ++(tracks_with_associated_truth[std::min(truth_particle_counts.size(),tracks_with_associated_truth.size()-1u)]);
243 ++track_i;
244 }
246 for (unsigned int elm : tracks_with_associated_truth) {
247 m_nTracksWithAssociatedTruth[
idx] += elm;
249 }
252
253 SG::WriteHandle<TrackToTruthParticleAssociation> associationOutHandle(
m_trackToTruthOut, ctx);
254 if (associationOutHandle.record( std::move(track_association)).isFailure()) {
256 return StatusCode::FAILURE;
257 }
258 return StatusCode::SUCCESS;
259 }
boost::container::small_vector< std::pair< const xAOD::TruthParticle *, HitCounterArray >, NTruthParticlesPerTrack > container
bool isCompatibleWith(const xAOD::UncalibratedMeasurementContainer *container) const
Gaudi::Property< float > m_maxEnergyLoss
std::atomic< std::size_t > m_nCcompatibleMeasurementContainer
AssociationCounter< TrackToTruthParticleAssociationDebugHists > m_associationCounter
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
SG::WriteHandleKey< TrackToTruthParticleAssociation > m_trackToTruthOut
std::atomic< std::size_t > m_nIncompatibleMeasurementContainer
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksContainerKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_hgtdClustersToTruth
ElasticDecayUtil< TrackToTruthParticleAssociationDebugHists > m_elasticDecayUtil
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_pixelClustersToTruth
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_stripClustersToTruth
static const xAOD::UncalibratedMeasurement * unpack(const Acts::SourceLink &sl)
Helper method to unpack an Acts source link to an uncalibrated measurement.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ u
Enums for curvilinear frames.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TruthParticle_v1 TruthParticle
Typedef to implementation.
UncalibMeasType
Define the type of the uncalibrated measurement.
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.