LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::LocalAsymmetryFeatureTool Class Referenceabstract

LocalAsymmetryFeatureTool class. More...

#include "LocalAsymmetryFeatureTool.h"

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

Public Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 

Public Member Functions

 LocalAsymmetryFeatureTool ()
 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 &, const float, float &)
 Run the tool. 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)
 
float GetLocalAsymmetryForView (const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
 Get the local asymmetry feature in a given view. More...
 
bool IncrementAsymmetryParameters (const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
 Increment the asymmetry parameters. More...
 
float CalculateLocalAsymmetry (const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const pandora::ClusterVector &asymmetryClusters, const pandora::CartesianVector &localWeightedDirectionSum) const
 Calculate the local asymmetry feature. More...
 

Private Attributes

float m_maxAsymmetryDistance
 The max distance between cluster (any hit) and vertex to calculate asymmetry score. More...
 
float m_minAsymmetryCosAngle
 The min opening angle cosine used to determine viability of asymmetry score. More...
 
unsigned int m_maxAsymmetryNClusters
 The max number of associated clusters to calculate the asymmetry. More...
 

Detailed Description

LocalAsymmetryFeatureTool class.

Definition at line 19 of file LocalAsymmetryFeatureTool.h.

Member Typedef Documentation

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

Definition at line 30 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::LocalAsymmetryFeatureTool::LocalAsymmetryFeatureTool ( )

Default constructor.

Definition at line 21 of file LocalAsymmetryFeatureTool.cc.

21  :
23  m_minAsymmetryCosAngle(0.9962),
25 {
26 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
TFile f
Definition: plotHisto.C:6
float m_minAsymmetryCosAngle
The min opening angle cosine used to determine viability of asymmetry score.
unsigned int m_maxAsymmetryNClusters
The max number of associated clusters to calculate the asymmetry.

Member Function Documentation

float lar_content::LocalAsymmetryFeatureTool::CalculateLocalAsymmetry ( const bool  useEnergyMetrics,
const pandora::CartesianVector &  vertexPosition2D,
const pandora::ClusterVector &  asymmetryClusters,
const pandora::CartesianVector &  localWeightedDirectionSum 
) const
private

Calculate the local asymmetry feature.

Parameters
useEnergyMetricswhether to use energy-based rather than hit-counting-based metrics
vertexPosition2Dthe vertex position
asymmetryClustersthe clusters to use to calculate the asymmetry
localWeightedDirectionSumthe local event axis
Returns
the local asymmetry feature

Definition at line 120 of file LocalAsymmetryFeatureTool.cc.

References f, m_maxAsymmetryNClusters, and lar_content::LArClusterHelper::SortHitsByPosition().

Referenced by GetLocalAsymmetryForView().

122 {
123  if (asymmetryClusters.empty() || (asymmetryClusters.size() > m_maxAsymmetryNClusters))
124  return 1.f;
125 
126  // Project every hit onto local event axis direction and record side of the projected vtx position on which it falls
127  float beforeVtxHitEnergy(0.f), afterVtxHitEnergy(0.f);
128  unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
129 
130  const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
131  const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
132 
133  for (const Cluster *const pCluster : asymmetryClusters)
134  {
135  CaloHitList caloHitList;
136  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
137 
138  CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
139  std::sort(caloHitVector.begin(), caloHitVector.end(), LArClusterHelper::SortHitsByPosition);
140 
141  for (const CaloHit *const pCaloHit : caloHitVector)
142  {
143  if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
144  {
145  beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
146  ++beforeVtxHitCount;
147  }
148 
149  else
150  {
151  afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
152  ++afterVtxHitCount;
153  }
154  }
155  }
156 
157  // Use energy metrics if possible, otherwise fall back on hit counting.
158  const float totHitEnergy(afterVtxHitEnergy + beforeVtxHitEnergy);
159  const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
160 
161  if (useEnergyMetrics && (totHitEnergy > std::numeric_limits<float>::epsilon()))
162  return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
163 
164  if (0 == totHitCount)
165  throw StatusCodeException(STATUS_CODE_FAILURE);
166 
167  return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) / static_cast<float>(totHitCount);
168 }
TFile f
Definition: plotHisto.C:6
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)
unsigned int m_maxAsymmetryNClusters
The max number of associated clusters to calculate the asymmetry.
float lar_content::LocalAsymmetryFeatureTool::GetLocalAsymmetryForView ( const pandora::CartesianVector &  vertexPosition2D,
const VertexSelectionBaseAlgorithm::SlidingFitDataList slidingFitDataList 
) const
private

Get the local asymmetry feature in a given view.

Parameters
vertexPosition2Dthe vertex position projected into this view
slidingFitDataListthe list of sliding fit data objects in this view
Returns
the local asymmetry feature

Definition at line 53 of file LocalAsymmetryFeatureTool.cc.

References CalculateLocalAsymmetry(), f, lar_content::LArClusterHelper::GetClosestDistance(), IncrementAsymmetryParameters(), and m_maxAsymmetryDistance.

Referenced by Run().

55 {
56  bool useEnergy(true), useAsymmetry(true);
57  CartesianVector energyWeightedDirectionSum(0.f, 0.f, 0.f), hitWeightedDirectionSum(0.f, 0.f, 0.f);
58  ClusterVector asymmetryClusters;
59 
60  for (const VertexSelectionBaseAlgorithm::SlidingFitData &slidingFitData : slidingFitDataList)
61  {
62  const Cluster *const pCluster(slidingFitData.GetCluster());
63 
64  if (pCluster->GetElectromagneticEnergy() < std::numeric_limits<float>::epsilon())
65  useEnergy = false;
66 
67  const CartesianVector vertexToMinLayer(slidingFitData.GetMinLayerPosition() - vertexPosition2D);
68  const CartesianVector vertexToMaxLayer(slidingFitData.GetMaxLayerPosition() - vertexPosition2D);
69 
70  const bool minLayerClosest(vertexToMinLayer.GetMagnitudeSquared() < vertexToMaxLayer.GetMagnitudeSquared());
71  const CartesianVector &clusterDirection((minLayerClosest) ? slidingFitData.GetMinLayerDirection() : slidingFitData.GetMaxLayerDirection());
72 
73  if (useAsymmetry && (LArClusterHelper::GetClosestDistance(vertexPosition2D, pCluster) < m_maxAsymmetryDistance))
74  {
75  useAsymmetry &= this->IncrementAsymmetryParameters(pCluster->GetElectromagneticEnergy(), clusterDirection, energyWeightedDirectionSum);
76  useAsymmetry &= this->IncrementAsymmetryParameters(static_cast<float>(pCluster->GetNCaloHits()), clusterDirection, hitWeightedDirectionSum);
77  asymmetryClusters.push_back(pCluster);
78  }
79 
80  if (!useAsymmetry)
81  return 1.f;
82  }
83 
84  // Default: maximum asymmetry (i.e. not suppressed), zero for energy kick (i.e. not suppressed)
85  if ((useEnergy && energyWeightedDirectionSum == CartesianVector(0.f, 0.f, 0.f)) || (!useEnergy && hitWeightedDirectionSum == CartesianVector(0.f, 0.f, 0.f)))
86  return 1.f;
87 
88  const CartesianVector &localWeightedDirectionSum(useEnergy ? energyWeightedDirectionSum : hitWeightedDirectionSum);
89  return this->CalculateLocalAsymmetry(useEnergy, vertexPosition2D, asymmetryClusters, localWeightedDirectionSum);
90 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
float CalculateLocalAsymmetry(const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const pandora::ClusterVector &asymmetryClusters, const pandora::CartesianVector &localWeightedDirectionSum) const
Calculate the local asymmetry feature.
TFile f
Definition: plotHisto.C:6
bool IncrementAsymmetryParameters(const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
Increment the asymmetry parameters.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
bool lar_content::LocalAsymmetryFeatureTool::IncrementAsymmetryParameters ( const float  weight,
const pandora::CartesianVector &  clusterDirection,
pandora::CartesianVector &  localWeightedDirectionSum 
) const
private

Increment the asymmetry parameters.

Parameters
weightthe weight for the increment
clusterDirectionthe cluster direction
localWeightedDirectionSumthe current value of the vector
Returns
whether the energy asymmetry score is still viable

Definition at line 94 of file LocalAsymmetryFeatureTool.cc.

References f, m_minAsymmetryCosAngle, and weight.

Referenced by GetLocalAsymmetryForView().

96 {
97  // If the new axis direction is at an angle of greater than 90 deg to the current axis direction, flip it 180 degs.
98  CartesianVector newDirection(clusterDirection);
99 
100  if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
101  {
102  const float cosOpeningAngle(localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection));
103 
104  if (std::fabs(cosOpeningAngle) > m_minAsymmetryCosAngle)
105  {
106  if (cosOpeningAngle < 0.f)
107  newDirection *= -1.f;
108  }
109 
110  else
111  return false;
112  }
113 
114  localWeightedDirectionSum += newDirection * weight;
115  return true;
116 }
TFile f
Definition: plotHisto.C:6
double weight
Definition: plottest35.C:25
float m_minAsymmetryCosAngle
The min opening angle cosine used to determine viability of asymmetry score.
StatusCode lar_content::LocalAsymmetryFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 172 of file LocalAsymmetryFeatureTool.cc.

References m_maxAsymmetryDistance, m_maxAsymmetryNClusters, and m_minAsymmetryCosAngle.

173 {
174  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
175  "MaxAsymmetryDistance", m_maxAsymmetryDistance));
176 
177  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
178  "MinAsymmetryCosAngle", m_minAsymmetryCosAngle));
179 
180  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
181  "MaxAsymmetryNClusters", m_maxAsymmetryNClusters));
182 
183  return STATUS_CODE_SUCCESS;
184 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
float m_minAsymmetryCosAngle
The min opening angle cosine used to determine viability of asymmetry score.
unsigned int m_maxAsymmetryNClusters
The max number of associated clusters to calculate the asymmetry.
void lar_content::LocalAsymmetryFeatureTool::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 ,
const float  ,
float &   
)

