Public Member Functions | Private Member Functions | Private Attributes | List of all members
lar_content::TwoDLinearFitFeatureTool Class Reference

TwoDLinearFitFeatureTool class for the calculation of variables related to 2d sliding linear fit. More...

#include <TrackShowerIdFeatureTool.h>

Inheritance diagram for lar_content::TwoDLinearFitFeatureTool:
lar_content::MvaFeatureTool< Ts >

Public Member Functions

 TwoDLinearFitFeatureTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster)
 
- Public Member Functions inherited from lar_content::MvaFeatureTool< Ts >
 MvaFeatureTool ()=default
 Default constructor. More...
 
virtual void Run (MvaTypes::MvaFeatureVector &featureVector, Ts...args)=0
 Run the algorithm tool. More...
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void CalculateVariablesSlidingLinearFit (const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &diffWithStraightLineSigma, float &dTdLWidth, float &maxFitGapLength, float &rmsSlidingLinearFit) const
 Calculation of several variables related to sliding linear fit. More...
 

Private Attributes

unsigned int m_slidingLinearFitWindow
 The sliding linear fit window. More...
 
unsigned int m_slidingLinearFitWindowLarge
 The sliding linear fit window - should be large, providing a simple linear fit. More...
 

Additional Inherited Members

- Public Types inherited from lar_content::MvaFeatureTool< Ts >
typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 

Detailed Description

TwoDLinearFitFeatureTool class for the calculation of variables related to 2d sliding linear fit.

Definition at line 56 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::TwoDLinearFitFeatureTool::TwoDLinearFitFeatureTool ( )

Default constructor.

Definition at line 69 of file TrackShowerIdFeatureTool.cc.

70 {
71 }
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.

Member Function Documentation

void lar_content::TwoDLinearFitFeatureTool::CalculateVariablesSlidingLinearFit ( const pandora::Cluster *const  pCluster,
float &  straightLineLengthLarge,
float &  diffWithStraigthLineMean,
float &  diffWithStraightLineSigma,
float &  dTdLWidth,
float &  maxFitGapLength,
float &  rmsSlidingLinearFit 
) const
private

Calculation of several variables related to sliding linear fit.

Parameters
pClusterthe cluster we are characterizing
straightLineLengthLargeto receive to length reported by the straight line fit
diffWithStraigthLineMeanto receive the difference with straight line mean variable
diffWithStraightLineSigmato receive the difference with straight line sigma variable
dTdLWidthto receive the dTdL width variable
maxFitGapLengthto receive the max fit gap length variable
rmsSlidingLinearFitto receive the RMS from the linear fit

Definition at line 104 of file TrackShowerIdFeatureTool.cc.

106 {
107  try
108  {
109  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
110  const TwoDSlidingFitResult slidingFitResultLarge(
111  pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
112 
113  if (slidingFitResult.GetLayerFitResultMap().empty())
114  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
115 
116  straightLineLengthLarge =
117  (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
118  rmsSlidingLinearFit = 0.f;
119 
120  FloatVector diffWithStraightLineVector;
121  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
122  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
124 
125  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
126  {
127  const LayerFitResult &layerFitResult(mapEntry.second);
128  rmsSlidingLinearFit += layerFitResult.GetRms();
129 
130  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
131  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
132 
134  slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
135 
136  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
137  throw StatusCodeException(STATUS_CODE_FAILURE);
138 
139  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
140 
141  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
142  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
143  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
144 
145  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
146  {
147  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
148  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
149 
150  if (correctedGapLength > maxFitGapLength)
151  maxFitGapLength = correctedGapLength;
152  }
153 
154  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
155  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
156  previousFitPosition = thisFitPosition;
157  }
158 
159  if (diffWithStraightLineVector.empty())
160  throw StatusCodeException(STATUS_CODE_FAILURE);
161 
162  diffWithStraightLineMean = 0.f;
163  diffWithStraightLineSigma = 0.f;
164 
165  for (const float diffWithStraightLine : diffWithStraightLineVector)
166  diffWithStraightLineMean += diffWithStraightLine;
167 
168  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
169 
170  for (const float diffWithStraightLine : diffWithStraightLineVector)
171  diffWithStraightLineSigma += (diffWithStraightLine - diffWithStraightLineMean) * (diffWithStraightLine - diffWithStraightLineMean);
172 
173  if (diffWithStraightLineSigma < 0.f)
174  throw StatusCodeException(STATUS_CODE_FAILURE);
175 
176  diffWithStraightLineSigma = std::sqrt(diffWithStraightLineSigma / static_cast<float>(diffWithStraightLineVector.size()));
177  dTdLWidth = dTdLMax - dTdLMin;
178  }
179  catch (const StatusCodeException &)
180  {
181  straightLineLengthLarge = -1.f;
182  diffWithStraightLineMean = -1.f;
183  diffWithStraightLineSigma = -1.f;
184  dTdLWidth = -1.f;
185  maxFitGapLength = -1.f;
186  rmsSlidingLinearFit = -1.f;
187  }
188 }
enum cvn::HType HitType
static float CalculateGapDeltaZ(const pandora::Pandora &pandora, const float minZ, const float maxZ, const pandora::HitType hitType)
Calculate the total distance within a given 2D region that is composed of detector gaps...
intermediate_table::const_iterator const_iterator
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.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
Dft::FloatVector FloatVector
StatusCode lar_content::TwoDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 192 of file TrackShowerIdFeatureTool.cc.

193 {
194  PANDORA_RETURN_RESULT_IF_AND_IF(
195  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
196 
197  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
198  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
199 
200  return STATUS_CODE_SUCCESS;
201 }
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
void lar_content::TwoDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::Cluster *const  pCluster 
)

Definition at line 75 of file TrackShowerIdFeatureTool.cc.

76 {
77  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
78  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
79 
80  float dTdLWidth(-1.f), straightLineLengthLarge(-1.f), diffWithStraightLineMean(-1.f), diffWithStraightLineSigma(-1.f),
81  maxFitGapLength(-1.f), rmsSlidingLinearFit(-1.f);
82  this->CalculateVariablesSlidingLinearFit(pCluster, straightLineLengthLarge, diffWithStraightLineMean, diffWithStraightLineSigma,
83  dTdLWidth, maxFitGapLength, rmsSlidingLinearFit);
84 
85  if (straightLineLengthLarge > std::numeric_limits<float>::epsilon())
86  {
87  diffWithStraightLineMean /= straightLineLengthLarge;
88  diffWithStraightLineSigma /= straightLineLengthLarge;
89  dTdLWidth /= straightLineLengthLarge;
90  maxFitGapLength /= straightLineLengthLarge;
91  rmsSlidingLinearFit /= straightLineLengthLarge;
92  }
93 
94  featureVector.push_back(straightLineLengthLarge);
95  featureVector.push_back(diffWithStraightLineMean);
96  featureVector.push_back(diffWithStraightLineSigma);
97  featureVector.push_back(dTdLWidth);
98  featureVector.push_back(maxFitGapLength);
99  featureVector.push_back(rmsSlidingLinearFit);
100 }
void CalculateVariablesSlidingLinearFit(const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &diffWithStraightLineSigma, float &dTdLWidth, float &maxFitGapLength, float &rmsSlidingLinearFit) const
Calculation of several variables related to sliding linear fit.
QTextStream & endl(QTextStream &s)

Member Data Documentation

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 83 of file TrackShowerIdFeatureTool.h.

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

The sliding linear fit window - should be large, providing a simple linear fit.

Definition at line 84 of file TrackShowerIdFeatureTool.h.


The documentation for this class was generated from the following files: