9 #include "Pandora/AlgorithmHeaders.h" 22 VisualParticleMonitoringAlgorithm::VisualParticleMonitoringAlgorithm() :
24 m_visualizePfo(false),
25 m_groupMCByPdg(false),
26 m_showPfoByPid(false),
27 m_showPfoMatchedMC(false),
49 const CaloHitList *pCaloHitList(
nullptr);
50 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
51 const MCParticleList *pMCParticleList(
nullptr);
52 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
53 this->MakeSelection(pMCParticleList, pCaloHitList, targetMCParticleToHitsMap);
59 this->VisualizeMCByPdgCode(targetMCParticleToHitsMap);
61 this->VisualizeIndependentMC(targetMCParticleToHitsMap);
65 const PfoList *pPfoList(
nullptr);
66 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_pfoListName, pPfoList));
69 this->VisualizePfoByParticleId(*pPfoList);
74 this->VisualizeIndependentPfo(*pPfoList, targetMCParticleToHitsMap);
76 this->VisualizeIndependentPfo(*pPfoList);
80 return STATUS_CODE_SUCCESS;
89 const std::map<int, const std::string>
keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
90 const std::map<int, Color>
colors = {{0, RED}, {1, BLACK}, {2,
BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
91 MCParticleList linearisedMC;
95 PANDORA_MONITORING_API(
101 for (
const MCParticle *pMC : linearisedMC)
103 const auto iter{mcMap.find(pMC)};
104 if (iter == mcMap.end())
110 if (keys.find(
pdg) != keys.end())
113 catch (
const StatusCodeException &)
118 CaloHitList uHits, vHits, wHits;
119 for (
const CaloHit *pCaloHit : iter->second)
121 const HitType view{pCaloHit->GetHitType()};
122 if (view == HitType::TPC_VIEW_U)
123 uHits.emplace_back(pCaloHit);
124 else if (view == HitType::TPC_VIEW_V)
125 vHits.emplace_back(pCaloHit);
127 wHits.emplace_back(pCaloHit);
131 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
133 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
135 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
136 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
140 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
147 const std::map<int, const std::string>
keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
148 const std::map<std::string, Color>
colors = {
149 {
"mu", MAGENTA}, {
"e", RED}, {
"gamma", ORANGE}, {
"kaon", BLACK}, {
"pi", GREEN}, {
"p",
BLUE}, {
"other", GRAY}};
151 std::map<std::string, CaloHitList> uHits, vHits, wHits;
152 for (
const auto & [
key,
value] : keys)
155 uHits[
value] = CaloHitList();
156 vHits[
value] = CaloHitList();
157 wHits[
value] = CaloHitList();
159 uHits[
"other"] = CaloHitList();
160 vHits[
"other"] = CaloHitList();
161 wHits[
"other"] = CaloHitList();
163 for (
const auto & [pMC, pCaloHits] : mcMap)
165 for (
const CaloHit *pCaloHit : pCaloHits)
167 const HitType view{pCaloHit->GetHitType()};
173 if (keys.find(
pdg) != keys.end())
176 if (view == HitType::TPC_VIEW_U)
177 uHits[
key].emplace_back(pCaloHit);
178 else if (view == HitType::TPC_VIEW_V)
179 vHits[
key].emplace_back(pCaloHit);
181 wHits[
key].emplace_back(pCaloHit);
183 catch (
const StatusCodeException &)
190 PANDORA_MONITORING_API(
193 for (
const auto & [
key,
value] : keys)
197 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
value],
"u_" + value, colors.at(value)));
199 if (!uHits[
"other"].
empty())
200 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"u_other", colors.at(
"other")));
202 for (
const auto & [
key,
value] : keys)
206 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits[
value],
"v_" +
value, colors.at(value)));
208 if (!vHits[
"other"].
empty())
209 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"v_other", colors.at(
"other")));
211 for (
const auto & [
key,
value] : keys)
215 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits[
value],
"w_" +
value, colors.at(value)));
217 if (!wHits[
"other"].
empty())
218 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"w_other", colors.at(
"other")));
220 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
225 void VisualParticleMonitoringAlgorithm::VisualizeIndependentPfo(
const PfoList &pfoList)
const 229 this->VisualizeIndependentPfo(pfoList, mcMap);
236 const std::map<int, Color>
colors = {{0, RED}, {1, BLACK}, {2,
BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
237 PfoList linearisedPfo;
241 PANDORA_MONITORING_API(
247 for (
const ParticleFlowObject *pPfo : linearisedPfo)
249 CaloHitList uHits, vHits, wHits;
251 CaloHitList caloHits;
252 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
257 for (
const CaloHit *pCaloHit : caloHits)
259 const HitType view{pCaloHit->GetHitType()};
260 if (view == HitType::TPC_VIEW_U)
261 uHits.emplace_back(pCaloHit);
262 else if (view == HitType::TPC_VIEW_V)
263 vHits.emplace_back(pCaloHit);
264 else if (view == HitType::TPC_VIEW_W)
265 wHits.emplace_back(pCaloHit);
268 suffix += isTrack ?
"_T" :
"_S";
270 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
272 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
274 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
275 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
283 const auto iter{mcMap.find(pMC)};
284 if (iter != mcMap.end())
286 CaloHitList uHitsMC, vHitsMC, wHitsMC;
287 for (
const CaloHit *pCaloHit : iter->second)
289 const HitType view{pCaloHit->GetHitType()};
290 if (view == HitType::TPC_VIEW_U)
291 uHitsMC.emplace_back(pCaloHit);
292 else if (view == HitType::TPC_VIEW_V)
293 vHitsMC.emplace_back(pCaloHit);
294 else if (view == HitType::TPC_VIEW_W)
295 wHitsMC.emplace_back(pCaloHit);
298 if (!uHitsMC.empty())
299 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHitsMC,
"u_" + mcSuffix, colors.at(colorIdx)));
300 if (!vHitsMC.empty())
301 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHitsMC,
"v_" + mcSuffix, colors.at(colorIdx)));
302 if (!wHitsMC.empty())
303 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHitsMC,
"w_" + mcSuffix, colors.at(colorIdx)));
307 catch (
const StatusCodeException &)
314 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
319 void VisualParticleMonitoringAlgorithm::VisualizePfoByParticleId(
const PfoList &pfoList)
const 321 PfoList linearisedPfo;
325 PANDORA_MONITORING_API(
330 for (
const ParticleFlowObject *pPfo : linearisedPfo)
332 CaloHitList uTrackHits, vTrackHits, wTrackHits, uShowerHits, vShowerHits, wShowerHits;
334 CaloHitList caloHits;
335 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
340 for (
const CaloHit *pCaloHit : caloHits)
342 const HitType view{pCaloHit->GetHitType()};
343 if (view == HitType::TPC_VIEW_U)
346 uTrackHits.emplace_back(pCaloHit);
348 uShowerHits.emplace_back(pCaloHit);
350 else if (view == HitType::TPC_VIEW_V)
353 vTrackHits.emplace_back(pCaloHit);
355 vShowerHits.emplace_back(pCaloHit);
360 wTrackHits.emplace_back(pCaloHit);
362 wShowerHits.emplace_back(pCaloHit);
368 if (!uTrackHits.empty())
369 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uTrackHits,
"u_" + suffix,
BLUE));
370 if (!vTrackHits.empty())
371 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vTrackHits,
"v_" + suffix,
BLUE));
372 if (!wTrackHits.empty())
373 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wTrackHits,
"w_" + suffix,
BLUE));
378 if (!uShowerHits.empty())
379 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uShowerHits,
"u_" + suffix, RED));
380 if (!vShowerHits.empty())
381 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vShowerHits,
"v_" + suffix, RED));
382 if (!wShowerHits.empty())
383 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wShowerHits,
"w_" + suffix, RED));
388 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
393 void VisualParticleMonitoringAlgorithm::MakeSelection(
421 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"CaloHitListName",
m_caloHitListName));
424 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"PfoListName",
m_pfoListName));
427 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizeMC",
m_visualizeMC));
428 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizePFO",
m_visualizePfo));
429 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"GroupMCByPDG",
m_groupMCByPdg));
430 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOByPID",
m_showPfoByPid));
431 PANDORA_RETURN_RESULT_IF_AND_IF(
432 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOMatchedMC",
m_showPfoMatchedMC));
433 PANDORA_RETURN_RESULT_IF_AND_IF(
434 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"TransparencyThresholdE",
m_transparencyThresholdE));
435 PANDORA_RETURN_RESULT_IF_AND_IF(
436 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"EnergyScaleThresholdE",
m_energyScaleThresholdE));
437 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ScalingFactor",
m_scalingFactor));
439 return STATUS_CODE_SUCCESS;
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
Header file for the lar calo hit class.
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
virtual ~VisualParticleMonitoringAlgorithm()
bool m_visualizePfo
Whether or not to visualize PFOs.
bool m_foldBackHierarchy
whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam) ...
float m_transparencyThresholdE
Cell energy for which transparency is saturated (0%, fully opaque)
float m_energyScaleThresholdE
Cell energy for which color is at top end of continous color palette.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static const pandora::MCParticle * GetMainMCParticle(const pandora::ParticleFlowObject *const pPfo)
Find the mc particle making the largest contribution to 2D clusters in a specified pfo...
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
bool m_showPfoMatchedMC
Whether or not to display the best matched MC particle for a PFO.
float m_maxPhotonPropagation
the maximum photon propagation length
bool m_showPfoByPid
Whether or not to colour PFOs by particle id.
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
pandora::StatusCode Run()
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters ¶meters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select target, reconstructable mc particles that match given criteria.
Header file for the particle visualisation algorithm.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
static int max(int a, int b)
float m_minHitSharingFraction
the minimum Hit sharing fraction
Header file for the lar mc particle class.
std::string m_pfoListName
Name of input PFO list.
static void GetBreadthFirstHierarchyRepresentation(const pandora::ParticleFlowObject *const pPfo, pandora::PfoList &pfoList)
Retrieve a linearised representation of the PFO hierarchy in breadth first order. This iterates over ...
bool m_isTestBeam
Whether or not this is a test beam experiment.
float m_scalingFactor
TEve works with [cm], Pandora usually works with [mm] (but LArContent went with cm too) ...
static void GetIsolatedCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of isolated calo hits of a particular hit type from a list of pfos.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
bool m_groupMCByPdg
Whether or not to group MC particles by particle id.
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
static void GetBreadthFirstHierarchyRepresentation(const pandora::MCParticle *const pMCParticle, pandora::MCParticleList &mcParticleList)
Retrieve a linearised representation of the MC particle hierarchy in breadth first order...
std::string to_string(ModuleType const mt)
std::string m_caloHitListName
Name of input calo hit list.
bool m_visualizeMC
Whether or not to visualize MC particles.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.