LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::NeutrinoIdTool::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 SVM. More...
 
float GetNeutrinoProbability (const SupportVectorMachine &supportVectorMachine) 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 SVM feature vector. More...
 
const NeutrinoIdTool *const m_pTool
 The tool that owns this. More...
 

Detailed Description

Slice features class.

Definition at line 44 of file NeutrinoIdTool.h.

Constructor & Destructor Documentation

lar_content::NeutrinoIdTool::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 289 of file NeutrinoIdTool.cc.

References dir, f, GetDirectionFromVertex(), GetLowerDirection(), GetNeutrino(), GetPointsInSphere(), GetSpacePoints(), GetUpperDirection(), lar_content::LArPfoHelper::GetVertex(), m_featureVector, m_isAvailable, max, and lar_content::LArPcaHelper::RunPca().

289  :
290  m_isAvailable(false),
291  m_pTool(pTool)
292 {
293  try
294  {
295  const ParticleFlowObject *const pNeutrino(this->GetNeutrino(nuPfos));
296  const CartesianVector &nuVertex(LArPfoHelper::GetVertex(pNeutrino)->GetPosition());
297  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
298 
299  // Neutrino features
300  CartesianVector nuWeightedDirTotal(0.f, 0.f, 0.f);
301  unsigned int nuNHitsUsedTotal(0);
302  unsigned int nuNHitsTotal(0);
303  CartesianPointVector nuAllSpacePoints;
304  for (const ParticleFlowObject *const pPfo : nuFinalStates)
305  {
306  CartesianPointVector spacePoints;
307  this->GetSpacePoints(pPfo, spacePoints);
308 
309  nuAllSpacePoints.insert(nuAllSpacePoints.end(), spacePoints.begin(), spacePoints.end());
310  nuNHitsTotal += spacePoints.size();
311 
312  if (spacePoints.size() < 5) continue;
313 
314  const CartesianVector dir(this->GetDirectionFromVertex(spacePoints, nuVertex));
315  nuWeightedDirTotal += dir * static_cast<float>(spacePoints.size());
316  nuNHitsUsedTotal += spacePoints.size();
317  }
318 
319  if (nuNHitsUsedTotal == 0) return;
320  const CartesianVector nuWeightedDir(nuWeightedDirTotal * (1.f / static_cast<float>(nuNHitsUsedTotal)));
321 
322  CartesianPointVector pointsInSphere;
323  this->GetPointsInSphere(nuAllSpacePoints, nuVertex, 10, pointsInSphere);
324 
327  LArPcaHelper::EigenVectors eigenVectors;
328  LArPcaHelper::RunPca(pointsInSphere, centroid, eigenValues, eigenVectors);
329 
330 
331  const float nuNFinalStatePfos(static_cast<float>(nuFinalStates.size()));
332  const float nuVertexY(nuVertex.GetY());
333  const float nuWeightedDirZ(nuWeightedDir.GetZ());
334  const float nuNSpacePointsInSphere(static_cast<float>(pointsInSphere.size()));
335 
336  if (eigenValues.GetX() <= std::numeric_limits<float>::epsilon()) return;
337  const float nuEigenRatioInSphere(eigenValues.GetY() / eigenValues.GetX());
338 
339  // Cosmic-ray features
340  unsigned int nCRHitsMax(0);
341  unsigned int nCRHitsTotal(0);
342  float crLongestTrackDirY(std::numeric_limits<float>::max());
343  float crLongestTrackDeflection(-std::numeric_limits<float>::max());
344 
345  for (const ParticleFlowObject *const pPfo : crPfos)
346  {
347  CartesianPointVector spacePoints;
348  this->GetSpacePoints(pPfo, spacePoints);
349 
350  nCRHitsTotal += spacePoints.size();
351 
352  if (spacePoints.size() < 5) continue;
353 
354  if (spacePoints.size() > nCRHitsMax)
355  {
356  nCRHitsMax = spacePoints.size();
357  const CartesianVector upperDir(this->GetUpperDirection(spacePoints));
358  const CartesianVector lowerDir(this->GetLowerDirection(spacePoints));
359 
360  crLongestTrackDirY = upperDir.GetY();
361  crLongestTrackDeflection = 1.f - upperDir.GetDotProduct(lowerDir * (-1.f));
362  }
363  }
364 
365  if (nCRHitsMax == 0) return;
366  if (nCRHitsTotal == 0) return;
367 
368  const float crFracHitsInLongestTrack = static_cast<float>(nCRHitsMax)/static_cast<float>(nCRHitsTotal);
369 
370  // Push the features to the feature vector
371  m_featureVector.push_back(nuNFinalStatePfos);
372  m_featureVector.push_back(nuNHitsTotal);
373  m_featureVector.push_back(nuVertexY);
374  m_featureVector.push_back(nuWeightedDirZ);
375  m_featureVector.push_back(nuNSpacePointsInSphere);
376  m_featureVector.push_back(nuEigenRatioInSphere);
377  m_featureVector.push_back(crLongestTrackDirY);
378  m_featureVector.push_back(crLongestTrackDeflection);
379  m_featureVector.push_back(crFracHitsInLongestTrack);
380  m_featureVector.push_back(nCRHitsMax);
381 
382  m_isAvailable = true;
383  }
384  catch (StatusCodeException &)
385  {
386  return;
387  }
388 }
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.
bool m_isAvailable
Is the feature vector available.
const NeutrinoIdTool *const m_pTool
The tool that owns this.
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:21
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
LArMvaHelper::MvaFeatureVector m_featureVector
The SVM feature vector.
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...
TFile f
Definition: plotHisto.C:6
void GetSpacePoints(const pandora::ParticleFlowObject *const pPfo, pandora::CartesianPointVector &spacePoints) const
Get the 3D space points in a given pfo.
Int_t max
Definition: plot.C:27
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...
TDirectory * dir
Definition: macro.C:5
std::vector< pandora::CartesianVector > EigenVectors
Definition: LArPcaHelper.h:22
pandora::CartesianVector GetLowerDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the lower direction of a collection of spacepoints.
pandora::CartesianVector GetUpperDirection(const pandora::CartesianPointVector &spacePoints) const
Use a sliding fit to get the upper direction of a collection of spacepoints.
const pandora::ParticleFlowObject * GetNeutrino(const pandora::PfoList &nuPfos) const
Get the recontructed neutrino the input list of neutrino Pfos.

