LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::CheatingClusterCreationAlgorithm Class Reference

CheatingClusterCreationAlgorithm class. More...

#include "CheatingClusterCreationAlgorithm.h"

Inheritance diagram for lar_content::CheatingClusterCreationAlgorithm:

Public Member Functions

 CheatingClusterCreationAlgorithm ()
 Default constructor. More...
 

Private Types

typedef std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCParticleToHitListMap
 

Private Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void GetMCParticleToHitListMap (MCParticleToHitListMap &mcParticleToHitListMap) const
 Create map between each (primary) MC particle and associated calo hits. More...
 
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. More...
 
bool SelectMCParticlesForClustering (const pandora::MCParticle *const pMCParticle) const
 Check whether mc particle is of a type specified for inclusion in cheated clustering. More...
 
void CreateClusters (const MCParticleToHitListMap &mcParticleToHitListMap) const
 Create clusters based on information in the mc particle to hit list map. More...
 

Private Attributes

bool m_collapseToPrimaryMCParticles
 Whether to collapse mc particle hierarchies to primary particles. More...
 
std::string m_mcParticleListName
 The mc particle list name, required if want to collapse mc particle hierarchy. More...
 
pandora::IntVector m_particleIdList
 list of particle ids of MCPFOs to be selected More...
 

Detailed Description

Member Typedef Documentation

typedef std::unordered_map<const pandora::MCParticle*, pandora::CaloHitList> lar_content::CheatingClusterCreationAlgorithm::MCParticleToHitListMap
private

Definition at line 35 of file CheatingClusterCreationAlgorithm.h.

Constructor & Destructor Documentation

lar_content::CheatingClusterCreationAlgorithm::CheatingClusterCreationAlgorithm ( )

Default constructor.

Definition at line 18 of file CheatingClusterCreationAlgorithm.cc.

18  :
20 {
21 }
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.

Member Function Documentation

void lar_content::CheatingClusterCreationAlgorithm::CreateClusters ( const MCParticleToHitListMap mcParticleToHitListMap) const
private

Create clusters based on information in the mc particle to hit list map.

Parameters
mcParticleToHitListMapthe mc particle to hit list map

Definition at line 105 of file CheatingClusterCreationAlgorithm.cc.

References lar_content::LArMCParticleHelper::SortByMomentum().

Referenced by Run().

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 }
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
void lar_content::CheatingClusterCreationAlgorithm::GetMCParticleToHitListMap ( MCParticleToHitListMap mcParticleToHitListMap) const
private

Create map between each (primary) MC particle and associated calo hits.

Parameters
mcParticleToHitListMapto receive the mc particle to hit list map

Definition at line 36 of file CheatingClusterCreationAlgorithm.cc.

References lar_content::LArMCParticleHelper::GetMCPrimaryMap(), m_collapseToPrimaryMCParticles, m_mcParticleListName, and SimpleMCParticleCollection().

Referenced by Run().

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 }
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...
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
StatusCode lar_content::CheatingClusterCreationAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 145 of file CheatingClusterCreationAlgorithm.cc.

References m_collapseToPrimaryMCParticles, m_mcParticleListName, and m_particleIdList.

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 }
pandora::IntVector m_particleIdList
list of particle ids of MCPFOs to be selected
std::string m_mcParticleListName
The mc particle list name, required if want to collapse mc particle hierarchy.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
StatusCode lar_content::CheatingClusterCreationAlgorithm::Run ( )
private

Definition at line 25 of file CheatingClusterCreationAlgorithm.cc.

References CreateClusters(), and GetMCParticleToHitListMap().

26 {
27  MCParticleToHitListMap mcParticleToHitListMap;
28  this->GetMCParticleToHitListMap(mcParticleToHitListMap);
29  this->CreateClusters(mcParticleToHitListMap);
30 
31  return STATUS_CODE_SUCCESS;
32 }
void GetMCParticleToHitListMap(MCParticleToHitListMap &mcParticleToHitListMap) const
Create map between each (primary) MC particle and associated calo hits.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCParticleToHitListMap
void CreateClusters(const MCParticleToHitListMap &mcParticleToHitListMap) const
Create clusters based on information in the mc particle to hit list map.
bool lar_content::CheatingClusterCreationAlgorithm::SelectMCParticlesForClustering ( const pandora::MCParticle *const  pMCParticle) const
private

Check whether mc particle is of a type specified for inclusion in cheated clustering.

Parameters
pMCParticlethe mc particle to hit list map
Returns
boolean

Definition at line 89 of file CheatingClusterCreationAlgorithm.cc.

References m_particleIdList.

Referenced by SimpleMCParticleCollection().

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 }
pandora::IntVector m_particleIdList
list of particle ids of MCPFOs to be selected
void lar_content::CheatingClusterCreationAlgorithm::SimpleMCParticleCollection ( const pandora::CaloHit *const  pCaloHit,
const LArMCParticleHelper::MCRelationMap mcPrimaryMap,
MCParticleToHitListMap mcParticleToHitListMap 
) const
private

Simple mc particle collection, using main mc particle associated with each calo hit.

Parameters
pCaloHitaddress of the calo hit
mcPrimaryMapthe mapping between mc particles and their parents
mcParticleToHitListMapthe mc particle to hit list map

Definition at line 66 of file CheatingClusterCreationAlgorithm.cc.

References m_collapseToPrimaryMCParticles, and SelectMCParticlesForClustering().

Referenced by GetMCParticleToHitListMap().

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 }
bool SelectMCParticlesForClustering(const pandora::MCParticle *const pMCParticle) const
Check whether mc particle is of a type specified for inclusion in cheated clustering.
intermediate_table::const_iterator const_iterator
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.

Member Data Documentation

bool lar_content::CheatingClusterCreationAlgorithm::m_collapseToPrimaryMCParticles
private

Whether to collapse mc particle hierarchies to primary particles.

Definition at line 70 of file CheatingClusterCreationAlgorithm.h.

Referenced by GetMCParticleToHitListMap(), ReadSettings(), and SimpleMCParticleCollection().

std::string lar_content::CheatingClusterCreationAlgorithm::m_mcParticleListName
private

The mc particle list name, required if want to collapse mc particle hierarchy.

Definition at line 71 of file CheatingClusterCreationAlgorithm.h.

Referenced by GetMCParticleToHitListMap(), and ReadSettings().

pandora::IntVector lar_content::CheatingClusterCreationAlgorithm::m_particleIdList
private

list of particle ids of MCPFOs to be selected

Definition at line 73 of file CheatingClusterCreationAlgorithm.h.

Referenced by ReadSettings(), and SelectMCParticlesForClustering().


The documentation for this class was generated from the following files: