LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::ThreeDOpeningAngleFeatureTool Class Referenceabstract

ThreeDOpeningAngleFeatureTool class for the calculation of distance to neutrino vertex. More...

#include "TrackShowerIdFeatureTool.h"

Inheritance diagram for lar_content::ThreeDOpeningAngleFeatureTool:
lar_content::MvaFeatureTool< Ts >

Public Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 
typedef std::map< std::string, MvaFeatureTool< Ts... > * > FeatureToolMap
 

Public Member Functions

 ThreeDOpeningAngleFeatureTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const pandora::Algorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pInputPfo)
 
void Run (LArMvaHelper::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, const pandora::Algorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pInputPfo)
 
virtual void Run (MvaTypes::MvaFeatureVector &featureVector, Ts...args)=0
 Run the algorithm tool. More...
 
virtual void Run (MvaTypes::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, Ts...)
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void Divide3DCaloHitList (const pandora::Algorithm *const pAlgorithm, const pandora::CaloHitList &threeDCaloHitList, pandora::CartesianPointVector &pointVectorStart, pandora::CartesianPointVector &pointVectorEnd)
 Obtain positions at the vertex and non-vertex end of a list of three dimensional calo hits. More...
 
float OpeningAngle (const pandora::CartesianVector &principal, const pandora::CartesianVector &secondary, const pandora::CartesianVector &eigenValues) const
 Use the results of principal component analysis to calculate an opening angle. More...
 

Private Attributes

float m_hitFraction
 Fraction of hits in start and end of pfo. More...
 
float m_defaultValue
 Default value to return, in case calculation not feasible. More...
 

Detailed Description

ThreeDOpeningAngleFeatureTool class for the calculation of distance to neutrino vertex.

Definition at line 271 of file TrackShowerIdFeatureTool.h.

Member Typedef Documentation

template<typename... Ts>
typedef std::map<std::string, MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolMap
inherited

Definition at line 37 of file LArMvaHelper.h.

template<typename... Ts>
typedef std::vector<MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolVector
inherited

Definition at line 36 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::ThreeDOpeningAngleFeatureTool::ThreeDOpeningAngleFeatureTool ( )

Default constructor.

Definition at line 811 of file TrackShowerIdFeatureTool.cc.

811  :
812  m_hitFraction(0.5f),
813  m_defaultValue(0.1f)
814 {
815 }
float m_hitFraction
Fraction of hits in start and end of pfo.
TFile f
Definition: plotHisto.C:6
float m_defaultValue
Default value to return, in case calculation not feasible.

Member Function Documentation

void lar_content::ThreeDOpeningAngleFeatureTool::Divide3DCaloHitList ( const pandora::Algorithm *const  pAlgorithm,
const pandora::CaloHitList &  threeDCaloHitList,
pandora::CartesianPointVector &  pointVectorStart,
pandora::CartesianPointVector &  pointVectorEnd 
)
private

Obtain positions at the vertex and non-vertex end of a list of three dimensional calo hits.

Parameters
threeDCaloHitListthe list of three dimensional calo hits
pointVectorStartto receive the positions at the start/vertex region
pointVectorEndto receive the positions at the end region (opposite end to vertex)

Definition at line 886 of file TrackShowerIdFeatureTool.cc.

References f, and m_hitFraction.

Referenced by Run().

