All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
 
void Run (LArMvaHelper::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, 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...
 
virtual void Run (MvaTypes::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, Ts...args)
 

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
 
typedef std::map< std::string,
MvaFeatureTool< Ts...> * > 
FeatureToolMap
 

Detailed Description

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

Definition at line 60 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::TwoDLinearFitFeatureTool::TwoDLinearFitFeatureTool ( )

Default constructor.

Definition at line 88 of file TrackShowerIdFeatureTool.cc.

89 {
90 }
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 157 of file TrackShowerIdFeatureTool.cc.

159 {
160  try
161  {
162  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
163  const TwoDSlidingFitResult slidingFitResultLarge(
164  pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
165 
166  if (slidingFitResult.GetLayerFitResultMap().empty())
167  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
168 
169  straightLineLengthLarge =
170  (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
171  rmsSlidingLinearFit = 0.f;
172 
173  FloatVector diffWithStraightLineVector;
174  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
175  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
176  float dTdLMin(+std::numeric_limits<float>::max()), dTdLMax(-std::numeric_limits<float>::max());
177 
178  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
179  {
180  const LayerFitResult &layerFitResult(mapEntry.second);
181  rmsSlidingLinearFit += layerFitResult.GetRms();
182 
183  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
184  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
185 
186  LayerFitResultMap::const_iterator iterLarge =
187  slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
188 
189  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
190  throw StatusCodeException(STATUS_CODE_FAILURE);
191 
192  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
193 
194  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
195  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
196  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
197 
198  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
199  {
200  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
201  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
202 
203  if (correctedGapLength > maxFitGapLength)
204  maxFitGapLength = correctedGapLength;
205  }
206 
207  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
208  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
209  previousFitPosition = thisFitPosition;
210  }
211 
212  if (diffWithStraightLineVector.empty())
213  throw StatusCodeException(STATUS_CODE_FAILURE);
214 
215  diffWithStraightLineMean = 0.f;
216  diffWithStraightLineSigma = 0.f;
217 
218  for (const float diffWithStraightLine : diffWithStraightLineVector)
219  diffWithStraightLineMean += diffWithStraightLine;
220 
221  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
222 
223  for (const float diffWithStraightLine : diffWithStraightLineVector)
224  diffWithStraightLineSigma += (diffWithStraightLine - diffWithStraightLineMean) * (diffWithStraightLine - diffWithStraightLineMean);
225 
226  if (diffWithStraightLineSigma < 0.f)
227  throw StatusCodeException(STATUS_CODE_FAILURE);
228 
229  diffWithStraightLineSigma = std::sqrt(diffWithStraightLineSigma / static_cast<float>(diffWithStraightLineVector.size()));
230  dTdLWidth = dTdLMax - dTdLMin;
231  }
232  catch (const StatusCodeException &)
233  {
234  straightLineLengthLarge = -1.f;
235  diffWithStraightLineMean = -1.f;
236  diffWithStraightLineSigma = -1.f;
237  dTdLWidth = -1.f;
238  maxFitGapLength = -1.f;
239  rmsSlidingLinearFit = -1.f;
240  }
241 }
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.
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 245 of file TrackShowerIdFeatureTool.cc.

246 {
247  PANDORA_RETURN_RESULT_IF_AND_IF(
248  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
249 
250  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
251  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
252 
253  return STATUS_CODE_SUCCESS;
254 }
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 94 of file TrackShowerIdFeatureTool.cc.

95 {
96  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
97  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
98 
99  float dTdLWidth(-1.f), straightLineLengthLarge(-1.f), diffWithStraightLineMean(-1.f), diffWithStraightLineSigma(-1.f),
100  maxFitGapLength(-1.f), rmsSlidingLinearFit(-1.f);
101  this->CalculateVariablesSlidingLinearFit(pCluster, straightLineLengthLarge, diffWithStraightLineMean, diffWithStraightLineSigma,
102  dTdLWidth, maxFitGapLength, rmsSlidingLinearFit);
103 
104  if (straightLineLengthLarge > std::numeric_limits<float>::epsilon())
105  {
106  diffWithStraightLineMean /= straightLineLengthLarge;
107  diffWithStraightLineSigma /= straightLineLengthLarge;
108  dTdLWidth /= straightLineLengthLarge;
109  maxFitGapLength /= straightLineLengthLarge;
110  rmsSlidingLinearFit /= straightLineLengthLarge;
111  }
112 
113  featureVector.push_back(straightLineLengthLarge);
114  featureVector.push_back(diffWithStraightLineMean);
115  featureVector.push_back(diffWithStraightLineSigma);
116  featureVector.push_back(dTdLWidth);
117  featureVector.push_back(maxFitGapLength);
118  featureVector.push_back(rmsSlidingLinearFit);
119 }
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.
BEGIN_PROLOG could also be cout
void lar_content::TwoDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
const pandora::Algorithm *const  pAlgorithm,
const pandora::Cluster *const  pCluster 
)

Member Data Documentation

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 89 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 90 of file TrackShowerIdFeatureTool.h.


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