LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
KinkSplittingAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 KinkSplittingAlgorithm::KinkSplittingAlgorithm() :
19  m_maxScatterRms(0.2f),
20  m_maxScatterCosTheta(0.905f),
21  m_maxSlidingCosTheta(0.985f)
22 {
23 }
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
27 StatusCode KinkSplittingAlgorithm::FindBestSplitPosition(const TwoDSlidingFitResult &slidingFitResult, CartesianVector &splitPosition) const
28 {
29  // Search for scatters by scanning over the layers in the sliding fit result
30  const LayerFitResultMap &layerFitResultMap(slidingFitResult.GetLayerFitResultMap());
31  const int minLayer(layerFitResultMap.begin()->first), maxLayer(layerFitResultMap.rbegin()->first);
32 
33  const int nLayersHalfWindow(slidingFitResult.GetLayerFitHalfWindow());
34  const int nLayersSpanned(1 + maxLayer - minLayer);
35 
36  if (nLayersSpanned <= 2 * nLayersHalfWindow)
37  return STATUS_CODE_NOT_FOUND;
38 
39  bool foundSplit(false);
40 
41  float bestCosTheta(1.f);
42 
43  for (LayerFitResultMap::const_iterator iter = layerFitResultMap.begin(), iterEnd = layerFitResultMap.end(); iter != iterEnd; ++iter)
44  {
45  const int iLayer(iter->first);
46 
47  const float rL(slidingFitResult.GetL(iLayer));
48  const float rL1(slidingFitResult.GetL(iLayer - nLayersHalfWindow));
49  const float rL2(slidingFitResult.GetL(iLayer + nLayersHalfWindow));
50 
51  CartesianVector centralPosition(0.f, 0.f, 0.f), firstDirection(0.f, 0.f, 0.f), secondDirection(0.f, 0.f, 0.f);
52 
53  if ((STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitPosition(rL, centralPosition)) ||
54  (STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitDirection(rL1, firstDirection)) ||
55  (STATUS_CODE_SUCCESS != slidingFitResult.GetGlobalFitDirection(rL2, secondDirection)))
56  {
57  continue;
58  }
59 
60  const float cosTheta(firstDirection.GetDotProduct(secondDirection));
61  const float rms1(slidingFitResult.GetFitRms(rL1));
62  const float rms2(slidingFitResult.GetFitRms(rL2));
63  const float rms(std::max(rms1, rms2));
64 
65  float rmsCut(m_maxScatterRms);
66 
67  if (cosTheta > m_maxScatterCosTheta)
68  {
69  rmsCut *= ((m_maxSlidingCosTheta > cosTheta) ? (m_maxSlidingCosTheta - cosTheta) / (m_maxSlidingCosTheta - m_maxScatterCosTheta) : 0.f);
70  }
71 
72  if (rms < rmsCut && cosTheta < bestCosTheta)
73  {
74  bestCosTheta = cosTheta;
75  splitPosition = centralPosition;
76  foundSplit = true;
77  }
78  }
79 
80  if (!foundSplit)
81  return STATUS_CODE_NOT_FOUND;
82 
83  return STATUS_CODE_SUCCESS;
84 }
85 
86 //------------------------------------------------------------------------------------------------------------------------------------------
87 
88 StatusCode KinkSplittingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
89 {
90  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxScatterRms", m_maxScatterRms));
91 
92  PANDORA_RETURN_RESULT_IF_AND_IF(
93  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxScatterCosTheta", m_maxScatterCosTheta));
94 
95  PANDORA_RETURN_RESULT_IF_AND_IF(
96  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxSlidingCosTeta", m_maxSlidingCosTheta));
97 
99 }
100 
101 } // namespace lar_content
unsigned int GetLayerFitHalfWindow() const
Get the layer fit half window.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
intermediate_table::const_iterator const_iterator
TFile f
Definition: plotHisto.C:6
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
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.