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::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)
 
void Run (LArMvaHelper::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, 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...
 
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 &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

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

Definition at line 151 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::ThreeDLinearFitFeatureTool::ThreeDLinearFitFeatureTool ( )

Default constructor.

Definition at line 542 of file TrackShowerIdFeatureTool.cc.

543 {
544 }
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 627 of file TrackShowerIdFeatureTool.cc.

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

Definition at line 707 of file TrackShowerIdFeatureTool.cc.

708 {
709  PANDORA_RETURN_RESULT_IF_AND_IF(
710  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
711 
712  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
713  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
714 
715  return STATUS_CODE_SUCCESS;
716 }
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 548 of file TrackShowerIdFeatureTool.cc.

550 {
551  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
552  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
553 
554  ClusterList clusterList;
555  LArPfoHelper::GetTwoDClusterList(pInputPfo, clusterList);
556  float diffWithStraightLineMean(0.f), maxFitGapLength(0.f), rmsSlidingLinearFit(0.f);
557  LArMvaHelper::MvaFeature length, diff, gap, rms;
558  unsigned int nClustersUsed(0);
559 
560  for (const Cluster *const pCluster : clusterList)
561  {
562  float straightLineLengthLargeCluster(-1.f), diffWithStraightLineMeanCluster(-1.f), maxFitGapLengthCluster(-1.f),
563  rmsSlidingLinearFitCluster(-1.f);
564 
566  pCluster, straightLineLengthLargeCluster, diffWithStraightLineMeanCluster, maxFitGapLengthCluster, rmsSlidingLinearFitCluster);
567 
568  if (straightLineLengthLargeCluster > std::numeric_limits<float>::epsilon())
569  {
570  diffWithStraightLineMeanCluster /= straightLineLengthLargeCluster;
571  maxFitGapLengthCluster /= straightLineLengthLargeCluster;
572  rmsSlidingLinearFitCluster /= straightLineLengthLargeCluster;
573 
574  diffWithStraightLineMean += diffWithStraightLineMeanCluster;
575  maxFitGapLength += maxFitGapLengthCluster;
576  rmsSlidingLinearFit += rmsSlidingLinearFitCluster;
577 
578  ++nClustersUsed;
579  }
580  }
581 
582  if (nClustersUsed > 0)
583  {
584  const float nClusters(static_cast<float>(nClustersUsed));
585  length = std::sqrt(LArPfoHelper::GetThreeDLengthSquared(pInputPfo));
586  diff = diffWithStraightLineMean / nClusters;
587  gap = maxFitGapLength / nClusters;
588  rms = rmsSlidingLinearFit / nClusters;
589  }
590 
591  featureVector.push_back(length);
592  featureVector.push_back(diff);
593  featureVector.push_back(gap);
594  featureVector.push_back(rms);
595 }
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:71
BEGIN_PROLOG could also be cout
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.

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.


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