Member Function Documentation

CartesianVector lar_content::NeutrinoIdTool::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 481 of file NeutrinoIdTool.cc.

References f, and m_pTool.

Referenced by GetDirectionFromVertex(), GetLowerDirection(), and GetUpperDirection().

482 {
483  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
484  const LArTPC *const pFirstLArTPC(m_pTool->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
485  const float layerPitch(pFirstLArTPC->GetWirePitchW());
486 
487  const ThreeDSlidingFitResult fit(&spacePoints, 5, layerPitch);
488  const CartesianVector endMin(fit.GetGlobalMinLayerPosition());
489  const CartesianVector endMax(fit.GetGlobalMaxLayerPosition());
490  const CartesianVector dirMin(fit.GetGlobalMinLayerDirection());
491  const CartesianVector dirMax(fit.GetGlobalMaxLayerDirection());
492 
493  const bool isMinStart(fShouldChooseA(endMin, endMax));
494  const CartesianVector startPoint(isMinStart ? endMin : endMax);
495  const CartesianVector endPoint(isMinStart ? endMax : endMin);
496  const CartesianVector startDir(isMinStart ? dirMin : dirMax);
497 
498  const bool shouldFlip((endPoint - startPoint).GetUnitVector().GetDotProduct(startDir) < 0.f);
499  return (shouldFlip ? startDir*(-1.f) : startDir);
500 }
const NeutrinoIdTool *const m_pTool
The tool that owns this.
TFile f
Definition: plotHisto.C:6
CartesianVector lar_content::NeutrinoIdTool::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 451 of file NeutrinoIdTool.cc.

References GetDirection().

Referenced by SliceFeatures().

452 {
453  return this->GetDirection(spacePoints, [&] (const CartesianVector &pointA, const CartesianVector &pointB)
454  {
455  return ((pointA - vertex).GetMagnitude() < (pointB - vertex).GetMagnitude());
456  });
457 }
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
void lar_content::NeutrinoIdTool::SliceFeatures::GetFeatureVector ( LArMvaHelper::MvaFeatureVector featureVector) const

Get the feature vector for the SVM.

Parameters
featuresVectorempty feature vector to populate

Definition at line 399 of file NeutrinoIdTool.cc.

References m_featureVector, and m_isAvailable.

Referenced by GetNeutrinoProbability(), and lar_content::NeutrinoIdTool::SelectOutputPfos().

400 {
401  if (!m_isAvailable)
402  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
403 
404  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
405 }
bool m_isAvailable
Is the feature vector available.
LArMvaHelper::MvaFeatureVector m_featureVector
The SVM feature vector.
CartesianVector lar_content::NeutrinoIdTool::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 471 of file NeutrinoIdTool.cc.

References GetDirection().

Referenced by SliceFeatures().

472 {
473  return this->GetDirection(spacePoints, [&] (const CartesianVector &pointA, const CartesianVector &pointB)
474  {
475  return (pointA.GetY() < pointB.GetY());
476  });
477 }
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.
const ParticleFlowObject * lar_content::NeutrinoIdTool::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 421 of file NeutrinoIdTool.cc.

Referenced by SliceFeatures().

422 {
423  // ATTN we should only ever have one neutrino reconstructed per slice
424  if (nuPfos.size() != 1)
425  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
426 
427  return nuPfos.front();
428 }
float lar_content::NeutrinoIdTool::SliceFeatures::GetNeutrinoProbability ( const SupportVectorMachine supportVectorMachine) const

Get the probability that this slice contains a neutrino interaction.

Parameters
supportVectorMachinethe SVM used to calculate the probability
Returns
the probability that the slice contains a neutrino interaction

Definition at line 409 of file NeutrinoIdTool.cc.

References lar_content::LArMvaHelper::CalculateProbability(), GetFeatureVector(), and IsFeatureVectorAvailable().

410 {
411  // ATTN if one or more of the features can not be calculated, then default to calling the slice a cosmic ray
412  if (!this->IsFeatureVectorAvailable()) return 0.f;
413 
414  LArMvaHelper::MvaFeatureVector featureVector;
415  this->GetFeatureVector(featureVector);
416  return LArMvaHelper::CalculateProbability(supportVectorMachine, featureVector);
417 }
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 SVM.
void lar_content::NeutrinoIdTool::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 504 of file NeutrinoIdTool.cc.

Referenced by SliceFeatures().

505 {
506  for (const CartesianVector &point : spacePoints)
507  {
508  if ((point - vertex).GetMagnitudeSquared() <= radius*radius)
509  spacePointsInSphere.push_back(point);
510  }
511 }
Double_t radius
vertex reconstruction
void lar_content::NeutrinoIdTool::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 432 of file NeutrinoIdTool.cc.

References lar_content::LArPfoHelper::GetThreeDClusterList().

Referenced by SliceFeatures().

433 {
434  ClusterList clusters3D;
435  LArPfoHelper::GetThreeDClusterList(pPfo, clusters3D);
436 
437  if (clusters3D.size() > 1)
438  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
439 
440  if (clusters3D.empty()) return;
441 
442  CaloHitList caloHits;
443  clusters3D.front()->GetOrderedCaloHitList().FillCaloHitList(caloHits);
444 
445  for (const CaloHit *const pCaloHit : caloHits)
446  spacePoints.push_back(pCaloHit->GetPositionVector());
447 }
static void GetThreeDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 3D clusters from an input pfo.
CartesianVector lar_content::NeutrinoIdTool::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 461 of file NeutrinoIdTool.cc.

References GetDirection().

Referenced by SliceFeatures().

462 {
463  return this->GetDirection(spacePoints, [&] (const CartesianVector &pointA, const CartesianVector &pointB)
464  {
465  return (pointA.GetY() > pointB.GetY());
466  });
467 }
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.
bool lar_content::NeutrinoIdTool::SliceFeatures::IsFeatureVectorAvailable ( ) const

Check if all features were calculable.

Returns
true if the feature vector is available

Definition at line 392 of file NeutrinoIdTool.cc.

References m_isAvailable.

Referenced by GetNeutrinoProbability().

393 {
394  return m_isAvailable;
395 }
bool m_isAvailable
Is the feature vector available.

Member Data Documentation

LArMvaHelper::MvaFeatureVector lar_content::NeutrinoIdTool::SliceFeatures::m_featureVector
private

The SVM feature vector.

Definition at line 144 of file NeutrinoIdTool.h.

Referenced by GetFeatureVector(), and SliceFeatures().

bool lar_content::NeutrinoIdTool::SliceFeatures::m_isAvailable
private

Is the feature vector available.

Definition at line 143 of file NeutrinoIdTool.h.

Referenced by GetFeatureVector(), IsFeatureVectorAvailable(), and SliceFeatures().

const NeutrinoIdTool* const lar_content::NeutrinoIdTool::SliceFeatures::m_pTool
private

The tool that owns this.

Definition at line 145 of file NeutrinoIdTool.h.

Referenced by GetDirection().


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