9 #include "Pandora/AlgorithmHeaders.h" 22 ThreeDKinkBaseTool::ThreeDKinkBaseTool(
const unsigned int nCommonClusters) :
23 m_nCommonClusters(nCommonClusters),
24 m_majorityRulesMode(false),
25 m_minMatchedFraction(0.75
f),
26 m_minMatchedSamplingPoints(10),
27 m_minLongitudinalImpactParameter(-1.
f),
28 m_nLayersForKinkSearch(10),
29 m_additionalXStepForKinkSearch(0.01
f)
32 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
45 if (usedClusters.count(eIter->GetClusterU()) || usedClusters.count(eIter->GetClusterV()) || usedClusters.count(eIter->GetClusterW()))
72 if (isForwardInX && ((commonX > xMax1) || (commonX > xMax2) || (commonX > xMax3)))
73 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
75 if (!isForwardInX && ((commonX < xMin1) || (commonX < xMin2) || (commonX < xMin3)))
76 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
79 float rL1(0.
f), rT1(0.
f);
81 const int splitLayer(fitResult1.
GetLayer(rL1));
86 CartesianVector minus(0.
f, 0.
f, 0.
f), plus(0.
f, 0.
f, 0.
f);
90 if (minus.GetX() > plus.GetX())
92 CartesianVector temporary(minus);
97 const float layerStepX(isForwardInX ? plus.GetX() : minus.GetX());
100 const float chosenX(isForwardInX ?
std::max(layerStepX, commonX) :
std::min(layerStepX, commonX));
128 if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
129 std::cout <<
"----> Running Algorithm Tool: " << this->GetInstanceName() <<
", " << this->GetType() << std::endl;
133 const bool changesMade(this->
ApplyChanges(pAlgorithm, modificationList));
142 ClusterSet usedClusters;
146 for (
const Cluster *
const pKeyCluster : sortedKeyClusters)
148 if (!pKeyCluster->IsAvailable())
151 unsigned int nU(0), nV(0), nW(0);
155 if (nU * nV * nW < 2)
166 if (iteratorList.size() < 2)
172 if (localModificationList.empty())
177 usedClusters.insert(mIter->m_affectedClusters.begin(), mIter->m_affectedClusters.end());
180 modificationList.insert(modificationList.end(), localModificationList.begin(), localModificationList.end());
192 for (
const Modification &modification : modificationList)
194 ClusterList parentClusters;
195 for (
const auto &mapEntry : modification.m_clusterMergeMap) parentClusters.push_back(mapEntry.first);
198 for (
const Cluster *
const pParentCluster : parentClusters)
200 const ClusterList &daughterClusters(modification.m_clusterMergeMap.at(pParentCluster));
202 for (
const Cluster *
const pDaughterCluster : daughterClusters)
204 if (consolidatedMergeMap.count(pDaughterCluster))
205 throw StatusCodeException(STATUS_CODE_FAILURE);
208 ClusterList &targetClusterList(consolidatedMergeMap[pParentCluster]);
209 targetClusterList.insert(targetClusterList.end(), daughterClusters.begin(), daughterClusters.end());
212 ClusterList splitClusters;
213 for (
const auto &mapEntry : modification.m_splitPositionMap) splitClusters.push_back(mapEntry.first);
216 for (
const Cluster *
const pSplitCluster : splitClusters)
218 const CartesianPointVector &splitPositions(modification.m_splitPositionMap.at(pSplitCluster));
220 CartesianPointVector &cartesianPointVector(consolidatedSplitMap[pSplitCluster]);
221 cartesianPointVector.insert(cartesianPointVector.end(), splitPositions.begin(), splitPositions.end());
225 bool changesMade(
false);
235 const ClusterSet &usedClusters,
IteratorList &iteratorList)
const 237 iteratorList.push_back(eIter);
249 if ((*iIter) == eIter2)
252 unsigned int nMatchedClusters(0);
254 if ((*iIter)->GetClusterU() == eIter2->GetClusterU())
257 if ((*iIter)->GetClusterV() == eIter2->GetClusterV())
260 if ((*iIter)->GetClusterW() == eIter2->GetClusterW())
265 iteratorList.push_back(eIter2);
276 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
279 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
282 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
285 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
288 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
291 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
294 return STATUS_CODE_SUCCESS;
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.
std::vector< Modification > ModificationList
float GetXSamplingPoint(const pandora::CartesianVector &splitPosition1, const bool isForwardInX, const TwoDSlidingFitResult &fitResult1, const TwoDSlidingFitResult &fitResult2, const TwoDSlidingFitResult &fitResult3) const
Get a sampling point in x that is common to sliding linear fit objects in three views.
std::unordered_map< const pandora::Cluster *, pandora::CartesianPointVector > SplitPositionMap
Header file for the lar pointing cluster class.
virtual bool MakeClusterSplits(const SplitPositionMap &splitPositionMap)
Make cluster splits.
void GetMinAndMaxX(float &minX, float &maxX) const
Get the minimum and maximum x coordinates associated with the sliding fit.
std::vector< TensorType::ElementList::const_iterator > IteratorList
virtual void GetIteratorListModifications(ThreeDTransverseTracksAlgorithm *const pAlgorithm, const IteratorList &iteratorList, ModificationList &modificationList) const =0
Get modification objects for a specific elements of the tensor, identifying required splits and merge...
unsigned int m_nCommonClusters
The number of common clusters.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
LArPointingCluster class.
virtual ~ThreeDKinkBaseTool()
Destructor.
int GetMaxLayer() const
Get the maximum occupied layer in the sliding fit.
std::vector< Element > ElementList
bool Run(ThreeDTransverseTracksAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.
int GetMinLayer() const
Get the minimum occupied layer in the sliding fit.
int m_nLayersForKinkSearch
The number of sliding fit layers to step in the kink search.
Header file for the cluster helper class.
pandora::StatusCode GetGlobalFitPosition(const float rL, pandora::CartesianVector &position) const
Get global fit position for a given longitudinal coordinate.
const Vertex & GetOuterVertex() const
Get the outer vertex.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
const Vertex & GetInnerVertex() const
Get the inner vertex.
void SelectTensorElements(TensorType::ElementList::const_iterator eIter, const TensorType::ElementList &elementList, const pandora::ClusterSet &usedClusters, IteratorList &iteratorList) const
Select elements representing possible components of interest due to overshoots or undershoots in clus...
virtual bool PassesElementCuts(TensorType::ElementList::const_iterator eIter, const pandora::ClusterSet &usedClusters) const
Whether a provided (iterator to a) tensor element passes the selection cuts for overshoot identificat...
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
static bool IsALowestInX(const LArPointingCluster &pointingClusterA, const LArPointingCluster &pointingClusterB)
Whether pointing cluster labelled A extends to lowest x positions (as opposed to that labelled B) ...
std::vector< art::Ptr< recob::Cluster > > ClusterVector
float m_additionalXStepForKinkSearch
An additional (safety) step to tack-on when choosing x sampling points.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
unsigned int m_minMatchedSamplingPoints
The min number of matched sampling points for use as a key tensor element.
float GetL(const int layer) const
Get longitudinal coordinate for a given sliding linear fit layer number.
bool m_majorityRulesMode
Whether to run in majority rules mode (always split overshoots, always merge undershoots) ...
float m_minLongitudinalImpactParameter
The min longitudinal impact parameter for connecting accompanying clusters.
bool ApplyChanges(ThreeDTransverseTracksAlgorithm *const pAlgorithm, const ModificationList &modificationList) const
Apply the changes cached in a modification list and update the tensor accordingly.
float m_minMatchedFraction
The min matched sampling point fraction for use as a key tensor element.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
TwoDSlidingFitResult class.
int GetLayer(const float rL) const
Get layer number for given sliding linear fit longitudinal coordinate.
ThreeDTransverseTracksAlgorithm class.
TheTensor::const_iterator const_iterator
void GetModifications(ThreeDTransverseTracksAlgorithm *const pAlgorithm, const TensorType &overlapTensor, ModificationList &modificationList) const
Get modification objects, identifying required splits and merges for clusters.
virtual bool MakeClusterMerges(const ClusterMergeMap &clusterMergeMap)
Merge clusters together.