LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::ThreeDLinearFitFeatureTool Class Referenceabstract

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 Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 
typedef std::map< std::string, MvaFeatureTool< Ts... > * > FeatureToolMap
 

Public Member Functions

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

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...
 

Detailed Description

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

Definition at line 151 of file TrackShowerIdFeatureTool.h.

Member Typedef Documentation

template<typename... Ts>
typedef std::map<std::string, MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolMap
inherited

Definition at line 37 of file LArMvaHelper.h.

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

Definition at line 36 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::ThreeDLinearFitFeatureTool::ThreeDLinearFitFeatureTool ( )

Default constructor.

Definition at line 547 of file TrackShowerIdFeatureTool.cc.

547  :
550 {
551 }
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 634 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, and m_slidingLinearFitWindowLarge.

Referenced by Run().

636 {
637  try
638  {
639  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
640  const TwoDSlidingFitResult slidingFitResultLarge(
641  pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
642 
643  if (slidingFitResult.GetLayerFitResultMap().empty())
644  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
645 
646  straightLineLengthLarge =
647  (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
648  rmsSlidingLinearFit = 0.f;
649 
650  FloatVector diffWithStraightLineVector;
651  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
652  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
653  float dTdLMin(+std::numeric_limits<float>::max()), dTdLMax(-std::numeric_limits<float>::max());
654 
655  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
656  {
657  const LayerFitResult &layerFitResult(mapEntry.second);
658  rmsSlidingLinearFit += layerFitResult.GetRms();
659 
660  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
661  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
662 
664  slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
665 
666  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
667  throw StatusCodeException(STATUS_CODE_FAILURE);
668 
669  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
670 
671  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
672  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
673  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
674 
675  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
676  {
677  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
678  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
679 
680  if (correctedGapLength > maxFitGapLength)
681  maxFitGapLength = correctedGapLength;
682  }
683  else
684  {
685  maxFitGapLength = 0.f;
686  }
687 
688  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
689  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
690  previousFitPosition = thisFitPosition;
691  }
692 
693  if (diffWithStraightLineVector.empty())
694  throw StatusCodeException(STATUS_CODE_FAILURE);
695 
696  diffWithStraightLineMean = 0.f;
697 
698  for (const float diffWithStraightLine : diffWithStraightLineVector)
699  diffWithStraightLineMean += diffWithStraightLine;
700 
701  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
702  }
703  catch (const StatusCodeException &)
704  {
705  straightLineLengthLarge = -1.f;
706  diffWithStraightLineMean = -1.f;
707  maxFitGapLength = -1.f;
708  rmsSlidingLinearFit = -1.f;
709  }
710 }
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.
TFile f
Definition: plotHisto.C:6
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
HitType
Definition: HitType.h:12
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
StatusCode lar_content::ThreeDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 714 of file TrackShowerIdFeatureTool.cc.

References m_slidingLinearFitWindow, and m_slidingLinearFitWindowLarge.

715 {
716  PANDORA_RETURN_RESULT_IF_AND_IF(
717  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
718 
719  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
720  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
721 
722  return STATUS_CODE_SUCCESS;
723 }
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.
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
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
Ts...   
)
inlinevirtualinherited

Definition at line 51 of file LArMvaHelper.h.

52  {
53  (void)featureMap;
54  (void)featureOrder;
55  (void)featureToolName;
56  return;
57  };
void lar_content::ThreeDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Definition at line 555 of file TrackShowerIdFeatureTool.cc.

References CalculateVariablesSlidingLinearFit(), f, lar_content::LArPfoHelper::GetThreeDLengthSquared(), and lar_content::LArPfoHelper::GetTwoDClusterList().

Referenced by lar_content::ThreeDVertexDistanceFeatureTool::Run().

557 {
558  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
559  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
560 
561  ClusterList clusterList;
562  LArPfoHelper::GetTwoDClusterList(pInputPfo, clusterList);
563  float diffWithStraightLineMean(0.f), maxFitGapLength(0.f), rmsSlidingLinearFit(0.f);
564  LArMvaHelper::MvaFeature length, diff, gap, rms;
565  unsigned int nClustersUsed(0);
566 
567  for (const Cluster *const pCluster : clusterList)
568  {
569  float straightLineLengthLargeCluster(-1.f), diffWithStraightLineMeanCluster(-1.f), maxFitGapLengthCluster(-1.f),
570  rmsSlidingLinearFitCluster(-1.f);
571 
573  pCluster, straightLineLengthLargeCluster, diffWithStraightLineMeanCluster, maxFitGapLengthCluster, rmsSlidingLinearFitCluster);
574 
575  if (straightLineLengthLargeCluster > std::numeric_limits<float>::epsilon())
576  {
577  diffWithStraightLineMeanCluster /= straightLineLengthLargeCluster;
578  maxFitGapLengthCluster /= straightLineLengthLargeCluster;
579  rmsSlidingLinearFitCluster /= straightLineLengthLargeCluster;
580 
581  diffWithStraightLineMean += diffWithStraightLineMeanCluster;
582  maxFitGapLength += maxFitGapLengthCluster;
583  rmsSlidingLinearFit += rmsSlidingLinearFitCluster;
584 
585  ++nClustersUsed;
586  }
587  }
588 
589  if (nClustersUsed > 0)
590  {
591  const float nClusters(static_cast<float>(nClustersUsed));
592  length = std::sqrt(LArPfoHelper::GetThreeDLengthSquared(pInputPfo));
593  diff = diffWithStraightLineMean / nClusters;
594  gap = maxFitGapLength / nClusters;
595  rms = rmsSlidingLinearFit / nClusters;
596  }
597 
598  featureVector.push_back(length);
599  featureVector.push_back(diff);
600  featureVector.push_back(gap);
601  featureVector.push_back(rms);
602 }
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:74
TFile f
Definition: plotHisto.C:6
void lar_content::ThreeDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Member Data Documentation

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 180 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

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

Definition at line 181 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().


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