LArSoft  v06_85_00
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 BdtBeamParticleIdTool *const pTool, 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...
 
const BdtBeamParticleIdToolm_pTool
 The tool that owns this. 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 BdtBeamParticleIdTool *const  pTool,
const SliceFeatureParameters sliceFeatureParameters 
)

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
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 633 of file BdtBeamParticleIdTool.cc.

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

634 {
635  if (!m_isAvailable)
636  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
637 
638  if (!featureVector.empty())
639  {
640  std::cout << "BdtBeamParticleIdTool::SliceFeatures::FillFeatureVector - feature vector already populated" << std::endl;
641  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
642  }
643 
644  featureVector.insert(featureVector.end(), m_featureVector.begin(), m_featureVector.end());
645 }
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 649 of file BdtBeamParticleIdTool.cc.

References lar_content::LArMvaHelper::CalculateClassificationScore().

650 {
651  // 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
652  // possible for a weighted bdt.
653  if (!this->IsFeatureVectorAvailable()) return -1.f;
654 
655  LArMvaHelper::MvaFeatureVector featureVector;
656 
657  try
658  {
659  this->FillFeatureVector(featureVector);
660  }
661  catch (const StatusCodeException &statusCodeException)
662  {
663  std::cout << "BdtBeamParticleIdTool::SliceFeatures::GetAdaBoostDecisionTreeScore - unable to fill feature vector" << std::endl;
664  return -1.f;
665  }
666 
667  return LArMvaHelper::CalculateClassificationScore(adaBoostDecisionTree, featureVector);
668 }
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 557 of file BdtBeamParticleIdTool.cc.

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

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

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

620 {
621  if ((m_sliceFeatureParameters.GetLArTPCMinX() - spacePoint.GetX() > limit) || (spacePoint.GetX() - m_sliceFeatureParameters.GetLArTPCMaxX() > limit) ||
622  (m_sliceFeatureParameters.GetLArTPCMinY() - spacePoint.GetY() > limit) || (spacePoint.GetY() - m_sliceFeatureParameters.GetLArTPCMaxY() > limit) ||
623  (m_sliceFeatureParameters.GetLArTPCMinZ() - spacePoint.GetZ() > limit) || (spacePoint.GetZ() - m_sliceFeatureParameters.GetLArTPCMaxZ() > limit))
624  {
625  return false;
626  }
627 
628  return true;
629 }
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 529 of file BdtBeamParticleIdTool.h.

530 {
531  return m_isAvailable;
532 }
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 305 of file BdtBeamParticleIdTool.h.

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

Is the feature vector available.

Definition at line 303 of file BdtBeamParticleIdTool.h.

const BdtBeamParticleIdTool* lar_content::BdtBeamParticleIdTool::SliceFeatures::m_pTool
private

The tool that owns this.

Definition at line 306 of file BdtBeamParticleIdTool.h.

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

Geometry information block.

Definition at line 304 of file BdtBeamParticleIdTool.h.


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