Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
DlHitValidationAlgorithm.cc
Go to the documentation of this file.
1
10
12
15
17
18using namespace pandora;
19using namespace lar_content;
20
21namespace lar_dl_content
22{
23
24DlHitValidationAlgorithm::DlHitValidationAlgorithm() : m_confusionU(), m_confusionV(), m_confusionW()
25{
26}
27
28//------------------------------------------------------------------------------------------------------------------------------------------
29
31{
32 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "u_true_shower", m_confusionU[0][0]));
33 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "u_false_shower", m_confusionU[1][0]));
34 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "u_false_track", m_confusionU[0][1]));
35 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "u_true_track", m_confusionU[1][1]));
36 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "v_true_shower", m_confusionV[0][0]));
37 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "v_false_shower", m_confusionV[1][0]));
38 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "v_false_track", m_confusionV[0][1]));
39 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "v_true_track", m_confusionV[1][1]));
40 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "w_true_shower", m_confusionW[0][0]));
41 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "w_false_shower", m_confusionW[1][0]));
42 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "w_false_track", m_confusionW[0][1]));
43 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), "confusion_tree", "w_true_track", m_confusionW[1][1]));
44 PANDORA_MONITORING_API(FillTree(this->GetPandora(), "confusion_tree"));
45 try
46 {
47 PANDORA_MONITORING_API(SaveTree(this->GetPandora(), "confusion_tree", "confusion.root", "UPDATE"));
48 }
49 catch (const StatusCodeException &)
50 {
51 std::cout << "DlHitValidationAlgorithm: Unable to write confusion_tree to file" << std::endl;
52 }
53}
54
55//------------------------------------------------------------------------------------------------------------------------------------------
56
58{
59 const int SHOWER_IDX{0}, TRACK_IDX{1};
60 for (const std::string &listName : m_caloHitListNames)
61 {
62 const CaloHitList *pCaloHitList(nullptr);
63 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listName, pCaloHitList));
64 const MCParticleList *pMCParticleList(nullptr);
65 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pMCParticleList));
66
67 const HitType view{pCaloHitList->front()->GetHitType()};
68
69 if (!(view == TPC_VIEW_U || view == TPC_VIEW_V || view == TPC_VIEW_W))
70 return STATUS_CODE_NOT_ALLOWED;
71
73 // Only care about reconstructability with respect to the current view, so skip good view check
74 parameters.m_minHitsForGoodView = 0;
75 // Turn off max photo propagation for now, only care about killing off daughters of neutrons
76 parameters.m_maxPhotonPropagation = std::numeric_limits<float>::max();
77 LArMCParticleHelper::MCContributionMap targetMCParticleToHitsMap;
79 pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsBeamNeutrinoFinalState, targetMCParticleToHitsMap);
80
81 for (const CaloHit *pCaloHit : *pCaloHitList)
82 {
83 try
84 {
85 const MCParticle *const pMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
86 const int pdg{std::abs(pMCParticle->GetParticleId())};
87 const int truth{(pdg == 11 || pdg == 22) ? SHOWER_IDX : TRACK_IDX};
88 const LArCaloHit *pLArCaloHit{dynamic_cast<const LArCaloHit *>(pCaloHit)};
89 const float pTrack{pLArCaloHit->GetTrackProbability()};
90 const float pShower{pLArCaloHit->GetShowerProbability()};
91 const int cls{(pShower > pTrack) ? SHOWER_IDX : TRACK_IDX};
92 if (view == TPC_VIEW_U)
93 ++m_confusionU[truth][cls];
94 else if (view == TPC_VIEW_V)
95 ++m_confusionV[truth][cls];
96 else
97 ++m_confusionW[truth][cls];
98 }
99 catch (const StatusCodeException &)
100 {
101 continue;
102 }
103 }
104 }
105
106 return STATUS_CODE_SUCCESS;
107}
108
109//------------------------------------------------------------------------------------------------------------------------------------------
110
112{
114 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "CaloHitListNames", m_caloHitListNames));
115
116 return STATUS_CODE_SUCCESS;
117}
118
119} // namespace lar_dl_content
Grouping of header files for many classes of use in particle flow algorithms.
#define PANDORA_MONITORING_API(command)
Header file for the deep learning track shower id validation algorithm.
Header file for the lar calo hit class.
Header file for the lar monte carlo particle helper helper class.
Header file for the lar monitoring helper helper class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
static pandora::StatusCode GetCurrentList(const pandora::Algorithm &algorithm, const T *&pT)
Get the current list.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
LAr calo hit class.
Definition LArCaloHit.h:40
float GetTrackProbability() const
Get the probability that the hit is track-like.
Definition LArCaloHit.h:210
float m_maxPhotonPropagation
the maximum photon propagation length
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
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.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
pandora::StringVector m_caloHitListNames
Name of input calo hit list.
int m_confusionV[2][2]
Confusion matrix for the V view.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
int m_confusionU[2][2]
Confusion matrix for the U view.
pandora::StatusCode Run()
Run the algorithm.
int m_confusionW[2][2]
Confusion matrix for the W view.
CaloHit class.
Definition CaloHit.h:26
static const MCParticle * GetMainMCParticle(const T *const pT)
Find the mc particle making the largest contribution to a specified calo hit, track or cluster.
MCParticle class.
Definition MCParticle.h:26
int GetParticleId() const
Get the PDG code of the mc particle.
Definition MCParticle.h:285
const Pandora & GetPandora() const
Get the associated pandora instance.
Definition Process.h:116
StatusCodeException class.
static StatusCode ReadVectorOfValues(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, std::vector< T > &vector)
Read a vector of values from a (space separated) list in an xml element.
Definition XmlHelper.h:229
HitType
Calorimeter hit type enum.
MANAGED_CONTAINER< const MCParticle * > MCParticleList
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.