9 #include "Pandora/AlgorithmHeaders.h" 22 VisualParticleMonitoringAlgorithm::VisualParticleMonitoringAlgorithm() :
24 m_visualizePfo(false),
25 m_visualizeSlice(false),
26 m_groupMCByPdg(false),
27 m_showPfoByPid(false),
28 m_showPfoMatchedMC(false),
50 const CaloHitList *pCaloHitList(
nullptr);
51 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
52 const MCParticleList *pMCParticleList(
nullptr);
53 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
54 this->MakeSelection(pMCParticleList, pCaloHitList, targetMCParticleToHitsMap);
60 this->VisualizeMCByPdgCode(targetMCParticleToHitsMap);
62 this->VisualizeIndependentMC(targetMCParticleToHitsMap);
66 const PfoList *pPfoList(
nullptr);
67 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_pfoListName, pPfoList));
70 this->VisualizePfoByParticleId(*pPfoList);
75 this->VisualizeIndependentPfo(*pPfoList, targetMCParticleToHitsMap);
77 this->VisualizeIndependentPfo(*pPfoList);
82 const PfoList *pPfoList(
nullptr);
83 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_pfoListName, pPfoList));
84 this->VisualizeReconstructedSlice(*pPfoList);
87 return STATUS_CODE_SUCCESS;
96 const std::map<int, const std::string> keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
97 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
98 MCParticleList linearisedMC;
102 PANDORA_MONITORING_API(
108 for (
const MCParticle *pMC : linearisedMC)
110 const auto iter{mcMap.find(pMC)};
111 if (iter == mcMap.end())
113 std::string key(
"other");
116 const int pdg{
std::abs(pMC->GetParticleId())};
117 if (keys.find(pdg) != keys.end())
120 catch (
const StatusCodeException &)
125 CaloHitList uHits, vHits, wHits;
126 for (
const CaloHit *pCaloHit : iter->second)
128 const HitType view{pCaloHit->GetHitType()};
129 if (view == HitType::TPC_VIEW_U)
130 uHits.emplace_back(pCaloHit);
131 else if (view == HitType::TPC_VIEW_V)
132 vHits.emplace_back(pCaloHit);
134 wHits.emplace_back(pCaloHit);
138 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
140 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
142 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
143 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
147 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
154 const std::map<int, const std::string> keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
155 const std::map<std::string, Color> colors = {
156 {
"mu", MAGENTA}, {
"e", RED}, {
"gamma", ORANGE}, {
"kaon", BLACK}, {
"pi", GREEN}, {
"p", BLUE}, {
"other", GRAY}};
158 std::map<std::string, CaloHitList> uHits, vHits, wHits;
159 for (
const auto &[key,
value] : keys)
162 uHits[
value] = CaloHitList();
163 vHits[
value] = CaloHitList();
164 wHits[
value] = CaloHitList();
166 uHits[
"other"] = CaloHitList();
167 vHits[
"other"] = CaloHitList();
168 wHits[
"other"] = CaloHitList();
170 for (
const auto &[pMC, pCaloHits] : mcMap)
172 for (
const CaloHit *pCaloHit : pCaloHits)
174 const HitType view{pCaloHit->GetHitType()};
178 const int pdg{
std::abs(pMC->GetParticleId())};
179 std::string key(
"other");
180 if (keys.find(pdg) != keys.end())
183 if (view == HitType::TPC_VIEW_U)
184 uHits[key].emplace_back(pCaloHit);
185 else if (view == HitType::TPC_VIEW_V)
186 vHits[key].emplace_back(pCaloHit);
188 wHits[key].emplace_back(pCaloHit);
190 catch (
const StatusCodeException &)
197 PANDORA_MONITORING_API(
200 for (
const auto &[key,
value] : keys)
204 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
value],
"u_" + value, colors.at(value)));
206 if (!uHits[
"other"].
empty())
207 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"u_other", colors.at(
"other")));
209 for (
const auto &[key,
value] : keys)
213 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits[
value],
"v_" +
value, colors.at(value)));
215 if (!vHits[
"other"].
empty())
216 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"v_other", colors.at(
"other")));
218 for (
const auto &[key,
value] : keys)
222 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits[
value],
"w_" +
value, colors.at(value)));
224 if (!wHits[
"other"].
empty())
225 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"w_other", colors.at(
"other")));
227 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
232 void VisualParticleMonitoringAlgorithm::VisualizeIndependentPfo(
const PfoList &pfoList)
const 236 this->VisualizeIndependentPfo(pfoList, mcMap);
243 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
244 PfoList linearisedPfo;
248 PANDORA_MONITORING_API(
254 for (
const ParticleFlowObject *pPfo : linearisedPfo)
256 CaloHitList uHits, vHits, wHits;
258 CaloHitList caloHits;
259 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
264 for (
const CaloHit *pCaloHit : caloHits)
266 const HitType view{pCaloHit->GetHitType()};
267 if (view == HitType::TPC_VIEW_U)
268 uHits.emplace_back(pCaloHit);
269 else if (view == HitType::TPC_VIEW_V)
270 vHits.emplace_back(pCaloHit);
271 else if (view == HitType::TPC_VIEW_W)
272 wHits.emplace_back(pCaloHit);
275 suffix += isTrack ?
"_T" :
"_S";
277 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
279 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
281 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
282 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
290 const auto iter{mcMap.find(pMC)};
291 if (iter != mcMap.end())
293 CaloHitList uHitsMC, vHitsMC, wHitsMC;
294 for (
const CaloHit *pCaloHit : iter->second)
296 const HitType view{pCaloHit->GetHitType()};
297 if (view == HitType::TPC_VIEW_U)
298 uHitsMC.emplace_back(pCaloHit);
299 else if (view == HitType::TPC_VIEW_V)
300 vHitsMC.emplace_back(pCaloHit);
301 else if (view == HitType::TPC_VIEW_W)
302 wHitsMC.emplace_back(pCaloHit);
304 std::string mcSuffix(suffix +
"_MC");
305 if (!uHitsMC.empty())
306 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHitsMC,
"u_" + mcSuffix, colors.at(colorIdx)));
307 if (!vHitsMC.empty())
308 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHitsMC,
"v_" + mcSuffix, colors.at(colorIdx)));
309 if (!wHitsMC.empty())
310 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHitsMC,
"w_" + mcSuffix, colors.at(colorIdx)));
314 catch (
const StatusCodeException &)
321 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
326 void VisualParticleMonitoringAlgorithm::VisualizeReconstructedSlice(
const PfoList &pfoList)
const 328 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
332 PANDORA_MONITORING_API(
337 for (
const ParticleFlowObject *pPfo : pfoList)
339 CaloHitList uHits, vHits, wHits;
341 CaloHitList caloHits;
342 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
347 for (
const CaloHit *pCaloHit : caloHits)
349 const HitType view{pCaloHit->GetHitType()};
350 if (view == HitType::TPC_VIEW_U)
351 uHits.emplace_back(pCaloHit);
352 else if (view == HitType::TPC_VIEW_V)
353 vHits.emplace_back(pCaloHit);
354 else if (view == HitType::TPC_VIEW_W)
355 wHits.emplace_back(pCaloHit);
358 suffix += isTrack ?
"_T" :
"_S";
360 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
362 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
364 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
365 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
369 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
374 void VisualParticleMonitoringAlgorithm::VisualizePfoByParticleId(
const PfoList &pfoList)
const 376 PfoList linearisedPfo;
380 PANDORA_MONITORING_API(
385 for (
const ParticleFlowObject *pPfo : linearisedPfo)
387 CaloHitList uTrackHits, vTrackHits, wTrackHits, uShowerHits, vShowerHits, wShowerHits;
389 CaloHitList caloHits;
390 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
395 for (
const CaloHit *pCaloHit : caloHits)
397 const HitType view{pCaloHit->GetHitType()};
398 if (view == HitType::TPC_VIEW_U)
401 uTrackHits.emplace_back(pCaloHit);
403 uShowerHits.emplace_back(pCaloHit);
405 else if (view == HitType::TPC_VIEW_V)
408 vTrackHits.emplace_back(pCaloHit);
410 vShowerHits.emplace_back(pCaloHit);
415 wTrackHits.emplace_back(pCaloHit);
417 wShowerHits.emplace_back(pCaloHit);
423 if (!uTrackHits.empty())
424 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uTrackHits,
"u_" + suffix, BLUE));
425 if (!vTrackHits.empty())
426 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vTrackHits,
"v_" + suffix, BLUE));
427 if (!wTrackHits.empty())
428 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wTrackHits,
"w_" + suffix, BLUE));
433 if (!uShowerHits.empty())
434 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uShowerHits,
"u_" + suffix, RED));
435 if (!vShowerHits.empty())
436 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vShowerHits,
"v_" + suffix, RED));
437 if (!wShowerHits.empty())
438 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wShowerHits,
"w_" + suffix, RED));
443 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
448 void VisualParticleMonitoringAlgorithm::MakeSelection(
476 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"CaloHitListName",
m_caloHitListName));
479 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"PfoListName",
m_pfoListName));
482 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizeMC",
m_visualizeMC));
483 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizePFO",
m_visualizePfo));
484 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizeSlice",
m_visualizeSlice));
485 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"GroupMCByPDG",
m_groupMCByPdg));
486 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOByPID",
m_showPfoByPid));
487 PANDORA_RETURN_RESULT_IF_AND_IF(
488 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOMatchedMC",
m_showPfoMatchedMC));
489 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"IsTestBeam",
m_isTestBeam));
490 PANDORA_RETURN_RESULT_IF_AND_IF(
491 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"TransparencyThresholdE",
m_transparencyThresholdE));
492 PANDORA_RETURN_RESULT_IF_AND_IF(
493 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"EnergyScaleThresholdE",
m_energyScaleThresholdE));
494 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ScalingFactor",
m_scalingFactor));
496 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()
constexpr auto abs(T v)
Returns the absolute value of the argument.
bool m_visualizePfo
Whether or not to visualize PFOs.
bool m_visualizeSlice
Whether or not to visualize reconstructed slices.
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.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Header file for the particle visualisation algorithm.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
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 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.