LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::BdtBeamParticleIdTool::SliceFeatures Class Reference

Slice features class. More...

Public Member Functions

 SliceFeatures (const pandora::PfoList &nuPfos, const pandora::PfoList &crPfos, const SliceFeatureParameters &sliceFeatureParameters)
 Constructor. More...
 
 SliceFeatures (const SliceFeatures &rhs)=default
 Copy constructor. More...
 
SliceFeaturesoperator= (const SliceFeatures &rhs)=default
 Assignment operator. More...
 
 ~SliceFeatures ()=default
 Destructor. More...
 
bool IsFeatureVectorAvailable () const
 Check if all features were calculable. More...
 
void FillFeatureVector (LArMvaHelper::MvaFeatureVector &featureVector) const
 Get the feature vector for the SVM. More...
 
float GetAdaBoostDecisionTreeScore (const AdaBoostDecisionTree &adaBoostDecisionTree) const
 Get the probability that this slice contains a beam particle. More...
 

Private Member Functions

void GetLeadingCaloHits (const pandora::CaloHitList &inputCaloHitList, pandora::CaloHitList &outputCaloHitList, double &closestHitToFaceDistance) const
 Select a given fraction of a slice's calo hits that are closest to the beam spot. More...
 
void GetLArTPCIntercepts (const pandora::CartesianVector &a0, const pandora::CartesianVector &majorAxis, pandora::CartesianVector &interceptOne, pandora::CartesianVector &interceptTwo) const
 Find the intercepts of a line with the protoDUNE detector. More...
 
bool IsContained (const pandora::CartesianVector &spacePoint, const float limit) const
 Check if a given 3D spacepoint is inside the global LArTPC volume. More...
 

Private Attributes

bool m_isAvailable
 Is the feature vector available. More...
 
const SliceFeatureParameters m_sliceFeatureParameters
 Geometry information block. More...
 
LArMvaHelper::MvaFeatureVector m_featureVector
 The MVA feature vector. More...
 

Detailed Description

Slice features class.

Definition at line 219 of file BdtBeamParticleIdTool.h.

Constructor & Destructor Documentation

lar_content::BdtBeamParticleIdTool::SliceFeatures::SliceFeatures ( const pandora::PfoList &  nuPfos,
const pandora::PfoList &  crPfos,
const SliceFeatureParameters sliceFeatureParameters 
)

Constructor.

Parameters
nuPfosinput list of Pfos reconstructed under the neutrino hypothesis
crPfosinput list of Pfos reconstructed under the cosmic ray hypothesis
geometryInfogeometry information block

Referenced by lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::Initialize().

lar_content::BdtBeamParticleIdTool::SliceFeatures::SliceFeatures ( const SliceFeatures rhs)
default

Copy constructor.

Parameters
rhsthe SliceFeatures to copy
lar_content::BdtBeamParticleIdTool::SliceFeatures::~SliceFeatures ( )
default

Destructor.

Member Function Documentation

void lar_content::BdtBeamParticleIdTool::SliceFeatures::FillFeatureVector ( LArMvaHelper::MvaFeatureVector featureVector) const

Get the feature vector for the SVM.

Parameters
featuresVectorempty feature vector to populate

Definition at line 632 of file BdtBeamParticleIdTool.cc.

Referenced by lar_content::BdtBeamParticleIdTool::SelectOutputPfos().

633 {
634  if (!m_isAvailable)
635  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
636 
637  if (!featureVector.empty())
638  {
639  std::cout << "BdtBeamParticleIdTool::SliceFeatures::FillFeatureVector - feature vector already populated" << std::endl;
640  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
641  }
642 
643  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
644 }
bool m_isAvailable
Is the feature vector available.
LArMvaHelper::MvaFeatureVector m_featureVector
The MVA feature vector.
float lar_content::BdtBeamParticleIdTool::SliceFeatures::GetAdaBoostDecisionTreeScore ( const AdaBoostDecisionTree adaBoostDecisionTree) const

Get the probability that this slice contains a beam particle.

Parameters
adaBoostDecisionTreethe adaptive boost decision tree used to calculate the probability
Returns
the probability that the slice contains a beam particle

Definition at line 648 of file BdtBeamParticleIdTool.cc.

References lar_content::LArMvaHelper::CalculateClassificationScore().