888 {
889  const VertexList *pVertexList(nullptr);
890  (void)PandoraContentApi::GetCurrentList(*pAlgorithm, pVertexList);
891 
892  if (threeDCaloHitList.empty() || !pVertexList || pVertexList->empty())
893  return;
894 
895  unsigned int nInteractionVertices(0);
896  const Vertex *pInteractionVertex(nullptr);
897 
898  for (const Vertex *pVertex : *pVertexList)
899  {
900  if ((pVertex->GetVertexLabel() == VERTEX_INTERACTION) && (pVertex->GetVertexType() == VERTEX_3D))
901  {
902  ++nInteractionVertices;
903  pInteractionVertex = pVertex;
904  }
905  }
906 
907  if (pInteractionVertex && (1 == nInteractionVertices))
908  {
909  // Order by distance to vertex, so first ones are closer to nuvertex
910  CaloHitVector threeDCaloHitVector(threeDCaloHitList.begin(), threeDCaloHitList.end());
911  std::sort(threeDCaloHitVector.begin(), threeDCaloHitVector.end(),
912  ThreeDChargeFeatureTool::VertexComparator(pInteractionVertex->GetPosition()));
913 
914  unsigned int iHit(1);
915  const unsigned int nHits(threeDCaloHitVector.size());
916 
917  for (const CaloHit *const pCaloHit : threeDCaloHitVector)
918  {
919  if (static_cast<float>(iHit) / static_cast<float>(nHits) <= m_hitFraction)
920  pointVectorStart.push_back(pCaloHit->GetPositionVector());
921 
922  if (static_cast<float>(iHit) / static_cast<float>(nHits) >= 1.f - m_hitFraction)
923  pointVectorEnd.push_back(pCaloHit->GetPositionVector());
924 
925  ++iHit;
926  }
927  }
928 }
float m_hitFraction
Fraction of hits in start and end of pfo.
TFile f
Definition: plotHisto.C:6
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
std::list< Vertex > VertexList
Definition: DCEL.h:169
float lar_content::ThreeDOpeningAngleFeatureTool::OpeningAngle ( const pandora::CartesianVector &  principal,
const pandora::CartesianVector &  secondary,
const pandora::CartesianVector &  eigenValues 
) const
private

Use the results of principal component analysis to calculate an opening angle.

Parameters
principalthe principal axis
secondarythe secondary axis
eigenValuesthe eigenvalues
Returns
the opening angle

Definition at line 932 of file TrackShowerIdFeatureTool.cc.

References f.

Referenced by Run().

933 {
934  const float principalMagnitude(principal.GetMagnitude());
935  const float secondaryMagnitude(secondary.GetMagnitude());
936 
937  if (std::fabs(principalMagnitude) < std::numeric_limits<float>::epsilon())
938  {
939  std::cout << "ThreeDOpeningAngleFeatureTool::OpeningAngle - The principal eigenvector is 0." << std::endl;
940  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
941  }
942  else if (std::fabs(secondaryMagnitude) < std::numeric_limits<float>::epsilon())
943  {
944  return 0.f;
945  }
946 
947  const float cosTheta(principal.GetDotProduct(secondary) / (principalMagnitude * secondaryMagnitude));
948 
949  if (cosTheta > 1.f)
950  {
951  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - cos(theta) reportedly greater than 1." << std::endl;
952  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
953  }
954 
955  const float sinTheta(std::sqrt(1.f - cosTheta * cosTheta));
956 
957  if (eigenValues.GetX() < std::numeric_limits<float>::epsilon())
958  {
959  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - principal eigenvalue less than or equal to 0." << std::endl;
960  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
961  }
962  else if (eigenValues.GetY() < std::numeric_limits<float>::epsilon())
963  {
964  return 0.f;
965  }
966 
967  return std::atan(std::sqrt(eigenValues.GetY()) * sinTheta / std::sqrt(eigenValues.GetX()));
968 }
TFile f
Definition: plotHisto.C:6
StatusCode lar_content::ThreeDOpeningAngleFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 972 of file TrackShowerIdFeatureTool.cc.

References m_defaultValue, and m_hitFraction.

973 {
974  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "HitFraction", m_hitFraction));
975 
976  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DefaultValue", m_defaultValue));
977 
978  return STATUS_CODE_SUCCESS;
979 }
float m_hitFraction
Fraction of hits in start and end of pfo.
float m_defaultValue
Default value to return, in case calculation not feasible.
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureVector featureVector,
Ts...  args 
)
pure virtualinherited

Run the algorithm tool.

Parameters
featureVectorthe vector of features to append
argsarguments to pass to the tool
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
Ts...   
)
inlinevirtualinherited

Definition at line 51 of file LArMvaHelper.h.

52  {
53  (void)featureMap;
54  (void)featureOrder;
55  (void)featureToolName;
56  return;
57  };
void lar_content::ThreeDOpeningAngleFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Definition at line 819 of file TrackShowerIdFeatureTool.cc.

