LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 &)=default
 Copy constructor. 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 222 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 )
default

Copy constructor.

Parameters
TheSliceFeatures 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 650 of file BdtBeamParticleIdTool.cc.

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

651 {
652  if (!m_isAvailable)
653  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
654 
655  if (!featureVector.empty())
656  {
657  std::cout << "BdtBeamParticleIdTool::SliceFeatures::FillFeatureVector - feature vector already populated" << std::endl;
658  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
659  }
660 
661  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
662 }
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 666 of file BdtBeamParticleIdTool.cc.

References lar_content::LArMvaHelper::CalculateClassificationScore().

667 {
668  // 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
669  // possible for a weighted bdt.
670  if (!this->IsFeatureVectorAvailable())
671  return -1.f;
672 
673  LArMvaHelper::MvaFeatureVector featureVector;
674 
675  try
676  {
677  this->FillFeatureVector(featureVector);
678  }
679  catch (const StatusCodeException &statusCodeException)
680  {
681  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetAdaBoostDecisionTreeScore - unable to fill feature vector" << std::endl;
682  return -1.f;
683  }
684 
685  return LArMvaHelper::CalculateClassificationScore(adaBoostDecisionTree, featureVector);
686 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:75
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, TCONTAINER &&featureContainer)
Use the trained classifer to calculate the classification score of an example (>0 means boolean class...
Definition: LArMvaHelper.h:361
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 569 of file BdtBeamParticleIdTool.cc.

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

571 {
572  CartesianPointVector intercepts;
573  CartesianVector lineUnitVector(0.f, 0.f, 0.f);
574 
575  try
576  {
577  lineUnitVector = lineDirection.GetUnitVector();
578  }
579  catch (const StatusCodeException &statusCodeException)
580  {
581  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - normal vector to plane has a magnitude of zero" << std::endl;
582  throw statusCodeException;
583  }
584 
585  for (const Plane &plane : m_sliceFeatureParameters.GetPlanes())
586  {
587  const CartesianVector intercept(plane.GetLineIntersection(a0, lineUnitVector));
588 
590  intercepts.push_back(intercept);
591  }
592 
593  if (intercepts.size() > 1)
594  {
595  float maximumSeparationSquared(0.f);
596  bool interceptsSet(false);
597 
598  for (unsigned int i = 0; i < intercepts.size(); i++)
599  {
600  for (unsigned int j = i + 1; j < intercepts.size(); j++)
601  {
602  const CartesianVector &candidateInterceptOne(intercepts.at(i));
603  const CartesianVector &candidateInterceptTwo(intercepts.at(j));
604  const float separationSquared((candidateInterceptOne - candidateInterceptTwo).GetMagnitudeSquared());
605 
606  if (separationSquared > maximumSeparationSquared)
607  {
608  maximumSeparationSquared = separationSquared;
609  interceptOne = candidateInterceptOne;
610  interceptTwo = candidateInterceptTwo;
611  interceptsSet = true;
612  }
613  }
614  }
615 
616  if (!interceptsSet)
617  {
618  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - unable to set the intercepts between a line and the LArTPC"
619  << std::endl;
620  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
621  }
622  }
623  else
624  {
625  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLArTPCIntercepts - inconsistent number of intercepts between a line and the LArTPC"
626  << std::endl;
627  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
628  }
629 }
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 525 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.

527 {
528  if (inputCaloHitList.empty())
529  {
530  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLeadingCaloHits - empty calo hit list" << std::endl;
531  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
532  }
533 
534  typedef std::pair<const CaloHit *, float> HitDistancePair;
535  typedef std::vector<HitDistancePair> HitDistanceVector;
536  HitDistanceVector hitDistanceVector;
537 
538  for (const CaloHit *const pCaloHit : inputCaloHitList)
539  hitDistanceVector.emplace_back(
540  pCaloHit, (pCaloHit->GetPositionVector() - m_sliceFeatureParameters.GetBeamLArTPCIntersection()).GetMagnitudeSquared());
541 
542  std::sort(hitDistanceVector.begin(), hitDistanceVector.end(),
543  [](const HitDistancePair &lhs, const HitDistancePair &rhs) -> bool { return (lhs.second < rhs.second); });
544 
545  if (hitDistanceVector.front().second < 0.f)
546  {
547  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetLeadingCaloHits - unphysical magnitude of a vector" << std::endl;
548  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
549  }
550 
551  closestHitToFaceDistance = std::sqrt(hitDistanceVector.front().second);
552 
553  const unsigned int nInputHits(inputCaloHitList.size());
554  const unsigned int nSelectedCaloHits(nInputHits < m_sliceFeatureParameters.GetNSelectedHits()
555  ? nInputHits
556  : static_cast<unsigned int>(std::ceil(static_cast<float>(nInputHits) * m_sliceFeatureParameters.GetSelectedFraction() / 100.f)));
557 
558  for (const HitDistancePair &hitDistancePair : hitDistanceVector)
559  {
560  outputCaloHitList.push_back(hitDistancePair.first);
561 
562  if (outputCaloHitList.size() >= nSelectedCaloHits)
563  break;
564  }
565 }
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 633 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.

634 {
635  if ((m_sliceFeatureParameters.GetLArTPCMinX() - spacePoint.GetX() > limit) ||
636  (spacePoint.GetX() - m_sliceFeatureParameters.GetLArTPCMaxX() > limit) ||
637  (m_sliceFeatureParameters.GetLArTPCMinY() - spacePoint.GetY() > limit) ||
638  (spacePoint.GetY() - m_sliceFeatureParameters.GetLArTPCMaxY() > limit) ||
639  (m_sliceFeatureParameters.GetLArTPCMinZ() - spacePoint.GetZ() > limit) ||
640  (spacePoint.GetZ() - m_sliceFeatureParameters.GetLArTPCMaxZ() > limit))
641  {
642  return false;
643  }
644 
645  return true;
646 }
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 525 of file BdtBeamParticleIdTool.h.

526 {
527  return m_isAvailable;
528 }
bool m_isAvailable
Is the feature vector available.

Member Data Documentation

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

The MVA feature vector.

Definition at line 300 of file BdtBeamParticleIdTool.h.

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

Is the feature vector available.

Definition at line 298 of file BdtBeamParticleIdTool.h.

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

Geometry information block.

Definition at line 299 of file BdtBeamParticleIdTool.h.


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