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

ThreeDLinearFitFeatureTool class for the calculation of variables related to 3d sliding linear fit. More...

#include <TrackShowerIdFeatureTool.h>

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

Public Member Functions

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

ThreeDLinearFitFeatureTool class for the calculation of variables related to 3d sliding linear fit.

Definition at line 141 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::ThreeDLinearFitFeatureTool::ThreeDLinearFitFeatureTool ( )

Default constructor.

Definition at line 301 of file TrackShowerIdFeatureTool.cc.

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

Member Function Documentation

void lar_content::ThreeDLinearFitFeatureTool::CalculateVariablesSlidingLinearFit ( const pandora::Cluster *const  pCluster,
float &  straightLineLengthLarge,
float &  diffWithStraigthLineMean,
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 358 of file TrackShowerIdFeatureTool.cc.

360 {
361  try
362  {
363  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
364  const TwoDSlidingFitResult slidingFitResultLarge(
365  pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
366 
367  if (slidingFitResult.GetLayerFitResultMap().empty())
368  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
369 
370  straightLineLengthLarge =
371  (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
372  rmsSlidingLinearFit = 0.f;
373 
374  FloatVector diffWithStraightLineVector;
375  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
376  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
378 
379  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
380  {
381  const LayerFitResult &layerFitResult(mapEntry.second);
382  rmsSlidingLinearFit += layerFitResult.GetRms();
383 
384  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
385  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
386 
388  slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
389 
390  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
391  throw StatusCodeException(STATUS_CODE_FAILURE);
392 
393  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
394 
395  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
396  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
397  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
398 
399  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
400  {
401  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
402  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
403 
404  if (correctedGapLength > maxFitGapLength)
405  maxFitGapLength = correctedGapLength;
406  }
407  else
408  {
409  maxFitGapLength = 0.f;
410  }
411 
412  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
413  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
414  previousFitPosition = thisFitPosition;
415  }
416 
417  if (diffWithStraightLineVector.empty())
418  throw StatusCodeException(STATUS_CODE_FAILURE);
419 
420  diffWithStraightLineMean = 0.f;
421 
422  for (const float diffWithStraightLine : diffWithStraightLineVector)
423  diffWithStraightLineMean += diffWithStraightLine;
424 
425  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
426  }
427  catch (const StatusCodeException &)
428  {
429  straightLineLengthLarge = -1.f;
430  diffWithStraightLineMean = -1.f;
431  maxFitGapLength = -1.f;
432  rmsSlidingLinearFit = -1.f;
433  }
434 }
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_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
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
Dft::FloatVector FloatVector
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
StatusCode lar_content::ThreeDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 438 of file TrackShowerIdFeatureTool.cc.

439 {
440  PANDORA_RETURN_RESULT_IF_AND_IF(
441  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
442 
443  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
444  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
445 
446  return STATUS_CODE_SUCCESS;
447 }
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
void lar_content::ThreeDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Definition at line 307 of file TrackShowerIdFeatureTool.cc.

309 {
310  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
311  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
312 
313  ClusterList clusterList;
314  LArPfoHelper::GetTwoDClusterList(pInputPfo, clusterList);
315  float diffWithStraightLineMean(0.f), maxFitGapLength(0.f), rmsSlidingLinearFit(0.f);
316  LArMvaHelper::MvaFeature length, diff, gap, rms;
317  unsigned int nClustersUsed(0);
318 
319  for (const Cluster *const pCluster : clusterList)
320  {
321  float straightLineLengthLargeCluster(-1.f), diffWithStraightLineMeanCluster(-1.f), maxFitGapLengthCluster(-1.f),
322  rmsSlidingLinearFitCluster(-1.f);
323 
325  pCluster, straightLineLengthLargeCluster, diffWithStraightLineMeanCluster, maxFitGapLengthCluster, rmsSlidingLinearFitCluster);
326 
327  if (straightLineLengthLargeCluster > std::numeric_limits<float>::epsilon())
328  {
329  diffWithStraightLineMeanCluster /= straightLineLengthLargeCluster;
330  maxFitGapLengthCluster /= straightLineLengthLargeCluster;
331  rmsSlidingLinearFitCluster /= straightLineLengthLargeCluster;
332 
333  diffWithStraightLineMean += diffWithStraightLineMeanCluster;
334  maxFitGapLength += maxFitGapLengthCluster;
335  rmsSlidingLinearFit += rmsSlidingLinearFitCluster;
336 
337  ++nClustersUsed;
338  }
339  }
340 
341  if (nClustersUsed > 0)
342  {
343  const float nClusters(static_cast<float>(nClustersUsed));
344  length = std::sqrt(LArPfoHelper::GetThreeDLengthSquared(pInputPfo));
345  diff = diffWithStraightLineMean / nClusters;
346  gap = maxFitGapLength / nClusters;
347  rms = rmsSlidingLinearFit / nClusters;
348  }
349 
350  featureVector.push_back(length);
351  featureVector.push_back(diff);
352  featureVector.push_back(gap);
353  featureVector.push_back(rms);
354 }
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
static void GetTwoDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 2D clusters from an input pfo.
static float GetThreeDLengthSquared(const pandora::ParticleFlowObject *const pPfo)
Calculate length of Pfo using 3D clusters.
void CalculateVariablesSlidingLinearFit(const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &maxFitGapLength, float &rmsSlidingLinearFit) const
Calculation of several variables related to sliding linear fit.
MvaTypes::MvaFeature MvaFeature
Definition: LArMvaHelper.h:57
QTextStream & endl(QTextStream &s)

Member Data Documentation

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 168 of file TrackShowerIdFeatureTool.h.

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

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

Definition at line 169 of file TrackShowerIdFeatureTool.h.


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