References Divide3DCaloHitList(), f, lar_content::LArPfoHelper::GetCaloHits(), m_defaultValue, OpeningAngle(), and lar_content::LArPcaHelper::RunPca().

Referenced by lar_content::ThreeDPCAFeatureTool::Run().

821 {
822  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
823  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
824 
825  // Need the 3D hits to calculate PCA components
826  CaloHitList threeDCaloHitList;
827  LArPfoHelper::GetCaloHits(pInputPfo, TPC_3D, threeDCaloHitList);
828 
829  LArMvaHelper::MvaFeature diffAngle;
830  if (!threeDCaloHitList.empty())
831  {
832  CartesianPointVector pointVectorStart, pointVectorEnd;
833  this->Divide3DCaloHitList(pAlgorithm, threeDCaloHitList, pointVectorStart, pointVectorEnd);
834 
835  // Able to calculate angles only if > 1 point provided
836  if ((pointVectorStart.size() > 1) && (pointVectorEnd.size() > 1))
837  {
838  try
839  {
840  // Run the PCA analysis twice
841  CartesianVector centroidStart(0.f, 0.f, 0.f), centroidEnd(0.f, 0.f, 0.f);
842  LArPcaHelper::EigenVectors eigenVecsStart, eigenVecsEnd;
843  LArPcaHelper::EigenValues eigenValuesStart(0.f, 0.f, 0.f), eigenValuesEnd(0.f, 0.f, 0.f);
844 
845  LArPcaHelper::RunPca(pointVectorStart, centroidStart, eigenValuesStart, eigenVecsStart);
846  LArPcaHelper::RunPca(pointVectorEnd, centroidEnd, eigenValuesEnd, eigenVecsEnd);
847 
848  const float openingAngle(this->OpeningAngle(eigenVecsStart.at(0), eigenVecsStart.at(1), eigenValuesStart));
849  const float closingAngle(this->OpeningAngle(eigenVecsEnd.at(0), eigenVecsEnd.at(1), eigenValuesEnd));
850  diffAngle = std::fabs(openingAngle - closingAngle);
851  }
852  catch (const StatusCodeException &)
853  {
854  }
855  }
856  else
857  {
858  diffAngle = m_defaultValue;
859  }
860  }
861 
862  featureVector.push_back(diffAngle);
863 }
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
MvaTypes::MvaFeature MvaFeature
Definition: LArMvaHelper.h:74
TFile f
Definition: plotHisto.C:6
float OpeningAngle(const pandora::CartesianVector &principal, const pandora::CartesianVector &secondary, const pandora::CartesianVector &eigenValues) const
Use the results of principal component analysis to calculate an opening angle.
static void RunPca(const T &t, pandora::CartesianVector &centroid, EigenValues &outputEigenValues, EigenVectors &outputEigenVectors)
Run principal component analysis using input calo hits (TPC_VIEW_U,V,W or TPC_3D; all treated as 3D p...
std::vector< pandora::CartesianVector > EigenVectors
Definition: LArPcaHelper.h:25
float m_defaultValue
Default value to return, in case calculation not feasible.
void Divide3DCaloHitList(const pandora::Algorithm *const pAlgorithm, const pandora::CaloHitList &threeDCaloHitList, pandora::CartesianPointVector &pointVectorStart, pandora::CartesianPointVector &pointVectorEnd)
Obtain positions at the vertex and non-vertex end of a list of three dimensional calo hits...
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
void lar_content::ThreeDOpeningAngleFeatureTool::Run ( LArMvaHelper::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Member Data Documentation

float lar_content::ThreeDOpeningAngleFeatureTool::m_defaultValue
private

Default value to return, in case calculation not feasible.

Definition at line 309 of file TrackShowerIdFeatureTool.h.

Referenced by ReadSettings(), and Run().

float lar_content::ThreeDOpeningAngleFeatureTool::m_hitFraction
private

Fraction of hits in start and end of pfo.

Definition at line 308 of file TrackShowerIdFeatureTool.h.

Referenced by Divide3DCaloHitList(), and ReadSettings().


The documentation for this class was generated from the following files: