9 #include "Pandora/AlgorithmHeaders.h" 23 VisualParticleMonitoringAlgorithm::VisualParticleMonitoringAlgorithm() :
25 m_visualizePfo(false),
26 m_visualizeSlice(false),
27 m_groupMCByPdg(false),
28 m_showPfoByPid(false),
29 m_showPfoMatchedMC(false),
51 const CaloHitList *pCaloHitList(
nullptr);
52 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
53 const MCParticleList *pMCParticleList(
nullptr);
54 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pMCParticleList));
55 this->MakeSelection(pCaloHitList, targetMCParticleToHitsMap);
61 this->VisualizeMCByPdgCode(targetMCParticleToHitsMap);
63 this->VisualizeIndependentMC(targetMCParticleToHitsMap);
67 const PfoList *pPfoList(
nullptr);
68 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_pfoListName, pPfoList));
71 this->VisualizePfoByParticleId(*pPfoList);
76 this->VisualizeIndependentPfo(*pPfoList, targetMCParticleToHitsMap);
78 this->VisualizeIndependentPfo(*pPfoList);
83 const PfoList *pPfoList(
nullptr);
84 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_pfoListName, pPfoList));
85 this->VisualizeReconstructedSlice(*pPfoList);
88 return STATUS_CODE_SUCCESS;
97 const std::map<int, const std::string> keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
98 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
99 MCParticleList linearisedMC;
103 PANDORA_MONITORING_API(
109 for (
const MCParticle *pMC : linearisedMC)
111 const auto iter{mcMap.find(pMC)};
112 if (iter == mcMap.end())
114 std::string key(
"other");
117 const int pdg{
std::abs(pMC->GetParticleId())};
118 if (keys.find(pdg) != keys.end())
121 catch (
const StatusCodeException &)
126 CaloHitList uHits, vHits, wHits;
127 for (
const CaloHit *pCaloHit : iter->second)
129 const HitType view{pCaloHit->GetHitType()};
130 if (view == HitType::TPC_VIEW_U)
131 uHits.emplace_back(pCaloHit);
132 else if (view == HitType::TPC_VIEW_V)
133 vHits.emplace_back(pCaloHit);
135 wHits.emplace_back(pCaloHit);
139 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
141 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
143 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
144 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
148 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
155 const std::map<int, const std::string> keys = {{13,
"mu"}, {11,
"e"}, {22,
"gamma"}, {321,
"kaon"}, {211,
"pi"}, {2212,
"p"}};
156 const std::map<std::string, Color> colors = {
157 {
"mu", MAGENTA}, {
"e", RED}, {
"gamma", ORANGE}, {
"kaon", BLACK}, {
"pi", GREEN}, {
"p", BLUE}, {
"other", GRAY}};
159 std::map<std::string, CaloHitList> uHits, vHits, wHits;
160 for (
const auto &[key,
value] : keys)
163 uHits[
value] = CaloHitList();
164 vHits[
value] = CaloHitList();
165 wHits[
value] = CaloHitList();
167 uHits[
"other"] = CaloHitList();
168 vHits[
"other"] = CaloHitList();
169 wHits[
"other"] = CaloHitList();
171 for (
const auto &[pMC, pCaloHits] : mcMap)
173 for (
const CaloHit *pCaloHit : pCaloHits)
175 const HitType view{pCaloHit->GetHitType()};
179 const int pdg{
std::abs(pMC->GetParticleId())};
180 std::string key(
"other");
181 if (keys.find(pdg) != keys.end())
184 if (view == HitType::TPC_VIEW_U)
185 uHits[key].emplace_back(pCaloHit);
186 else if (view == HitType::TPC_VIEW_V)
187 vHits[key].emplace_back(pCaloHit);
189 wHits[key].emplace_back(pCaloHit);
191 catch (
const StatusCodeException &)
198 PANDORA_MONITORING_API(
201 for (
const auto &[key,
value] : keys)
205 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
value],
"u_" + value, colors.at(value)));
207 if (!uHits[
"other"].
empty())
208 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"u_other", colors.at(
"other")));
210 for (
const auto &[key,
value] : keys)
214 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits[
value],
"v_" +
value, colors.at(value)));
216 if (!vHits[
"other"].
empty())
217 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"v_other", colors.at(
"other")));
219 for (
const auto &[key,
value] : keys)
223 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits[
value],
"w_" +
value, colors.at(value)));
225 if (!wHits[
"other"].
empty())
226 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits[
"other"],
"w_other", colors.at(
"other")));
228 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
233 void VisualParticleMonitoringAlgorithm::VisualizeIndependentPfo(
const PfoList &pfoList)
const 237 this->VisualizeIndependentPfo(pfoList, mcMap);
244 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
245 PfoList linearisedPfo;
249 PANDORA_MONITORING_API(
255 for (
const ParticleFlowObject *pPfo : linearisedPfo)
257 CaloHitList uHits, vHits, wHits;
259 CaloHitList caloHits;
260 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
265 for (
const CaloHit *pCaloHit : caloHits)
267 const HitType view{pCaloHit->GetHitType()};
268 if (view == HitType::TPC_VIEW_U)
269 uHits.emplace_back(pCaloHit);
270 else if (view == HitType::TPC_VIEW_V)
271 vHits.emplace_back(pCaloHit);
272 else if (view == HitType::TPC_VIEW_W)
273 wHits.emplace_back(pCaloHit);
276 suffix += isTrack ?
"_T" :
"_S";
278 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
280 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
282 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
283 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
291 const auto iter{mcMap.find(pMC)};
292 if (iter != mcMap.end())
294 CaloHitList uHitsMC, vHitsMC, wHitsMC;
295 for (
const CaloHit *pCaloHit : iter->second)
297 const HitType view{pCaloHit->GetHitType()};
298 if (view == HitType::TPC_VIEW_U)
299 uHitsMC.emplace_back(pCaloHit);
300 else if (view == HitType::TPC_VIEW_V)
301 vHitsMC.emplace_back(pCaloHit);
302 else if (view == HitType::TPC_VIEW_W)
303 wHitsMC.emplace_back(pCaloHit);
305 std::string mcSuffix(suffix +
"_MC");
306 if (!uHitsMC.empty())
307 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHitsMC,
"u_" + mcSuffix, colors.at(colorIdx)));
308 if (!vHitsMC.empty())
309 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHitsMC,
"v_" + mcSuffix, colors.at(colorIdx)));
310 if (!wHitsMC.empty())
311 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHitsMC,
"w_" + mcSuffix, colors.at(colorIdx)));
315 catch (
const StatusCodeException &)
322 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
327 void VisualParticleMonitoringAlgorithm::VisualizeReconstructedSlice(
const PfoList &pfoList)
const 329 const std::map<int, Color> colors = {{0, RED}, {1, BLACK}, {2, BLUE}, {3, CYAN}, {4, MAGENTA}, {5, GREEN}, {6, ORANGE}, {7, GRAY}};
333 PANDORA_MONITORING_API(
338 for (
const ParticleFlowObject *pPfo : pfoList)
340 CaloHitList uHits, vHits, wHits;
342 CaloHitList caloHits;
343 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
348 for (
const CaloHit *pCaloHit : caloHits)
350 const HitType view{pCaloHit->GetHitType()};
351 if (view == HitType::TPC_VIEW_U)
352 uHits.emplace_back(pCaloHit);
353 else if (view == HitType::TPC_VIEW_V)
354 vHits.emplace_back(pCaloHit);
355 else if (view == HitType::TPC_VIEW_W)
356 wHits.emplace_back(pCaloHit);
359 suffix += isTrack ?
"_T" :
"_S";
361 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uHits,
"u_" + suffix, colors.at(colorIdx)));
363 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vHits,
"v_" + suffix, colors.at(colorIdx)));
365 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wHits,
"w_" + suffix, colors.at(colorIdx)));
366 colorIdx = (colorIdx + 1) >= colors.size() ? 0 : colorIdx + 1;
370 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
375 void VisualParticleMonitoringAlgorithm::VisualizePfoByParticleId(
const PfoList &pfoList)
const 377 PfoList linearisedPfo;
381 PANDORA_MONITORING_API(
386 for (
const ParticleFlowObject *pPfo : linearisedPfo)
388 CaloHitList uTrackHits, vTrackHits, wTrackHits, uShowerHits, vShowerHits, wShowerHits;
390 CaloHitList caloHits;
391 for (
const auto view : {HitType::TPC_VIEW_U, HitType::TPC_VIEW_V, HitType::TPC_VIEW_W})
396 for (
const CaloHit *pCaloHit : caloHits)
398 const HitType view{pCaloHit->GetHitType()};
399 if (view == HitType::TPC_VIEW_U)
402 uTrackHits.emplace_back(pCaloHit);
404 uShowerHits.emplace_back(pCaloHit);
406 else if (view == HitType::TPC_VIEW_V)
409 vTrackHits.emplace_back(pCaloHit);
411 vShowerHits.emplace_back(pCaloHit);
416 wTrackHits.emplace_back(pCaloHit);
418 wShowerHits.emplace_back(pCaloHit);
424 if (!uTrackHits.empty())
425 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uTrackHits,
"u_" + suffix, BLUE));
426 if (!vTrackHits.empty())
427 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vTrackHits,
"v_" + suffix, BLUE));
428 if (!wTrackHits.empty())
429 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wTrackHits,
"w_" + suffix, BLUE));
434 if (!uShowerHits.empty())
435 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &uShowerHits,
"u_" + suffix, RED));
436 if (!vShowerHits.empty())
437 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &vShowerHits,
"v_" + suffix, RED));
438 if (!wShowerHits.empty())
439 PANDORA_MONITORING_API(VisualizeCaloHits(this->GetPandora(), &wShowerHits,
"w_" + suffix, RED));
444 PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
452 for (
const CaloHit *pCaloHit : *pCaloHitList)
456 const MCParticle *pMC{MCParticleHelper::GetMainMCParticle(pCaloHit)};
460 mcMap[pMC].emplace_back(pCaloHit);
463 catch (
const StatusCodeException &)
474 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"CaloHitListName",
m_caloHitListName));
477 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"PfoListName",
m_pfoListName));
480 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizeMC",
m_visualizeMC));
481 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizePFO",
m_visualizePfo));
482 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"VisualizeSlice",
m_visualizeSlice));
483 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"GroupMCByPDG",
m_groupMCByPdg));
484 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOByPID",
m_showPfoByPid));
485 PANDORA_RETURN_RESULT_IF_AND_IF(
486 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ShowPFOMatchedMC",
m_showPfoMatchedMC));
487 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"IsTestBeam",
m_isTestBeam));
488 PANDORA_RETURN_RESULT_IF_AND_IF(
489 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"TransparencyThresholdE",
m_transparencyThresholdE));
490 PANDORA_RETURN_RESULT_IF_AND_IF(
491 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"EnergyScaleThresholdE",
m_energyScaleThresholdE));
492 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ScalingFactor",
m_scalingFactor));
494 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.
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.
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...
bool m_showPfoMatchedMC
Whether or not to display the best matched MC particle for a PFO.
bool m_showPfoByPid
Whether or not to colour PFOs by particle id.
pandora::StatusCode Run()
Header file for the lar monte carlo particle helper helper class.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Header file for the particle visualisation algorithm.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
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 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.
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
bool m_visualizeMC
Whether or not to visualize MC particles.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.