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

LocalAsymmetryFeatureTool class. More...

#include "LocalAsymmetryFeatureTool.h"

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

Public Types

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

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 &showerClusterListMap, const float, float &)
 Run the tool. 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...)
 

Protected Member Functions

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

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle) override
 
float GetAsymmetryForView (const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const VertexSelectionBaseAlgorithm::ShowerClusterList &) const override
 Get the local asymmetry feature in a given view. More...
 
bool CheckAngle (const pandora::CartesianVector &weightedDirectionSum, const pandora::CartesianVector &clusterDirection) const
 Check whether a cluster's direction agrees with the current weighted direction. More...
 

Private Attributes

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::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::LocalAsymmetryFeatureTool::LocalAsymmetryFeatureTool ( )

Default constructor.

Definition at line 20 of file LocalAsymmetryFeatureTool.cc.

20  :
22  m_minAsymmetryCosAngle(0.9962),
24 {
25 }
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::AsymmetryFeatureBaseTool::CalculateAsymmetry ( const bool  useEnergyMetrics,
const pandora::CartesianVector &  vertexPosition2D,
const pandora::ClusterVector &  asymmetryClusters,
const pandora::CartesianVector &  localWeightedDirectionSum 
) const
protectedvirtualinherited

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 70 of file AsymmetryFeatureBaseTool.cc.

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

Referenced by GetAsymmetryForView(), lar_content::GlobalAsymmetryFeatureTool::GetAsymmetryForView(), and lar_content::ShowerAsymmetryFeatureTool::GetAsymmetryForView().

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

Check whether a cluster's direction agrees with the current weighted direction.

Parameters
weightedDirectionSumthe current weighted direction
clusterDirectionthe cluster's direction
Returns
boolean

Definition at line 78 of file LocalAsymmetryFeatureTool.cc.

References m_minAsymmetryCosAngle.

Referenced by GetAsymmetryForView().

79 {
80  if (!(weightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon()))
81  return true;
82 
83  const float cosOpeningAngle(weightedDirectionSum.GetCosOpeningAngle(clusterDirection));
84  return std::fabs(cosOpeningAngle) > m_minAsymmetryCosAngle;
85 }
float m_minAsymmetryCosAngle
The min opening angle cosine used to determine viability of asymmetry score.
float lar_content::LocalAsymmetryFeatureTool::GetAsymmetryForView ( const pandora::CartesianVector &  vertexPosition2D,
const VertexSelectionBaseAlgorithm::SlidingFitDataList slidingFitDataList,
const VertexSelectionBaseAlgorithm::ShowerClusterList  
) const
overrideprivatevirtual

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

Implements lar_content::AsymmetryFeatureBaseTool.

Definition at line 29 of file LocalAsymmetryFeatureTool.cc.

References lar_content::AsymmetryFeatureBaseTool::CalculateAsymmetry(), CheckAngle(), f, lar_content::LArClusterHelper::GetClosestDistance(), lar_content::AsymmetryFeatureBaseTool::IncrementAsymmetryParameters(), lar_content::AsymmetryFeatureBaseTool::m_maxAsymmetryDistance, and m_maxAsymmetryNClusters.

