8 #include <unordered_map>
15 {
return static_cast< std::underlying_type_t<T>
>(
val); }
19 ISvcLocator* pSvcLocator)
32 ATH_MSG_ERROR(
"Inconsistent sizes of Clusters and TruthAssociationMaps");
33 return StatusCode::FAILURE;
36 for (
const auto& trackKey :
m_tracks) {
37 std::string containerName = trackKey.key();
38 m_onTrack_clusterStat.push_back( std::make_pair(containerName,
cluster_stat_t()) );
39 m_trackStat.push_back( std::make_pair(containerName,
track_stat_t()) );
42 return StatusCode::SUCCESS;
48 ATH_MSG_INFO(
"Statistics from Seed check with truth info:" );
50 if ( printStatTables<ActsInspectTruthContentAlg::EStatClusters, xAOD::UncalibMeasType>(
"Clusters", m_clusterStat).isFailure() ) {
52 return StatusCode::FAILURE;
55 if ( printStatTables<ActsInspectTruthContentAlg::EStatSeeds, ActsInspectTruthContentAlg::SeedType>(
"Seeds", m_seedStat).isFailure() ) {
57 return StatusCode::FAILURE;
60 for (
const auto& [trackCollectionName, onTrackStat] : m_onTrack_clusterStat) {
61 std::string reportName =
"On Track Clusters (" + trackCollectionName +
")";
62 if ( printStatTables<ActsInspectTruthContentAlg::EStatClusters, xAOD::UncalibMeasType>(reportName, onTrackStat).isFailure() ) {
63 ATH_MSG_FATAL(
"Problem dumping On Track Cluster truth info (" << trackCollectionName <<
")");
64 return StatusCode::FAILURE;
68 for (
const auto& [trackCollectionName, trackStat] : m_trackStat) {
69 std::string reportName =
"Track (" + trackCollectionName +
")";
70 if ( printStatTables<ActsInspectTruthContentAlg::EStatTracks, ActsInspectTruthContentAlg::TrackType>(reportName, trackStat).isFailure() ) {
71 ATH_MSG_FATAL(
"Problem dumping Track truth info (" << trackCollectionName <<
")");
72 return StatusCode::FAILURE;
76 return StatusCode::SUCCESS;
87 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes> truths {};
101 truths[
static_cast<std::size_t
>(elementType)] = truthHandle.
cptr();
104 ATH_CHECK( truths[
static_cast<std::size_t
>(elementType)]->isCompatibleWith(
clusters) );
107 *truths[
static_cast<std::size_t
>(elementType)],
113 for (std::size_t
i(0);
i<
m_seeds.size(); ++
i) {
137 onTrack_clusterStat) );
143 return StatusCode::SUCCESS;
153 std::size_t clusterTypeIndex =
static_cast<std::size_t
>(meas->type());
155 const auto& tps = truth.at(meas->index());
164 bool allValidParticles =
true;
165 for (
const auto*
tp : tps) {
167 allValidParticles =
false;
171 if (tps.size() == 1) {
175 else if (tps.size() == 2) {
185 bool hasContributionFromPrimaryParticle =
false;
186 for (
const auto*
tp : tps) {
188 hasContributionFromPrimaryParticle =
true;
196 return StatusCode::SUCCESS;
201 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes>& truths,
205 for (std::size_t
i(0);
i<seeds.
size(); ++
i) {
209 int nMeasurements = 0;
210 std::unordered_map<std::size_t, int> particleIds {};
215 const auto& sps = seed->sp();
217 const auto& measurements = sp->measurements();
223 auto tps = truth->at(meas->index());
225 if (tps.empty())
continue;
227 bool contributionOnlyFromSimulationParticles =
true;
228 for (
const auto*
tp : tps) {
230 contributionOnlyFromSimulationParticles =
false;
233 particleIds.try_emplace(
pid, 0 );
236 if (contributionOnlyFromSimulationParticles)
continue;
245 bool isFromSameParticle =
false;
247 if (
nEntries != nMeasurements)
continue;
248 isFromSameParticle =
true;
255 }
else if (nMatches == 1) {
257 }
else if (nMatches == 2) {
260 }
else if (nMatches == 3) {
263 }
else if (nMatches == 4) {
266 }
else if (nMatches == 5) {
269 }
else if (nMatches == 6) {
275 return StatusCode::SUCCESS;
279 assert(seed.sp().size() == 3
ul);
280 const auto& bottom = seed.sp().at(0);
281 const auto& middle = seed.sp().at(1);
282 const auto&
top = seed.sp().at(2);
310 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes>& truths,
314 for (
const auto track : tracks) {
316 std::size_t nHoles =
track.nHoles();
322 std::size_t nOutliers =
track.nOutliers();
329 bool AllValids =
true;
330 int nConsideredMeasurements = 0;
331 std::unordered_map<std::size_t, int> particleIds {};
335 .trackStateContainer().visitBackwards(
track.tipIndex(),
336 [&truths, &onTrackStat,
338 &nConsideredMeasurements, &particleIds]
339 (
const auto& state) {
340 auto flags = state.typeFlags();
341 if (not flags.test(Acts::TrackStateFlag::MeasurementFlag) and
342 not flags.test(Acts::TrackStateFlag::OutlierFlag)) return;
343 ++nConsideredMeasurements;
346 auto sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
347 assert( sl != nullptr);
348 const xAOD::UncalibratedMeasurement &meas = getUncalibratedMeasurement(sl);
350 std::size_t clusterTypeIndex = to_underlying(meas.type());
351 ++onTrackStat[to_underlying(EStatClusters::kNTotal)][clusterTypeIndex];
353 const ActsTrk::MeasurementToTruthParticleAssociation* truth = truths[clusterTypeIndex];
354 const auto& tps = truth->at(meas.index());
357 ++onTrackStat[to_underlying(EStatClusters::kNClustersWithNoBarcode)][clusterTypeIndex];
362 bool allBarcodesValid =
true;
363 bool hasContributionFromPrimaryParticle =
false;
364 for (
const auto*
tp : tps) {
366 hasContributionFromPrimaryParticle =
true;
369 allBarcodesValid =
false;
372 if (not hasContributionFromPrimaryParticle) AllValids =
false;
374 if (tps.size() == 1) {
375 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith1Contribution)][clusterTypeIndex];
376 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith1ValidContribution)][clusterTypeIndex];
378 else if (tps.size() == 2) {
379 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith2Contribution)][clusterTypeIndex];
380 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith2ValidContribution)][clusterTypeIndex];
383 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith3Contribution)][clusterTypeIndex];
384 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith3ValidContribution)][clusterTypeIndex];
387 bool contributionOnlyFromSimulationParticles =
true;
388 for (
const auto*
tp : tps) {
390 contributionOnlyFromSimulationParticles =
false;
393 particleIds.try_emplace(
pid, 0 );
402 bool AllSameBarcode =
false;
404 if (
nEntries != nConsideredMeasurements)
continue;
405 AllSameBarcode =
true;
413 return StatusCode::SUCCESS;