107 {
108 std::unique_ptr<TrackToTruthParticleAssociation>
109 track_association( std::make_unique<TrackToTruthParticleAssociation>() );
110
112 if (!pixelClustersToTruthAssociation.
isValid()) {
114 return StatusCode::FAILURE;
115 }
117 if (!stripClustersToTruthAssociation.
isValid()) {
119 return StatusCode::FAILURE;
120 }
121
123 if (!tracksContainer.
isValid()) {
125 return StatusCode::FAILURE;
126 }
127 track_association->resize( tracksContainer->size() );
128 track_association->setSourceContainer(DataLink<ActsTrk::TrackContainer>(*tracksContainer,ctx));
130
131 std::array<const ActsTrk::MeasurementToTruthParticleAssociation *,
133 measurement_to_truth_association_maps{};
134
137
140 if (!hgtdClustersToTruthAssociation.
isValid()) {
142 }
144 }
145
147 const ActsTrk::MeasurementToTruthParticleAssociation *assoc = measurement_to_truth_association_maps[Acts::toUnderlying(type)];
148 return assoc ? assoc->size() : 0
ul;
149 };
150
154 );
155 unsigned int track_i=0;
156 std::array<unsigned int,s_NCounterForAssociatedTruth> tracks_with_associated_truth{};
157 std::pair<unsigned int, unsigned int> compatible_assoc_container_counts{};
159
161 ++compatible_assoc_container_counts.second;
162 }
163
164 std::vector<unsigned int> counted_truth_particles;
165 counted_truth_particles.reserve(10);
166
167 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
168 const auto lastMeasurementIndex =
track.tipIndex();
169
170 unsigned int n_measurements=0
u;
171
172 HitCounterArray &reco_hits = track_association->at(track_i).totalCounts();
173 HitCounterArray &noise_hits = track_association->at(track_i).noiseCounts();
175 tracksContainer->trackStateContainer().visitBackwards(
176 lastMeasurementIndex,
177 [this,
178 &n_measurements,
179 &measurement_to_truth_association_maps,
180 &truth_particle_counts,
181 &reco_hits,
182 &noise_hits,
183 &counted_truth_particles,
184 &compatible_assoc_container_counts
185 ](const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
186 {
187 if (!state.typeFlags().isOutlier() && state.hasUncalibratedSourceLink()) {
189 assert( sl != nullptr );
191
192 const ActsTrk::MeasurementToTruthParticleAssociation *association_map = measurement_to_truth_association_maps.at(Acts::toUnderlying(uncalibMeas.
type()));
193 if (association_map) {
195 if (compatible_assoc_container_counts.second==0) {
196 ATH_MSG_ERROR(
"MeasurementToTruthParticleAssociation for measurement type " << Acts::toUnderlying(uncalibMeas.
type())
197 << " is not compatible with the measurement on track.");
198 }
199 ++compatible_assoc_container_counts.second;
200 return;
201 }
202 else {
203 ++compatible_assoc_container_counts.first;
204 }
205 ++n_measurements;
206 counted_truth_particles.clear();
207 for (
const xAOD::TruthParticle *truth_particle : association_map->at(uncalibMeas.index()) ) {
209
210
211 if (std::find(counted_truth_particles.begin(), counted_truth_particles.end(), mother_particle->index())
212 ==counted_truth_particles.end()) {
213 counted_truth_particles.push_back(mother_particle->index());
214
215 ActsTrk::HitCountsPerTrack::container::iterator
216 hit_count_iter = std::find_if(truth_particle_counts.begin(),
217 truth_particle_counts.end(),
218 [mother_particle](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a) {
219 return a.first == mother_particle;
220 });
221 if (hit_count_iter == truth_particle_counts.end()) {
222 truth_particle_counts.push_back( std::make_pair(mother_particle, HitCounterArray{}));
223 hit_count_iter = truth_particle_counts.end()-1;
224 }
225 ++(hit_count_iter->second.at( Acts::toUnderlying(uncalibMeas.
type())));
226 }
227 }
228 if (association_map->at(uncalibMeas.index()).empty()) {
229 ++noise_hits.at( Acts::toUnderlying(uncalibMeas.
type()));
230 }
231 }
232 ++reco_hits.at( Acts::toUnderlying(uncalibMeas.
type()));
233 }
234
235 });
236 std::sort( truth_particle_counts.begin(),
237 truth_particle_counts.end(),
238 [](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a,
239 const std::pair<const xAOD::TruthParticle *, HitCounterArray > &b) {
240 return std::accumulate(a.second.begin(),a.second.end(),0u) > std::accumulate(b.second.begin(),b.second.end(),0u);
241 });
243 ++(tracks_with_associated_truth[std::min(truth_particle_counts.size(),tracks_with_associated_truth.size()-1u)]);
244 ++track_i;
245 }
247 for (unsigned int elm : tracks_with_associated_truth) {
248 m_nTracksWithAssociatedTruth[
idx] += elm;
250 }
253
254 SG::WriteHandle<TrackToTruthParticleAssociation> associationOutHandle(
m_trackToTruthOut, ctx);
255 if (associationOutHandle.record( std::move(track_association)).isFailure()) {
257 return StatusCode::FAILURE;
258 }
259 return StatusCode::SUCCESS;
260 }
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
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
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.
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.