LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::TwoDLinearFitFeatureTool Class Referenceabstract

LinearFitFeatureTool class for the calculation of variables related to sliding linear fit. More...

#include "TrackShowerIdFeatureTool.h"

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

Public Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 

Public Member Functions

 TwoDLinearFitFeatureTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster)
 
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...
 

Detailed Description

LinearFitFeatureTool class for the calculation of variables related to sliding linear fit.

Definition at line 55 of file TrackShowerIdFeatureTool.h.

Member Typedef Documentation

template<typename... Ts>
typedef std::vector<MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolVector
inherited

Definition at line 30 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::TwoDLinearFitFeatureTool::TwoDLinearFitFeatureTool ( )

Default constructor.

Definition at line 76 of file TrackShowerIdFeatureTool.cc.

76  :
79 {
80 }
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 112 of file TrackShowerIdFeatureTool.cc.

References lar_content::LArGeometryHelper::CalculateGapDeltaZ(), f, lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LayerFitResult::GetFitT(), lar_content::TwoDSlidingFitResult::GetGlobalMaxLayerPosition(), lar_content::TwoDSlidingFitResult::GetGlobalMinLayerPosition(), lar_content::TwoDSlidingFitResult::GetGlobalPosition(), lar_content::LayerFitResult::GetGradient(), lar_content::LayerFitResult::GetL(), lar_content::TwoDSlidingFitResult::GetLayer(), lar_content::TwoDSlidingFitResult::GetLayerFitResultMap(), lar_content::LayerFitResult::GetRms(), lar_content::LArGeometryHelper::GetWireZPitch(), m_slidingLinearFitWindow, m_slidingLinearFitWindowLarge, max, and min.

Referenced by Run().

114 {
115  try
116  {
117  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
118  const TwoDSlidingFitResult slidingFitResultLarge(pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
119 
120  if (slidingFitResult.GetLayerFitResultMap().empty())
121  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
122 
123  straightLineLengthLarge = (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
124  rmsSlidingLinearFit = 0.f;
125 
126  FloatVector diffWithStraightLineVector;
127  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
128  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
130 
131  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
132  {
133  const LayerFitResult &layerFitResult(mapEntry.second);
134  rmsSlidingLinearFit += layerFitResult.GetRms();
135 
136  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
137  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
138 
139  LayerFitResultMap::const_iterator iterLarge = slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
140 
141  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
142  throw StatusCodeException(STATUS_CODE_FAILURE);
143 
144  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
145 
146  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
147  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
148  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
149 
150  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
151  {
152  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
153  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
154 
155  if (correctedGapLength > maxFitGapLength)
156  maxFitGapLength = correctedGapLength;
157  }
158 
159  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
160  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
161  previousFitPosition = thisFitPosition;
162  }
163 
164  if (diffWithStraightLineVector.empty())
165  throw StatusCodeException(STATUS_CODE_FAILURE);
166 
167  diffWithStraightLineMean = 0.f;
168  diffWithStraightLineSigma = 0.f;
169 
170  for (const float diffWithStraightLine : diffWithStraightLineVector)
171  diffWithStraightLineMean += diffWithStraightLine;
172 
173  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
174 
175  for (const float diffWithStraightLine : diffWithStraightLineVector)
176  diffWithStraightLineSigma += (diffWithStraightLine - diffWithStraightLineMean) * (diffWithStraightLine - diffWithStraightLineMean);
177 
178  if (diffWithStraightLineSigma < 0.f)
179  throw StatusCodeException(STATUS_CODE_FAILURE);
180 
181  diffWithStraightLineSigma = std::sqrt(diffWithStraightLineSigma / static_cast<float>(diffWithStraightLineVector.size()));
182  dTdLWidth = dTdLMax - dTdLMin;
183  }
184  catch (const StatusCodeException &)
185  {
186  straightLineLengthLarge = -1.f;
187  diffWithStraightLineMean = -1.f;
188  diffWithStraightLineSigma = -1.f;
189  dTdLWidth = -1.f;
190  maxFitGapLength = -1.f;
191  rmsSlidingLinearFit = -1.f;
192  }
193 }
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...
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.
TFile f
Definition: plotHisto.C:6
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
Int_t min
Definition: plot.C:26
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
StatusCode lar_content::TwoDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 197 of file TrackShowerIdFeatureTool.cc.

References m_slidingLinearFitWindow, and m_slidingLinearFitWindowLarge.

198 {
199  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
200  "SlidingLinearFitWindow", m_slidingLinearFitWindow));
201 
202  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
203  "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
204 
205  return STATUS_CODE_SUCCESS;
206 }
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.
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureVector featureVector,
Ts...  args 
)
pure virtualinherited

Run the algorithm tool.

Parameters
featureVectorthe vector of features to append
argsarguments to pass to the tool
void lar_content::TwoDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::Cluster *const  pCluster 
)

Definition at line 84 of file TrackShowerIdFeatureTool.cc.

References CalculateVariablesSlidingLinearFit(), and f.

86 {
87  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
88  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
89 
90  float dTdLWidth(-1.f), straightLineLengthLarge(-1.f), diffWithStraightLineMean(-1.f), diffWithStraightLineSigma(-1.f), maxFitGapLength(-1.f), rmsSlidingLinearFit(-1.f);
91  this->CalculateVariablesSlidingLinearFit(pCluster, straightLineLengthLarge, diffWithStraightLineMean, diffWithStraightLineSigma, dTdLWidth, maxFitGapLength, rmsSlidingLinearFit);
92 
93  if (straightLineLengthLarge > std::numeric_limits<float>::epsilon())
94  {
95  diffWithStraightLineMean /= straightLineLengthLarge;
96  diffWithStraightLineSigma /= straightLineLengthLarge;
97  dTdLWidth /= straightLineLengthLarge;
98  maxFitGapLength /= straightLineLengthLarge;
99  rmsSlidingLinearFit /= straightLineLengthLarge;
100  }
101 
102  featureVector.push_back(straightLineLengthLarge);
103  featureVector.push_back(diffWithStraightLineMean);
104  featureVector.push_back(diffWithStraightLineSigma);
105  featureVector.push_back(dTdLWidth);
106  featureVector.push_back(maxFitGapLength);
107  featureVector.push_back(rmsSlidingLinearFit);
108 }
TFile f
Definition: plotHisto.C:6
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.

Member Data Documentation

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 82 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

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

Definition at line 83 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().


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