112 {
113 std::unique_ptr<TrackToTruthParticleAssociation>
114 track_association( std::make_unique<TrackToTruthParticleAssociation>() );
115
117 if (!pixelClustersToTruthAssociation.
isValid()) {
119 return StatusCode::FAILURE;
120 }
122 if (!stripClustersToTruthAssociation.
isValid()) {
124 return StatusCode::FAILURE;
125 }
126
128 if (!tracksContainer.
isValid()) {
130 return StatusCode::FAILURE;
131 }
132 track_association->resize( tracksContainer->size() );
133 track_association->setSourceContainer(DataLink<ActsTrk::TrackContainer>(*tracksContainer,ctx));
135
136 std::array<const ActsTrk::MeasurementToTruthParticleAssociation *,
138 measurement_to_truth_association_maps{};
139
142
145 if (!hgtdClustersToTruthAssociation.
isValid()) {
147 }
149 }
150
152 const ActsTrk::MeasurementToTruthParticleAssociation *assoc = measurement_to_truth_association_maps[
to_underlying(type)];
153 return assoc ? assoc->size() : 0
ul;
154 };
155
159 );
160 unsigned int track_i=0;
161 std::array<unsigned int,s_NCounterForAssociatedTruth> tracks_with_associated_truth{};
162 std::pair<unsigned int, unsigned int> compatible_assoc_container_counts{};
164
166 ++compatible_assoc_container_counts.second;
167 }
168
169 std::vector<unsigned int> counted_truth_particles;
170 counted_truth_particles.reserve(10);
171
172 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
173 const auto lastMeasurementIndex =
track.tipIndex();
174
175 unsigned int n_measurements=0
u;
176
177 HitCounterArray &reco_hits = track_association->at(track_i).totalCounts();
178 HitCounterArray &noise_hits = track_association->at(track_i).noiseCounts();
180 tracksContainer->trackStateContainer().visitBackwards(
181 lastMeasurementIndex,
182 [this,
183 &n_measurements,
184 &measurement_to_truth_association_maps,
185 &truth_particle_counts,
186 &reco_hits,
187 &noise_hits,
188 &counted_truth_particles,
189 &compatible_assoc_container_counts
190 ](const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
191 {
192 if (!state.typeFlags().test(Acts::TrackStateFlag::OutlierFlag) && state.hasUncalibratedSourceLink()) {
194 assert( sl != nullptr );
196
197 const ActsTrk::MeasurementToTruthParticleAssociation *association_map = measurement_to_truth_association_maps.at(
to_underlying(uncalibMeas.
type()));
198 if (association_map) {
200 if (compatible_assoc_container_counts.second==0) {
202 << " is not compatible with the measurement on track.");
203 }
204 ++compatible_assoc_container_counts.second;
205 return;
206 }
207 else {
208 ++compatible_assoc_container_counts.first;
209 }
210 ++n_measurements;
211 counted_truth_particles.clear();
214
215
216 if (std::find(counted_truth_particles.begin(), counted_truth_particles.end(), mother_particle->
index())
217 ==counted_truth_particles.end()) {
218 counted_truth_particles.push_back(mother_particle->
index());
219
220 ActsTrk::HitCountsPerTrack::container::iterator
221 hit_count_iter = std::find_if(truth_particle_counts.begin(),
222 truth_particle_counts.end(),
223 [mother_particle](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a) {
224 return a.first == mother_particle;
225 });
226 if (hit_count_iter == truth_particle_counts.end()) {
227 truth_particle_counts.push_back( std::make_pair(mother_particle, HitCounterArray{}));
228 hit_count_iter = truth_particle_counts.end()-1;
229 }
231 }
232 }
233 if (association_map->at(uncalibMeas.
index()).empty()) {
235 }
236 }
238 }
239
240 });
241 std::sort( truth_particle_counts.begin(),
242 truth_particle_counts.end(),
243 [](
const std::pair<const xAOD::TruthParticle *, HitCounterArray > &
a,
244 const std::pair<const xAOD::TruthParticle *, HitCounterArray > &b) {
245 return std::accumulate(a.second.begin(),a.second.end(),0u) > std::accumulate(b.second.begin(),b.second.end(),0u);
246 });
248 ++(tracks_with_associated_truth[std::min(truth_particle_counts.size(),tracks_with_associated_truth.size()-1u)]);
249 ++track_i;
250 }
252 for (unsigned int elm : tracks_with_associated_truth) {
253 m_nTracksWithAssociatedTruth[
idx] += elm;
255 }
258
259 SG::WriteHandle<TrackToTruthParticleAssociation> associationOutHandle(
m_trackToTruthOut, ctx);
260 if (associationOutHandle.record( std::move(track_association)).isFailure()) {
262 return StatusCode::FAILURE;
263 }
264 return StatusCode::SUCCESS;
265 }
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
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
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)
std::underlying_type_t< T > to_underlying(T val)
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.