9 #include "Helpers/MCParticleHelper.h" 10 #include "Objects/MCParticle.h" 11 #include "Pandora/AlgorithmHeaders.h" 26 CheatingClusterMergingAlgorithm::CheatingClusterMergingAlgorithm() :
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));
42 if (!pClusterList || pClusterList->empty())
44 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
45 std::cout <<
"ClusterMergingAlgorithm: unable to find cluster list " << clusterListName << std::endl;
51 catch (StatusCodeException &statusCodeException)
53 throw statusCodeException;
56 return STATUS_CODE_SUCCESS;
60 const Cluster *
const cluster, std::map<const Cluster *, const MCParticle *> &clusterToMCMap)
const 62 const MCParticle *clusterMC{
nullptr};
64 if (clusterToMCMap.count(cluster) > 0)
66 clusterMC = clusterToMCMap.at(cluster);
72 clusterMC = MCParticleHelper::GetMainMCParticle(cluster);
73 clusterToMCMap[cluster] = clusterMC;
75 catch (StatusCodeException
e)
77 std::cout <<
"Failed to get MC particle for cluster of " << cluster->GetOrderedCaloHitList().size() <<
" : " << e.ToString() << std::endl;
87 if (!cluster->IsAvailable())
93 if (clusterIsUsed.count(cluster) > 0)
103 std::map<const Cluster *, const MCParticle *> clusterToMCParticleMap;
104 std::map<const Cluster *, bool> clusterIsUsed;
105 std::map<const Cluster *, ClusterVector> clustersToMerge;
107 for (
auto it = pClusterList->begin(); it != pClusterList->end(); ++it)
114 const MCParticle *clusterMC(this->
GetMCForCluster(cluster, clusterToMCParticleMap));
116 for (
auto it2 = std::next(it); it2 != pClusterList->end(); ++it2)
118 const Cluster *
const otherCluster(*it2);
123 const MCParticle *otherClusterMC(this->
GetMCForCluster(otherCluster, clusterToMCParticleMap));
125 if (clusterMC == otherClusterMC)
127 clusterIsUsed[cluster] =
true;
128 clusterIsUsed[otherCluster] =
true;
129 clustersToMerge[cluster].emplace_back(otherCluster);
134 for (
auto clusterToMergePair : clustersToMerge)
136 const Cluster *currentCluster{clusterToMergePair.first};
137 const auto clusters{clusterToMergePair.second};
139 for (
auto clusterToMerge : clusters)
141 if (!clusterToMerge->IsAvailable())
146 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
147 PandoraContentApi::MergeAndDeleteClusters(*
this, currentCluster, clusterToMerge, listName, listName));
149 catch (StatusCodeException)
160 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
"InputClusterListNames",
m_inputClusterListNames));
162 PANDORA_RETURN_RESULT_IF_AND_IF(
163 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MCParticleListName",
m_mcParticleListName));
165 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MinNCaloHits",
m_minNCaloHits));
167 return STATUS_CODE_SUCCESS;
Header file for the cheating cluster merging algorithm.
pandora::StringVector m_inputClusterListNames
The names of the input cluster lists.
std::string m_mcParticleListName
Input MC particle list name.
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.
Cluster finding and building.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the lar monte carlo particle helper helper class.
Header file for the cluster helper class.
Header file for the lar mc particle class.
pandora::StatusCode Run()
Header file for the shower growing algorithm class.
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.
float m_minNCaloHits
The minimum number of hits for a cluster to be deemed true for IsAvailableToUse.