LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CheatingClusterCreationAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 CheatingClusterCreationAlgorithm::CheatingClusterCreationAlgorithm() :
19  m_collapseToPrimaryMCParticles(false)
20 {
21 }
22 
23 //------------------------------------------------------------------------------------------------------------------------------------------
24 
26 {
27  MCParticleToHitListMap mcParticleToHitListMap;
28  this->GetMCParticleToHitListMap(mcParticleToHitListMap);
29  this->CreateClusters(mcParticleToHitListMap);
30 
31  return STATUS_CODE_SUCCESS;
32 }
33 
34 //------------------------------------------------------------------------------------------------------------------------------------------
35 
37 {
39 
41  {
42  const MCParticleList *pMCParticleList(nullptr);
43  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_mcParticleListName, pMCParticleList));
44 
45  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcPrimaryMap);
46  }
47 
48  const CaloHitList *pCaloHitList(nullptr);
49  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pCaloHitList));
50 
51  for (const CaloHit *const pCaloHit : *pCaloHitList)
52  {
53  try
54  {
55  if (!PandoraContentApi::IsAvailable(*this, pCaloHit))
56  continue;
57 
58  this->SimpleMCParticleCollection(pCaloHit, mcPrimaryMap, mcParticleToHitListMap);
59  }
60  catch (const StatusCodeException &) {}
61  }
62 }
63 
64 //------------------------------------------------------------------------------------------------------------------------------------------
65 
67  MCParticleToHitListMap &mcParticleToHitListMap) const
68 {
69  const MCParticle *pMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
70 
71  if (!this->SelectMCParticlesForClustering(pMCParticle))
72  return;
73 
75  {
76  LArMCParticleHelper::MCRelationMap::const_iterator primaryIter = mcPrimaryMap.find(pMCParticle);
77 
78  if (mcPrimaryMap.end() == primaryIter)
79  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
80 
81  pMCParticle = primaryIter->second;
82  }
83 
84  mcParticleToHitListMap[pMCParticle].push_back(pCaloHit);
85 }
86 
87 //------------------------------------------------------------------------------------------------------------------------------------------
88 
89 bool CheatingClusterCreationAlgorithm::SelectMCParticlesForClustering(const MCParticle *const pMCParticle) const
90 {
91  if (m_particleIdList.empty())
92  return true;
93 
94  for (const int particleId : m_particleIdList)
95  {
96  if (pMCParticle->GetParticleId() == particleId)
97  return true;
98  }
99 
100  return false;
101 }
102 
103 //------------------------------------------------------------------------------------------------------------------------------------------
104 
106 {
107  MCParticleVector mcParticleVector;
108  for (const auto &mapEntry : mcParticleToHitListMap) mcParticleVector.push_back(mapEntry.first);
109  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
110 
111  for (const MCParticle *const pMCParticle : mcParticleVector)
112  {
113  const CaloHitList &caloHitList(mcParticleToHitListMap.at(pMCParticle));
114 
115  if (caloHitList.empty())
116  continue;
117 
118  const Cluster *pCluster(nullptr);
119  PandoraContentApi::Cluster::Parameters parameters;
120  parameters.m_caloHitList = caloHitList;
121  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, parameters, pCluster));
122 
123  PandoraContentApi::Cluster::Metadata metadata;
124 
125  switch (pMCParticle->GetParticleId())
126  {
127  case PHOTON:
128  case E_PLUS:
129  case E_MINUS:
130  case MU_PLUS:
131  case MU_MINUS:
132  metadata.m_particleId = pMCParticle->GetParticleId();
133  break;
134  default:
135  break;
136  }
137 
138  if (metadata.m_particleId.IsInitialized())
139  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::AlterMetadata(*this, pCluster, metadata));
140  }
141 }
142 
143 //------------------------------------------------------------------------------------------------------------------------------------------
144 
145 StatusCode CheatingClusterCreationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
146 {
147  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
148  "CollapseToPrimaryMCParticles", m_collapseToPrimaryMCParticles));
149 
151  {
152  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
153  "MCParticleListName", m_mcParticleListName));
154  }
155 
156  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
157  "ParticleIdList", m_particleIdList));
158 
159  return STATUS_CODE_SUCCESS;
160 }
161 
162 } // namespace lar_content
pandora::IntVector m_particleIdList
list of particle ids of MCPFOs to be selected
void GetMCParticleToHitListMap(MCParticleToHitListMap &mcParticleToHitListMap) const
Create map between each (primary) MC particle and associated calo hits.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCParticleToHitListMap
std::string m_mcParticleListName
The mc particle list name, required if want to collapse mc particle hierarchy.
void SimpleMCParticleCollection(const pandora::CaloHit *const pCaloHit, const LArMCParticleHelper::MCRelationMap &mcPrimaryMap, MCParticleToHitListMap &mcParticleToHitListMap) const
Simple mc particle collection, using main mc particle associated with each calo hit.
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
bool SelectMCParticlesForClustering(const pandora::MCParticle *const pMCParticle) const
Check whether mc particle is of a type specified for inclusion in cheated clustering.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
Header file for the cheating cluster creation algorithm class.
intermediate_table::const_iterator const_iterator
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
void CreateClusters(const MCParticleToHitListMap &mcParticleToHitListMap) const
Create clusters based on information in the mc particle to hit list map.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap