LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PfoValidationAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
15 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 PfoValidationAlgorithm::PfoValidationAlgorithm() :
24  m_nMatchesToShow(3)
25 {
26 }
27 
28 //------------------------------------------------------------------------------------------------------------------------------------------
29 
31 {
32  const MCParticleList *pMCParticleList = nullptr;
33  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pMCParticleList));
34 
35  const CaloHitList *pCaloHitList = nullptr;
36  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_caloHitListName, pCaloHitList));
37 
38  const PfoList *pPfoList = nullptr;
39  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_pfoListName, pPfoList));
40 
41  // Identify reconstructable MCParticles, and get mappings to their good hits
42  LArMCParticleHelper::MCContributionMap nuMCParticlesToGoodHitsMap;
43  LArMCParticleHelper::MCContributionMap beamMCParticlesToGoodHitsMap;
44  LArMCParticleHelper::MCContributionMap crMCParticlesToGoodHitsMap;
45 
47  pMCParticleList, pCaloHitList, m_parameters, LArMCParticleHelper::IsBeamNeutrinoFinalState, nuMCParticlesToGoodHitsMap);
49  pMCParticleList, pCaloHitList, m_parameters, LArMCParticleHelper::IsBeamParticle, beamMCParticlesToGoodHitsMap);
51  pMCParticleList, pCaloHitList, m_parameters, LArMCParticleHelper::IsCosmicRay, crMCParticlesToGoodHitsMap);
52 
53  const LArMCParticleHelper::MCContributionMapVector mcParticlesToGoodHitsMaps{
54  nuMCParticlesToGoodHitsMap, beamMCParticlesToGoodHitsMap, crMCParticlesToGoodHitsMap};
55 
56  // Get the mappings detailing the hits shared between Pfos and reconstructable MCParticles
57  PfoList finalStatePfos;
58 
59  for (const ParticleFlowObject *const pPfo : *pPfoList)
60  {
62  finalStatePfos.push_back(pPfo);
63  }
64 
65  LArMCParticleHelper::PfoContributionMap pfoToReconstructable2DHitsMap;
67  finalStatePfos, mcParticlesToGoodHitsMaps, pfoToReconstructable2DHitsMap, m_parameters.m_foldBackHierarchy);
68 
69  LArMCParticleHelper::PfoToMCParticleHitSharingMap pfoToMCParticleHitSharingMap;
70  LArMCParticleHelper::MCParticleToPfoHitSharingMap mcParticleToPfoHitSharingMap;
72  pfoToReconstructable2DHitsMap, mcParticlesToGoodHitsMaps, pfoToMCParticleHitSharingMap, mcParticleToPfoHitSharingMap);
73 
74  // Print the monte-carlo information for this event
75  MCParticleVector orderedMCParticleVector;
76  LArMonitoringHelper::GetOrderedMCParticleVector(mcParticlesToGoodHitsMaps, orderedMCParticleVector);
77 
78  LArFormattingHelper::PrintHeader("MC : Reconstructable neutrino final state particles");
79  LArMonitoringHelper::PrintMCParticleTable(nuMCParticlesToGoodHitsMap, orderedMCParticleVector);
80 
81  LArFormattingHelper::PrintHeader("MC : Reconstructable primary beam particles");
82  LArMonitoringHelper::PrintMCParticleTable(beamMCParticlesToGoodHitsMap, orderedMCParticleVector);
83 
84  LArFormattingHelper::PrintHeader("MC : Reconstructable primary cosmic-rays");
85  LArMonitoringHelper::PrintMCParticleTable(crMCParticlesToGoodHitsMap, orderedMCParticleVector);
86 
87  // Print the pfo information for this event
88  PfoVector orderedPfoVector;
89  LArMonitoringHelper::GetOrderedPfoVector(pfoToReconstructable2DHitsMap, orderedPfoVector);
90 
91  LArFormattingHelper::PrintHeader("Reco : Primary Pfos");
92  LArMonitoringHelper::PrintPfoTable(pfoToReconstructable2DHitsMap, orderedPfoVector);
93 
94  // Print the raw matching between Pfos and MCParticles
95  LArFormattingHelper::PrintHeader("Raw Reco vs. MC matching");
96  LArMonitoringHelper::PrintMatchingTable(orderedPfoVector, orderedMCParticleVector, mcParticleToPfoHitSharingMap, m_nMatchesToShow);
97 
98  return STATUS_CODE_SUCCESS;
99 }
100 
101 //------------------------------------------------------------------------------------------------------------------------------------------
102 
103 StatusCode PfoValidationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
104 {
105  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "CaloHitListName", m_caloHitListName));
106  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "PfoListName", m_pfoListName));
107 
108  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
109  XmlHelper::ReadValue(xmlHandle, "MinPrimaryGoodHits", m_parameters.m_minPrimaryGoodHits));
110 
111  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
112  XmlHelper::ReadValue(xmlHandle, "MinHitsForGoodView", m_parameters.m_minHitsForGoodView));
113 
114  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
115  XmlHelper::ReadValue(xmlHandle, "MinPrimaryGoodViews", m_parameters.m_minPrimaryGoodViews));
116 
117  PANDORA_RETURN_RESULT_IF_AND_IF(
118  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SelectInputHits", m_parameters.m_selectInputHits));
119 
120  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
121  XmlHelper::ReadValue(xmlHandle, "MaxPhotonPropagation", m_parameters.m_maxPhotonPropagation));
122 
123  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
124  XmlHelper::ReadValue(xmlHandle, "MinHitSharingFraction", m_parameters.m_minHitSharingFraction));
125 
126  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "NumMatchesToShow", m_nMatchesToShow));
127 
128  return STATUS_CODE_SUCCESS;
129 }
130 
131 } // namespace lar_content
unsigned int m_minPrimaryGoodViews
the minimum number of primary good views
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
bool m_selectInputHits
whether to select input hits
static void PrintMCParticleTable(const LArMCParticleHelper::MCContributionMap &selectedMCParticleToGoodHitsMaps, const pandora::MCParticleVector &orderedMCParticleVector)
Print details of selected MCParticles to the terminal in a table.
Header file for the pfo validation algorithm.
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
static void GetPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable M...
static void GetPfoMCParticleHitSharingMaps(const PfoContributionMap &pfoToReconstructable2DHitsMap, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoToMCParticleHitSharingMap &pfoToMCParticleHitSharingMap, MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap)
Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits sha...
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
unsigned int m_nMatchesToShow
The maximum number of MCParticle to Pfo matches to show.
bool m_foldBackHierarchy
whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam) ...
Header file for the lar monitoring helper helper class.
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
float m_maxPhotonPropagation
the maximum photon propagation length
static void GetOrderedMCParticleVector(const LArMCParticleHelper::MCContributionMapVector &selectedMCParticleToGoodHitsMaps, pandora::MCParticleVector &orderedMCParticleVector)
Order input MCParticles by their number of hits.
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select target, reconstructable mc particles that match given criteria.
Header file for the lar monte carlo particle helper helper class.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static void PrintHeader(const std::string &title="", const unsigned int width=140)
Print a header line of a given width.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static void GetOrderedPfoVector(const LArMCParticleHelper::PfoContributionMap &pfoToReconstructable2DHitsMap, pandora::PfoVector &orderedPfoVector)
Order input Pfos by their number of hits.
float m_minHitSharingFraction
the minimum Hit sharing fraction
std::vector< MCContributionMap > MCContributionMapVector
LArMCParticleHelper::PrimaryParameters m_parameters
Parameters used to decide when an MCParticle is reconstructable.
static bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
std::string m_caloHitListName
Name of input calo hit list.
static void PrintMatchingTable(const pandora::PfoVector &orderedPfoVector, const pandora::MCParticleVector &orderedMCParticleVector, const LArMCParticleHelper::MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap, const unsigned int nMatches)
Print the shared good hits between all Pfos and MCParticles.
std::string m_pfoListName
Name of input pfo list.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
static void PrintPfoTable(const LArMCParticleHelper::PfoContributionMap &pfoToReconstructable2DHitsMap, const pandora::PfoVector &orderedPfoVector)
Print details of input Pfos to the terminal in a table.
std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector > PfoToMCParticleHitSharingMap