9 #include "Pandora/AlgorithmHeaders.h" 21 TwoDSlidingFitMultiSplitAlgorithm::TwoDSlidingFitMultiSplitAlgorithm() :
22 m_slidingFitHalfWindow(15),
23 m_inputClusterList(
"")
31 std::string originalListName;
32 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentListName<Cluster>(*
this, originalListName));
36 const StatusCode statusCode(PandoraContentApi::ReplaceCurrentList<Cluster>(*
this,
m_inputClusterList));
38 if (STATUS_CODE_NOT_FOUND == statusCode)
40 std::cout <<
"TwoDSlidingFitMultiSplitAlgorithm: cluster list not found " <<
m_inputClusterList << std::endl;
41 return STATUS_CODE_SUCCESS;
44 if (STATUS_CODE_SUCCESS != statusCode)
48 const ClusterList *pClusterList = NULL;
49 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
64 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->
SplitClusters(slidingFitResultMap, clusterSplittingMap));
67 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*
this, originalListName));
69 return STATUS_CODE_SUCCESS;
79 if (slidingFitResultMap.end() == slidingFitResultMap.find(*iter))
86 if (!slidingFitResultMap.insert(TwoDSlidingFitResultMap::value_type(*iter, slidingFitResult)).second)
87 throw StatusCodeException(STATUS_CODE_FAILURE);
89 catch (StatusCodeException &statusCodeException)
91 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
92 throw statusCodeException;
103 ClusterList clusterList;
104 for (
const auto &mapEntry : clusterSplittingMap)
105 clusterList.push_back(mapEntry.first);
108 for (
const Cluster *
const pCluster : clusterList)
110 const CartesianPointVector &splitPositionVector(clusterSplittingMap.at(pCluster));
112 if (splitPositionVector.empty())
116 if (slidingFitResultMap.end() == sIter)
117 throw StatusCodeException(STATUS_CODE_FAILURE);
121 StatusCode statusCode(this->
SplitCluster(slidingFitResult, splitPositionVector));
123 if (STATUS_CODE_SUCCESS != statusCode)
127 return STATUS_CODE_SUCCESS;
134 const Cluster *
const pCluster = slidingFitResult.
GetCluster();
137 FloatVector displacementVector;
141 const CartesianVector &splitPosition = *pIter;
143 float rL(0.
f), rT(0.
f);
145 displacementVector.push_back(rL);
148 const float bigL(2.
f * slidingFitResult.
GetL(slidingFitResult.
GetMaxLayer()));
149 displacementVector.push_back(-bigL);
150 displacementVector.push_back(+bigL);
152 std::sort(displacementVector.begin(), displacementVector.end());
155 const ClusterList clusterList(1, pCluster);
156 std::string clusterListToSave, clusterListToDelete;
158 PANDORA_RETURN_RESULT_IF(
159 STATUS_CODE_SUCCESS, !=, PandoraContentApi::InitializeFragmentation(*
this, clusterList, clusterListToDelete, clusterListToSave));
161 CaloHitList oldCaloHitList;
162 pCluster->GetOrderedCaloHitList().FillCaloHitList(oldCaloHitList);
164 bool foundPreviousL(
false);
167 for (
FloatVector::const_iterator fIter = displacementVector.begin(), fIterEnd = displacementVector.end(); fIter != fIterEnd; ++fIter)
169 const float nextL(*fIter);
174 CaloHitList newCaloHitList;
178 const CaloHit *
const pCaloHit = *hIter;
180 float rL(0.
f), rT(0.
f);
183 if (rL >= prevL && rL < nextL)
184 newCaloHitList.push_back(pCaloHit);
187 if (newCaloHitList.empty())
191 PandoraContentApi::Cluster::Parameters newParameters;
192 newParameters.m_caloHitList = newCaloHitList;
194 const Cluster *pNewCluster(NULL);
195 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*
this, newParameters, pNewCluster));
199 foundPreviousL =
true;
203 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::EndFragmentation(*
this, clusterListToSave, clusterListToDelete));
205 return STATUS_CODE_SUCCESS;
212 PANDORA_RETURN_RESULT_IF_AND_IF(
213 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"InputClusterListName",
m_inputClusterList));
215 PANDORA_RETURN_RESULT_IF_AND_IF(
216 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SlidingFitHalfWindow",
m_slidingFitHalfWindow));
218 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.
unsigned int m_slidingFitHalfWindow
virtual void FindBestSplitPositions(const TwoDSlidingFitResultMap &slidingFitResultMap, ClusterPositionMap &clusterSplittingMap) const =0
Determine best split positions based on sliding fit result.
pandora::StatusCode Run()
std::string m_inputClusterList
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
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.
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...
std::unordered_map< const pandora::Cluster *, pandora::CartesianPointVector > ClusterPositionMap
Header file for the cluster helper class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static float GetWirePitch(const pandora::Pandora &pandora, const pandora::HitType view, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
std::unordered_map< const pandora::Cluster *, TwoDSlidingFitResult > TwoDSlidingFitResultMap
const pandora::Cluster * GetCluster() const
Get the address of the cluster, if originally provided.
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.
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.