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

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
 

Detailed Description

ThreeDOpeningAngleFeatureTool class for the calculation of distance to neutrino vertex.

Definition at line 196 of file TrackShowerIdFeatureTool.h.

Constructor & Destructor Documentation

lar_content::ThreeDOpeningAngleFeatureTool::ThreeDOpeningAngleFeatureTool ( )

Default constructor.

Definition at line 516 of file TrackShowerIdFeatureTool.cc.

516  : m_hitFraction(0.5f), m_defaultValue(0.1f)
517 {
518 }
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 570 of file TrackShowerIdFeatureTool.cc.

572 {
573  const VertexList *pVertexList(nullptr);
574  (void)PandoraContentApi::GetCurrentList(*pAlgorithm, pVertexList);
575 
576  if (threeDCaloHitList.empty() || !pVertexList || pVertexList->empty())
577  return;
578 
579  unsigned int nInteractionVertices(0);
580  const Vertex *pInteractionVertex(nullptr);
581 
582  for (const Vertex *pVertex : *pVertexList)
583  {
584  if ((pVertex->GetVertexLabel() == VERTEX_INTERACTION) && (pVertex->GetVertexType() == VERTEX_3D))
585  {
586  ++nInteractionVertices;
587  pInteractionVertex = pVertex;
588  }
589  }
590 
591  if (pInteractionVertex && (1 == nInteractionVertices))
592  {
593  // Order by distance to vertex, so first ones are closer to nuvertex
594  CaloHitVector threeDCaloHitVector(threeDCaloHitList.begin(), threeDCaloHitList.end());
595  std::sort(threeDCaloHitVector.begin(), threeDCaloHitVector.end(),
596  ThreeDChargeFeatureTool::VertexComparator(pInteractionVertex->GetPosition()));
597 
598  unsigned int iHit(1);
599  const unsigned int nHits(threeDCaloHitVector.size());
600 
601  for (const CaloHit *const pCaloHit : threeDCaloHitVector)
602  {
603  if (static_cast<float>(iHit) / static_cast<float>(nHits) <= m_hitFraction)
604  pointVectorStart.push_back(pCaloHit->GetPositionVector());
605 
606  if (static_cast<float>(iHit) / static_cast<float>(nHits) >= 1.f - m_hitFraction)
607  pointVectorEnd.push_back(pCaloHit->GetPositionVector());
608 
609  ++iHit;
610  }
611  }
612 }
float m_hitFraction
Fraction of hits in start and end of pfo.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
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 616 of file TrackShowerIdFeatureTool.cc.

617 {
618  const float principalMagnitude(principal.GetMagnitude());
619  const float secondaryMagnitude(secondary.GetMagnitude());
620 
621  if (std::fabs(principalMagnitude) < std::numeric_limits<float>::epsilon())
622  {
623  std::cout << "ThreeDOpeningAngleFeatureTool::OpeningAngle - The principal eigenvector is 0." << std::endl;
624  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
625  }
626  else if (std::fabs(secondaryMagnitude) < std::numeric_limits<float>::epsilon())
627  {
628  return 0.f;
629  }
630 
631  const float cosTheta(principal.GetDotProduct(secondary) / (principalMagnitude * secondaryMagnitude));
632 
633  if (cosTheta > 1.f)
634  {
635  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - cos(theta) reportedly greater than 1." << std::endl;
636  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
637  }
638 
639  const float sinTheta(std::sqrt(1.f - cosTheta * cosTheta));
640 
641  if (eigenValues.GetX() < std::numeric_limits<float>::epsilon())
642  {
643  std::cout << "PcaShowerParticleBuildingAlgorithm::OpeningAngle - principal eigenvalue less than or equal to 0." << std::endl;
644  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
645  }
646  else if (eigenValues.GetY() < std::numeric_limits<float>::epsilon())
647  {
648  return 0.f;
649  }
650 
651  return std::atan(std::sqrt(eigenValues.GetY()) * sinTheta / std::sqrt(eigenValues.GetX()));
652 }
QTextStream & endl(QTextStream &s)
StatusCode lar_content::ThreeDOpeningAngleFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 656 of file TrackShowerIdFeatureTool.cc.

657 {
658  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "HitFraction", m_hitFraction));
659 
660  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DefaultValue", m_defaultValue));
661 
662  return STATUS_CODE_SUCCESS;
663 }
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 522 of file TrackShowerIdFeatureTool.cc.

524 {
525  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
526  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
527 
528  // Need the 3D hits to calculate PCA components
529  CaloHitList threeDCaloHitList;
530  LArPfoHelper::GetCaloHits(pInputPfo, TPC_3D, threeDCaloHitList);
531 
532  LArMvaHelper::MvaFeature diffAngle;
533  if (!threeDCaloHitList.empty())
534  {
535  CartesianPointVector pointVectorStart, pointVectorEnd;
536  this->Divide3DCaloHitList(pAlgorithm, threeDCaloHitList, pointVectorStart, pointVectorEnd);
537 
538  // Able to calculate angles only if > 1 point provided
539  if ((pointVectorStart.size() > 1) && (pointVectorEnd.size() > 1))
540  {
541  try
542  {
543  // Run the PCA analysis twice
544  CartesianVector centroidStart(0.f, 0.f, 0.f), centroidEnd(0.f, 0.f, 0.f);
545  LArPcaHelper::EigenVectors eigenVecsStart, eigenVecsEnd;
546  LArPcaHelper::EigenValues eigenValuesStart(0.f, 0.f, 0.f), eigenValuesEnd(0.f, 0.f, 0.f);
547 
548  LArPcaHelper::RunPca(pointVectorStart, centroidStart, eigenValuesStart, eigenVecsStart);
549  LArPcaHelper::RunPca(pointVectorEnd, centroidEnd, eigenValuesEnd, eigenVecsEnd);
550 
551  const float openingAngle(this->OpeningAngle(eigenVecsStart.at(0), eigenVecsStart.at(1), eigenValuesStart));
552  const float closingAngle(this->OpeningAngle(eigenVecsEnd.at(0), eigenVecsEnd.at(1), eigenValuesEnd));
553  diffAngle = std::fabs(openingAngle - closingAngle);
554  }
555  catch (const StatusCodeException &)
556  {
557  }
558  }
559  else
560  {
561  diffAngle = m_defaultValue;
562  }
563  }
564 
565  featureVector.push_back(diffAngle);
566 }
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
MvaTypes::MvaFeature MvaFeature
Definition: LArMvaHelper.h:57
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.
QTextStream & endl(QTextStream &s)

Member Data Documentation

float lar_content::ThreeDOpeningAngleFeatureTool::m_defaultValue
private

Default value to return, in case calculation not feasible.

Definition at line 232 of file TrackShowerIdFeatureTool.h.

float lar_content::ThreeDOpeningAngleFeatureTool::m_hitFraction
private

Fraction of hits in start and end of pfo.

Definition at line 231 of file TrackShowerIdFeatureTool.h.


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