22 m_selectAllBeamParticles(false),
23 m_selectOnlyFirstSliceBeamParticles(false),
24 m_tpcMinX(std::numeric_limits<float>::max()),
25 m_tpcMaxX(-std::numeric_limits<float>::max()),
26 m_tpcMinY(std::numeric_limits<float>::max()),
27 m_tpcMaxY(-std::numeric_limits<float>::max()),
28 m_tpcMinZ(std::numeric_limits<float>::max()),
29 m_tpcMaxZ(-std::numeric_limits<float>::max()),
30 m_beamTPCIntersection(0.f, 0.f, 0.f),
31 m_beamDirection(0.f, 0.f, 0.f),
32 m_projectionIntersectionCut(100.f),
33 m_closestDistanceCut(100.f),
34 m_angleToBeamCut(150.f * M_PI / 180.f),
35 m_selectedFraction(10.f),
45 if (beamSliceHypotheses.size() != crSliceHypotheses.size())
51 for (
unsigned int sliceIndex = 0, nSlices = beamSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
54 ? beamSliceHypotheses.at(sliceIndex)
55 : crSliceHypotheses.at(sliceIndex));
62 metadata.m_propertiesToAdd[
"TestBeamScore"] = score;
66 selectedPfos.insert(selectedPfos.end(), sliceOutput.begin(), sliceOutput.end());
73 for (
unsigned int sliceIndex = 0, nSlices = beamSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
75 bool usebeamHypothesis(
false);
86 float closestDistance(std::numeric_limits<float>::max());
89 if (!selectedCaloHitList.empty())
99 CartesianVector interceptOne(0.f, 0.f, 0.f), interceptTwo(0.f, 0.f, 0.f);
100 this->
GetTPCIntercepts(centroidSel, majorAxisSel, interceptOne, interceptTwo);
108 usebeamHypothesis =
true;
114 usebeamHypothesis =
false;
117 const PfoList &sliceOutput(usebeamHypothesis ? beamSliceHypotheses.at(sliceIndex) : crSliceHypotheses.at(sliceIndex));
118 selectedPfos.insert(selectedPfos.end(), sliceOutput.begin(), sliceOutput.end());
120 const float score(usebeamHypothesis ? 1.f : -1.f);
125 metadata.m_propertiesToAdd[
"TestBeamScore"] = score;
137 const LArTPC *
const pFirstLArTPC(larTPCMap.begin()->second);
145 for (
const LArTPCMap::value_type &mapEntry : larTPCMap)
147 const LArTPC *
const pLArTPC(mapEntry.second);
169 m_tpcPlanes.emplace_back(normalBottom, pointBottom);
175 return STATUS_CODE_SUCCESS;
182 if (inputCaloHitList.empty())
185 typedef std::pair<const CaloHit *, float> HitDistancePair;
186 typedef std::vector<HitDistancePair> HitDistanceVector;
187 HitDistanceVector hitDistanceVector;
189 for (
const CaloHit *
const pCaloHit : inputCaloHitList)
190 hitDistanceVector.emplace_back(pCaloHit, (pCaloHit->GetPositionVector() -
m_beamTPCIntersection).GetMagnitudeSquared());
192 std::sort(hitDistanceVector.begin(), hitDistanceVector.end(),
193 [](
const HitDistancePair &lhs,
const HitDistancePair &rhs) ->
bool { return (lhs.second < rhs.second); });
194 closestHitToFaceDistance = std::sqrt(hitDistanceVector.front().second);
196 const unsigned int nInputHits(inputCaloHitList.size());
197 const unsigned int nSelectedCaloHits(
199 :
static_cast<unsigned int>(std::round(
static_cast<float>(nInputHits) *
m_selectedFraction / 100.f + 0.5f)));
201 for (
const HitDistancePair &hitDistancePair : hitDistanceVector)
203 outputCaloHitList.push_back(hitDistancePair.first);
205 if (outputCaloHitList.size() >= nSelectedCaloHits)
220 const CartesianVector intercept(plane.GetLineIntersection(a0, lineUnitVector));
223 intercepts.push_back(intercept);
226 if (intercepts.size() == 2)
228 interceptOne = intercepts.at(0);
229 interceptTwo = intercepts.at(1);
241 if ((
m_tpcMinX - spacePoint.
GetX() > std::numeric_limits<float>::epsilon()) ||
242 (spacePoint.
GetX() -
m_tpcMaxX > std::numeric_limits<float>::epsilon()) ||
243 (
m_tpcMinY - spacePoint.
GetY() > std::numeric_limits<float>::epsilon()) ||
244 (spacePoint.
GetY() -
m_tpcMaxY > std::numeric_limits<float>::epsilon()) ||
245 (
m_tpcMinZ - spacePoint.
GetZ() > std::numeric_limits<float>::epsilon()) ||
246 (spacePoint.
GetZ() -
m_tpcMaxZ > std::numeric_limits<float>::epsilon()))
258 m_unitNormal(normal.GetUnitVector()),
260 m_d(-1.f * (normal.GetDotProduct(point)))
268 if (std::fabs(a.
GetDotProduct(m_unitNormal)) < std::numeric_limits<float>::min())
269 return CartesianVector(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
273 if (std::fabs(denominator) < std::numeric_limits<float>::epsilon())
276 const float t(-1.f * (a0.
GetDotProduct(m_unitNormal) + m_d) / denominator);
277 return (a0 + (a * t));
293 std::cout <<
"BeamParticleIdTool::ReadSettings - cannot use both SelectAllBeamParticles and SelectOnlyFirstSliceBeamParticles simultaneously"
295 return STATUS_CODE_INVALID_PARAMETER;
302 if (3 == beamTPCIntersection.size())
306 else if (!beamTPCIntersection.empty())
308 std::cout <<
"BeamParticleIdTool::ReadSettings - invalid BeamTPCIntersection specified " << std::endl;
309 return STATUS_CODE_INVALID_PARAMETER;
321 if (3 == beamDirection.size())
325 else if (!beamDirection.empty())
327 std::cout <<
"BeamParticleIdTool::ReadSettings - invalid BeamDirection specified " << std::endl;
328 return STATUS_CODE_INVALID_PARAMETER;
333 const float thetaXZ0(-11.844f * M_PI / 180.f);
350 return STATUS_CODE_SUCCESS;
Header file for the beam particle id tool class.
Header file for the principal curve analysis helper class.
Header file for the pfo helper class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
pandora::CartesianVector GetLineIntersection(const pandora::CartesianVector &a0, const pandora::CartesianVector &a) const
Return the intersection between the plane and a line.
Plane(const pandora::CartesianVector &normal, const pandora::CartesianVector &point)
Constructor, using equation of plane: m_a*x + m_b*y + m_c*z + m_d = 0.
void GetTPCIntercepts(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.
float m_tpcMaxX
Global TPC volume maximum x extent.
pandora::CartesianVector m_beamDirection
Beam direction.
float m_tpcMinZ
Global TPC volume minimum z extent.
bool m_selectAllBeamParticles
First approach: select all beam particles, as opposed to selecting all cosmics.
BeamParticleIdTool()
Default constructor.
pandora::StatusCode Initialize()
Perform any operations that must occur after reading settings, but before running the process.
bool IsContained(const pandora::CartesianVector &spacePoint) const
Check if a given 3D spacepoint is inside the global TPC volume.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &beamSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos)
Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each...
float m_tpcMinY
Global TPC volume minimum y extent.
float m_tpcMaxZ
Global TPC volume maximum z extent.
bool m_selectOnlyFirstSliceBeamParticles
First approach: select first slice beam particles, cosmics for all subsequent slices.
PlaneVector m_tpcPlanes
Vector of all planes making up global TPC volume.
float m_selectedFraction
Fraction of hits to use in 3D cluster fits.
float m_tpcMinX
Global TPC volume minimum x extent.
pandora::CartesianVector m_beamTPCIntersection
Intersection of beam and global TPC volume.
float m_projectionIntersectionCut
Projection intersection distance cut, used in beam event selection.
float m_closestDistanceCut
Closest distance (of hit to beam spot), used in beam event selection.
float m_tpcMaxY
Global TPC volume maximum y extent.
void GetSelectedCaloHits(const pandora::CaloHitList &inputCaloHitList, pandora::CaloHitList &outputCaloHitList, float &closestHitToFaceDistance) const
Select a given fraction of a slice's calo hits that are closest to the beam spot.
float m_angleToBeamCut
Angle between major axis and beam direction, used in beam event selection.
unsigned int m_nSelectedHits
Minimum number of hits to use in 3D cluster fits.
std::vector< pandora::CartesianVector > EigenVectors
static void RunPca(const T &t, pandora::CartesianVector ¢roid, 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...
static void GetAllConnectedPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively including all daughters and parents associated with those pf...
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
Algorithm class. Algorithm addresses are held only by the algorithm manager. They have a fully define...
void SetValues(float x, float y, float z)
Set the values of cartesian vector components.
float GetX() const
Get the cartesian x coordinate.
CartesianVector GetUnitVector() const
Get a unit vector in the direction of the cartesian vector.
float GetZ() const
Get the cartesian z coordinate.
float GetDotProduct(const CartesianVector &rhs) const
Get the dot product of the cartesian vector with a second cartesian vector.
float GetOpeningAngle(const CartesianVector &rhs) const
Get the opening angle of the cartesian vector with respect to a second cartesian vector.
float GetY() const
Get the cartesian y coordinate.
float GetCenterY() const
Get center in y, units mm.
float GetWidthZ() const
Get the width in z, units mm.
float GetCenterZ() const
Get center in z, units mm.
float GetCenterX() const
Get center in x, units mm.
float GetWidthX() const
Get the width in x, units mm.
float GetWidthY() const
Get the width in y, units mm.
ParticleFlowObject class.
StatusCode AlterMetadata(const object_creation::ParticleFlowObject::Metadata &metadata)
Alter particle flow object metadata parameters.
const Pandora & GetPandora() const
Get the associated pandora instance.
StatusCodeException class.
static StatusCode ReadVectorOfValues(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, std::vector< T > &vector)
Read a vector of values from a (space separated) list in an xml element.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
std::vector< pandora::PfoList > SliceHypotheses
std::vector< CartesianVector > CartesianPointVector
std::map< unsigned int, const LArTPC * > LArTPCMap
MANAGED_CONTAINER< const CaloHit * > CaloHitList
std::vector< float > FloatVector
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList