Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lar_content::AsymmetryFeatureBaseTool Class Referenceabstract

AsymmetryFeatureBaseTool class. More...

#include <AsymmetryFeatureBaseTool.h>

Inheritance diagram for lar_content::AsymmetryFeatureBaseTool:
lar_content::MvaFeatureTool< Ts > lar_content::GlobalAsymmetryFeatureTool lar_content::LocalAsymmetryFeatureTool lar_content::ShowerAsymmetryFeatureTool lar_content::EnergyDepositionAsymmetryFeatureTool

Public Member Functions

 AsymmetryFeatureBaseTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm, const pandora::Vertex *const pVertex, const VertexSelectionBaseAlgorithm::SlidingFitDataListMap &slidingFitDataListMap, const VertexSelectionBaseAlgorithm::ClusterListMap &, const VertexSelectionBaseAlgorithm::KDTreeMap &, const VertexSelectionBaseAlgorithm::ShowerClusterListMap &showerClusterListMap, const float, float &)
 Run the tool. More...
 
- 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...
 

Protected Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
virtual float GetAsymmetryForView (const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const VertexSelectionBaseAlgorithm::ShowerClusterList &showerClusterList) const =0
 Get the asymmetry feature for a given view. More...
 
void IncrementAsymmetryParameters (const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
 Increment the asymmetry parameters. More...
 
virtual float CalculateAsymmetry (const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const pandora::ClusterVector &asymmetryClusters, const pandora::CartesianVector &localWeightedDirectionSum) const
 Calculate the asymmetry feature. More...
 

Protected Attributes

float m_maxAsymmetryDistance
 The max distance between cluster (any hit) and vertex to calculate asymmetry score. More...
 

Additional Inherited Members

- Public Types inherited from lar_content::MvaFeatureTool< Ts >
typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 

Detailed Description

AsymmetryFeatureBaseTool class.

Definition at line 19 of file AsymmetryFeatureBaseTool.h.

Constructor & Destructor Documentation

lar_content::AsymmetryFeatureBaseTool::AsymmetryFeatureBaseTool ( )

Default constructor.

Definition at line 19 of file AsymmetryFeatureBaseTool.cc.

20 {
21 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.

Member Function Documentation

float lar_content::AsymmetryFeatureBaseTool::CalculateAsymmetry ( const bool  useEnergyMetrics,
const pandora::CartesianVector &  vertexPosition2D,
const pandora::ClusterVector &  asymmetryClusters,
const pandora::CartesianVector &  localWeightedDirectionSum 
) const
protectedvirtual

Calculate the asymmetry feature.

Parameters
useEnergyMetricswhether to use energy-based metrics instead of hit-counting-based metrics
vertexPosition2Dthe vertex position in this view
asymmetryClusterthe vector of cluster objects to be used in the asymmetry calculation
localWeightedDirectionSumthe local event axis
Returns
the asymmetry feature

Reimplemented in lar_content::EnergyDepositionAsymmetryFeatureTool.

Definition at line 69 of file AsymmetryFeatureBaseTool.cc.

71 {
72  // Project every hit onto local event axis direction and record side of the projected vtx position on which it falls
73  float beforeVtxHitEnergy(0.f), afterVtxHitEnergy(0.f);
74  unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
75 
76  const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
77  const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
78 
79  for (const Cluster *const pCluster : asymmetryClusters)
80  {
81  CaloHitList caloHitList;
82  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
83 
84  CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
85  std::sort(caloHitVector.begin(), caloHitVector.end(), LArClusterHelper::SortHitsByPosition);
86 
87  for (const CaloHit *const pCaloHit : caloHitVector)
88  {
89  if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
90  {
91  beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
92  ++beforeVtxHitCount;
93  }
94  else
95  {
96  afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
97  ++afterVtxHitCount;
98  }
99  }
100  }
101 
102  // Use energy metrics if possible, otherwise fall back on hit counting.
103  const float totHitEnergy(beforeVtxHitEnergy + afterVtxHitEnergy);
104  const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
105 
106  if (useEnergyMetrics && (totHitEnergy > std::numeric_limits<float>::epsilon()))
107  return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
108 
109  if (0 == totHitCount)
110  throw StatusCodeException(STATUS_CODE_FAILURE);
111 
112  return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) / static_cast<float>(totHitCount);
113 }
static bool SortHitsByPosition(const pandora::CaloHit *const pLhs, const pandora::CaloHit *const pRhs)
Sort calo hits by their position (use Z, followed by X, followed by Y)
virtual float lar_content::AsymmetryFeatureBaseTool::GetAsymmetryForView ( const pandora::CartesianVector &  vertexPosition2D,
const VertexSelectionBaseAlgorithm::SlidingFitDataList slidingFitDataList,
const VertexSelectionBaseAlgorithm::ShowerClusterList showerClusterList 
) const
protectedpure virtual

Get the asymmetry feature for a given view.

Parameters
vertexPosition2Dthe vertex position projected into this view
slidingFitDataListthe list of sliding fit data objects for this view
showerClusterListthe list of shower cluster objects for this view
Returns
the asymmetry feature

Implemented in lar_content::ShowerAsymmetryFeatureTool, lar_content::GlobalAsymmetryFeatureTool, and lar_content::LocalAsymmetryFeatureTool.

void lar_content::AsymmetryFeatureBaseTool::IncrementAsymmetryParameters ( const float  weight,
const pandora::CartesianVector &  clusterDirection,
pandora::CartesianVector &  localWeightedDirectionSum 
) const
protected

Increment the asymmetry parameters.

Parameters
weightthe weight to assign to this vector
clusterDirectionthe direction of the cluster
localWeightedDirectionSumthe current energy-weighted local cluster direction vector

Definition at line 52 of file AsymmetryFeatureBaseTool.cc.

54 {
55  // If the new axis direction is at an angle of greater than 90 deg to the current axis direction, flip it 180 degs.
56  CartesianVector newDirection(clusterDirection);
57 
58  if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
59  {
60  if (localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection) < 0.f)
61  newDirection *= -1.f;
62  }
63 
64  localWeightedDirectionSum += newDirection * weight;
65 }
weight
Definition: test.py:257
StatusCode lar_content::AsymmetryFeatureBaseTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
protected