649 {
650  // ATTN if one or more of the features can not be calculated, then default to calling the slice a cosmic ray. -1.f is the minimum score
651  // possible for a weighted bdt.
652  if (!this->IsFeatureVectorAvailable()) return -1.f;
653 
654  LArMvaHelper::MvaFeatureVector featureVector;
655 
656  try
657  {
658  this->FillFeatureVector(featureVector);
659  }
660  catch (const StatusCodeException &statusCodeException)
661  {
662  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetAdaBoostDecisionTreeScore - unable to fill feature vector" << std::endl;
663  return -1.f;
664  }
665 
666  return LArMvaHelper::CalculateClassificationScore(adaBoostDecisionTree, featureVector);
667 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
void FillFeatureVector(LArMvaHelper::MvaFeatureVector &featureVector) const
Get the feature vector for the SVM.
bool IsFeatureVectorAvailable() const
Check if all features were calculable.
static double CalculateClassificationScore(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained classifer to calculate the classification score of an example (>0 means boolean class...
Definition: LArMvaHelper.h:228
void lar_content::BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts ( const pandora::CartesianVector &  a0,
const pandora::CartesianVector &  majorAxis,
pandora::CartesianVector &  interceptOne,
pandora::CartesianVector &  interceptTwo 
) const
private

Find the intercepts of a line with the protoDUNE detector.

Parameters
a0a point on the line in question
majorAxisthe direction of the line in question
interceptOneto receive the first intersection between line and protoDUNE detector
interceptTwoto receive the second intersection between line and protoDUNE detector

Definition at line 556 of file BdtBeamParticleIdTool.cc.

References f, lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetContainmentLimit(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetPlanes(), and lar_content::BdtBeamParticleIdTool::m_sliceFeatureParameters.

558 {
559  CartesianPointVector intercepts;
560  CartesianVector lineUnitVector(0.f, 0.f, 0.f);
561 
562  try
563  {
564  lineUnitVector = lineDirection.GetUnitVector();
565  }
566  catch (const StatusCodeException &statusCodeException)
567  {
568  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - normal vector to plane has a magnitude of zero" << std::endl;
569  throw statusCodeException;
570  }
571 
572  for (const Plane &plane : m_sliceFeatureParameters.GetPlanes())
573  {
574  const CartesianVector intercept(plane.GetLineIntersection(a0, lineUnitVector));
575 
577  intercepts.push_back(intercept);
578  }
579 
580  if (intercepts.size() > 1)
581  {
582  float maximumSeparationSquared(0.f);
583  bool interceptsSet(false);
584 
585  for (unsigned int i = 0; i < intercepts.size(); i++)
586  {
587  for (unsigned int j = i + 1; j < intercepts.size(); j++)
588  {
589  const CartesianVector &candidateInterceptOne(intercepts.at(i));
590  const CartesianVector &candidateInterceptTwo(intercepts.at(j));
591  const float separationSquared((candidateInterceptOne - candidateInterceptTwo).GetMagnitudeSquared());
592 
593  if (separationSquared > maximumSeparationSquared)
594  {
595  maximumSeparationSquared = separationSquared;
596  interceptOne = candidateInterceptOne;
597  interceptTwo = candidateInterceptTwo;
598  interceptsSet = true;
599  }
600  }
601  }
602 
603  if (!interceptsSet)
604  {
605  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - unable to set the intercepts between a line and the LArTPC" << std::endl;
606  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
607  }
608  }
609  else
610  {
611  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - inconsistent number of intercepts between a line and the LArTPC" << std::endl;
612  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
613  }
614 }
const SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
#define a0
TFile f
Definition: plotHisto.C:6
bool IsContained(const pandora::CartesianVector &spacePoint, const float limit) const
Check if a given 3D spacepoint is inside the global LArTPC volume.
const PlaneVector & GetPlanes() const
Get vector of planes.
recob::tracking::Plane Plane
Definition: TrackState.h:17
void lar_content::BdtBeamParticleIdTool::SliceFeatures::GetLeadingCaloHits ( const pandora::CaloHitList &  inputCaloHitList,
pandora::CaloHitList &  outputCaloHitList,
double &  closestHitToFaceDistance 
) const
private

Select a given fraction of a slice's calo hits that are closest to the beam spot.

Parameters
inputCaloHitListall calo hits in slice
outputCaloHitListto receive the list of selected calo hits
closestHitToFaceDistanceto receive the distance of closest hit to beam spot

Definition at line 515 of file BdtBeamParticleIdTool.cc.

References lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetBeamLArTPCIntersection(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetNSelectedHits(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetSelectedFraction(), and lar_content::BdtBeamParticleIdTool::m_sliceFeatureParameters.

517 {
518  if (inputCaloHitList.empty())
519  {
520  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLeadingCaloHits - empty calo hit list" << std::endl;
521  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
522  }
523 
524  typedef std::pair<const CaloHit*, float> HitDistancePair;
525  typedef std::vector<HitDistancePair> HitDistanceVector;
526  HitDistanceVector hitDistanceVector;
527 
528  for (const CaloHit *const pCaloHit : inputCaloHitList)
529  hitDistanceVector.emplace_back(pCaloHit, (pCaloHit->GetPositionVector() - m_sliceFeatureParameters.GetBeamLArTPCIntersection()).GetMagnitudeSquared());
530 
531  std::sort(hitDistanceVector.begin(), hitDistanceVector.end(), [](const HitDistancePair &lhs, const HitDistancePair &rhs) -> bool {return (lhs.second < rhs.second);});
532 
533  if (hitDistanceVector.front().second < 0.f)
534  {
535  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLeadingCaloHits - unphysical magnitude of a vector" << std::endl;
536  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
537  }
538 
539  closestHitToFaceDistance = std::sqrt(hitDistanceVector.front().second);
540 
541  const unsigned int nInputHits(inputCaloHitList.size());
542  const unsigned int nSelectedCaloHits(nInputHits < m_sliceFeatureParameters.GetNSelectedHits() ? nInputHits :
543  static_cast<unsigned int>(std::ceil(static_cast<float>(nInputHits) * m_sliceFeatureParameters.GetSelectedFraction() / 100.f)));
544 
545  for (const HitDistancePair &hitDistancePair : hitDistanceVector)
546  {
547  outputCaloHitList.push_back(hitDistancePair.first);
548 
549  if (outputCaloHitList.size() >= nSelectedCaloHits)
550  break;
551  }
552 }
const SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
unsigned int GetNSelectedHits() const
Get m_nSelectedHits.
const pandora::CartesianVector & GetBeamLArTPCIntersection() const
Get the beam LArTPC intersection.
bool lar_content::BdtBeamParticleIdTool::SliceFeatures::IsContained ( const pandora::CartesianVector &  spacePoint,
const float  limit 
) const
private

Check if a given 3D spacepoint is inside the global LArTPC volume.

Parameters
spacePoint

Definition at line 618 of file BdtBeamParticleIdTool.cc.

References lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMaxX(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMaxY(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMaxZ(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMinX(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMinY(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::GetLArTPCMinZ(), and lar_content::BdtBeamParticleIdTool::m_sliceFeatureParameters.

619 {
620  if ((m_sliceFeatureParameters.GetLArTPCMinX() - spacePoint.GetX() > limit) || (spacePoint.GetX() - m_sliceFeatureParameters.GetLArTPCMaxX() > limit) ||
621  (m_sliceFeatureParameters.GetLArTPCMinY() - spacePoint.GetY() > limit) || (spacePoint.GetY() - m_sliceFeatureParameters.GetLArTPCMaxY() > limit) ||
622  (m_sliceFeatureParameters.GetLArTPCMinZ() - spacePoint.GetZ() > limit) || (spacePoint.GetZ() - m_sliceFeatureParameters.GetLArTPCMaxZ() > limit))
623  {
624  return false;
625  }
626 
627  return true;
628 }
const SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
bool lar_content::BdtBeamParticleIdTool::SliceFeatures::IsFeatureVectorAvailable ( ) const
inline

Check if all features were calculable.

Returns
true if the feature vector is available

Definition at line 526 of file BdtBeamParticleIdTool.h.

527 {
528  return m_isAvailable;
529 }
bool m_isAvailable
Is the feature vector available.
SliceFeatures& lar_content::BdtBeamParticleIdTool::SliceFeatures::operator= ( const SliceFeatures rhs)
default

Assignment operator.

Parameters
rhsthe SliceFeatures to assign

Member Data Documentation

LArMvaHelper::MvaFeatureVector lar_content::BdtBeamParticleIdTool::SliceFeatures::m_featureVector
private

The MVA feature vector.

Definition at line 304 of file BdtBeamParticleIdTool.h.

bool lar_content::BdtBeamParticleIdTool::SliceFeatures::m_isAvailable
private

Is the feature vector available.

Definition at line 302 of file BdtBeamParticleIdTool.h.

const SliceFeatureParameters lar_content::BdtBeamParticleIdTool::SliceFeatures::m_sliceFeatureParameters
private

Geometry information block.

Definition at line 303 of file BdtBeamParticleIdTool.h.


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