All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lar_content::ThreeDOpeningAngleFeatureTool Class Reference

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 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)
 
- Public Member Functions inherited from lar_content::MvaFeatureTool< Ts >
 MvaFeatureTool ()=default
 Default constructor. More...
 
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...args)
 

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...
 

Additional Inherited Members

- Public Types inherited from lar_content::MvaFeatureTool< Ts >
typedef std::vector
< MvaFeatureTool< Ts...> * > 
FeatureToolVector
 
typedef std::map< std::string,
MvaFeatureTool< Ts...> * > 
FeatureToolMap
 

Detailed Description

ThreeDOpeningAngleFeatureTool class for the calculation of distance to neutrino vertex.

Definition at line 271 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::ThreeDOpeningAngleFeatureTool::ThreeDOpeningAngleFeatureTool ( )

Default constructor.

Definition at line 804 of file TrackShowerIdFeatureTool.cc.

804  : m_hitFraction(0.5f), m_defaultValue(0.1f)
805 {
806 }
float m_hitFraction
Fraction of hits in start and end of pfo.
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 877 of file TrackShowerIdFeatureTool.cc.

879 {
880  const VertexList *pVertexList(nullptr);
881  (void)PandoraContentApi::GetCurrentList(*pAlgorithm, pVertexList);
882 
883  if (threeDCaloHitList.empty() || !pVertexList || pVertexList->empty())
884  return;
885 
886  unsigned int nInteractionVertices(0);
887  const Vertex *pInteractionVertex(nullptr);
888 
889  for (const Vertex *pVertex : *pVertexList)
890  {
891  if ((pVertex->GetVertexLabel() == VERTEX_INTERACTION) && (pVertex->GetVertexType() == VERTEX_3D))
892  {
893  ++nInteractionVertices;
894  pInteractionVertex = pVertex;
895  }
896  }
897 
898  if (pInteractionVertex && (1 == nInteractionVertices))
899  {
900  // Order by distance to vertex, so first ones are closer to nuvertex
901  CaloHitVector threeDCaloHitVector(threeDCaloHitList.begin(), threeDCaloHitList.end());
902  std::sort(threeDCaloHitVector.begin(), threeDCaloHitVector.end(),
903  ThreeDChargeFeatureTool::VertexComparator(pInteractionVertex->GetPosition()));
904 
905  unsigned int iHit(1);
906  const unsigned int nHits(threeDCaloHitVector.size());
907 
908  for (const CaloHit *const pCaloHit : threeDCaloHitVector)
909  {
910  if (static_cast<float>(iHit) / static_cast<float>(nHits) <= m_hitFraction)
911  pointVectorStart.push_back(pCaloHit->GetPositionVector());
912 
913  if (static_cast<float>(iHit) / static_cast<float>(nHits) >= 1.f - m_hitFraction)
914  pointVectorEnd.push_back(pCaloHit->GetPositionVector());
915 
916  ++iHit;
917  }
918  }
919 }
float m_hitFraction
Fraction of hits in start and end of pfo.
j template void())
Definition: json.hpp:3108
std::list< Vertex > VertexList
Definition: DCEL.h:182
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 923 of file TrackShowerIdFeatureTool.cc.

924 {
925  const float principalMagnitude(principal.GetMagnitude());
926  const float secondaryMagnitude(secondary.GetMagnitude());
927 
928  if (std::fabs(principalMagnitude) < std::numeric_limits<float>::epsilon())
929  {
930  std::cout << "ThreeDOpeningAngleFeatureTool::OpeningAngle - The principal eigenvector is 0." << std::endl;
931  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
932  }
933  else if (std::fabs(secondaryMagnitude) < std::numeric_limits<float>::epsilon())
934  {
935  return 0.f;
936  }
937 
938  const float cosTheta(principal.GetDotProduct(secondary) / (principalMagnitude * secondaryMagnitude));
939 
940  if (cosTheta > 1.f)
941  {
942  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - cos(theta) reportedly greater than 1." << std::endl;
943  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
944  }
945 
946  const float sinTheta(std::sqrt(1.f - cosTheta * cosTheta));
947 
948  if (eigenValues.GetX() < std::numeric_limits<float>::epsilon())
949  {
950  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - principal eigenvalue less than or equal to 0." << std::endl;
951  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
952  }
953  else if (eigenValues.GetY() < std::numeric_limits<float>::epsilon())
954  {
955  return 0.f;
956  }
957 
958  return std::atan(std::sqrt(eigenValues.GetY()) * sinTheta / std::sqrt(eigenValues.GetX()));
959 }
BEGIN_PROLOG could also be cout
StatusCode lar_content::ThreeDOpeningAngleFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 963 of file TrackShowerIdFeatureTool.cc.

964 {
965  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "HitFraction", m_hitFraction));
966 
967  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DefaultValue", m_defaultValue));
968 
969  return STATUS_CODE_SUCCESS;
970 }
float m_hitFraction
Fraction of hits in start and end of pfo.
float m_defaultValue
Default value to return, in case calculation not feasible.
void lar_content::ThreeDOpeningAngleFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Definition at line 810 of file TrackShowerIdFeatureTool.cc.

812 {
813  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
814  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
815 
816  // Need the 3D hits to calculate PCA components
817  CaloHitList threeDCaloHitList;
818  LArPfoHelper::GetCaloHits(pInputPfo, TPC_3D, threeDCaloHitList);
819 
820  LArMvaHelper::MvaFeature diffAngle;
821  if (!threeDCaloHitList.empty())
822  {
823  CartesianPointVector pointVectorStart, pointVectorEnd;
824  this->Divide3DCaloHitList(pAlgorithm, threeDCaloHitList, pointVectorStart, pointVectorEnd);
825 
826  // Able to calculate angles only if > 1 point provided
827  if ((pointVectorStart.size() > 1) && (pointVectorEnd.size() > 1))
828  {
829  try
830  {
831  // Run the PCA analysis twice
832  CartesianVector centroidStart(0.f, 0.f, 0.f), centroidEnd(0.f, 0.f, 0.f);
833  LArPcaHelper::EigenVectors eigenVecsStart, eigenVecsEnd;
834  LArPcaHelper::EigenValues eigenValuesStart(0.f, 0.f, 0.f), eigenValuesEnd(0.f, 0.f, 0.f);
835 
836  LArPcaHelper::RunPca(pointVectorStart, centroidStart, eigenValuesStart, eigenVecsStart);
837  LArPcaHelper::RunPca(pointVectorEnd, centroidEnd, eigenValuesEnd, eigenVecsEnd);
838 
839  const float openingAngle(this->OpeningAngle(eigenVecsStart.at(0), eigenVecsStart.at(1), eigenValuesStart));
840  const float closingAngle(this->OpeningAngle(eigenVecsEnd.at(0), eigenVecsEnd.at(1), eigenValuesEnd));
841  diffAngle = std::fabs(openingAngle - closingAngle);
842  }
843  catch (const StatusCodeException &)
844  {
845  }
846  }
847  else
848  {
849  diffAngle = m_defaultValue;
850  }
851  }
852 
853  featureVector.push_back(diffAngle);
854 }
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
MvaTypes::MvaFeature MvaFeature
Definition: LArMvaHelper.h:71
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.
BEGIN_PROLOG could also be cout
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.

float lar_content::ThreeDOpeningAngleFeatureTool::m_hitFraction
private

Fraction of hits in start and end of pfo.

Definition at line 308 of file TrackShowerIdFeatureTool.h.


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