10 #include "Pandora/AlgorithmHeaders.h"
19 AsymmetryFeatureBaseTool::AsymmetryFeatureBaseTool() : m_maxAsymmetryDistance(5.f)
30 if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31 std::cout <<
"----> Running Algorithm Tool: " << this->GetInstanceName() <<
", " << this->GetType() << std::endl;
36 slidingFitDataListMap.at(TPC_VIEW_U),
40 slidingFitDataListMap.at(TPC_VIEW_V),
44 slidingFitDataListMap.at(TPC_VIEW_W),
47 featureVector.push_back(asymmetry);
53 const float weight,
const CartesianVector &clusterDirection, CartesianVector &localWeightedDirectionSum)
const
56 CartesianVector newDirection(clusterDirection);
58 if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
60 if (localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection) < 0.f)
64 localWeightedDirectionSum += newDirection * weight;
70 const ClusterVector &asymmetryClusters,
const CartesianVector &localWeightedDirectionSum)
const
73 float beforeVtxHitEnergy(0.f), afterVtxHitEnergy(0.f);
74 unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
76 const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
77 const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
79 for (
const Cluster *
const pCluster : asymmetryClusters)
81 CaloHitList caloHitList;
82 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
84 CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
87 for (
const CaloHit *
const pCaloHit : caloHitVector)
89 if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
91 beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
96 afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
103 const float totHitEnergy(beforeVtxHitEnergy + afterVtxHitEnergy);
104 const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
106 if (useEnergyMetrics && (totHitEnergy > std::numeric_limits<float>::epsilon()))
107 return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
109 if (0 == totHitCount)
110 throw StatusCodeException(STATUS_CODE_FAILURE);
112 return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) /
static_cast<float>(totHitCount);
119 PANDORA_RETURN_RESULT_IF_AND_IF(
120 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxAsymmetryDistance",
m_maxAsymmetryDistance));
122 return STATUS_CODE_SUCCESS;
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.
MvaTypes::MvaFeatureVector MvaFeatureVector
virtual float CalculateAsymmetry(const bool useEnergyMetrics, const pandora::CartesianVector &vertexPosition2D, const pandora::ClusterVector &asymmetryClusters, const pandora::CartesianVector &localWeightedDirectionSum) const
Calculate the asymmetry feature.
std::vector< ShowerCluster > ShowerClusterList
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 m_maxAsymmetryDistance
The max distance between cluster (any hit) and vertex to calculate asymmetry score.
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.
VertexSelectionBaseAlgorithm class.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
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.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
void IncrementAsymmetryParameters(const float weight, const pandora::CartesianVector &clusterDirection, pandora::CartesianVector &localWeightedDirectionSum) const
Increment the asymmetry parameters.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
BEGIN_PROLOG could also be cout