LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCParticleMonitoringAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
15 
17 
20 
21 using namespace pandora;
22 
23 namespace lar_content
24 {
25 
26 MCParticleMonitoringAlgorithm::MCParticleMonitoringAlgorithm() :
27  m_useTrueNeutrinosOnly(false),
28  m_minHitsForDisplay(1)
29 {
30 }
31 
32 //------------------------------------------------------------------------------------------------------------------------------------------
33 
35 {
36  std::cout << "---MC-PARTICLE-MONITORING-----------------------------------------------------------------------" << std::endl;
37  const MCParticleList *pMCParticleList = nullptr;
38  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_mcParticleListName, pMCParticleList));
39 
40  const CaloHitList *pCaloHitList = nullptr;
41  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_caloHitListName, pCaloHitList));
42 
44  parameters.m_minHitSharingFraction = 0.f;
45 
46  LArMCParticleHelper::MCContributionMap nuMCParticlesToGoodHitsMap;
47  LArMCParticleHelper::MCContributionMap beamMCParticlesToGoodHitsMap;
48  LArMCParticleHelper::MCContributionMap crMCParticlesToGoodHitsMap;
50  pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsBeamNeutrinoFinalState, nuMCParticlesToGoodHitsMap);
51 
53  {
55  pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsBeamParticle, beamMCParticlesToGoodHitsMap);
57  pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsCosmicRay, crMCParticlesToGoodHitsMap);
58  }
59 
60  if (!nuMCParticlesToGoodHitsMap.empty())
61  {
62  std::cout << std::endl << "BeamNeutrinos: " << std::endl;
63  this->PrintPrimaryMCParticles(nuMCParticlesToGoodHitsMap);
64  }
65 
66  if (!beamMCParticlesToGoodHitsMap.empty())
67  {
68  std::cout << std::endl << "BeamParticles: " << std::endl;
69  this->PrintPrimaryMCParticles(beamMCParticlesToGoodHitsMap);
70  }
71 
72  if (!crMCParticlesToGoodHitsMap.empty())
73  {
74  std::cout << std::endl << "CosmicRays: " << std::endl;
75  this->PrintPrimaryMCParticles(crMCParticlesToGoodHitsMap);
76  }
77 
78  std::cout << "------------------------------------------------------------------------------------------------" << std::endl;
79 
80  return STATUS_CODE_SUCCESS;
81 }
82 
83 //------------------------------------------------------------------------------------------------------------------------------------------
84 
86 {
87  MCParticleVector mcPrimaryVector;
88  LArMonitoringHelper::GetOrderedMCParticleVector({mcContributionMap}, mcPrimaryVector);
89 
90  unsigned int index(0);
91 
92  for (const MCParticle *const pMCPrimary : mcPrimaryVector)
93  {
94  const CaloHitList &caloHitList(mcContributionMap.at(pMCPrimary));
95 
96  if (caloHitList.size() >= m_minHitsForDisplay)
97  {
98  std::cout << std::endl
99  << "--Primary " << index << ", MCPDG " << pMCPrimary->GetParticleId() << ", Energy " << pMCPrimary->GetEnergy()
100  << ", Dist. " << (pMCPrimary->GetEndpoint() - pMCPrimary->GetVertex()).GetMagnitude() << ", nMCHits "
101  << caloHitList.size() << " (" << LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, caloHitList) << ", "
102  << LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, caloHitList) << ", "
103  << LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, caloHitList) << ")" << std::endl;
104 
105  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
106  LArMCParticleHelper::CaloHitToMCMap caloHitToPrimaryMCMap;
107  LArMCParticleHelper::MCContributionMap mcToTrueHitListMap;
108  LArMCParticleHelper::GetMCParticleToCaloHitMatches(&caloHitList, mcToPrimaryMCMap, caloHitToPrimaryMCMap, mcToTrueHitListMap);
109  this->PrintMCParticle(pMCPrimary, mcToTrueHitListMap, 1);
110  }
111 
112  ++index;
113  }
114 }
115 
116 //------------------------------------------------------------------------------------------------------------------------------------------
117 
119  const MCParticle *const pMCParticle, const LArMCParticleHelper::MCContributionMap &mcToTrueHitListMap, const int depth) const
120 {
121  const CaloHitList &caloHitList(mcToTrueHitListMap.count(pMCParticle) ? mcToTrueHitListMap.at(pMCParticle) : CaloHitList());
122 
123  if (caloHitList.size() >= m_minHitsForDisplay)
124  {
125  if (depth > 1)
126  {
127  for (int iDepth = 1; iDepth < depth - 1; ++iDepth)
128  std::cout << " ";
129  std::cout << "\\_ ";
130  }
131 
132  std::cout << "MCPDG " << pMCParticle->GetParticleId() << ", Energy " << pMCParticle->GetEnergy() << ", Dist. "
133  << (pMCParticle->GetEndpoint() - pMCParticle->GetVertex()).GetMagnitude() << ", nMCHits " << caloHitList.size() << " ("
134  << LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, caloHitList) << ", "
135  << LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, caloHitList) << ", "
136  << LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, caloHitList) << ")" << std::endl;
137  }
138 
139  for (const MCParticle *const pDaughterParticle : pMCParticle->GetDaughterList())
140  this->PrintMCParticle(pDaughterParticle, mcToTrueHitListMap, depth + 1);
141 }
142 
143 //------------------------------------------------------------------------------------------------------------------------------------------
144 
145 StatusCode MCParticleMonitoringAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
146 {
147  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "CaloHitListName", m_caloHitListName));
148  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MCParticleListName", m_mcParticleListName));
149 
150  PANDORA_RETURN_RESULT_IF_AND_IF(
151  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseTrueNeutrinosOnly", m_useTrueNeutrinosOnly));
152 
153  PANDORA_RETURN_RESULT_IF_AND_IF(
154  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinHitsForDisplay", m_minHitsForDisplay));
155 
156  return STATUS_CODE_SUCCESS;
157 }
158 
159 } // namespace lar_content
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
Header file for the mc particle monitoring algorithm.
Header file for the lar pfo class.
bool m_useTrueNeutrinosOnly
Whether to consider only mc particles that were neutrino induced.
std::unordered_map< const pandora::CaloHit *, const pandora::MCParticle * > CaloHitToMCMap
Header file for the lar monitoring helper helper class.
unsigned int m_minHitsForDisplay
Min hits associated with mc particle to warrant display to terminal.
Header file for the geometry helper class.
static void GetOrderedMCParticleVector(const LArMCParticleHelper::MCContributionMapVector &selectedMCParticleToGoodHitsMaps, pandora::MCParticleVector &orderedMCParticleVector)
Order input MCParticles by their number of hits.
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
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.
void PrintMCParticle(const pandora::MCParticle *const pMCParticle, const LArMCParticleHelper::MCContributionMap &mcToTrueHitListMap, const int depth) const
Print information for a given mc particle to screen.
Header file for the cluster helper class.
static void GetMCParticleToCaloHitMatches(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, CaloHitToMCMap &hitToMCMap, MCContributionMap &mcToTrueHitListMap)
Match calo hits to their parent particles.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::string m_caloHitListName
Name of input calo hit list.
void PrintPrimaryMCParticles(const LArMCParticleHelper::MCContributionMap &mcContributionMap) const
Extract details of each mc primary in a given mc contribution map.
float m_minHitSharingFraction
the minimum Hit sharing fraction
Header file for the lar mc particle class.
std::string m_mcParticleListName
Name of input MC particle list.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
static unsigned int CountHitsByType(const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
Count the number of calo hits, in a provided list, of a specified type.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap