9 #include "Pandora/AlgorithmHeaders.h"
21 TwoDSlidingFitMultiSplitAlgorithm::TwoDSlidingFitMultiSplitAlgorithm() : m_slidingFitHalfWindow(15), m_inputClusterList(
"")
29 std::string originalListName;
30 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentListName<Cluster>(*
this, originalListName));
34 const StatusCode statusCode(PandoraContentApi::ReplaceCurrentList<Cluster>(*
this,
m_inputClusterList));
36 if (STATUS_CODE_NOT_FOUND == statusCode)
39 return STATUS_CODE_SUCCESS;
42 if (STATUS_CODE_SUCCESS != statusCode)
46 const ClusterList *pClusterList = NULL;
47 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
62 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->
SplitClusters(slidingFitResultMap, clusterSplittingMap));
65 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*
this, originalListName));
67 return STATUS_CODE_SUCCESS;
77 for (ClusterVector::const_iterator iter = clusterVector.begin(), iterEnd = clusterVector.end(); iter != iterEnd; ++iter)
79 if (slidingFitResultMap.end() == slidingFitResultMap.find(*iter))
85 if (!slidingFitResultMap.insert(TwoDSlidingFitResultMap::value_type(*iter, slidingFitResult)).second)
86 throw StatusCodeException(STATUS_CODE_FAILURE);
88 catch (StatusCodeException &statusCodeException)
90 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
91 throw statusCodeException;
102 ClusterList clusterList;
103 for (
const auto &mapEntry : clusterSplittingMap)
104 clusterList.push_back(mapEntry.first);
107 for (
const Cluster *
const pCluster : clusterList)
109 const CartesianPointVector &splitPositionVector(clusterSplittingMap.at(pCluster));
111 if (splitPositionVector.empty())
114 TwoDSlidingFitResultMap::const_iterator sIter = slidingFitResultMap.find(pCluster);
115 if (slidingFitResultMap.end() == sIter)
116 throw StatusCodeException(STATUS_CODE_FAILURE);
120 StatusCode statusCode(this->
SplitCluster(slidingFitResult, splitPositionVector));
122 if (STATUS_CODE_SUCCESS != statusCode)
126 return STATUS_CODE_SUCCESS;
133 const Cluster *
const pCluster = slidingFitResult.
GetCluster();
136 FloatVector displacementVector;
138 for (CartesianPointVector::const_iterator pIter = splitPositionVector.begin(), pIterEnd = splitPositionVector.end(); pIter != pIterEnd; ++pIter)
140 const CartesianVector &splitPosition = *pIter;
142 float rL(0.f), rT(0.f);
144 displacementVector.push_back(rL);
147 const float bigL(2.f * slidingFitResult.
GetL(slidingFitResult.
GetMaxLayer()));
148 displacementVector.push_back(-bigL);
149 displacementVector.push_back(+bigL);
151 std::sort(displacementVector.begin(), displacementVector.end());
154 const ClusterList clusterList(1, pCluster);
155 std::string clusterListToSave, clusterListToDelete;
157 PANDORA_RETURN_RESULT_IF(
158 STATUS_CODE_SUCCESS, !=, PandoraContentApi::InitializeFragmentation(*
this, clusterList, clusterListToDelete, clusterListToSave));
160 CaloHitList oldCaloHitList;
161 pCluster->GetOrderedCaloHitList().FillCaloHitList(oldCaloHitList);
163 bool foundPreviousL(
false);
166 for (FloatVector::const_iterator fIter = displacementVector.begin(), fIterEnd = displacementVector.end(); fIter != fIterEnd; ++fIter)
168 const float nextL(*fIter);
173 CaloHitList newCaloHitList;
175 for (CaloHitList::const_iterator hIter = oldCaloHitList.begin(), hIterEnd = oldCaloHitList.end(); hIter != hIterEnd; ++hIter)
177 const CaloHit *
const pCaloHit = *hIter;
179 float rL(0.f), rT(0.f);
182 if (rL >= prevL && rL < nextL)
183 newCaloHitList.push_back(pCaloHit);
186 if (newCaloHitList.empty())
191 newParameters.m_caloHitList = newCaloHitList;
193 const Cluster *pNewCluster(NULL);
194 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*
this, newParameters, pNewCluster));
198 foundPreviousL =
true;
202 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::EndFragmentation(*
this, clusterListToSave, clusterListToDelete));
204 return STATUS_CODE_SUCCESS;
211 PANDORA_RETURN_RESULT_IF_AND_IF(
212 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"InputClusterListName",
m_inputClusterList));
214 PANDORA_RETURN_RESULT_IF_AND_IF(
215 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SlidingFitHalfWindow",
m_slidingFitHalfWindow));
217 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.
virtual void GetListOfCleanClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const =0
Populate cluster vector with subset of cluster list, containing clusters judged to be clean...
unsigned int m_slidingFitHalfWindow
pandora::StatusCode Run()
std::string m_inputClusterList
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
pandora::StatusCode SplitClusters(const TwoDSlidingFitResultMap &slidingFitResultMap, const ClusterPositionMap &clusterSplittingMap) const
Split clusters.
Header file for the geometry helper class.
void BuildSlidingFitResultMap(const pandora::ClusterVector &clusterVector, const unsigned int halfWindowLayers, TwoDSlidingFitResultMap &slidingFitResultMap) const
Build the map of sliding fit results.
int GetMaxLayer() const
Get the maximum occupied layer in the sliding fit.
std::unordered_map< const pandora::Cluster *, pandora::CartesianPointVector > ClusterPositionMap
Header file for the cluster helper class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::Cluster *, TwoDSlidingFitResult > TwoDSlidingFitResultMap
fhicl::Table< sbnd::crt::CRTDetSimParams > Parameters
const pandora::Cluster * GetCluster() const
Get the address of the cluster, if originally provided.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Header file for the 2D sliding fit multi-split algorithm class.
float GetL(const int layer) const
Get longitudinal coordinate for a given sliding linear fit layer number.
virtual void FindBestSplitPositions(const TwoDSlidingFitResultMap &slidingFitResultMap, ClusterPositionMap &clusterSplittingMap) const =0
Determine best split positions based on sliding fit result.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
pandora::StatusCode SplitCluster(const TwoDSlidingFitResult &slidingFitResult, const pandora::CartesianPointVector &splitPositionList) const
Split cluster.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
TwoDSlidingFitResult class.
BEGIN_PROLOG could also be cout