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...
 
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...
 
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 309 of file NeutrinoIdTool.cc.

309  :
310  m_isAvailable(false),
311  m_pTool(pTool)
312 {
313  try
314  {
315  const ParticleFlowObject *const pNeutrino(this->GetNeutrino(nuPfos));
316  const CartesianVector &nuVertex(LArPfoHelper::GetVertex(pNeutrino)->GetPosition());
317  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
318 
319  // Neutrino features
320  CartesianVector nuWeightedDirTotal(0.f, 0.f, 0.f);
321  unsigned int nuNHitsUsedTotal(0);
322  unsigned int nuNHitsTotal(0);
323  CartesianPointVector nuAllSpacePoints;
324  for (const ParticleFlowObject *const pPfo : nuFinalStates)
325  {
326  CartesianPointVector spacePoints;
327  this->GetSpacePoints(pPfo, spacePoints);
328 
329  nuAllSpacePoints.insert(nuAllSpacePoints.end(), spacePoints.begin(), spacePoints.end());
330  nuNHitsTotal += spacePoints.size();
331 
332  if (spacePoints.size() < 5)
333  continue;
334 
335  const CartesianVector dir(this->GetDirectionFromVertex(spacePoints, nuVertex));
336  nuWeightedDirTotal += dir * static_cast<float>(spacePoints.size());
337  nuNHitsUsedTotal += spacePoints.size();
338  }
339 
340  if (nuNHitsUsedTotal == 0)
341  return;
342  const CartesianVector nuWeightedDir(nuWeightedDirTotal * (1.f / static_cast<float>(nuNHitsUsedTotal)));
343 
344  CartesianPointVector pointsInSphere;
345  this->GetPointsInSphere(nuAllSpacePoints, nuVertex, 10, pointsInSphere);
346 
349  LArPcaHelper::EigenVectors eigenVectors;
350  LArPcaHelper::RunPca(pointsInSphere, centroid, eigenValues, eigenVectors);
351 
352  const float nuNFinalStatePfos(static_cast<float>(nuFinalStates.size()));
353  const float nuVertexY(nuVertex.GetY());
354  const float nuWeightedDirZ(nuWeightedDir.GetZ());
355  const float nuNSpacePointsInSphere(static_cast<float>(pointsInSphere.size()));
356 
357  if (eigenValues.GetX() <= std::numeric_limits<float>::epsilon())
358  return;
359  const float nuEigenRatioInSphere(eigenValues.GetY() / eigenValues.GetX());
360 
361  // Cosmic-ray features
362  unsigned int nCRHitsMax(0);
363  unsigned int nCRHitsTotal(0);
364  float crLongestTrackDirY(std::numeric_limits<float>::max());
365  float crLongestTrackDeflection(-std::numeric_limits<float>::max());
366 
367  for (const ParticleFlowObject *const pPfo : crPfos)
368  {
369  CartesianPointVector spacePoints;
370  this->GetSpacePoints(pPfo, spacePoints);
371 
372  nCRHitsTotal += spacePoints.size();
373 
374  if (spacePoints.size() < 5)
375  continue;
376 
377  if (spacePoints.size() > nCRHitsMax)
378  {
379  nCRHitsMax = spacePoints.size();
380  const CartesianVector upperDir(this->GetUpperDirection(spacePoints));
381  const CartesianVector lowerDir(this->GetLowerDirection(spacePoints));
382 
383  crLongestTrackDirY = upperDir.GetY();
384  crLongestTrackDeflection = 1.f - upperDir.GetDotProduct(lowerDir * (-1.f));
385  }
386  }
387 
388  if (nCRHitsMax == 0)
389  return;
390  if (nCRHitsTotal == 0)
391  return;
392 
393  const float crFracHitsInLongestTrack = static_cast<float>(nCRHitsMax) / static_cast<float>(nCRHitsTotal);
394 
395  // Push the features to the feature vector
396  m_featureVector.push_back(nuNFinalStatePfos);
397  m_featureVector.push_back(nuNHitsTotal);
398  m_featureVector.push_back(nuVertexY);
399  m_featureVector.push_back(nuWeightedDirZ);
400  m_featureVector.push_back(nuNSpacePointsInSphere);
401  m_featureVector.push_back(nuEigenRatioInSphere);
402  m_featureVector.push_back(crLongestTrackDirY);
403  m_featureVector.push_back(crLongestTrackDeflection);
404  m_featureVector.push_back(crFracHitsInLongestTrack);
405  m_featureVector.push_back(nCRHitsMax);
406 
407  m_isAvailable = true;
408  }
409  catch (StatusCodeException &)
410  {
411  return;
412  }
413 }
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.
string dir
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.
static int max(int a, int b)
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 512 of file NeutrinoIdTool.cc.

