KinkSplittingAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArTwoDReco/LArClusterSplitting/KinkSplittingAlgorithm.cc
3  *
4  * @brief Implementation of the kink splitting algorithm class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 KinkSplittingAlgorithm::KinkSplittingAlgorithm() : m_maxScatterRms(0.2f), m_maxScatterCosTheta(0.905f), m_maxSlidingCosTheta(0.985f)
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 StatusCode KinkSplittingAlgorithm::FindBestSplitPosition(const TwoDSlidingFitResult &slidingFitResult, CartesianVector &splitPosition) const
25 {
26  // Search for scatters by scanning over the layers in the sliding fit result
27  const LayerFitResultMap &layerFitResultMap(slidingFitResult.GetLayerFitResultMap());
28  const int minLayer(layerFitResultMap.begin()->first), maxLayer(layerFitResultMap.rbegin()->first);
29 
30  const int nLayersHalfWindow(slidingFitResult.GetLayerFitHalfWindow());
31  const int nLayersSpanned(1 + maxLayer - minLayer);
32 
33  if (nLayersSpanned <= 2 * nLayersHalfWindow)
34  return STATUS_CODE_NOT_FOUND;
35 
36  bool foundSplit(false);
37 
38  float bestCosTheta(1.f);
39 
40  for (LayerFitResultMap::const_iterator iter = layerFitResultMap.begin(), iterEnd = layerFitResultMap.end(); iter != iterEnd; ++iter)
41  {
42  const int iLayer(iter->first);
43 
44  const float rL(slidingFitResult.GetL(iLayer));
45  const float rL1(slidingFitResult.GetL(iLayer - nLayersHalfWindow));
46  const float rL2(slidingFitResult.GetL(iLayer + nLayersHalfWindow));
47 
48  CartesianVector centralPosition(0.f, 0.f, 0.f), firstDirection(0.f, 0.f, 0.f), secondDirection(0.f, 0.f, 0.f);
49 
50  if ((STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitPosition(rL, centralPosition)) ||
51  (STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitDirection(rL1, firstDirection)) ||
52  (STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitDirection(rL2, secondDirection)))
53  {
54  continue;
55  }
56 
57  const float cosTheta(firstDirection.GetDotProduct(secondDirection));
58  const float rms1(slidingFitResult.GetFitRms(rL1));
59  const float rms2(slidingFitResult.GetFitRms(rL2));
60  const float rms(std::max(rms1, rms2));
61 
62  float rmsCut(m_maxScatterRms);
63 
64  if (cosTheta > m_maxScatterCosTheta)
65  {
66  rmsCut *= ((m_maxSlidingCosTheta > cosTheta) ? (m_maxSlidingCosTheta - cosTheta) / (m_maxSlidingCosTheta - m_maxScatterCosTheta) : 0.f);
67  }
68 
69  if (rms < rmsCut && cosTheta < bestCosTheta)
70  {
71  bestCosTheta = cosTheta;
72  splitPosition = centralPosition;
73  foundSplit = true;
74  }
75  }
76 
77  if (!foundSplit)
78  return STATUS_CODE_NOT_FOUND;
79 
80  return STATUS_CODE_SUCCESS;
81 }
82 
83 //------------------------------------------------------------------------------------------------------------------------------------------
84 
85 StatusCode KinkSplittingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
86 {
87  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxScatterRms", m_maxScatterRms));
88 
89  PANDORA_RETURN_RESULT_IF_AND_IF(
90  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxScatterCosTheta", m_maxScatterCosTheta));
91 
92  PANDORA_RETURN_RESULT_IF_AND_IF(
93  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxSlidingCosTeta", m_maxSlidingCosTheta));
94 
96 }
97 
98 } // namespace lar_content
unsigned int GetLayerFitHalfWindow() const
Get the layer fit half window.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
intermediate_table::const_iterator const_iterator
float GetFitRms(const float rL) const
Get fit rms for a given longitudinal coordinate.
pandora::StatusCode GetGlobalFitPosition(const float rL, pandora::CartesianVector &position) const
Get global fit position for a given longitudinal coordinate.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::map< int, LayerFitResult > LayerFitResultMap
static int max(int a, int b)
const LayerFitResultMap & GetLayerFitResultMap() const
Get the layer fit result map.
pandora::StatusCode GetGlobalFitDirection(const float rL, pandora::CartesianVector &direction) const
Get global fit direction for a given longitudinal coordinate.
float GetL(const int layer) const
Get longitudinal coordinate for a given sliding linear fit layer number.
pandora::StatusCode FindBestSplitPosition(const TwoDSlidingFitResult &slidingFitResult, pandora::CartesianVector &splitPosition) const
Use sliding linear fit to identify the best split position.
Header file for the kink splitting algorithm class.