9 #include "Pandora/AlgorithmHeaders.h"
24 EventValidationBaseAlgorithm::EventValidationBaseAlgorithm() :
27 m_printAllToScreen(
false),
28 m_printMatchingToScreen(
true),
30 m_useSmallPrimaries(
true),
31 m_matchingMinSharedHits(5),
32 m_matchingMinCompleteness(0.1f),
33 m_matchingMinPurity(0.5f)
45 PANDORA_MONITORING_API(SaveTree(this->GetPandora(),
m_treeName.c_str(),
m_fileName.c_str(),
"UPDATE"));
47 catch (
const StatusCodeException &)
60 const MCParticleList *pMCParticleList =
nullptr;
61 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
63 const CaloHitList *pCaloHitList =
nullptr;
64 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
66 const PfoList *pPfoList =
nullptr;
81 return STATUS_CODE_SUCCESS;
93 while (this->
GetStrongestPfoMatch(validationInfo, mcPrimaryVector, usedPfos, interpretedMCToPfoHitSharingMap))
99 for (
const MCParticle *
const pMCPrimary : mcPrimaryVector)
102 std::sort(pfoHitPairs.begin(), pfoHitPairs.end(),
104 return ((a.second.size() != b.second.size()) ? a.second.size() > b.second.size() :
LArPfoHelper::SortByNHits(a.first, b.first));
114 const MCParticle *pBestMCParticle(
nullptr);
117 for (
const MCParticle *
const pMCPrimary : mcPrimaryVector)
119 if (interpretedMCToPfoHitSharingMap.count(pMCPrimary))
130 if (usedPfos.count(pfoToSharedHits.first))
134 validationInfo.
GetPfoToHitsMap().at(pfoToSharedHits.first), pfoToSharedHits.second))
137 if (pfoToSharedHits.second.size() > bestPfoHitPair.second.size())
139 pBestMCParticle = pMCPrimary;
140 bestPfoHitPair = pfoToSharedHits;
145 if (!pBestMCParticle || !bestPfoHitPair.first)
148 interpretedMCToPfoHitSharingMap[pBestMCParticle].push_back(bestPfoHitPair);
149 usedPfos.insert(bestPfoHitPair.first);
160 for (
const MCParticle *
const pMCPrimary : mcPrimaryVector)
170 if (usedPfos.count(pfoToSharedHits.first))
174 LArMCParticleHelper::PfoToMCParticleHitSharingMap::iterator iter(pfoToMCParticleHitSharingMap.find(pfoToSharedHits.first));
176 if (pfoToMCParticleHitSharingMap.end() == iter)
178 pfoToMCParticleHitSharingMap[pfoToSharedHits.first].push_back(mcParticleToHits);
182 if (1 != iter->second.size())
183 throw StatusCodeException(STATUS_CODE_FAILURE);
187 if (mcParticleToHits.second.size() > originalMCParticleToHits.second.size())
188 originalMCParticleToHits = mcParticleToHits;
193 for (
const auto &mapEntry : pfoToMCParticleHitSharingMap)
196 interpretedMCToPfoHitSharingMap[mcParticleToHits.first].push_back(
205 const float purity((recoHits.size() > 0) ? static_cast<float>(sharedHits.size()) / static_cast<float>(recoHits.size()) : 0.f);
206 const float completeness((trueHits.size() > 0) ? static_cast<float>(sharedHits.size()) / static_cast<float>(trueHits.size()) : 0.f);
215 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"CaloHitListName",
m_caloHitListName));
216 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"MCParticleListName",
m_mcParticleListName));
217 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"PfoListName",
m_pfoListName));
219 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
222 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
225 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
228 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
231 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
234 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
237 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
240 PANDORA_RETURN_RESULT_IF_AND_IF(
241 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"PrintAllToScreen",
m_printAllToScreen));
243 PANDORA_RETURN_RESULT_IF_AND_IF(
244 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"PrintMatchingToScreen",
m_printMatchingToScreen));
246 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"WriteToTree",
m_writeToTree));
248 PANDORA_RETURN_RESULT_IF_AND_IF(
249 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"UseSmallPrimaries",
m_useSmallPrimaries));
251 PANDORA_RETURN_RESULT_IF_AND_IF(
252 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MatchingMinSharedHits",
m_matchingMinSharedHits));
254 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
257 PANDORA_RETURN_RESULT_IF_AND_IF(
258 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MatchingMinPurity",
m_matchingMinPurity));
262 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"OutputTree",
m_treeName));
263 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"OutputFile",
m_fileName));
265 PANDORA_RETURN_RESULT_IF_AND_IF(
266 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"FileIdentifier",
m_fileIdentifier));
269 return STATUS_CODE_SUCCESS;
const LArMCParticleHelper::PfoContributionMap & GetPfoToHitsMap() const
Get the pfo to hits map.
unsigned int m_minPrimaryGoodViews
the minimum number of primary good views
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
Header file for the pfo helper class.
bool m_selectInputHits
whether to select input hits
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
const LArMCParticleHelper::MCContributionMap & GetTargetMCParticleToHitsMap() const
Get the target mc particle to hits map.
Header file for the interaction type helper class.
int m_eventNumber
The event number.
int m_fileIdentifier
The input file identifier.
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
void InterpretMatching(const ValidationInfo &validationInfo, LArMCParticleHelper::MCParticleToPfoHitSharingMap &interpretedMCToPfoHitSharingMap) const
Apply an interpretative matching procedure to the comprehensive matches in the provided validation in...
void PrintAllMatches(const ValidationInfo &validationInfo) const
Print all/raw matching information to screen.
const LArMCParticleHelper::MCContributionMap & GetAllMCParticleToHitsMap() const
Get the all mc particle to hits map.
float m_matchingMinPurity
The minimum particle purity to declare a match.
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
std::vector< PfoCaloHitListPair > PfoToSharedHitsVector
const LArMCParticleHelper::MCParticleToPfoHitSharingMap & GetMCToPfoHitSharingMap() const
Get the mc to pfo hit sharing map.
pandora::StatusCode Run()
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.
bool m_printAllToScreen
Whether to print all/raw matching details to screen.
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
~EventValidationBaseAlgorithm()
Destructor.
float m_maxPhotonPropagation
the maximum photon propagation length
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void WriteInterpretedMatches(const ValidationInfo &validationInfo) const
Write interpreted matching information to tree.
Header file for the event validation algorithm.
std::string m_pfoListName
Name of input Pfo list.
static void GetOrderedMCParticleVector(const LArMCParticleHelper::MCContributionMapVector &selectedMCParticleToGoodHitsMaps, pandora::MCParticleVector &orderedMCParticleVector)
Order input MCParticles by their number of hits.
void PrintInterpretedMatches(const ValidationInfo &validationInfo) const
Print interpreted matching information to screen.
LArMCParticleHelper::PrimaryParameters m_primaryParameters
The mc particle primary selection parameters.
std::string m_fileName
Name of output file.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::string m_mcParticleListName
Name of input MC particle list.
bool m_writeToTree
Whether to write all/raw matching details to tree.
unsigned int m_matchingMinSharedHits
The minimum number of shared hits used in matching scheme.
float m_minHitSharingFraction
the minimum Hit sharing fraction
bool GetStrongestPfoMatch(const ValidationInfo &validationInfo, const pandora::MCParticleVector &mcPrimaryVector, pandora::PfoSet &usedPfos, LArMCParticleHelper::MCParticleToPfoHitSharingMap &interpretedMCToPfoHitSharingMap) const
Get the strongest pfo match (most matched hits) between an available mc primary and an available pfo...
bool m_useSmallPrimaries
Whether to consider matches to mc primaries with fewer than m_matchingMinPrimaryHits.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
void GetRemainingPfoMatches(const ValidationInfo &validationInfo, const pandora::MCParticleVector &mcPrimaryVector, const pandora::PfoSet &usedPfos, LArMCParticleHelper::MCParticleToPfoHitSharingMap &interpretedMCToPfoHitSharingMap) const
Get the best matches for any pfos left-over after the strong matching procedure.
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
bool m_printMatchingToScreen
Whether to print matching output to screen.
std::string m_treeName
Name of output tree.
float m_matchingMinCompleteness
The minimum particle completeness to declare a match.
virtual void FillValidationInfo(const pandora::MCParticleList *const pMCParticleList, const pandora::CaloHitList *const pCaloHitList, const pandora::PfoList *const pPfoList, ValidationInfo &validationInfo) const =0
Fill the validation info containers.
bool IsGoodMatch(const pandora::CaloHitList &trueHits, const pandora::CaloHitList &recoHits, const pandora::CaloHitList &sharedHits) const
Whether a provided mc primary and pfo are deemed to be a good match.
std::string m_caloHitListName
Name of input calo hit list.
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
BEGIN_PROLOG could also be cout
std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector > PfoToMCParticleHitSharingMap