31 {
32  bool useEnergy(true), useAsymmetry(true);
33  CartesianVector energyWeightedDirectionSum(0.f, 0.f, 0.f), hitWeightedDirectionSum(0.f, 0.f, 0.f);
34  ClusterVector asymmetryClusters;
35 
36  for (const VertexSelectionBaseAlgorithm::SlidingFitData &slidingFitData : slidingFitDataList)
37  {
38  const Cluster *const pCluster(slidingFitData.GetCluster());
39 
40  if (pCluster->GetElectromagneticEnergy() < std::numeric_limits<float>::epsilon())
41  useEnergy = false;
42 
43  const CartesianVector vertexToMinLayer(slidingFitData.GetMinLayerPosition() - vertexPosition2D);
44  const CartesianVector vertexToMaxLayer(slidingFitData.GetMaxLayerPosition() - vertexPosition2D);
45 
46  const bool minLayerClosest(vertexToMinLayer.GetMagnitudeSquared() < vertexToMaxLayer.GetMagnitudeSquared());
47  const CartesianVector &clusterDirection((minLayerClosest) ? slidingFitData.GetMinLayerDirection() : slidingFitData.GetMaxLayerDirection());
48 
49  if (useAsymmetry && (LArClusterHelper::GetClosestDistance(vertexPosition2D, pCluster) < m_maxAsymmetryDistance))
50  {
51  useAsymmetry &= this->CheckAngle(energyWeightedDirectionSum, clusterDirection);
52  this->IncrementAsymmetryParameters(pCluster->GetElectromagneticEnergy(), clusterDirection, energyWeightedDirectionSum);
53 
54  useAsymmetry &= this->CheckAngle(hitWeightedDirectionSum, clusterDirection);
55  this->IncrementAsymmetryParameters(static_cast<float>(pCluster->GetNCaloHits()), clusterDirection, hitWeightedDirectionSum);
56 
57  asymmetryClusters.push_back(pCluster);
58  }
59 
60  if (!useAsymmetry)
61  return 1.f;
62  }
63 
64  // Default: maximum asymmetry (i.e. not suppressed), zero for energy kick (i.e. not suppressed)
65  if ((useEnergy && energyWeightedDirectionSum == CartesianVector(0.f, 0.f, 0.f)) ||
66  (!useEnergy && hitWeightedDirectionSum == CartesianVector(0.f, 0.f, 0.f)))
67  return 1.f;
68 
69  if (asymmetryClusters.empty() || (asymmetryClusters.size() > m_maxAsymmetryNClusters))
70  return 1.f;
71 
72  const CartesianVector &localWeightedDirectionSum(useEnergy ? energyWeightedDirectionSum : hitWeightedDirectionSum);
73  return this->CalculateAsymmetry(useEnergy, vertexPosition2D, asymmetryClusters, localWeightedDirectionSum);
74 }
virtual float CalculateAsymmetry(const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const pandora::ClusterVector &asymmetryClusters, const pandora::CartesianVector &localWeightedDirectionSum) const
Calculate the asymmetry feature.
bool CheckAngle(const pandora::CartesianVector &weightedDirectionSum, const pandora::CartesianVector &clusterDirection) const
Check whether a cluster&#39;s direction agrees with the current weighted direction.
float m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
TFile f
Definition: plotHisto.C:6
void IncrementAsymmetryParameters(const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
Increment the asymmetry parameters.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
unsigned int m_maxAsymmetryNClusters
The max number of associated clusters to calculate the asymmetry.
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::AsymmetryFeatureBaseTool::IncrementAsymmetryParameters ( const float  weight,
const pandora::CartesianVector &  clusterDirection,
pandora::CartesianVector &  localWeightedDirectionSum 
) const
protectedinherited

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 53 of file AsymmetryFeatureBaseTool.cc.

References f, and weight.

Referenced by GetAsymmetryForView(), and lar_content::GlobalAsymmetryFeatureTool::GetAsymmetryForView().

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

Definition at line 89 of file LocalAsymmetryFeatureTool.cc.

References m_maxAsymmetryNClusters, m_minAsymmetryCosAngle, and lar_content::AsymmetryFeatureBaseTool::ReadSettings().

90 {
91  PANDORA_RETURN_RESULT_IF_AND_IF(
92  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinAsymmetryCosAngle", m_minAsymmetryCosAngle));
93 
94  PANDORA_RETURN_RESULT_IF_AND_IF(
95  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxAsymmetryNClusters", m_maxAsymmetryNClusters));
96 
98 }
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.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
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 &   
)
inherited

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 26 of file AsymmetryFeatureBaseTool.cc.

References f, lar_content::AsymmetryFeatureBaseTool::GetAsymmetryForView(), and lar_content::LArGeometryHelper::ProjectPosition().

30 {
31  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
32  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
33 
34  float asymmetry(0.f);
35 
36  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_U),
37  slidingFitDataListMap.at(TPC_VIEW_U),
38  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_U));
39 
40  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_V),
41  slidingFitDataListMap.at(TPC_VIEW_V),
42  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_V));
43 
44  asymmetry += this->GetAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_W),
45  slidingFitDataListMap.at(TPC_VIEW_W),
46  showerClusterListMap.empty() ? VertexSelectionBaseAlgorithm::ShowerClusterList() : showerClusterListMap.at(TPC_VIEW_W));
47 
48  featureVector.push_back(asymmetry);
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.
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.
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
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  };

Member Data Documentation

float lar_content::AsymmetryFeatureBaseTool::m_maxAsymmetryDistance
protectedinherited

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

Definition at line 81 of file AsymmetryFeatureBaseTool.h.

Referenced by GetAsymmetryForView(), lar_content::GlobalAsymmetryFeatureTool::GetAsymmetryForView(), and lar_content::AsymmetryFeatureBaseTool::ReadSettings().

unsigned int lar_content::LocalAsymmetryFeatureTool::m_maxAsymmetryNClusters
private

The max number of associated clusters to calculate the asymmetry.

Definition at line 52 of file LocalAsymmetryFeatureTool.h.

Referenced by GetAsymmetryForView(), and ReadSettings().

float lar_content::LocalAsymmetryFeatureTool::m_minAsymmetryCosAngle
private

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

Definition at line 51 of file LocalAsymmetryFeatureTool.h.

Referenced by CheckAngle(), and ReadSettings().


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