Run the tool.

Parameters
pAlgorithmaddress of the calling algorithm
pVertexaddress of the vertex
slidingFitDataListMapmap of the sliding fit data lists
Returns
the energy kick feature

Definition at line 30 of file LocalAsymmetryFeatureTool.cc.

References f, GetLocalAsymmetryForView(), and lar_content::LArGeometryHelper::ProjectPosition().

33 {
34  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
35  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
36 
37  float localAsymmetry(0.f);
38 
39  localAsymmetry += this->GetLocalAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_U),
40  slidingFitDataListMap.at(TPC_VIEW_U));
41 
42  localAsymmetry += this->GetLocalAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_V),
43  slidingFitDataListMap.at(TPC_VIEW_V));
44 
45  localAsymmetry += this->GetLocalAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_W),
46  slidingFitDataListMap.at(TPC_VIEW_W));
47 
48  featureVector.push_back(localAsymmetry);
49 }
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
float GetLocalAsymmetryForView(const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
Get the local asymmetry feature in a given view.
TFile f
Definition: plotHisto.C:6
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

Member Data Documentation

float lar_content::LocalAsymmetryFeatureTool::m_maxAsymmetryDistance
private

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

Definition at line 78 of file LocalAsymmetryFeatureTool.h.

Referenced by GetLocalAsymmetryForView(), and ReadSettings().

unsigned int lar_content::LocalAsymmetryFeatureTool::m_maxAsymmetryNClusters
private

The max number of associated clusters to calculate the asymmetry.

Definition at line 80 of file LocalAsymmetryFeatureTool.h.

Referenced by CalculateLocalAsymmetry(), and ReadSettings().

float lar_content::LocalAsymmetryFeatureTool::m_minAsymmetryCosAngle
private

The min opening angle cosine used to determine viability of asymmetry score.

Definition at line 79 of file LocalAsymmetryFeatureTool.h.

Referenced by IncrementAsymmetryParameters(), and ReadSettings().


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