9 #include "Pandora/AlgorithmHeaders.h" 19 GlobalAsymmetryFeatureTool::GlobalAsymmetryFeatureTool() :
20 m_maxAsymmetryDistance(5.
f)
30 if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31 std::cout <<
"----> Running Algorithm Tool: " << this->GetInstanceName() <<
", " << this->GetType() << std::endl;
33 float globalAsymmetry(0.
f);
36 slidingFitDataListMap.at(TPC_VIEW_U));
39 slidingFitDataListMap.at(TPC_VIEW_V));
42 slidingFitDataListMap.at(TPC_VIEW_W));
44 featureVector.push_back(globalAsymmetry);
53 CartesianVector energyWeightedDirectionSum(0.
f, 0.
f, 0.
f), hitWeightedDirectionSum(0.
f, 0.
f, 0.
f);
57 const Cluster *
const pCluster(slidingFitData.GetCluster());
59 if (pCluster->GetElectromagneticEnergy() < std::numeric_limits<float>::epsilon())
62 const CartesianVector vertexToMinLayer(slidingFitData.GetMinLayerPosition() - vertexPosition2D);
63 const CartesianVector vertexToMaxLayer(slidingFitData.GetMaxLayerPosition() - vertexPosition2D);
65 const bool minLayerClosest(vertexToMinLayer.GetMagnitudeSquared() < vertexToMaxLayer.GetMagnitudeSquared());
66 const CartesianVector &clusterDirection((minLayerClosest) ? slidingFitData.GetMinLayerDirection() : slidingFitData.GetMaxLayerDirection());
75 const CartesianVector &localWeightedDirectionSum(useEnergy ? energyWeightedDirectionSum : hitWeightedDirectionSum);
77 if (localWeightedDirectionSum.GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
86 CartesianVector &localWeightedDirectionSum)
const 89 CartesianVector newDirection(clusterDirection);
91 if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
93 if (localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection) < 0.f)
97 localWeightedDirectionSum += newDirection *
weight;
106 float beforeVtxHitEnergy(0.
f), afterVtxHitEnergy(0.
f);
107 unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
109 const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
110 const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
114 const Cluster *
const pCluster(slidingFitData.GetCluster());
116 CaloHitList caloHitList;
117 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
119 CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
122 for (
const CaloHit *
const pCaloHit : caloHitVector)
124 if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
126 beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
132 afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
139 const float totHitEnergy(beforeVtxHitEnergy + afterVtxHitEnergy);
140 const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
142 if (useEnergyMetrics)
143 return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
145 if (0 == totHitCount)
146 throw StatusCodeException(STATUS_CODE_FAILURE);
148 return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) /
static_cast<float>(totHitCount);
155 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
158 return STATUS_CODE_SUCCESS;
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
MvaTypes::MvaFeatureVector MvaFeatureVector
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
void IncrementAsymmetryParameters(const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
Increment the asymmetry parameters.
std::vector< SlidingFitData > SlidingFitDataList
Header file for the geometry helper class.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
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)
Header file for the cluster helper class.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
float CalculateGlobalAsymmetry(const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList, const pandora::CartesianVector &localWeightedDirectionSum) const
Calculate the global asymmetry feature.
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.
VertexSelectionBaseAlgorithm class.
float GetGlobalAsymmetryForView(const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
Get the global asymmetry feature for a given view.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
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.