Definition at line 117 of file AsymmetryFeatureBaseTool.cc.

118 {
119  PANDORA_RETURN_RESULT_IF_AND_IF(
120  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxAsymmetryDistance", m_maxAsymmetryDistance));
121 
122  return STATUS_CODE_SUCCESS;
123 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
void lar_content::AsymmetryFeatureBaseTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const VertexSelectionBaseAlgorithm *const  pAlgorithm,
const pandora::Vertex *const  pVertex,
const VertexSelectionBaseAlgorithm::SlidingFitDataListMap slidingFitDataListMap,
const VertexSelectionBaseAlgorithm::ClusterListMap ,
const VertexSelectionBaseAlgorithm::KDTreeMap ,
const VertexSelectionBaseAlgorithm::ShowerClusterListMap showerClusterListMap,
const float  ,
float &   
)

Run the tool.

Parameters
pAlgorithmaddress of the calling algorithm
pVertexaddress of the vertex
slidingFitDataListMapmap of the sliding fit data lists
showerClusterListMapmap of the shower cluster lists
Returns
the asymmetry feature

Definition at line 25 of file AsymmetryFeatureBaseTool.cc.

29 {
30  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
32 
33  float asymmetry(0.f);
34 
35  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_U),
36  slidingFitDataListMap.at(TPC_VIEW_U),
37  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_U));
38 
39  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_V),
40  slidingFitDataListMap.at(TPC_VIEW_V),
41  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_V));
42 
43  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_W),
44  slidingFitDataListMap.at(TPC_VIEW_W),
45  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_W));
46 
47  featureVector.push_back(asymmetry);
48 }
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
virtual float GetAsymmetryForView(const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const VertexSelectionBaseAlgorithm::ShowerClusterList &showerClusterList) const =0
Get the asymmetry feature for a given view.
QTextStream & endl(QTextStream &s)

Member Data Documentation

float lar_content::AsymmetryFeatureBaseTool::m_maxAsymmetryDistance
protected

The max distance between cluster (any hit) and vertex to calculate asymmetry score.

Definition at line 81 of file AsymmetryFeatureBaseTool.h.


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