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::NeutrinoIdTool< T >::SliceFeatures Class Reference

Slice features class. More...

Public Member Functions

 SliceFeatures (const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const NeutrinoIdTool *const pTool)
 Constructor. More...
 
bool IsFeatureVectorAvailable () const
 Check if all features were calculable. More...
 
void GetFeatureVector (LArMvaHelper::MvaFeatureVector &featureVector) const
 Get the feature vector for the MVA. More...
 
void GetFeatureMap (LArMvaHelper::DoubleMap &featureMap) const
 Get the feature map for the MVA. More...
 
float GetNeutrinoProbability (const T &t) const
 Get the probability that this slice contains a neutrino interaction. More...
 

Private Member Functions

const pandora::ParticleFlowObject * GetNeutrino (const pandora::PfoList &nuPfos) const
 Get the recontructed neutrino the input list of neutrino Pfos. More...
 
void GetSpacePoints (const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const
 Get the 3D space points in a given pfo. More...
 
pandora::CartesianVector GetDirection (const pandora::CartesianPointVector &spacePoints, std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const
 Use a sliding fit to get the direction of a collection of spacepoints. More...
 
pandora::CartesianVector GetDirectionFromVertex (const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex) const
 Use a sliding fit to get the direction of a collection of spacepoint near a vertex position. More...
 
pandora::CartesianVector GetUpperDirection (const pandora::CartesianPointVector &spacePoints) const
 Use a sliding fit to get the upper direction of a collection of spacepoints. More...
 
pandora::CartesianVector GetLowerDirection (const pandora::CartesianPointVector &spacePoints) const
 Use a sliding fit to get the lower direction of a collection of spacepoints. More...
 
void GetPointsInSphere (const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex, const float radius, pandora::CartesianPointVector &spacePointsInSphere) const
 Get a vector of spacepoints within a given radius of a vertex point. More...
 

Private Attributes

bool m_isAvailable
 Is the feature vector available. More...
 
LArMvaHelper::MvaFeatureVector m_featureVector
 The MVA feature vector. More...
 
LArMvaHelper::DoubleMap m_featureMap
 A map between MVA features and their names. More...
 
const NeutrinoIdTool *const m_pTool
 The tool that owns this. More...
 

Detailed Description

template<typename T>
class lar_content::NeutrinoIdTool< T >::SliceFeatures

Slice features class.

Definition at line 47 of file NeutrinoIdTool.h.

Constructor & Destructor Documentation

template<typename T>
lar_content::NeutrinoIdTool< T >::SliceFeatures::SliceFeatures ( const pandora::PfoList &  nuPfos,
const pandora::PfoList &  crPfos,
const NeutrinoIdTool *const  pTool 
)

Constructor.

Parameters
nuPfosinput list of Pfos reconstructed under the neutrino hypothesis
crPfosinput list of Pfos reconstructed under the cosmic ray hypothesis
pTooladdress of the tool using this class

Definition at line 330 of file NeutrinoIdTool.cc.

330  :
331  m_isAvailable(false),
332  m_pTool(pTool)
333 {
334  try
335  {
336  const ParticleFlowObject *const pNeutrino(this->GetNeutrino(nuPfos));
337  const CartesianVector &nuVertex(LArPfoHelper::GetVertex(pNeutrino)->GetPosition());
338  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
339 
340  // Neutrino features
341  CartesianVector nuWeightedDirTotal(0.f, 0.f, 0.f);
342  unsigned int nuNHitsUsedTotal(0);
343  unsigned int nuNHitsTotal(0);
344  CartesianPointVector nuAllSpacePoints;
345  for (const ParticleFlowObject *const pPfo : nuFinalStates)
346  {
347  CartesianPointVector spacePoints;
348  this->GetSpacePoints(pPfo, spacePoints);
349 
350  nuAllSpacePoints.insert(nuAllSpacePoints.end(), spacePoints.begin(), spacePoints.end());
351  nuNHitsTotal += spacePoints.size();
352 
353  if (spacePoints.size() < 5)
354  continue;
355 
356  const CartesianVector dir(this->GetDirectionFromVertex(spacePoints, nuVertex));
357  nuWeightedDirTotal += dir * static_cast<float>(spacePoints.size());
358  nuNHitsUsedTotal += spacePoints.size();
359  }
360 
361  if (nuNHitsUsedTotal == 0)
362  return;
363  const CartesianVector nuWeightedDir(nuWeightedDirTotal * (1.f / static_cast<float>(nuNHitsUsedTotal)));
364 
365  CartesianPointVector pointsInSphere;
366  this->GetPointsInSphere(nuAllSpacePoints, nuVertex, 10, pointsInSphere);
367 
368  CartesianVector centroid(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
369  LArPcaHelper::EigenValues eigenValues(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
370  LArPcaHelper::EigenVectors eigenVectors;
371  LArPcaHelper::RunPca(pointsInSphere, centroid, eigenValues, eigenVectors);
372 
373  const float nuNFinalStatePfos(static_cast<float>(nuFinalStates.size()));
374  const float nuVertexY(nuVertex.GetY());
375  const float nuWeightedDirZ(nuWeightedDir.GetZ());
376  const float nuNSpacePointsInSphere(static_cast<float>(pointsInSphere.size()));
377 
378  if (eigenValues.GetX() <= std::numeric_limits<float>::epsilon())
379  return;
380  const float nuEigenRatioInSphere(eigenValues.GetY() / eigenValues.GetX());
381 
382  // Cosmic-ray features
383  unsigned int nCRHitsMax(0);
384  unsigned int nCRHitsTotal(0);
385  float crLongestTrackDirY(std::numeric_limits<float>::max());
386  float crLongestTrackDeflection(-std::numeric_limits<float>::max());
387 
388  for (const ParticleFlowObject *const pPfo : crPfos)
389  {
390  CartesianPointVector spacePoints;
391  this->GetSpacePoints(pPfo, spacePoints);
392 
393  nCRHitsTotal += spacePoints.size();
394 
395  if (spacePoints.size() < 5)
396  continue;
397 
398  if (spacePoints.size() > nCRHitsMax)
399  {
400  nCRHitsMax = spacePoints.size();
401  const CartesianVector upperDir(this->GetUpperDirection(spacePoints));
402  const CartesianVector lowerDir(this->GetLowerDirection(spacePoints));
403 
404  crLongestTrackDirY = upperDir.GetY();
405  crLongestTrackDeflection = 1.f - upperDir.GetDotProduct(lowerDir * (-1.f));
406  }
407  }
408 
409  if (nCRHitsMax == 0)
410  return;
411  if (nCRHitsTotal == 0)
412  return;
413 
414  const float crFracHitsInLongestTrack = static_cast<float>(nCRHitsMax) / static_cast<float>(nCRHitsTotal);
415 
416  // Push the features to the feature vector
417  m_featureVector.push_back(nuNFinalStatePfos);
418  m_featureVector.push_back(nuNHitsTotal);
419  m_featureVector.push_back(nuVertexY);
420  m_featureVector.push_back(nuWeightedDirZ);
421  m_featureVector.push_back(nuNSpacePointsInSphere);
422  m_featureVector.push_back(nuEigenRatioInSphere);
423  m_featureVector.push_back(crLongestTrackDirY);
424  m_featureVector.push_back(crLongestTrackDeflection);
425  m_featureVector.push_back(crFracHitsInLongestTrack);
426  m_featureVector.push_back(nCRHitsMax);
427 
428  m_featureMap["NuNFinalStatePfos"] = nuNFinalStatePfos;
429  m_featureMap["NuNHitsTotal"] = nuNHitsTotal;
430  m_featureMap["NuVertexY"] = nuVertexY;
431  m_featureMap["NuWeightedDirZ"] = nuWeightedDirZ;
432  m_featureMap["NuNSpacePointsInSphere"] = nuNSpacePointsInSphere;
433  m_featureMap["NuEigenRatioInSphere"] = nuEigenRatioInSphere;
434  m_featureMap["CRLongestTrackDirY"] = crLongestTrackDirY;
435  m_featureMap["CRLongestTrackDeflection"] = crLongestTrackDeflection;
436  m_featureMap["CRFracHitsInLongestTrack"] = crFracHitsInLongestTrack;
437  m_featureMap["CRNHitsMax"] = nCRHitsMax;
438 
439  m_isAvailable = true;
440  }
441  catch (StatusCodeException &)
442  {
443  return;
444  }
445 }
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
const NeutrinoIdTool *const m_pTool
The tool that owns this.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
LArMvaHelper::DoubleMap m_featureMap
A map between MVA features and their names.
pandora::CartesianVector GetLowerDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the lower direction of a collection of spacepoints.
bool m_isAvailable
Is the feature vector available.
LArMvaHelper::MvaFeatureVector m_featureVector
The MVA feature vector.
const pandora::ParticleFlowObject * GetNeutrino(const pandora::PfoList &nuPfos) const
Get the recontructed neutrino the input list of neutrino Pfos.
tuple dir
Definition: dropbox.py:28
pandora::CartesianVector GetDirectionFromVertex(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex) const
Use a sliding fit to get the direction of a collection of spacepoint near a vertex position...
pandora::CartesianVector GetUpperDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the upper direction of a collection of spacepoints.
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
void GetPointsInSphere(const pandora::CartesianPointVector &spacePoints, const pandora::CartesianVector &vertex, const float radius, pandora::CartesianPointVector &spacePointsInSphere) const
Get a vector of spacepoints within a given radius of a vertex point.
void GetSpacePoints(const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const
Get the 3D space points in a given pfo.

Member Function Documentation

template<typename T>
CartesianVector lar_content::NeutrinoIdTool< T >::SliceFeatures::GetDirection ( const pandora::CartesianPointVector &  spacePoints,
std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)>  fShouldChooseA 
) const
private

Use a sliding fit to get the direction of a collection of spacepoints.

Parameters
spacePointsthe input spacepoints to fit
fShouldChooseAa function that when given two fitted endpoints A and B, will return true if A is the endpoint at which to calculate the direction
Returns
the direction of the input spacepoints

Definition at line 555 of file NeutrinoIdTool.cc.

557 {
558  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
559  const LArTPC *const pFirstLArTPC(m_pTool->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
560  const float layerPitch(pFirstLArTPC->GetWirePitchW());
561 
562  const ThreeDSlidingFitResult fit(&spacePoints, 5, layerPitch);
563  const CartesianVector endMin(fit.GetGlobalMinLayerPosition());
564  const CartesianVector endMax(fit.GetGlobalMaxLayerPosition());
565  const CartesianVector dirMin(fit.GetGlobalMinLayerDirection());
566  const CartesianVector dirMax(fit.GetGlobalMaxLayerDirection());
567 
568  const bool isMinStart(fShouldChooseA(endMin, endMax));
569  const CartesianVector startPoint(isMinStart ? endMin : endMax);
570  const CartesianVector endPoint(isMinStart ? endMax : endMin);
571  const CartesianVector startDir(isMinStart ? dirMin : dirMax);
572 
573  const bool shouldFlip((endPoint - startPoint).GetUnitVector().GetDotProduct(startDir) < 0.f);
574  return (shouldFlip ? startDir * (-1.f) : startDir);
575 }
const NeutrinoIdTool *const m_pTool
The tool that owns this.
template<typename T>
CartesianVector lar_content::NeutrinoIdTool< T >::SliceFeatures::GetDirectionFromVertex ( const pandora::CartesianPointVector &  spacePoints,
const pandora::CartesianVector &  vertex 
) const
private

Use a sliding fit to get the direction of a collection of spacepoint near a vertex position.

Parameters
spacePointsthe input spacepoints to fit
vertexthe position from which the fitted direction should be calculated
Returns
the direction of the input space points from the vertex supplied

Definition at line 527 of file NeutrinoIdTool.cc.

528 {
529  return this->GetDirection(spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) {
530  return ((pointA - vertex).GetMagnitude() < (pointB - vertex).GetMagnitude());
531  });
532 }
process_name vertex
Definition: cheaterreco.fcl:51
pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints, std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const
Use a sliding fit to get the direction of a collection of spacepoints.
template<typename T >
void lar_content::NeutrinoIdTool< T >::SliceFeatures::GetFeatureMap ( LArMvaHelper::DoubleMap featureMap) const

Get the feature map for the MVA.

Parameters
featuresMapempty feature map to populate

Definition at line 469 of file NeutrinoIdTool.cc.

470 {
471  if (!m_isAvailable)
472  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
473 
474  featureMap.insert(m_featureMap.begin(), m_featureMap.end());
475 }
LArMvaHelper::DoubleMap m_featureMap
A map between MVA features and their names.
bool m_isAvailable
Is the feature vector available.
template<typename T >
void lar_content::NeutrinoIdTool< T >::SliceFeatures::GetFeatureVector ( LArMvaHelper::MvaFeatureVector featureVector) const

Get the feature vector for the MVA.

Parameters
featuresVectorempty feature vector to populate

Definition at line 458 of file NeutrinoIdTool.cc.

459 {
460  if (!m_isAvailable)
461  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
462 
463  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
464 }
bool m_isAvailable
Is the feature vector available.
LArMvaHelper::MvaFeatureVector m_featureVector
The MVA feature vector.
template<typename T>
CartesianVector lar_content::NeutrinoIdTool< T >::SliceFeatures::GetLowerDirection ( const pandora::CartesianPointVector &  spacePoints) const
private

Use a sliding fit to get the lower direction of a collection of spacepoints.

Parameters
spacePointsthe input spacepoints to fit
Returns
the direction of the lower input space points

Definition at line 546 of file NeutrinoIdTool.cc.

547 {
548  return this->GetDirection(
549  spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) { return (pointA.GetY() < pointB.GetY()); });
550 }
pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints, std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const
Use a sliding fit to get the direction of a collection of spacepoints.
template<typename T>
const ParticleFlowObject * lar_content::NeutrinoIdTool< T >::SliceFeatures::GetNeutrino ( const pandora::PfoList &  nuPfos) const
private

Get the recontructed neutrino the input list of neutrino Pfos.

Parameters
nuPfosinput list of neutrino pfos

Definition at line 494 of file NeutrinoIdTool.cc.

495 {
496  // ATTN we should only ever have one neutrino reconstructed per slice
497  if (nuPfos.size() != 1)
498  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
499 
500  return nuPfos.front();
501 }
template<typename T >
float lar_content::NeutrinoIdTool< T >::SliceFeatures::GetNeutrinoProbability ( const T &  t) const

Get the probability that this slice contains a neutrino interaction.

Parameters
tthe MVA used to calculate the probability
Returns
the probability that the slice contains a neutrino interaction

Definition at line 480 of file NeutrinoIdTool.cc.

481 {
482  // ATTN if one or more of the features can not be calculated, then default to calling the slice a cosmic ray
483  if (!this->IsFeatureVectorAvailable())
484  return 0.f;
485 
486  LArMvaHelper::MvaFeatureVector featureVector;
487  this->GetFeatureVector(featureVector);
488  return LArMvaHelper::CalculateProbability(t, featureVector);
489 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:72
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
void GetFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const
Get the feature vector for the MVA.
static double CalculateProbability(const MvaInterface &classifier, TCONTAINER &&featureContainer)
Use the trained mva to calculate a classification probability for an example.
Definition: LArMvaHelper.h:366
template<typename T>
void lar_content::NeutrinoIdTool< T >::SliceFeatures::GetPointsInSphere ( const pandora::CartesianPointVector &  spacePoints,
const pandora::CartesianVector &  vertex,
const float  radius,
pandora::CartesianPointVector &  spacePointsInSphere 
) const
private

Get a vector of spacepoints within a given radius of a vertex point.

Parameters
spacePointsthe input spacepoints
vertexthe center of the sphere
radiusthe radius of the sphere
spacePointsInSpherethe vector to hold the spacepoint in the sphere

Definition at line 580 of file NeutrinoIdTool.cc.

582 {
583  for (const CartesianVector &point : spacePoints)
584  {
585  if ((point - vertex).GetMagnitudeSquared() <= radius * radius)
586  spacePointsInSphere.push_back(point);
587  }
588 }
process_name vertex
Definition: cheaterreco.fcl:51
template<typename T>
void lar_content::NeutrinoIdTool< T >::SliceFeatures::GetSpacePoints ( const pandora::ParticleFlowObject *const  pPfo,
pandora::CartesianPointVector &  spacePoints 
) const
private

Get the 3D space points in a given pfo.

Parameters
pPfoinput pfo
spacePointsvector to hold the 3D space points associated with the input pfo

Definition at line 506 of file NeutrinoIdTool.cc.

507 {
508  ClusterList clusters3D;
509  LArPfoHelper::GetThreeDClusterList(pPfo, clusters3D);
510 
511  if (clusters3D.size() > 1)
512  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
513 
514  if (clusters3D.empty())
515  return;
516 
517  CaloHitList caloHits;
518  clusters3D.front()->GetOrderedCaloHitList().FillCaloHitList(caloHits);
519 
520  for (const CaloHit *const pCaloHit : caloHits)
521  spacePoints.push_back(pCaloHit->GetPositionVector());
522 }
static void GetThreeDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 3D clusters from an input pfo.
template<typename T>
CartesianVector lar_content::NeutrinoIdTool< T >::SliceFeatures::GetUpperDirection ( const pandora::CartesianPointVector &  spacePoints) const
private

Use a sliding fit to get the upper direction of a collection of spacepoints.

Parameters
spacePointsthe input spacepoints to fit
Returns
the direction of the upper input space points

Definition at line 537 of file NeutrinoIdTool.cc.

538 {
539  return this->GetDirection(
540  spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) { return (pointA.GetY() > pointB.GetY()); });
541 }
pandora::CartesianVector GetDirection(const pandora::CartesianPointVector &spacePoints, std::function< bool(const pandora::CartesianVector &pointA, const pandora::CartesianVector &pointB)> fShouldChooseA) const
Use a sliding fit to get the direction of a collection of spacepoints.
template<typename T >
bool lar_content::NeutrinoIdTool< T >::SliceFeatures::IsFeatureVectorAvailable ( ) const

Check if all features were calculable.

Returns
true if the feature vector is available

Definition at line 450 of file NeutrinoIdTool.cc.

451 {
452  return m_isAvailable;
453 }
bool m_isAvailable
Is the feature vector available.

Member Data Documentation

template<typename T>
LArMvaHelper::DoubleMap lar_content::NeutrinoIdTool< T >::SliceFeatures::m_featureMap
private

A map between MVA features and their names.

Definition at line 157 of file NeutrinoIdTool.h.

template<typename T>
LArMvaHelper::MvaFeatureVector lar_content::NeutrinoIdTool< T >::SliceFeatures::m_featureVector
private

The MVA feature vector.

Definition at line 156 of file NeutrinoIdTool.h.

template<typename T>
bool lar_content::NeutrinoIdTool< T >::SliceFeatures::m_isAvailable
private

Is the feature vector available.

Definition at line 155 of file NeutrinoIdTool.h.

template<typename T>
const NeutrinoIdTool* const lar_content::NeutrinoIdTool< T >::SliceFeatures::m_pTool
private

The tool that owns this.

Definition at line 158 of file NeutrinoIdTool.h.


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