10 #include "Pandora/AlgorithmHeaders.h" 19 AsymmetryFeatureBaseTool::AsymmetryFeatureBaseTool() :
20 m_maxAsymmetryDistance(5.
f)
31 if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
32 std::cout <<
"----> Running Algorithm Tool: " << this->GetInstanceName() <<
", " << this->GetType() << std::endl;
37 slidingFitDataListMap.at(TPC_VIEW_U),
41 slidingFitDataListMap.at(TPC_VIEW_V),
45 slidingFitDataListMap.at(TPC_VIEW_W),
48 featureVector.push_back(asymmetry);
54 const float weight,
const CartesianVector &clusterDirection, CartesianVector &localWeightedDirectionSum)
const 57 CartesianVector newDirection(clusterDirection);
59 if (localWeightedDirectionSum.GetMagnitudeSquared() > std::numeric_limits<float>::epsilon())
61 if (localWeightedDirectionSum.GetCosOpeningAngle(clusterDirection) < 0.f)
65 localWeightedDirectionSum += newDirection *
weight;
71 const ClusterVector &asymmetryClusters,
const CartesianVector &localWeightedDirectionSum)
const 74 float beforeVtxHitEnergy(0.
f), afterVtxHitEnergy(0.
f);
75 unsigned int beforeVtxHitCount(0), afterVtxHitCount(0);
77 const CartesianVector localWeightedDirection(localWeightedDirectionSum.GetUnitVector());
78 const float evtProjectedVtxPos(vertexPosition2D.GetDotProduct(localWeightedDirection));
80 for (
const Cluster *
const pCluster : asymmetryClusters)
82 CaloHitList caloHitList;
83 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
85 CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
88 for (
const CaloHit *
const pCaloHit : caloHitVector)
90 if (pCaloHit->GetPositionVector().GetDotProduct(localWeightedDirection) < evtProjectedVtxPos)
92 beforeVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
97 afterVtxHitEnergy += pCaloHit->GetElectromagneticEnergy();
104 const float totHitEnergy(beforeVtxHitEnergy + afterVtxHitEnergy);
105 const unsigned int totHitCount(beforeVtxHitCount + afterVtxHitCount);
107 if (useEnergyMetrics && (totHitEnergy > std::numeric_limits<float>::epsilon()))
108 return std::fabs((afterVtxHitEnergy - beforeVtxHitEnergy)) / totHitEnergy;
110 if (0 == totHitCount)
111 throw StatusCodeException(STATUS_CODE_FAILURE);
113 return std::fabs((static_cast<float>(afterVtxHitCount) - static_cast<float>(beforeVtxHitCount))) /
static_cast<float>(totHitCount);
120 PANDORA_RETURN_RESULT_IF_AND_IF(
121 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxAsymmetryDistance",
m_maxAsymmetryDistance));
123 return STATUS_CODE_SUCCESS;
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.
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.
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.
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.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
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)