8 #include <unordered_map>
14 {
return static_cast< std::underlying_type_t<T>
>(
val); }
18 ISvcLocator* pSvcLocator)
31 ATH_MSG_ERROR(
"Inconsistent sizes of Clusters and TruthAssociationMaps");
32 return StatusCode::FAILURE;
35 for (
const auto& trackKey :
m_tracks) {
36 std::string containerName = trackKey.key();
37 m_onTrack_clusterStat.push_back( std::make_pair(containerName,
cluster_stat_t()) );
38 m_trackStat.push_back( std::make_pair(containerName,
track_stat_t()) );
41 return StatusCode::SUCCESS;
47 ATH_MSG_INFO(
"Statistics from Seed check with truth info:" );
49 if ( printStatTables<ActsInspectTruthContentAlg::EStatClusters, xAOD::UncalibMeasType>(
"Clusters", m_clusterStat).isFailure() ) {
51 return StatusCode::FAILURE;
54 if ( printStatTables<ActsInspectTruthContentAlg::EStatSeeds, ActsInspectTruthContentAlg::SeedType>(
"Seeds", m_seedStat).isFailure() ) {
56 return StatusCode::FAILURE;
59 for (
const auto& [trackCollectionName, onTrackStat] : m_onTrack_clusterStat) {
60 std::string reportName =
"On Track Clusters (" + trackCollectionName +
")";
61 if ( printStatTables<ActsInspectTruthContentAlg::EStatClusters, xAOD::UncalibMeasType>(reportName, onTrackStat).isFailure() ) {
62 ATH_MSG_FATAL(
"Problem dumping On Track Cluster truth info (" << trackCollectionName <<
")");
63 return StatusCode::FAILURE;
67 for (
const auto& [trackCollectionName, trackStat] : m_trackStat) {
68 std::string reportName =
"Track (" + trackCollectionName +
")";
69 if ( printStatTables<ActsInspectTruthContentAlg::EStatTracks, ActsInspectTruthContentAlg::TrackType>(reportName, trackStat).isFailure() ) {
70 ATH_MSG_FATAL(
"Problem dumping Track truth info (" << trackCollectionName <<
")");
71 return StatusCode::FAILURE;
75 return StatusCode::SUCCESS;
86 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes> truths {};
100 truths[
static_cast<std::size_t
>(elementType)] = truthHandle.
cptr();
103 ATH_CHECK( truths[
static_cast<std::size_t
>(elementType)]->isCompatibleWith(
clusters) );
106 *truths[
static_cast<std::size_t
>(elementType)],
112 for (std::size_t
i(0);
i<
m_seeds.size(); ++
i) {
136 onTrack_clusterStat) );
142 return StatusCode::SUCCESS;
152 std::size_t clusterTypeIndex =
static_cast<std::size_t
>(meas->type());
154 const auto& tps = truth.at(meas->index());
163 bool allValidParticles =
true;
164 for (
const auto*
tp : tps) {
166 allValidParticles =
false;
170 if (tps.size() == 1) {
174 else if (tps.size() == 2) {
184 bool hasContributionFromPrimaryParticle =
false;
185 for (
const auto*
tp : tps) {
187 hasContributionFromPrimaryParticle =
true;
195 return StatusCode::SUCCESS;
200 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes>& truths,
204 for (std::size_t
i(0);
i<seeds.
size(); ++
i) {
208 int nMeasurements = 0;
209 std::unordered_map<std::size_t, int> particleIds {};
214 const auto& sps = seed->sp();
216 const auto& measurements = sp->measurements();
222 auto tps = truth->at(meas->index());
224 if (tps.empty())
continue;
226 bool contributionOnlyFromSimulationParticles =
true;
227 for (
const auto*
tp : tps) {
229 contributionOnlyFromSimulationParticles =
false;
232 particleIds.try_emplace(
pid, 0 );
235 if (contributionOnlyFromSimulationParticles)
continue;
244 bool isFromSameParticle =
false;
246 if (
nEntries != nMeasurements)
continue;
247 isFromSameParticle =
true;
254 }
else if (nMatches == 1) {
256 }
else if (nMatches == 2) {
259 }
else if (nMatches == 3) {
262 }
else if (nMatches == 4) {
265 }
else if (nMatches == 5) {
268 }
else if (nMatches == 6) {
274 return StatusCode::SUCCESS;
278 const auto& [bottom, middle,
top] = seed.sp();
306 std::array<const ActsTrk::MeasurementToTruthParticleAssociation*, s_nClusterTypes>& truths,
310 for (
const auto& track : tracks) {
312 std::size_t nHoles = track.nHoles();
318 std::size_t nOutliers = track.nOutliers();
325 bool AllValids =
true;
326 int nConsideredMeasurements = 0;
327 std::unordered_map<std::size_t, int> particleIds {};
331 .trackStateContainer().visitBackwards(track.tipIndex(),
332 [&truths, &onTrackStat,
334 &nConsideredMeasurements, &particleIds]
335 (
const auto& state) {
336 auto flags = state.typeFlags();
337 if (not flags.test(Acts::TrackStateFlag::MeasurementFlag) and
338 not flags.test(Acts::TrackStateFlag::OutlierFlag)) return;
339 ++nConsideredMeasurements;
342 auto sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
343 assert( sl != nullptr);
344 const xAOD::UncalibratedMeasurement &meas = getUncalibratedMeasurement(sl);
346 std::size_t clusterTypeIndex = to_underlying(meas.type());
347 ++onTrackStat[to_underlying(EStatClusters::kNTotal)][clusterTypeIndex];
349 const ActsTrk::MeasurementToTruthParticleAssociation* truth = truths[clusterTypeIndex];
350 const auto& tps = truth->at(meas.index());
353 ++onTrackStat[to_underlying(EStatClusters::kNClustersWithNoBarcode)][clusterTypeIndex];
358 bool allBarcodesValid =
true;
359 bool hasContributionFromPrimaryParticle =
false;
360 for (
const auto*
tp : tps) {
362 hasContributionFromPrimaryParticle =
true;
365 allBarcodesValid =
false;
368 if (not hasContributionFromPrimaryParticle) AllValids =
false;
370 if (tps.size() == 1) {
371 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith1Contribution)][clusterTypeIndex];
372 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith1ValidContribution)][clusterTypeIndex];
374 else if (tps.size() == 2) {
375 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith2Contribution)][clusterTypeIndex];
376 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith2ValidContribution)][clusterTypeIndex];
379 ++onTrackStat[to_underlying(EStatClusters::kNClustersWith3Contribution)][clusterTypeIndex];
380 if (allBarcodesValid) ++onTrackStat[to_underlying(EStatClusters::kNClustersWith3ValidContribution)][clusterTypeIndex];
383 bool contributionOnlyFromSimulationParticles =
true;
384 for (
const auto*
tp : tps) {
386 contributionOnlyFromSimulationParticles =
false;
389 particleIds.try_emplace(
pid, 0 );
398 bool AllSameBarcode =
false;
400 if (
nEntries != nConsideredMeasurements)
continue;
401 AllSameBarcode =
true;
409 return StatusCode::SUCCESS;