LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ShowerAsymmetryFeatureTool.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
13 
14 using namespace pandora;
15 
16 namespace lar_content
17 {
18 
19 ShowerAsymmetryFeatureTool::ShowerAsymmetryFeatureTool() :
20  m_vertexClusterDistance(4.f)
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
28  const VertexSelectionBaseAlgorithm::ShowerClusterListMap &showerClusterListMap, const float, float &)
29 {
30  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
32 
33  float showerAsymmetry(0.f);
34 
35  showerAsymmetry += this->GetShowerAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_U),
36  showerClusterListMap.at(TPC_VIEW_U));
37 
38  showerAsymmetry += this->GetShowerAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_V),
39  showerClusterListMap.at(TPC_VIEW_V));
40 
41  showerAsymmetry += this->GetShowerAsymmetryForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_W),
42  showerClusterListMap.at(TPC_VIEW_W));
43 
44  featureVector.push_back(showerAsymmetry);
45 }
46 
47 //------------------------------------------------------------------------------------------------------------------------------------------
48 
49 float ShowerAsymmetryFeatureTool::GetShowerAsymmetryForView(const CartesianVector &vertexPosition2D,
50  const VertexSelectionBaseAlgorithm::ShowerClusterList &showerClusterList) const
51 {
52  float showerAsymmetry(1.f);
53 
54  for (const VertexSelectionBaseAlgorithm::ShowerCluster &showerCluster : showerClusterList)
55  {
56  if (this->ShouldUseShowerCluster(vertexPosition2D, showerCluster))
57  {
58  const TwoDSlidingFitResult &showerFit = showerCluster.GetFit();
59 
60  float rL(0.f), rT(0.f);
61  showerFit.GetLocalPosition(vertexPosition2D, rL, rT);
62 
63  CartesianVector showerDirection(0.f, 0.f, 0.f);
64  showerFit.GetGlobalFitDirection(rL, showerDirection);
65 
66  const float projectedVtxPosition = vertexPosition2D.GetDotProduct(showerDirection);
67 
68  float beforeVtxEnergy(0.f), afterVtxEnergy(0.f);
69  this->CalculateAsymmetryParameters(showerCluster, projectedVtxPosition, showerDirection, beforeVtxEnergy, afterVtxEnergy);
70 
71  if (beforeVtxEnergy + afterVtxEnergy > 0.f)
72  showerAsymmetry = std::fabs(afterVtxEnergy - beforeVtxEnergy) / (afterVtxEnergy + beforeVtxEnergy);
73 
74  break;
75  }
76  }
77 
78  return showerAsymmetry;
79 }
80 
81 //------------------------------------------------------------------------------------------------------------------------------------------
82 
83 bool ShowerAsymmetryFeatureTool::ShouldUseShowerCluster(const CartesianVector &vertexPosition,
84  const VertexSelectionBaseAlgorithm::ShowerCluster &showerCluster) const
85 {
86  for (const Cluster * const pCluster : showerCluster.GetClusters())
87  {
88  if (LArClusterHelper::GetClosestDistance(vertexPosition, pCluster) < m_vertexClusterDistance)
89  return true;
90  }
91 
92  return false;
93 }
94 
95 //------------------------------------------------------------------------------------------------------------------------------------------
96 
98  const float projectedVtxPosition, const CartesianVector &showerDirection, float &beforeVtxEnergy, float &afterVtxEnergy) const
99 {
100  beforeVtxEnergy = 0.f;
101  afterVtxEnergy = 0.f;
102 
103  for (const Cluster * const pCluster : showerCluster.GetClusters())
104  {
105  CaloHitList caloHitList;
106  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
107 
108  CaloHitVector caloHitVector(caloHitList.begin(), caloHitList.end());
109  std::sort(caloHitVector.begin(), caloHitVector.end(), LArClusterHelper::SortHitsByPosition);
110 
111  for (const CaloHit *const pCaloHit : caloHitVector)
112  {
113  if (pCaloHit->GetPositionVector().GetDotProduct(showerDirection) < projectedVtxPosition)
114  beforeVtxEnergy += pCaloHit->GetElectromagneticEnergy();
115 
116  else if (pCaloHit->GetPositionVector().GetDotProduct(showerDirection) > projectedVtxPosition)
117  afterVtxEnergy += pCaloHit->GetElectromagneticEnergy();
118  }
119  }
120 }
121 
122 //------------------------------------------------------------------------------------------------------------------------------------------
123 //------------------------------------------------------------------------------------------------------------------------------------------
124 
125 StatusCode ShowerAsymmetryFeatureTool::ReadSettings(const TiXmlHandle xmlHandle)
126 {
127  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
128  "VertexClusterDistance", m_vertexClusterDistance));
129 
130  return STATUS_CODE_SUCCESS;
131 }
132 
133 } // namespace lar_content
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
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 Run(LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm, const pandora::Vertex *const pVertex, const VertexSelectionBaseAlgorithm::SlidingFitDataListMap &, const VertexSelectionBaseAlgorithm::ClusterListMap &, const VertexSelectionBaseAlgorithm::KDTreeMap &, const VertexSelectionBaseAlgorithm::ShowerClusterListMap &showerClusterListMap, const float, float &)
Run the tool.
const pandora::ClusterList & GetClusters() const
Get the cluster list.
TFile f
Definition: plotHisto.C:6
void CalculateAsymmetryParameters(const VertexSelectionBaseAlgorithm::ShowerCluster &showerCluster, const float projectedVtxPosition, const pandora::CartesianVector &showerDirection, float &beforeVtxEnergy, float &afterVtxEnergy) const
Calculate the parameters for the asymmetry calculation.
Header file for the geometry helper class.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
float m_vertexClusterDistance
The distance around the vertex to look for shower clusters.
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 GetShowerAsymmetryForView(const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::ShowerClusterList &showerClusterList) const
Get the shower asymmetry feature for a given view.
Header file for the cluster helper class.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
pandora::StatusCode GetGlobalFitDirection(const float rL, pandora::CartesianVector &direction) const
Get global fit direction for a given longitudinal coordinate.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
Header file for the shower asymmetry feature tool class.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
bool ShouldUseShowerCluster(const pandora::CartesianVector &vertexPosition, const VertexSelectionBaseAlgorithm::ShowerCluster &showerCluster) const
Get whether we should use a given shower cluster for asymmetry calculation.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.