514 {
515  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
516  const LArTPC *const pFirstLArTPC(m_pTool->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
517  const float layerPitch(pFirstLArTPC->GetWirePitchW());
518 
519  const ThreeDSlidingFitResult fit(&spacePoints, 5, layerPitch);
520  const CartesianVector endMin(fit.GetGlobalMinLayerPosition());
521  const CartesianVector endMax(fit.GetGlobalMaxLayerPosition());
522  const CartesianVector dirMin(fit.GetGlobalMinLayerDirection());
523  const CartesianVector dirMax(fit.GetGlobalMaxLayerDirection());
524 
525  const bool isMinStart(fShouldChooseA(endMin, endMax));
526  const CartesianVector startPoint(isMinStart ? endMin : endMax);
527  const CartesianVector endPoint(isMinStart ? endMax : endMin);
528  const CartesianVector startDir(isMinStart ? dirMin : dirMax);
529 
530  const bool shouldFlip((endPoint - startPoint).GetUnitVector().GetDotProduct(startDir) < 0.f);
531  return (shouldFlip ? startDir * (-1.f) : startDir);
532 }
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 484 of file NeutrinoIdTool.cc.

485 {
486  return this->GetDirection(spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) {
487  return ((pointA - vertex).GetMagnitude() < (pointB - vertex).GetMagnitude());
488  });
489 }
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.
vertex reconstruction
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 426 of file NeutrinoIdTool.cc.

427 {
428  if (!m_isAvailable)
429  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
430 
431  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
432 }
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 503 of file NeutrinoIdTool.cc.

504 {
505  return this->GetDirection(
506  spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) { return (pointA.GetY() < pointB.GetY()); });
507 }
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 451 of file NeutrinoIdTool.cc.

452 {
453  // ATTN we should only ever have one neutrino reconstructed per slice
454  if (nuPfos.size() != 1)
455  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
456 
457  return nuPfos.front();
458 }
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 437 of file NeutrinoIdTool.cc.

438 {
439  // ATTN if one or more of the features can not be calculated, then default to calling the slice a cosmic ray
440  if (!this->IsFeatureVectorAvailable())
441  return 0.f;
442 
443  LArMvaHelper::MvaFeatureVector featureVector;
444  this->GetFeatureVector(featureVector);
445  return LArMvaHelper::CalculateProbability(t, featureVector);
446 }
static double CalculateProbability(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained mva to calculate a classification probability for an example.
Definition: LArMvaHelper.h:236
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
void GetFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const
Get the feature vector for the MVA.
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 537 of file NeutrinoIdTool.cc.

539 {
540  for (const CartesianVector &point : spacePoints)
541  {
542  if ((point - vertex).GetMagnitudeSquared() <= radius * radius)
543  spacePointsInSphere.push_back(point);
544  }
545 }
vertex reconstruction
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 463 of file NeutrinoIdTool.cc.

464 {
465  ClusterList clusters3D;
466  LArPfoHelper::GetThreeDClusterList(pPfo, clusters3D);
467 
468  if (clusters3D.size() > 1)
469  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
470 
471  if (clusters3D.empty())
472  return;
473 
474  CaloHitList caloHits;
475  clusters3D.front()->GetOrderedCaloHitList().FillCaloHitList(caloHits);
476 
477  for (const CaloHit *const pCaloHit : caloHits)
478  spacePoints.push_back(pCaloHit->GetPositionVector());
479 }
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 494 of file NeutrinoIdTool.cc.

495 {
496  return this->GetDirection(
497  spacePoints, [&](const CartesianVector &pointA, const CartesianVector &pointB) { return (pointA.GetY() > pointB.GetY()); });
498 }
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 418 of file NeutrinoIdTool.cc.

419 {
420  return m_isAvailable;
421 }
bool m_isAvailable
Is the feature vector available.

Member Data Documentation

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

The MVA feature vector.

Definition at line 149 of file NeutrinoIdTool.h.

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

Is the feature vector available.

Definition at line 148 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 150 of file NeutrinoIdTool.h.


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