LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
EnergyKickFeatureTool.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 EnergyKickFeatureTool::EnergyKickFeatureTool() :
21  m_rOffset(10.f),
22  m_xOffset(0.06f)
23 {
24 }
25 
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
28 void EnergyKickFeatureTool::Run(LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm, const Vertex * const pVertex,
31 {
32  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
33  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
34 
35  float energyKick(0.f);
36 
37  energyKick += this->GetEnergyKickForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_U),
38  slidingFitDataListMap.at(TPC_VIEW_U));
39 
40  energyKick += this->GetEnergyKickForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_V),
41  slidingFitDataListMap.at(TPC_VIEW_V));
42 
43  energyKick += this->GetEnergyKickForView(LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), TPC_VIEW_W),
44  slidingFitDataListMap.at(TPC_VIEW_W));
45 
46  featureVector.push_back(energyKick);
47 }
48 
49 //------------------------------------------------------------------------------------------------------------------------------------------
50 
51 float EnergyKickFeatureTool::GetEnergyKickForView(const CartesianVector &vertexPosition2D,
52  const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
53 {
54  unsigned int totHits(0);
55  bool useEnergy(true);
56  float totEnergy(0.f), totEnergyKick(0.f), totHitKick(0.f);
57 
58  for (const VertexSelectionBaseAlgorithm::SlidingFitData &slidingFitData : slidingFitDataList)
59  {
60  const Cluster *const pCluster(slidingFitData.GetCluster());
61 
62  if (pCluster->GetElectromagneticEnergy() < std::numeric_limits<float>::epsilon())
63  useEnergy = false;
64 
65  const CartesianVector vertexToMinLayer(slidingFitData.GetMinLayerPosition() - vertexPosition2D);
66  const CartesianVector vertexToMaxLayer(slidingFitData.GetMaxLayerPosition() - vertexPosition2D);
67 
68  const bool minLayerClosest(vertexToMinLayer.GetMagnitudeSquared() < vertexToMaxLayer.GetMagnitudeSquared());
69  const CartesianVector &clusterDisplacement((minLayerClosest) ? vertexToMinLayer : vertexToMaxLayer);
70  const CartesianVector &clusterDirection((minLayerClosest) ? slidingFitData.GetMinLayerDirection() : slidingFitData.GetMaxLayerDirection());
71 
72  this->IncrementEnergyKickParameters(pCluster, clusterDisplacement, clusterDirection, totEnergyKick, totEnergy, totHitKick, totHits);
73  }
74 
75  float energyKick(0.f);
76  if (useEnergy && totEnergy > std::numeric_limits<float>::epsilon())
77  energyKick = totEnergyKick / totEnergy;
78 
79  else if (!useEnergy && totHits > 0)
80  energyKick = totHitKick / static_cast<float>(totHits);
81 
82  return energyKick;
83 }
84 
85 //------------------------------------------------------------------------------------------------------------------------------------------
86 
87 void EnergyKickFeatureTool::IncrementEnergyKickParameters(const Cluster *const pCluster, const CartesianVector &clusterDisplacement,
88  const CartesianVector &clusterDirection, float &totEnergyKick, float &totEnergy, float &totHitKick, unsigned int &totHits) const
89 {
90  const float impactParameter(clusterDisplacement.GetCrossProduct(clusterDirection).GetMagnitude());
91  const float displacement(clusterDisplacement.GetMagnitude());
92 
93  totEnergyKick += pCluster->GetElectromagneticEnergy() * (impactParameter + m_xOffset) / (displacement + m_rOffset);
94  totEnergy += pCluster->GetElectromagneticEnergy();
95 
96  totHitKick += static_cast<float>(pCluster->GetNCaloHits()) * (impactParameter + m_xOffset) / (displacement + m_rOffset);
97  totHits += pCluster->GetNCaloHits();
98 }
99 
100 //------------------------------------------------------------------------------------------------------------------------------------------
101 
102 StatusCode EnergyKickFeatureTool::ReadSettings(const TiXmlHandle xmlHandle)
103 {
104  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
105  "ROffset", m_rOffset));
106 
107  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
108  "XOffset", m_xOffset));
109 
110  return STATUS_CODE_SUCCESS;
111 }
112 
113 } // namespace lar_content
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
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.
void IncrementEnergyKickParameters(const pandora::Cluster *const pCluster, const pandora::CartesianVector &clusterDisplacement, const pandora::CartesianVector &clusterDirection, float &totEnergyKick, float &totEnergy, float &totHitKick, unsigned int &totHits) const
Increment the energy kick parameters for a given cluster.
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_xOffset
The x offset parameter in the energy score.
float m_rOffset
The r offset parameter in the energy score.
TFile f
Definition: plotHisto.C:6
Header file for the geometry helper class.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
float GetEnergyKickForView(const pandora::CartesianVector &vertexPosition2D, const VertexSelectionBaseAlgorithm::SlidingFitDataList &slidingFitDataList) const
Get the energy kick feature for a given view.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
Header file for the energy kick feature tool class.