LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CutClusterCharacterisationAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
13 
16 
18 
19 using namespace pandora;
20 
21 namespace lar_content
22 {
23 
24 CutClusterCharacterisationAlgorithm::CutClusterCharacterisationAlgorithm() :
25  m_slidingFitWindow(5),
26  m_slidingShowerFitWindow(10),
27  m_minCaloHitsCut(6),
28  m_maxShowerLengthCut(80.f),
29  m_pathLengthRatioCut(1.005f),
30  m_rTWidthRatioCut(0.05f),
31  m_vertexDistanceRatioCut(0.5f),
32  m_showerWidthRatioCut(0.35f)
33 {
34 }
35 
36 //------------------------------------------------------------------------------------------------------------------------------------------
37 
38 float CutClusterCharacterisationAlgorithm::GetVertexDistance(const Algorithm *const pAlgorithm, const Cluster *const pCluster)
39 {
40  const VertexList *pVertexList = nullptr;
41  (void) PandoraContentApi::GetCurrentList(*pAlgorithm, pVertexList);
42 
43  if (!pVertexList || (pVertexList->size() != 1) || (VERTEX_3D != pVertexList->front()->GetVertexType()))
44  return -1.f;
45 
46  const Vertex *const pVertex(pVertexList->front());
47  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
48 
49  const CartesianVector vertexPosition2D(LArGeometryHelper::ProjectPosition(pAlgorithm->GetPandora(), pVertex->GetPosition(), hitType));
50  return LArClusterHelper::GetClosestDistance(vertexPosition2D, pCluster);
51 }
52 
53 //------------------------------------------------------------------------------------------------------------------------------------------
54 
55 float CutClusterCharacterisationAlgorithm::GetShowerFitWidth(const Algorithm *const pAlgorithm, const Cluster *const pCluster,
56  const unsigned int showerFitWindow)
57 {
58  try
59  {
60  const TwoDSlidingShowerFitResult showerFitResult(pCluster, showerFitWindow, LArGeometryHelper::GetWireZPitch(pAlgorithm->GetPandora()));
61  const LayerFitResultMap &layerFitResultMapS(showerFitResult.GetShowerFitResult().GetLayerFitResultMap());
62  const LayerFitResultMap &layerFitResultMapP(showerFitResult.GetPositiveEdgeFitResult().GetLayerFitResultMap());
63  const LayerFitResultMap &layerFitResultMapN(showerFitResult.GetNegativeEdgeFitResult().GetLayerFitResultMap());
64 
65  if (!layerFitResultMapS.empty())
66  {
67  float showerFitWidth(0.f);
68 
69  for (const auto &mapEntryS : layerFitResultMapS)
70  {
71  LayerFitResultMap::const_iterator iterP = layerFitResultMapP.find(mapEntryS.first);
72  LayerFitResultMap::const_iterator iterN = layerFitResultMapN.find(mapEntryS.first);
73 
74  if ((layerFitResultMapP.end() != iterP) && (layerFitResultMapN.end() != iterN))
75  showerFitWidth += std::fabs(iterP->second.GetFitT() - iterN->second.GetFitT());
76  }
77 
78  return showerFitWidth;
79  }
80  }
81  catch (const StatusCodeException &)
82  {
83  }
84 
85  return -1.f;
86 }
87 
88 //------------------------------------------------------------------------------------------------------------------------------------------
89 
90 bool CutClusterCharacterisationAlgorithm::IsClearTrack(const Cluster *const pCluster) const
91 {
92  if (pCluster->GetNCaloHits() < m_minCaloHitsCut)
93  return false;
94 
95  float straightLineLength(-1.f), integratedPathLength(-1.f);
97 
98  try
99  {
100  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
101  const CartesianVector globalMinLayerPosition(slidingFitResult.GetGlobalMinLayerPosition());
102  straightLineLength = (slidingFitResult.GetGlobalMaxLayerPosition() - globalMinLayerPosition).GetMagnitude();
103 
104  integratedPathLength = 0.f;
105  CartesianVector previousFitPosition(globalMinLayerPosition);
106 
107  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
108  {
109  rTMin = std::min(rTMin, static_cast<float>(mapEntry.second.GetFitT()));
110  rTMax = std::max(rTMax, static_cast<float>(mapEntry.second.GetFitT()));
111 
112  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
113  slidingFitResult.GetGlobalPosition(mapEntry.second.GetL(), mapEntry.second.GetFitT(), thisFitPosition);
114  integratedPathLength += (thisFitPosition - previousFitPosition).GetMagnitude();
115  previousFitPosition = thisFitPosition;
116  }
117  }
118  catch (const StatusCodeException &)
119  {
120  }
121 
122  if (straightLineLength < std::numeric_limits<float>::epsilon())
123  return false;
124 
125  if (straightLineLength > m_maxShowerLengthCut)
126  return true;
127 
128  if ((integratedPathLength < std::numeric_limits<float>::epsilon()) || (integratedPathLength / straightLineLength > m_pathLengthRatioCut))
129  return false;
130 
131  if ((rTMax - rTMin) / straightLineLength > m_rTWidthRatioCut)
132  return false;
133 
134  const float vertexDistance(CutClusterCharacterisationAlgorithm::GetVertexDistance(this, pCluster));
135 
136  if ((vertexDistance > std::numeric_limits<float>::epsilon()) && ((vertexDistance / straightLineLength) > m_vertexDistanceRatioCut))
137  return false;
138 
139  const float showerFitWidth(CutClusterCharacterisationAlgorithm::GetShowerFitWidth(this, pCluster, m_slidingShowerFitWindow));
140 
141  if ((showerFitWidth < std::numeric_limits<float>::epsilon()) || ((showerFitWidth / straightLineLength) > m_showerWidthRatioCut))
142  return false;
143 
144  return true;
145 }
146 
147 //------------------------------------------------------------------------------------------------------------------------------------------
148 
149 StatusCode CutClusterCharacterisationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
150 {
151  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
152  "SlidingFitWindow", m_slidingFitWindow));
153 
154  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
155  "SlidingShowerFitWindow", m_slidingShowerFitWindow));
156 
157  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
158  "MinCaloHitsCut", m_minCaloHitsCut));
159 
160  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
161  "MaxShowerLengthCut", m_maxShowerLengthCut));
162 
163  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
164  "PathLengthRatioCut", m_pathLengthRatioCut));
165 
166  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
167  "RTWidthRatioCut", m_rTWidthRatioCut));
168 
169  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
170  "VertexDistanceRatioCut", m_vertexDistanceRatioCut));
171 
172  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
173  "ShowerWidthRatioCut", m_showerWidthRatioCut));
174 
176 }
177 
178 } // namespace lar_content
Header file for the lar two dimensional sliding shower fit result class.
Header file for the cut based cluster characterisation algorithm class.
virtual bool IsClearTrack(const pandora::Cluster *const pCluster) const
Whether cluster is identified as a clear track.
static float GetVertexDistance(const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster)
Get the distance between the interaction vertex (if present in the current vertex list) and a provide...
const TwoDSlidingFitResult & GetShowerFitResult() const
Get the sliding fit result for the full shower cluster.
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.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
float m_rTWidthRatioCut
The maximum ratio of transverse fit position width to straight line length to qualify as a track...
float m_vertexDistanceRatioCut
The maximum ratio of vertex separation to straight line length to qualify as a track.
TFile f
Definition: plotHisto.C:6
Header file for the geometry helper class.
float m_maxShowerLengthCut
The maximum cluster length to qualify as a shower.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
Header file for the cluster helper class.
unsigned int m_minCaloHitsCut
The minimum number of calo hits to qualify as a track.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the lar two dimensional sliding fit result class.
std::map< int, LayerFitResult > LayerFitResultMap
pandora::CartesianVector GetGlobalMinLayerPosition() const
Get global position corresponding to the fit result in minimum fit layer.
unsigned int m_slidingShowerFitWindow
The layer window for the sliding shower fits.
const TwoDSlidingFitResult & GetPositiveEdgeFitResult() const
Get the sliding fit result for the positive shower edge.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
const LayerFitResultMap & GetLayerFitResultMap() const
Get the layer fit result map.
Int_t min
Definition: plot.C:26
const TwoDSlidingFitResult & GetNegativeEdgeFitResult() const
Get the sliding fit result for the negative shower edge.
float m_showerWidthRatioCut
The maximum ratio of shower fit width to straight line length to qualify as a track.
void GetGlobalPosition(const float rL, const float rT, pandora::CartesianVector &position) const
Get global coordinates for given sliding linear fit coordinates.
static float GetShowerFitWidth(const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster, const unsigned int showerFitWindow)
Get a measure of the width of a cluster, using a sliding shower fit result.
std::list< Vertex > VertexList
Definition: DCEL.h:178
pandora::CartesianVector GetGlobalMaxLayerPosition() const
Get global position corresponding to the fit result in maximum fit layer.
float m_pathLengthRatioCut
The maximum ratio of path length to straight line length to qualify as a track.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.