8 #include "Pandora/AlgorithmHeaders.h" 22 VertexSelectionBaseAlgorithm::VertexSelectionBaseAlgorithm() :
23 m_replaceCurrentVertexList(true),
25 m_nDecayLengthsInZSpan(2.
f),
26 m_selectSingleVertex(true),
27 m_maxTopScoreSelections(3),
28 m_maxOnHitDisplacement(1.
f),
29 m_minCandidateDisplacement(2.
f),
30 m_minCandidateScoreFraction(0.5
f),
31 m_useDetectorGaps(true),
33 m_isEmptyViewAcceptable(true),
34 m_minVertexAcceptableViews(3)
43 for (
const Vertex *
const pVertex : *pInputVertexList)
45 unsigned int nAcceptableViews(0);
57 filteredVertices.push_back(pVertex);
70 if (vertexVector.empty())
71 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
75 for (
const Vertex *
const pVertex : vertexVector)
77 if (pVertex->GetPosition().GetZ() < minZCoordinate)
78 minZCoordinate = pVertex->GetPosition().GetZ();
80 if (pVertex->GetPosition().GetZ() > maxZCoordinate)
81 maxZCoordinate = pVertex->GetPosition().GetZ();
84 const float zSpan(maxZCoordinate - minZCoordinate);
85 const float decayConstant((zSpan < std::numeric_limits<float>::epsilon()) ? 0.
f : (
m_nDecayLengthsInZSpan / zSpan));
86 beamConstants.
SetConstants(minZCoordinate, decayConstant);
92 ClusterList &clusterListW)
const 94 for (
const std::string &clusterListName : inputClusterListNames)
96 const ClusterList *pClusterList(NULL);
97 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this, clusterListName, pClusterList));
99 if (!pClusterList || pClusterList->empty())
101 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
102 std::cout <<
"EnergyKickVertexSelectionAlgorithm: unable to find cluster list " << clusterListName << std::endl;
109 if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
110 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
112 ClusterList &clusterList((TPC_VIEW_U == hitType) ? clusterListU : (TPC_VIEW_V == hitType) ? clusterListV : clusterListW);
113 clusterList.insert(clusterList.end(), pClusterList->begin(), pClusterList->end());
124 ClusterVector sortedClusters(inputClusterList.begin(), inputClusterList.end());
127 for (
const Cluster *
const pCluster : sortedClusters)
129 if (pCluster->GetNCaloHits() < minClusterCaloHits)
133 const unsigned int newSlidingFitWindow(
std::min(static_cast<int>(pCluster->GetNCaloHits()), static_cast<int>(slidingFitPitch * slidingFitWindow)));
134 slidingFitDataList.emplace_back(pCluster, newSlidingFitWindow, slidingFitPitch);
143 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pInputVertexList));
145 if (!pInputVertexList || pInputVertexList->empty())
147 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
148 std::cout <<
"VertexSelectionBaseAlgorithm: unable to find current vertex list " << std::endl;
150 return STATUS_CODE_SUCCESS;
157 this->
FilterVertexList(pInputVertexList, kdTreeU, kdTreeV, kdTreeW, filteredVertices);
159 if (filteredVertices.empty())
160 return STATUS_CODE_SUCCESS;
166 this->
GetVertexScoreList(filteredVertices, beamConstants, kdTreeU, kdTreeV, kdTreeW, vertexScoreList);
171 if (!selectedVertexList.empty())
173 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*
this,
m_outputVertexListName, selectedVertexList));
176 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*
this,
m_outputVertexListName));
179 return STATUS_CODE_SUCCESS;
188 const CaloHitList *pCaloHitList = NULL;
189 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this, caloHitListName, pCaloHitList));
191 if (!pCaloHitList || pCaloHitList->empty())
193 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
194 std::cout <<
"VertexSelectionBaseAlgorithm: unable to find calo hit list " << caloHitListName << std::endl;
199 const HitType hitType((*(pCaloHitList->begin()))->GetHitType());
201 if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
202 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
204 HitKDTree2D &kdTree((TPC_VIEW_U == hitType) ? kdTreeU : (TPC_VIEW_V == hitType) ? kdTreeV : kdTreeW);
207 throw StatusCodeException(STATUS_CODE_FAILURE);
211 kdTree.
build(hitKDNode2DList, hitsBoundingRegion2D);
223 kdTree.
search(searchRegionHits, found);
225 return (!found.empty());
242 float bestScore(0.
f);
243 std::sort(vertexScoreList.begin(), vertexScoreList.end());
245 for (
const VertexScore &vertexScore : vertexScoreList)
250 if (!selectedVertexList.empty() && !this->
AcceptVertexLocation(vertexScore.GetVertex(), selectedVertexList))
256 selectedVertexList.push_back(vertexScore.GetVertex());
261 if (vertexScore.GetScore() > bestScore)
262 bestScore = vertexScore.GetScore();
270 const CartesianVector &position(pVertex->GetPosition());
273 for (
const Vertex *
const pSelectedVertex : selectedVertexList)
275 if (pVertex == pSelectedVertex)
278 if ((position - pSelectedVertex->GetPosition()).GetMagnitudeSquared() < minCandidateDisplacementSquared)
289 const CartesianVector deltaPosition(pRhs->GetPosition() - pLhs->GetPosition());
291 if (std::fabs(deltaPosition.GetZ()) > std::numeric_limits<float>::epsilon())
292 return (deltaPosition.GetZ() > std::numeric_limits<float>::epsilon());
294 if (std::fabs(deltaPosition.GetX()) > std::numeric_limits<float>::epsilon())
295 return (deltaPosition.GetX() > std::numeric_limits<float>::epsilon());
298 return (deltaPosition.GetY() > std::numeric_limits<float>::epsilon());
304 const float slidingFitPitch) :
305 m_minLayerDirection(0.
f, 0.
f, 0.
f),
306 m_maxLayerDirection(0.
f, 0.
f, 0.
f),
307 m_minLayerPosition(0.
f, 0.
f, 0.
f),
308 m_maxLayerPosition(0.
f, 0.
f, 0.
f),
321 const float slidingFitPitch) :
322 m_clusterList(clusterList),
323 m_coordinateVector(this->GetClusterListCoordinateVector(clusterList)),
324 m_twoDSlidingFitResult(&m_coordinateVector, slidingFitWindow, slidingFitPitch)
332 CartesianPointVector coordinateVector;
334 for (
const Cluster *
const pCluster : clusterList)
336 CartesianPointVector clusterCoordinateVector;
339 coordinateVector.insert(coordinateVector.end(), std::make_move_iterator(clusterCoordinateVector.begin()),
340 std::make_move_iterator(clusterCoordinateVector.end()));
343 return coordinateVector;
351 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
354 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
357 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
360 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
363 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
366 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
369 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
372 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
375 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
378 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
381 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
384 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
387 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
390 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
393 return STATUS_CODE_SUCCESS;
float m_minCandidateScoreFraction
Ignore other top-scoring candidates with score less than a fraction of original.
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.
Header file for the kd tree linker algo template class.
void SetConstants(const float minZCoordinate, const float decayConstant)
Set the beam constants.
pandora::CartesianPointVector GetClusterListCoordinateVector(const pandora::ClusterList &clusterList) const
Get the coordinate vector for a cluster list.
virtual void FilterVertexList(const pandora::VertexList *const pInputVertexList, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, pandora::VertexVector &filteredVertices) const
Filter the input list of vertices to obtain a reduced number of vertex candidates.
pandora::StatusCode Run()
std::string m_outputVertexListName
The name under which to save the output vertex list.
pandora::StringVector m_inputCaloHitListNames
The list of calo hit list names.
void GetClusterLists(const pandora::StringVector &inputClusterListNames, pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const
Get the cluster lists.
Class that implements the KDTree partition of 2D space and a closest point search algorithm...
void CalculateClusterSlidingFits(const pandora::ClusterList &inputClusterList, const unsigned int minClusterCaloHits, const unsigned int slidingFitWindow, SlidingFitDataList &slidingFitDataList) const
Calculate the cluster sliding fits.
Box structure used to define 2D field. It's used in KDTree building step to divide the detector space...
pandora::CartesianVector m_minLayerPosition
The position of the fit at the max layer.
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
pandora::CartesianVector GetGlobalMinLayerDirection() const
Get global direction corresponding to the fit result in minimum fit layer.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
bool empty()
Whether the tree is empty.
bool IsVertexOnHit(const pandora::Vertex *const pVertex, const pandora::HitType hitType, HitKDTree2D &kdTree) const
Whether the vertex lies on a hit in the specified view.
std::vector< SlidingFitData > SlidingFitDataList
pandora::CartesianVector m_maxLayerDirection
The direction of the fit at the min layer.
bool AcceptVertexLocation(const pandora::Vertex *const pVertex, const pandora::VertexList &selectedVertexList) const
Whether to accept a candidate vertex, based on its spatial position in relation to other selected can...
Header file for the geometry helper class.
std::vector< HitKDNode2D > HitKDNode2DList
void search(const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM > > &resRecHitList)
Search in the KDTree for all points that would be contained in the given searchbox The founded points...
virtual void GetBeamConstants(const pandora::VertexVector &vertexVector, BeamConstants &beamConstants) const
Get the beam score constants for a provided list of candidate vertices.
ShowerCluster(const pandora::ClusterList &clusterList, const int slidingFitWindow, const float slidingFitPitch)
Constructor.
unsigned int m_maxTopScoreSelections
Max number of top-scoring vertex candidate to select for output.
pandora::CartesianVector m_minLayerDirection
The direction of the fit at the min layer.
bool IsVertexInGap(const pandora::Vertex *const pVertex, const pandora::HitType hitType) const
Whether the vertex lies in a registered gap.
Header file for the cluster helper class.
SlidingFitData(const pandora::Cluster *const pCluster, const int slidingFitWindow, const float slidingFitPitch)
Constructor.
Header file for the vertex selection base algorithm class.
pandora::CartesianVector m_maxLayerPosition
The position of the fit at the max layer.
bool m_useDetectorGaps
Whether to account for registered detector gaps in vertex selection.
static bool SortByVertexZPosition(const pandora::Vertex *const pLhs, const pandora::Vertex *const pRhs)
Sort vertices by increasing z position.
pandora::CartesianVector GetGlobalMinLayerPosition() const
Get global position corresponding to the fit result in minimum fit layer.
void InitializeKDTrees(HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW) const
Initialize kd trees with details of hits in algorithm-configured cluster lists.
std::vector< VertexScore > VertexScoreList
std::vector< art::Ptr< recob::Cluster > > ClusterVector
bool m_beamMode
Whether to run in beam mode, assuming neutrinos travel in positive z-direction.
bool m_isEmptyViewAcceptable
Whether views entirely empty of hits are classed as 'acceptable' for candidate filtration.
bool m_selectSingleVertex
Whether to make a final decision and select just one vertex candidate.
unsigned int m_minVertexAcceptableViews
The minimum number of views in which a candidate must sit on/near a hit or in a gap (or view can be e...
pandora::CartesianVector GetGlobalMaxLayerDirection() const
Get global direction corresponding to the fit result in maximum fit layer.
static void GetCoordinateVector(const pandora::Cluster *const pCluster, pandora::CartesianPointVector &coordinateVector)
Get vector of hit coordinates from an input cluster.
virtual void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const =0
Get the vertex score list for a provided list of candidate vertices.
KDTreeBox fill_and_bound_2d_kd_tree(const MANAGED_CONTAINER< const T * > &points, std::vector< KDTreeNodeInfoT< const T *, 2 > > &nodes)
fill_and_bound_2d_kd_tree
void SelectTopScoreVertices(VertexScoreList &vertexScoreList, pandora::VertexList &selectedVertexList) const
From the top-scoring candidate vertices, select a subset for further investigation.
float m_nDecayLengthsInZSpan
The number of score decay lengths to use over the course of the vertex z-span.
float m_minCandidateDisplacement
Ignore other top-scoring candidates located in close proximity to original.
bool m_replaceCurrentVertexList
Whether to replace the current vertex list with the output list.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region
std::list< Vertex > VertexList
float m_gapTolerance
The tolerance to use when querying whether a sampling point is in a gap, units cm.
pandora::CartesianVector GetGlobalMaxLayerPosition() const
Get global position corresponding to the fit result in maximum fit layer.
TwoDSlidingFitResult class.
float m_maxOnHitDisplacement
Max hit-vertex displacement for declaring vertex to lie on a hit in each view.
static bool IsInGap3D(const pandora::Pandora &pandora, const pandora::CartesianVector &testPoint3D, const pandora::HitType hitType, const float gapTolerance=0.f)
Whether a 3D test point lies in a registered gap with the associated hit type.
void build(std::vector< KDTreeNodeInfoT< DATA, DIM > > &eltList, const KDTreeBoxT< DIM > ®ion)
Build the KD tree from the "eltList" in the space define by "region".
std::vector< art::Ptr< recob::Vertex > > VertexVector