9 #include "Pandora/AlgorithmHeaders.h"
25 SlidingConePfoMopUpAlgorithm::SlidingConePfoMopUpAlgorithm() :
27 m_maxIterations(1000),
28 m_maxHitsToConsider3DTrack(100),
29 m_minHitsToConsider3DShower(20),
30 m_halfWindowLayers(20),
33 m_coneLengthMultiplier(7.f),
34 m_maxConeLength(126.f),
35 m_coneTanHalfAngle1(0.5f),
36 m_coneBoundedFraction1(0.5f),
37 m_coneTanHalfAngle2(0.75f),
38 m_coneBoundedFraction2(0.75f),
39 m_minVertexLongitudinalDistance(-2.5f),
40 m_maxVertexTransverseDistance(3.5f)
48 const Vertex *pVertex(
nullptr);
53 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
54 std::cout <<
"SlidingConePfoMopUpAlgorithm - interaction vertex not available for use." << std::endl;
55 return STATUS_CODE_SUCCESS;
58 unsigned int nIterations(0);
73 return STATUS_CODE_SUCCESS;
84 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetCurrentList(*
this, pVertexList));
87 ((pVertexList && (pVertexList->size() == 1) && (VERTEX_3D == (*(pVertexList->begin()))->GetVertexType())) ? *(pVertexList->begin()) :
nullptr);
96 const PfoList *pPfoList(
nullptr);
98 if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*
this, pfoListName, pPfoList))
101 for (
const Pfo *
const pPfo : *pPfoList)
103 ClusterList pfoClusters3D;
106 for (
const Cluster *
const pCluster3D : pfoClusters3D)
111 if (!clusterToPfoMap.insert(ClusterToPfoMap::value_type(pCluster3D, pPfo)).second)
112 throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
114 clusters3D.push_back(pCluster3D);
130 for (
const Cluster *
const pShowerCluster : clusters3D)
135 float coneLength(0.f);
137 bool isShowerVertexAssociated(
false);
147 const float vertexToMinLayer(!pVertex ? 0.f : (pVertex->GetPosition() - minLayerPosition).GetMagnitude());
148 const float vertexToMaxLayer(!pVertex ? 0.f : (pVertex->GetPosition() - maxLayerPosition).GetMagnitude());
153 isShowerVertexAssociated =
156 catch (
const StatusCodeException &)
161 for (
const Cluster *
const pNearbyCluster : clusters3D)
163 if (pNearbyCluster == pShowerCluster)
168 for (
const SimpleCone &simpleCone : simpleConeList)
170 const float boundedFraction1(simpleCone.GetBoundedHitFraction(pNearbyCluster, coneLength,
m_coneTanHalfAngle1));
171 const float boundedFraction2(simpleCone.GetBoundedHitFraction(pNearbyCluster, coneLength,
m_coneTanHalfAngle2));
172 const ClusterMerge clusterMerge(pShowerCluster, boundedFraction1, boundedFraction2);
174 if (clusterMerge < bestClusterMerge)
175 bestClusterMerge = clusterMerge;
178 if (isShowerVertexAssociated && this->
IsVertexAssociated(pNearbyCluster, pVertex, vertexAssociationMap))
183 clusterMergeMap[pNearbyCluster].push_back(bestClusterMerge);
187 for (ClusterMergeMap::value_type &mapEntry : clusterMergeMap)
188 std::sort(mapEntry.second.begin(), mapEntry.second.end());
199 VertexAssociationMap::const_iterator iter = vertexAssociationMap.find(pCluster);
201 if (vertexAssociationMap.end() != iter)
204 const bool isVertexAssociated(this->
IsVertexAssociated(pCluster, pVertex->GetPosition(), pSlidingFitResult));
205 (
void)vertexAssociationMap.insert(VertexAssociationMap::value_type(pCluster, isVertexAssociated));
207 return isVertexAssociated;
213 const Cluster *
const pCluster,
const CartesianVector &vertexPosition,
const ThreeDSlidingFitResult *
const pSlidingFitResult)
const
218 const LArPointingCluster pointingCluster(
219 pSlidingFitResult ? LArPointingCluster(*pSlidingFitResult) : LArPointingCluster(pCluster,
m_halfWindowLayers, layerPitch));
221 const bool useInner((pointingCluster.GetInnerVertex().GetPosition() - vertexPosition).GetMagnitudeSquared() <
222 (pointingCluster.GetOuterVertex().GetPosition() - vertexPosition).GetMagnitudeSquared());
224 const LArPointingCluster::Vertex &daughterVertex(useInner ? pointingCluster.GetInnerVertex() : pointingCluster.GetOuterVertex());
227 catch (
const StatusCodeException &)
239 for (
const ClusterMergeMap::value_type &mapEntry : clusterMergeMap)
240 daughterClusters.push_back(mapEntry.first);
243 bool pfosMerged(
false);
246 for (ClusterVector::const_reverse_iterator rIter = daughterClusters.rbegin(), rIterEnd = daughterClusters.rend(); rIter != rIterEnd; ++rIter)
248 const Cluster *
const pDaughterCluster(*rIter);
250 if (clusterReplacementMap.count(pDaughterCluster))
251 throw StatusCodeException(STATUS_CODE_FAILURE);
253 const Cluster *pParentCluster(clusterMergeMap.at(pDaughterCluster).at(0).GetParentCluster());
255 if (clusterReplacementMap.count(pParentCluster))
256 pParentCluster = clusterReplacementMap.at(pParentCluster);
259 if (pDaughterCluster == pParentCluster)
263 const Pfo *
const pDaughterPfo(clusterToPfoMap.at(pDaughterCluster));
264 const Pfo *
const pParentPfo(clusterToPfoMap.at(pParentCluster));
269 clusterReplacementMap[pDaughterCluster] = pParentCluster;
271 for (ClusterReplacementMap::value_type &mapEntry : clusterReplacementMap)
273 if (pDaughterCluster == mapEntry.second)
274 mapEntry.second = pParentCluster;
309 PANDORA_RETURN_RESULT_IF_AND_IF(
310 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
"InputPfoListNames",
m_inputPfoListNames));
312 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"UseVertex",
m_useVertex));
314 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxIterations",
m_maxIterations));
316 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
319 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
322 PANDORA_RETURN_RESULT_IF_AND_IF(
323 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SlidingFitHalfWindow",
m_halfWindowLayers));
325 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"NConeFitLayers",
m_nConeFitLayers));
327 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"NConeFits",
m_nConeFits));
329 PANDORA_RETURN_RESULT_IF_AND_IF(
330 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ConeLengthMultiplier",
m_coneLengthMultiplier));
332 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxConeLength",
m_maxConeLength));
334 PANDORA_RETURN_RESULT_IF_AND_IF(
335 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ConeTanHalfAngle1",
m_coneTanHalfAngle1));
337 PANDORA_RETURN_RESULT_IF_AND_IF(
338 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ConeBoundedFraction1",
m_coneBoundedFraction1));
340 PANDORA_RETURN_RESULT_IF_AND_IF(
341 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ConeTanHalfAngle2",
m_coneTanHalfAngle2));
343 PANDORA_RETURN_RESULT_IF_AND_IF(
344 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ConeBoundedFraction2",
m_coneBoundedFraction2));
346 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
349 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
std::unordered_map< const pandora::Cluster *, const pandora::Cluster * > ClusterReplacementMap
float GetBoundedFraction2() const
Get the bounded fraction for algorithm-specified cone angle 2.
void GetClusterMergeMap(const pandora::Vertex *const pVertex, const pandora::ClusterVector &clusters3D, const ClusterToPfoMap &clusterToPfoMap, ClusterMergeMap &clusterMergeMap) const
Get the cluster merge map describing all potential 3d cluster merges.
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, then pulse-height.
float m_coneBoundedFraction2
The minimum cluster bounded fraction for association 2.
void GetInteractionVertex(const pandora::Vertex *&pVertex) const
Get the neutrino interaction vertex if it is available and if the algorithm is configured to do so...
Header file for the pfo helper class.
float m_maxConeLength
The maximum allowed cone length to use when calculating bounded cluster fractions.
float m_maxVertexTransverseDistance
Vertex association check: max transverse distance cut.
std::unordered_map< const pandora::Cluster *, const pandora::ParticleFlowObject * > ClusterToPfoMap
float m_coneLengthMultiplier
The cone length multiplier to use when calculating bounded cluster fractions.
std::vector< SimpleCone > SimpleConeList
pandora::StringVector m_daughterListNames
The list of potential daughter object list names.
bool MakePfoMerges(const ClusterToPfoMap &clusterToPfoMap, const ClusterMergeMap &clusterMergeMap) const
Make pfo merges based on the provided cluster merge map.
const ThreeDSlidingFitResult & GetSlidingFitResult() const
Get the sliding fit result for the full cluster.
void GetThreeDClusters(pandora::ClusterVector &clusters3D, ClusterToPfoMap &clusterToPfoMap) const
Get all 3d clusters contained in the input pfo lists and a mapping from clusters to pfos...
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
bool m_useVertex
Whether to use the interaction vertex to select useful cone directions.
Header file for the lar three dimensional sliding cone fit result class.
float GetBoundedFraction1() const
Get the bounded fraction for algorithm-specified cone angle 1.
void GetSimpleConeList(const unsigned int nLayersForConeFit, const unsigned int nCones, const ConeSelection coneSelection, SimpleConeList &simpleConeList) const
Get the list of simple cones fitted to the three dimensional cluster.
bool IsVertexAssociated(const pandora::Cluster *const pCluster, const pandora::Vertex *const pVertex, VertexAssociationMap &vertexAssociationMap, const ThreeDSlidingFitResult *const pSlidingFitResult=nullptr) const
Whether a 3D cluster is nodally associated with a provided vertex.
Header file for the geometry helper class.
float m_minVertexLongitudinalDistance
Vertex association check: min longitudinal distance cut.
static bool IsShower(const pandora::ParticleFlowObject *const pPfo)
Return shower flag based on Pfo Particle ID.
unsigned int m_nConeFitLayers
The number of layers over which to sum fitted direction to obtain cone fit.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the cluster helper class.
unsigned int m_maxHitsToConsider3DTrack
The maximum number of hits in a 3d track cluster to warrant inclusion in algorithm.
float m_coneTanHalfAngle1
The cone tan half angle to use when calculating bounded cluster fractions 1.
pandora::StringVector m_inputPfoListNames
The input pfo list names.
Header file for the sliding cone pfo mop up algorithm class.
static void GetThreeDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 3D clusters from an input pfo.
const pandora::CartesianVector & GetGlobalMaxLayerPosition() const
Get global position corresponding to the fit result in maximum fit layer.
float m_coneBoundedFraction1
The minimum cluster bounded fraction for association 1.
pandora::StatusCode Run()
std::unordered_map< const pandora::Cluster *, bool > VertexAssociationMap
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
ThreeDSlidingFitResult class.
unsigned int m_maxIterations
The maximum allowed number of algorithm iterations.
virtual void MergeAndDeletePfos(const pandora::ParticleFlowObject *const pPfoToEnlarge, const pandora::ParticleFlowObject *const pPfoToDelete) const
Merge and delete a pair of pfos, with a specific set of conventions for cluster merging, vertex use, etc.
ConeSelection
ConeSelection enum.
unsigned int m_minHitsToConsider3DShower
The minimum number of hits in a 3d shower cluster to attempt cone fits.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
ThreeDSlidingConeFitResult class.
bool operator<(const ClusterMerge &rhs) const
operator <
unsigned int m_nConeFits
The number of cone fits to perform, spread roughly uniformly along the shower length.
std::unordered_map< const pandora::Cluster *, ClusterMergeList > ClusterMergeMap
const pandora::Cluster * GetParentCluster() const
Get the address of the candidate parent (shower) cluster.
std::list< Vertex > VertexList
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
BEGIN_PROLOG could also be cout
static bool IsNode(const pandora::CartesianVector &parentVertex, const LArPointingCluster::Vertex &daughterVertex, const float minLongitudinalDistance, const float maxTransverseDistance)
Whether pointing vertex is adjacent to a given position.
float m_coneTanHalfAngle2
The cone tan half angle to use when calculating bounded cluster fractions 2.
unsigned int m_halfWindowLayers
The number of layers to use for half-window of sliding fit.
const pandora::CartesianVector & GetGlobalMinLayerPosition() const
Get global position corresponding to the fit result in minimum fit layer.