LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::CheatingClusterMergingAlgorithm Class Reference

CheatingClusterMergingAlgorithm class. More...

#include "CheatingClusterMergingAlgorithm.h"

Inheritance diagram for lar_content::CheatingClusterMergingAlgorithm:

Public Member Functions

 CheatingClusterMergingAlgorithm ()
 Default constructor. More...
 

Private Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void CheatedClusterMerging (const pandora::ClusterList *const pClusterList, const std::string &listName) const
 Cheated Cluster Merging. Use MC to match clusters based on the main MC particle. More...
 
const pandora::MCParticle * GetMCForCluster (const pandora::Cluster *const cluster, std::map< const pandora::Cluster *, const pandora::MCParticle * > &clusterToMCMap) const
 Get the MC particle for a given cluster, caching to a map. More...
 
bool IsValidToUse (const pandora::Cluster *const cluster, std::map< const pandora::Cluster *, bool > &clusterIsUsed) const
 If a cluster is valid to use: Is a shower tagged cluster, and not been used yet. More...
 

Private Attributes

pandora::StringVector m_inputClusterListNames
 The names of the input cluster lists. More...
 
std::string m_mcParticleListName
 Input MC particle list name. More...
 
float m_minNCaloHits
 The minimum number of hits for a cluster to be deemed true for IsAvailableToUse. More...
 

Detailed Description

Constructor & Destructor Documentation

lar_content::CheatingClusterMergingAlgorithm::CheatingClusterMergingAlgorithm ( )

Default constructor.

Definition at line 26 of file CheatingClusterMergingAlgorithm.cc.

26  :
28 {
29 }
float m_minNCaloHits
The minimum number of hits for a cluster to be deemed true for IsAvailableToUse.

Member Function Documentation

void lar_content::CheatingClusterMergingAlgorithm::CheatedClusterMerging ( const pandora::ClusterList *const  pClusterList,
const std::string &  listName 
) const
private

Cheated Cluster Merging. Use MC to match clusters based on the main MC particle.

Parameters
pClusterListthe list of clusters
listNamethe name of the current cluster list (ClustersU, ClustersV, ClustersW normally)

Definition at line 101 of file CheatingClusterMergingAlgorithm.cc.

References GetMCForCluster(), and IsValidToUse().

Referenced by Run().

102 {
103  std::map<const Cluster *, const MCParticle *> clusterToMCParticleMap;
104  std::map<const Cluster *, bool> clusterIsUsed;
105  std::map<const Cluster *, ClusterVector> clustersToMerge;
106 
107  for (auto it = pClusterList->begin(); it != pClusterList->end(); ++it)
108  {
109  const Cluster *cluster(*it);
110 
111  if (!this->IsValidToUse(cluster, clusterIsUsed))
112  continue;
113 
114  const MCParticle *clusterMC(this->GetMCForCluster(cluster, clusterToMCParticleMap));
115 
116  for (auto it2 = std::next(it); it2 != pClusterList->end(); ++it2)
117  {
118  const Cluster *const otherCluster(*it2);
119 
120  if (!this->IsValidToUse(otherCluster, clusterIsUsed))
121  continue;
122 
123  const MCParticle *otherClusterMC(this->GetMCForCluster(otherCluster, clusterToMCParticleMap));
124 
125  if (clusterMC == otherClusterMC)
126  {
127  clusterIsUsed[cluster] = true;
128  clusterIsUsed[otherCluster] = true;
129  clustersToMerge[cluster].emplace_back(otherCluster);
130  }
131  }
132  }
133 
134  for (auto clusterToMergePair : clustersToMerge)
135  {
136  const Cluster *currentCluster{clusterToMergePair.first};
137  const auto clusters{clusterToMergePair.second};
138 
139  for (auto clusterToMerge : clusters)
140  {
141  if (!clusterToMerge->IsAvailable())
142  continue;
143 
144  try
145  {
146  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
147  PandoraContentApi::MergeAndDeleteClusters(*this, currentCluster, clusterToMerge, listName, listName));
148  }
149  catch (StatusCodeException)
150  {
151  }
152  }
153  }
154 }
Cluster finding and building.
bool IsValidToUse(const pandora::Cluster *const cluster, std::map< const pandora::Cluster *, bool > &clusterIsUsed) const
If a cluster is valid to use: Is a shower tagged cluster, and not been used yet.
const pandora::MCParticle * GetMCForCluster(const pandora::Cluster *const cluster, std::map< const pandora::Cluster *, const pandora::MCParticle * > &clusterToMCMap) const
Get the MC particle for a given cluster, caching to a map.
const MCParticle * lar_content::CheatingClusterMergingAlgorithm::GetMCForCluster ( const pandora::Cluster *const  cluster,
std::map< const pandora::Cluster *, const pandora::MCParticle * > &  clusterToMCMap 
) const
private

Get the MC particle for a given cluster, caching to a map.

Parameters
clusterThe current cluster to lookup
clusterToMCMapMap from Cluster to MC to cache results.

Definition at line 59 of file CheatingClusterMergingAlgorithm.cc.

References e.

Referenced by CheatedClusterMerging().

61 {
62  const MCParticle *clusterMC{nullptr};
63 
64  if (clusterToMCMap.count(cluster) > 0)
65  {
66  clusterMC = clusterToMCMap.at(cluster);
67  }
68  else
69  {
70  try
71  {
72  clusterMC = MCParticleHelper::GetMainMCParticle(cluster);
73  clusterToMCMap[cluster] = clusterMC;
74  }
75  catch (StatusCodeException e)
76  {
77  std::cout << "Failed to get MC particle for cluster of " << cluster->GetOrderedCaloHitList().size() << " : " << e.ToString() << std::endl;
78  }
79  }
80  return clusterMC;
81 }
Cluster finding and building.
Float_t e
Definition: plot.C:35
bool lar_content::CheatingClusterMergingAlgorithm::IsValidToUse ( const pandora::Cluster *const  cluster,
std::map< const pandora::Cluster *, bool > &  clusterIsUsed 
) const
private

If a cluster is valid to use: Is a shower tagged cluster, and not been used yet.

Parameters
clusterThe current cluster to lookup
clusterIsUsedMap from Cluster to bool to check if a cluster has been used yet.

Definition at line 85 of file CheatingClusterMergingAlgorithm.cc.

References m_minNCaloHits.

Referenced by CheatedClusterMerging().

86 {
87  if (!cluster->IsAvailable())
88  return false;
89 
90  if (cluster->GetNCaloHits() < m_minNCaloHits)
91  return false;
92 
93  if (clusterIsUsed.count(cluster) > 0)
94  return false;
95 
96  return true;
97 }
Cluster finding and building.
float m_minNCaloHits
The minimum number of hits for a cluster to be deemed true for IsAvailableToUse.
StatusCode lar_content::CheatingClusterMergingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 158 of file CheatingClusterMergingAlgorithm.cc.

References m_inputClusterListNames, m_mcParticleListName, and m_minNCaloHits.

159 {
160  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "InputClusterListNames", m_inputClusterListNames));
161 
162  PANDORA_RETURN_RESULT_IF_AND_IF(
163  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MCParticleListName", m_mcParticleListName));
164 
165  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinNCaloHits", m_minNCaloHits));
166 
167  return STATUS_CODE_SUCCESS;
168 }
pandora::StringVector m_inputClusterListNames
The names of the input cluster lists.
std::string m_mcParticleListName
Input MC particle list name.
float m_minNCaloHits
The minimum number of hits for a cluster to be deemed true for IsAvailableToUse.
StatusCode lar_content::CheatingClusterMergingAlgorithm::Run ( )
private

Definition at line 32 of file CheatingClusterMergingAlgorithm.cc.

References CheatedClusterMerging(), and m_inputClusterListNames.

33 {
34  for (const std::string &clusterListName : m_inputClusterListNames)
35  {
36  try
37  {
38  const ClusterList *pClusterList{nullptr};
39  PANDORA_RETURN_RESULT_IF_AND_IF(
40  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, clusterListName, pClusterList));
41 
42  if (!pClusterList || pClusterList->empty())
43  {
44  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
45  std::cout << "ClusterMergingAlgorithm: unable to find cluster list " << clusterListName << std::endl;
46 
47  continue;
48  }
49  this->CheatedClusterMerging(pClusterList, clusterListName);
50  }
51  catch (StatusCodeException &statusCodeException)
52  {
53  throw statusCodeException;
54  }
55  }
56  return STATUS_CODE_SUCCESS;
57 }
pandora::StringVector m_inputClusterListNames
The names of the input cluster lists.
void CheatedClusterMerging(const pandora::ClusterList *const pClusterList, const std::string &listName) const
Cheated Cluster Merging. Use MC to match clusters based on the main MC particle.

Member Data Documentation

pandora::StringVector lar_content::CheatingClusterMergingAlgorithm::m_inputClusterListNames
private

The names of the input cluster lists.

Definition at line 57 of file CheatingClusterMergingAlgorithm.h.

Referenced by ReadSettings(), and Run().

std::string lar_content::CheatingClusterMergingAlgorithm::m_mcParticleListName
private

Input MC particle list name.

Definition at line 58 of file CheatingClusterMergingAlgorithm.h.

Referenced by ReadSettings().

float lar_content::CheatingClusterMergingAlgorithm::m_minNCaloHits
private

The minimum number of hits for a cluster to be deemed true for IsAvailableToUse.

Definition at line 59 of file CheatingClusterMergingAlgorithm.h.

Referenced by IsValidToUse(), and ReadSettings().


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