24 ClusterVector availableClustersU, availableClustersV, availableClustersW;
37 this->
MatchClusters(cleanClustersU, cleanClustersV, matchedClusterUV);
38 this->
MatchClusters(cleanClustersV, cleanClustersW, matchedClusterVW);
39 this->
MatchClusters(cleanClustersW, cleanClustersU, matchedClusterWU);
43 this->
MatchThreeViews(matchedClusterUV, matchedClusterVW, matchedClusterWU, particleList);
44 this->
MatchTwoViews(matchedClusterUV, matchedClusterVW, matchedClusterWU, particleList);
47 return STATUS_CODE_SUCCESS;
58 if (!pClusterList || pClusterList->empty())
61 std::cout <<
"CosmicRayBaseMatchingAlgorithm: unable to find cluster list " << inputClusterListName << std::endl;
63 return STATUS_CODE_SUCCESS;
66 for (
const Cluster *
const pCluster : *pClusterList)
68 if (!pCluster->IsAvailable())
71 clusterVector.push_back(pCluster);
76 return STATUS_CODE_SUCCESS;
85 if (clusterVector1.empty() || clusterVector2.empty())
91 if (hitType1 == hitType2)
94 for (
const Cluster *
const pCluster1 : clusterVector1)
96 for (
const Cluster *
const pCluster2 : clusterVector2)
100 UIntSet daughterVolumeIntersection;
103 if (!daughterVolumeIntersection.empty())
104 matchedClusters12[pCluster1].push_back(pCluster2);
115 if (matchedClusters12.empty() || matchedClusters23.empty() || matchedClusters31.empty())
121 for (
const auto &mapEntry : matchedClusters12)
122 clusterList1.push_back(mapEntry.first);
125 for (
const Cluster *
const pCluster1 : clusterList1)
127 const ClusterList &clusterList2(matchedClusters12.at(pCluster1));
129 for (
const Cluster *
const pCluster2 : clusterList2)
131 ClusterAssociationMap::const_iterator iter23 = matchedClusters23.find(pCluster2);
133 if (matchedClusters23.end() == iter23)
138 for (
const Cluster *
const pCluster3 : clusterList3)
140 ClusterAssociationMap::const_iterator iter31 = matchedClusters31.find(pCluster3);
142 if (matchedClusters31.end() == iter31)
145 if (iter31->second.end() == std::find(iter31->second.begin(), iter31->second.end(), pCluster1))
155 const Cluster *
const pClusterU(
157 const Cluster *
const pClusterV(
159 const Cluster *
const pClusterW(
162 candidateParticles.push_back(
Particle(pClusterU, pClusterV, pClusterW));
187 if (matchedClusters12.empty())
191 for (
const auto &mapEntry : matchedClusters12)
192 clusterList1.push_back(mapEntry.first);
195 for (
const Cluster *
const pCluster1 : clusterList1)
197 const ClusterList &clusterList2(matchedClusters12.at(pCluster1));
199 for (
const Cluster *
const pCluster2 : clusterList2)
208 matchedParticles.push_back(
Particle(pClusterU, pClusterV, pClusterW));
217 for (
const Particle &particle1 : candidateParticles)
219 bool isGoodMatch(
true);
221 for (
const Particle &particle2 : candidateParticles)
223 const bool commonU(particle1.m_pClusterU == particle2.m_pClusterU);
224 const bool commonV(particle1.m_pClusterV == particle2.m_pClusterV);
225 const bool commonW(particle1.m_pClusterW == particle2.m_pClusterW);
227 const bool ambiguousU(commonU && NULL != particle1.m_pClusterU);
228 const bool ambiguousV(commonV && NULL != particle1.m_pClusterV);
229 const bool ambiguousW(commonW && NULL != particle1.m_pClusterW);
231 if (commonU && commonV && commonW)
234 if (ambiguousU || ambiguousV || ambiguousW)
242 matchedParticles.push_back(particle1);
250 if (particleList.empty())
253 const PfoList *pPfoList = NULL;
254 std::string pfoListName;
257 for (
const Particle &particle : particleList)
259 const Cluster *
const pClusterU = particle.m_pClusterU;
260 const Cluster *
const pClusterV = particle.m_pClusterV;
261 const Cluster *
const pClusterW = particle.m_pClusterW;
263 const bool isAvailableU((NULL != pClusterU) ? pClusterU->
IsAvailable() :
true);
264 const bool isAvailableV((NULL != pClusterV) ? pClusterV->
IsAvailable() :
true);
265 const bool isAvailableW((NULL != pClusterW) ? pClusterW->
IsAvailable() :
true);
267 if (!(isAvailableU && isAvailableV && isAvailableW))
270 PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
273 if (pfoParameters.m_clusterList.empty())
277 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*
this, pfoParameters, pPfo));
280 if (!pPfoList->empty())
287 m_pClusterU(pClusterU),
288 m_pClusterV(pClusterV),
289 m_pClusterW(pClusterW)
311 return STATUS_CODE_SUCCESS;
Header file for the cosmic ray base matching algorithm class.
Header file for the cluster helper class.
Header file for the geometry helper class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode CreateTemporaryListAndSetCurrent(const pandora::Algorithm &algorithm, const T *&pT, std::string &temporaryListName)
Create a temporary list and set it to be the current list, enabling object creation.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
const pandora::Cluster * m_pClusterW
Address of cluster in W view.
const pandora::Cluster * m_pClusterU
Address of cluster in U view.
Particle(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW)
Constructor.
const pandora::Cluster * m_pClusterV
Address of cluster in V view.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterAssociationMap
virtual void SelectCleanClusters(const pandora::ClusterVector &inputVector, pandora::ClusterVector &outputVector) const =0
Select a set of clusters judged to be clean.
void ResolveAmbiguities(const ParticleList &inputList, ParticleList &outputList) const
Remove ambiguities between candidate particles.
std::set< unsigned int > UIntSet
pandora::StatusCode GetAvailableClusters(const std::string inputClusterListName, pandora::ClusterVector &clusterVector) const
Get a vector of available clusters.
virtual bool CheckMatchedClusters3D(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3) const =0
Check that three clusters have a consistent 3D position.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
std::string m_inputClusterListNameW
The name of the view W cluster list.
virtual void SetPfoParameters(const CosmicRayBaseMatchingAlgorithm::Particle &protoParticle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const =0
Calculate Pfo properties from proto particle.
virtual bool MatchClusters(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const =0
Match a pair of clusters from two views.
void MatchTwoViews(const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters12, const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters23, const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters31, ParticleList &particleList) const
Match clusters from two views and form into particles.
pandora::StatusCode Run()
Run the algorithm.
void MatchThreeViews(const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters12, const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters23, const CosmicRayBaseMatchingAlgorithm::ClusterAssociationMap &matchedClusters31, ParticleList &particleList) const
Match clusters from three views and form into particles.
std::string m_inputClusterListNameV
The name of the view V cluster list.
void BuildParticles(const ParticleList &particleList)
Build PFO objects from candidate particles.
std::string m_inputClusterListNameU
The name of the view U cluster list.
std::vector< Particle > ParticleList
std::string m_outputPfoListName
The name of the output PFO list.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static bool SortByNHits(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by number of hits, then layer span, then inner layer, then position,...
static void GetCommonDaughterVolumes(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, UIntSet &intersect)
Return the set of common daughter volumes between two 2D clusters.
bool IsAvailable() const
Whether the cluster is available to be added to a particle flow object.
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
ParticleFlowObject class.
StatusCodeException class.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
HitType
Calorimeter hit type enum.
std::vector< const Cluster * > ClusterVector
MANAGED_CONTAINER< const Cluster * > ClusterList
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList