Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ConeClusterMopUpAlgorithm.cc
Go to the documentation of this file.
1
10
13
15
17
18using namespace pandora;
19
20namespace lar_content
21{
22
24 m_slidingFitWindow(20),
25 m_showerEdgeMultiplier(1.5f),
26 m_coneAngleCentile(0.85f),
27 m_maxConeLengthMultiplier(1.5f),
28 m_minBoundedFraction(0.5f)
29{
30}
31
32//------------------------------------------------------------------------------------------------------------------------------------------
33
34void ConeClusterMopUpAlgorithm::ClusterMopUp(const ClusterList &pfoClusters, const ClusterList &remnantClusters) const
35{
36 ClusterAssociationMap clusterAssociationMap;
37 const float slidingFitPitch(LArGeometryHelper::GetWireZPitch(this->GetPandora()));
38
39 const VertexList *pVertexList(NULL);
40 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pVertexList));
41
42 if ((pVertexList->size() != 1) || (VERTEX_3D != (*(pVertexList->begin()))->GetVertexType()))
43 return;
44
45 const Vertex *const pVertex(*(pVertexList->begin()));
46
47 ClusterVector sortedPfoClusters(pfoClusters.begin(), pfoClusters.end());
48 std::sort(sortedPfoClusters.begin(), sortedPfoClusters.end(), LArClusterHelper::SortByNHits);
49
50 ClusterVector sortedRemnantClusters(remnantClusters.begin(), remnantClusters.end());
51 std::sort(sortedRemnantClusters.begin(), sortedRemnantClusters.end(), LArClusterHelper::SortByNHits);
52
53 for (const Cluster *const pPfoCluster : sortedPfoClusters)
54 {
55 try
56 {
57 const TwoDSlidingShowerFitResult showerFitResult(pPfoCluster, m_slidingFitWindow, slidingFitPitch, m_showerEdgeMultiplier);
58
59 const LayerFitResultMap &layerFitResultMapS(showerFitResult.GetShowerFitResult().GetLayerFitResultMap());
60 const LayerFitResultMap &layerFitResultMapP(showerFitResult.GetPositiveEdgeFitResult().GetLayerFitResultMap());
61 const LayerFitResultMap &layerFitResultMapN(showerFitResult.GetNegativeEdgeFitResult().GetLayerFitResultMap());
62
63 if (layerFitResultMapS.size() < 2)
64 continue;
65
66 // Cone direction
67 CartesianVector minLayerPositionOnAxis(0.f, 0.f, 0.f), maxLayerPositionOnAxis(0.f, 0.f, 0.f);
68 showerFitResult.GetShowerFitResult().GetGlobalPosition(layerFitResultMapS.begin()->second.GetL(), 0.f, minLayerPositionOnAxis);
69 showerFitResult.GetShowerFitResult().GetGlobalPosition(layerFitResultMapS.rbegin()->second.GetL(), 0.f, maxLayerPositionOnAxis);
70
71 const HitType hitType(LArClusterHelper::GetClusterHitType(pPfoCluster));
72 const CartesianVector vertexPosition2D(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), hitType));
73 const bool vertexAtMinL((vertexPosition2D - minLayerPositionOnAxis).GetMagnitudeSquared() <
74 (vertexPosition2D - maxLayerPositionOnAxis).GetMagnitudeSquared());
75
76 // Cone edges
77 CoordinateList coordinateListP, coordinateListN;
78
79 for (LayerFitResultMap::const_iterator iterS = layerFitResultMapS.begin(); iterS != layerFitResultMapS.end(); ++iterS)
80 {
81 LayerFitResultMap::const_iterator iterP = layerFitResultMapP.find(iterS->first);
82 LayerFitResultMap::const_iterator iterN = layerFitResultMapN.find(iterS->first);
83
84 if (layerFitResultMapP.end() != iterP)
85 coordinateListP.push_back(Coordinate(iterP->second.GetL(), iterP->second.GetFitT()));
86
87 if (layerFitResultMapN.end() != iterN)
88 coordinateListN.push_back(Coordinate(iterN->second.GetL(), iterN->second.GetFitT()));
89 }
90
91 if (coordinateListP.empty() || coordinateListN.empty())
92 continue;
93
94 std::sort(coordinateListP.begin(), coordinateListP.end(), ConeClusterMopUpAlgorithm::SortCoordinates);
95 std::sort(coordinateListN.begin(), coordinateListN.end(), ConeClusterMopUpAlgorithm::SortCoordinates);
96
97 const Coordinate maxP(coordinateListP.at(m_coneAngleCentile * coordinateListP.size()));
98 const Coordinate minP(vertexAtMinL
99 ? Coordinate(layerFitResultMapP.begin()->second.GetL(), layerFitResultMapP.begin()->second.GetFitT())
100 : Coordinate(layerFitResultMapP.rbegin()->second.GetL(), layerFitResultMapP.rbegin()->second.GetFitT()));
101
102 const Coordinate maxN(coordinateListN.at((1.f - m_coneAngleCentile) * coordinateListN.size()));
103 const Coordinate minN(vertexAtMinL
104 ? Coordinate(layerFitResultMapN.begin()->second.GetL(), layerFitResultMapN.begin()->second.GetFitT())
105 : Coordinate(layerFitResultMapN.rbegin()->second.GetL(), layerFitResultMapN.rbegin()->second.GetFitT()));
106
107 const float minL(layerFitResultMapS.begin()->second.GetL());
108 const float maxL(minL + m_maxConeLengthMultiplier * std::fabs(layerFitResultMapS.rbegin()->second.GetL() - minL));
109
110 if ((std::fabs(maxP.first - minP.first) < std::numeric_limits<float>::epsilon()) ||
111 (std::fabs(maxN.first - minN.first) < std::numeric_limits<float>::epsilon()) ||
112 (std::fabs(maxL - minL) < std::numeric_limits<float>::epsilon()))
113 {
114 continue;
115 }
116
117 // Bounded fraction calculation
118 for (const Cluster *const pRemnantCluster : sortedRemnantClusters)
119 {
120 const unsigned int nHits(pRemnantCluster->GetNCaloHits());
121
122 unsigned int nMatchedHits(0);
123 const OrderedCaloHitList &orderedCaloHitList(pRemnantCluster->GetOrderedCaloHitList());
124
125 for (OrderedCaloHitList::const_iterator iter = orderedCaloHitList.begin(), iterEnd = orderedCaloHitList.end(); iter != iterEnd; ++iter)
126 {
127 for (CaloHitList::const_iterator hIter = iter->second->begin(), hIterEnd = iter->second->end(); hIter != hIterEnd; ++hIter)
128 {
129 float rL(0.f), rT(0.f);
130 showerFitResult.GetShowerFitResult().GetLocalPosition((*hIter)->GetPositionVector(), rL, rT);
131
132 if ((rL < minL) || (rL > maxL))
133 continue;
134
135 const float rTP(minP.second + (rL - minP.first) * ((maxP.second - minP.second) / (maxP.first - minP.first)));
136 const float rTN(minN.second + (rL - minN.first) * ((maxN.second - minN.second) / (maxN.first - minN.first)));
137
138 if ((rT > rTP) || (rT < rTN))
139 continue;
140
141 ++nMatchedHits;
142 }
143 }
144
145 const float boundedFraction((nHits > 0) ? static_cast<float>(nMatchedHits) / static_cast<float>(nHits) : 0.f);
146
147 if (boundedFraction < m_minBoundedFraction)
148 continue;
149
150 AssociationDetails &associationDetails(clusterAssociationMap[pRemnantCluster]);
151
152 if (!associationDetails.insert(AssociationDetails::value_type(pPfoCluster, boundedFraction)).second)
153 throw StatusCodeException(STATUS_CODE_FAILURE);
154 }
155 }
156 catch (StatusCodeException &statusCodeException)
157 {
158 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
159 throw statusCodeException;
160 }
161 }
162
163 this->MakeClusterMerges(clusterAssociationMap);
164}
165
166//------------------------------------------------------------------------------------------------------------------------------------------
167
169{
170 return (lhs.second < rhs.second);
171}
172
173//------------------------------------------------------------------------------------------------------------------------------------------
174
176{
178 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitWindow", m_slidingFitWindow));
179
181 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ShowerEdgeMultiplier", m_showerEdgeMultiplier));
182
184 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ConeAngleCentile", m_coneAngleCentile));
185
186 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
187 XmlHelper::ReadValue(xmlHandle, "MaxConeLengthMultiplier", m_maxConeLengthMultiplier));
188
190 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinBoundedFraction", m_minBoundedFraction));
191
193}
194
195} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the cone cluster mop up algorithm class.
Header file for the cluster helper class.
Header file for the geometry helper class.
Header file for the lar two dimensional sliding shower fit result class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
static pandora::StatusCode GetCurrentList(const pandora::Algorithm &algorithm, const T *&pT)
Get the current list.
std::unordered_map< const pandora::Cluster *, AssociationDetails > ClusterAssociationMap
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
virtual void MakeClusterMerges(const ClusterAssociationMap &clusterAssociationMap) const
Make the cluster merges specified in the cluster association map, using list name information in the ...
std::unordered_map< const pandora::Cluster *, float > AssociationDetails
static bool SortCoordinates(const Coordinate &lhs, const Coordinate &rhs)
Sort coordinates by increasing transverse displacement.
float m_minBoundedFraction
The minimum cluster bounded fraction for merging.
float m_maxConeLengthMultiplier
Consider hits as bound if inside cone, with projected distance less than N times cone length.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
void ClusterMopUp(const pandora::ClusterList &pfoClusters, const pandora::ClusterList &remnantClusters) const
Cluster mop up for a single view. This function is responsible for instructing pandora to make cluste...
float m_showerEdgeMultiplier
Artificially tune width of shower envelope so as to make it more/less inclusive.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
float m_coneAngleCentile
Cluster cone angle is defined using specified centile of distribution of hit half angles.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
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,...
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
const LayerFitResultMap & GetLayerFitResultMap() const
Get the layer fit result map.
void GetGlobalPosition(const float rL, const float rT, pandora::CartesianVector &position) const
Get global coordinates for given sliding linear fit coordinates.
const TwoDSlidingFitResult & GetNegativeEdgeFitResult() const
Get the sliding fit result for the negative shower edge.
const TwoDSlidingFitResult & GetShowerFitResult() const
Get the sliding fit result for the full shower cluster.
const TwoDSlidingFitResult & GetPositiveEdgeFitResult() const
Get the sliding fit result for the positive shower edge.
CartesianVector class.
Cluster class.
Definition Cluster.h:31
Calo hit lists arranged by pseudo layer.
const_iterator end() const
Returns a const iterator referring to the past-the-end element in the ordered calo hit list.
const_iterator begin() const
Returns a const iterator referring to the first element in the ordered calo hit list.
TheList::const_iterator const_iterator
const Pandora & GetPandora() const
Get the associated pandora instance.
Definition Process.h:116
StatusCodeException class.
StatusCode GetStatusCode() const
Get status code.
Vertex class.
Definition Vertex.h:26
const CartesianVector & GetPosition() const
Get the vertex position.
Definition Vertex.h:103
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
std::map< int, LayerFitResult > LayerFitResultMap
HitType
Calorimeter hit type enum.
std::vector< const Cluster * > ClusterVector
MANAGED_CONTAINER< const Cluster * > ClusterList
MANAGED_CONTAINER< const Vertex * > VertexList
StatusCode
The StatusCode enum.