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

GlobalAsymmetryFeatureTool class. More...

#include "GlobalAsymmetryFeatureTool.h"

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

Public Types

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

Public Member Functions

 GlobalAsymmetryFeatureTool ()
 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 GetGlobalAsymmetryForView (const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
 Get the global 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...
 
float CalculateGlobalAsymmetry (const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const pandora::CartesianVector &localWeightedDirectionSum) const
 Calculate the global asymmetry feature. More...
 

Private Attributes

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

Detailed Description

GlobalAsymmetryFeatureTool class.

Definition at line 19 of file GlobalAsymmetryFeatureTool.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::GlobalAsymmetryFeatureTool::GlobalAsymmetryFeatureTool ( )

Default constructor.

Definition at line 19 of file GlobalAsymmetryFeatureTool.cc.

19  :
21 {
22 }
TFile f
Definition: plotHisto.C:6
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.

Member Function Documentation

float lar_content::GlobalAsymmetryFeatureTool::CalculateGlobalAsymmetry ( const bool  useEnergyMetrics,
const pandora::CartesianVector &  vertexPosition2D,
const VertexSelectionBaseAlgorithm::SlidingFitDataList slidingFitDataList,
const pandora::CartesianVector &  localWeightedDirectionSum 
) const
private

Calculate the global asymmetry feature.

Parameters
useEnergyMetricswhether to use energy-based metrics instead of hit-counting-based metrics
vertexPosition2Dthe vertex position in this view
slidingFitDataListthe list of sliding fit data objects
localWeightedDirectionSumthe local event axis
Returns
the global asymmetry feature

Definition at line 102 of file GlobalAsymmetryFeatureTool.cc.

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

Referenced by GetGlobalAsymmetryForView().

104 {
105  // Project every hit onto local event axis direction and record side of the projected vtx position on which it falls
106  float beforeVtxHitEnergy(0.f), afterVtxHitEnergy(0.f);
107  unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
108 
109  const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
110  const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
111 
112  for (const VertexSelectionBaseAlgorithm::SlidingFitData &slidingFitData : slidingFitDataList)
113  {
114  const Cluster * const pCluster(slidingFitData.GetCluster());
115 
116  CaloHitList caloHitList;
117  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
118 
119  CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
120  std::sort(caloHitVector.begin(), caloHitVector.end(), LArClusterHelper::SortHitsByPosition);
121 
122  for (const CaloHit *const pCaloHit : caloHitVector)
123  {
124  if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
125  {
126  beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
127  ++beforeVtxHitCount;
128  }
129 
130  else
131  {
132  afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
133  ++afterVtxHitCount;
134  }
135  }
136  }
137 
138  // Use energy metrics if possible, otherwise fall back on hit counting.
139  const float totHitEnergy(beforeVtxHitEnergy + afterVtxHitEnergy);
140  const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
141 
142  if (useEnergyMetrics)
143  return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
144 
145  if (0 == totHitCount)
146  throw StatusCodeException(STATUS_CODE_FAILURE);
147 
148  return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) / static_cast<float>(totHitCount);
149 }
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)
float lar_content::GlobalAsymmetryFeatureTool::GetGlobalAsymmetryForView ( const pandora::CartesianVector &  vertexPosition2D,
const VertexSelectionBaseAlgorithm::SlidingFitDataList slidingFitDataList 
) const
private

Get the global asymmetry feature for a given view.

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

Definition at line 49 of file GlobalAsymmetryFeatureTool.cc.

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

Referenced by Run().

51 {
52  bool useEnergy(true);
53  CartesianVector energyWeightedDirectionSum(0.f, 0.f, 0.f), hitWeightedDirectionSum(0.f, 0.f, 0.f);
54 
55  for (const VertexSelectionBaseAlgorithm::SlidingFitData &slidingFitData : slidingFitDataList)
56  {
57  const Cluster *const pCluster(slidingFitData.GetCluster());
58 
59  if (pCluster->GetElectromagneticEnergy() < std::numeric_limits<float>::epsilon())
60  useEnergy = false;
61 
62  const CartesianVector vertexToMinLayer(slidingFitData.GetMinLayerPosition() - vertexPosition2D);
63  const CartesianVector vertexToMaxLayer(slidingFitData.GetMaxLayerPosition() - vertexPosition2D);
64 
65  const bool minLayerClosest(vertexToMinLayer.GetMagnitudeSquared() < vertexToMaxLayer.GetMagnitudeSquared());
66  const CartesianVector &clusterDirection((minLayerClosest) ? slidingFitData.GetMinLayerDirection() : slidingFitData.GetMaxLayerDirection());
67 
68  if ((LArClusterHelper::GetClosestDistance(vertexPosition2D, pCluster) < m_maxAsymmetryDistance))
69  {
70  this->IncrementAsymmetryParameters(pCluster->GetElectromagneticEnergy(), clusterDirection, energyWeightedDirectionSum);
71  this->IncrementAsymmetryParameters(static_cast<float>(pCluster->GetNCaloHits()), clusterDirection, hitWeightedDirectionSum);
72  }
73  }
74 
75  const CartesianVector &localWeightedDirectionSum(useEnergy ? energyWeightedDirectionSum : hitWeightedDirectionSum);
76 
77  if (localWeightedDirectionSum.GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
78  return 0.f;
79 
80  return this->CalculateGlobalAsymmetry(useEnergy, vertexPosition2D, slidingFitDataList, localWeightedDirectionSum);
81 }
void IncrementAsymmetryParameters(const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
Increment the asymmetry parameters.
TFile f
Definition: plotHisto.C:6
float CalculateGlobalAsymmetry(const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const pandora::CartesianVector &localWeightedDirectionSum) const
Calculate the global asymmetry feature.
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
void lar_content::GlobalAsymmetryFeatureTool::IncrementAsymmetryParameters ( const float  weight,
const pandora::CartesianVector &  clusterDirection,
pandora::CartesianVector &  localWeightedDirectionSum 
) const
private

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 85 of file GlobalAsymmetryFeatureTool.cc.

References f, and weight.

Referenced by GetGlobalAsymmetryForView().

87 {
88  // If the new axis direction is at an angle of greater than 90 deg to the current axis direction, flip it 180 degs.
89  CartesianVector newDirection(clusterDirection);
90 
91  if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
92  {
93  if (localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection) < 0.f)
94  newDirection *= -1.f;
95  }
96 
97  localWeightedDirectionSum += newDirection * weight;
98 }
TFile f
Definition: plotHisto.C:6
double weight
Definition: plottest35.C:25
StatusCode lar_content::GlobalAsymmetryFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 153 of file GlobalAsymmetryFeatureTool.cc.

References m_maxAsymmetryDistance.

154 {
155  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
156  "MaxAsymmetryDistance", m_maxAsymmetryDistance));
157 
158  return STATUS_CODE_SUCCESS;
159 }
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
void lar_content::GlobalAsymmetryFeatureTool::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 global asymmetry feature

Definition at line 26 of file GlobalAsymmetryFeatureTool.cc.

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

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

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

Definition at line 75 of file GlobalAsymmetryFeatureTool.h.

Referenced by GetGlobalAsymmetryForView(), and ReadSettings().


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