23 m_pathwaySearchRegion(10.f),
24 m_theta0XZBinSize(0.005f),
26 m_ambiguousParticleMode(false)
44 if (viewROIHits.empty())
45 return STATUS_CODE_NOT_FOUND;
51 if (angularDecompositionMap.empty())
52 return STATUS_CODE_NOT_FOUND;
60 if (peakDirectionVector.empty())
61 return STATUS_CODE_NOT_FOUND;
63 return STATUS_CODE_SUCCESS;
73 for (
const CaloHit *
const pCaloHit : *pViewHitList)
75 if (std::find(showerHitList.begin(), showerHitList.end(), pCaloHit) != showerHitList.end())
78 viewROIHits.push_back(pCaloHit);
83 float lowestTheta(std::numeric_limits<float>::max()), highestTheta((-1.f) * std::numeric_limits<float>::max());
95 lowestTheta = std::numeric_limits<float>::max();
96 highestTheta = (-1.f) * std::numeric_limits<float>::max();
100 for (
const CaloHit *
const pCaloHit : showerHitList)
107 if (displacementVector.
GetZ() < 0.f)
108 theta0XZ = (2.0 * M_PI) - theta0XZ;
110 if (theta0XZ < lowestTheta)
111 lowestTheta = theta0XZ;
113 if (theta0XZ > highestTheta)
114 highestTheta = theta0XZ;
121 const float lowestTheta,
const float highestTheta,
CaloHitList &viewROIHits)
const
125 for (
const CaloHit *
const pCaloHit : *pViewHitList)
132 if (displacementVector.
GetZ() < 0.f)
133 theta0XZ = (2.0 * M_PI) - theta0XZ;
135 if ((theta0XZ < lowestTheta) || (theta0XZ > highestTheta))
138 viewROIHits.push_back(pCaloHit);
149 for (
const CaloHit *
const pCaloHit : viewShowerHitList)
159 if (displacementVector.
GetZ() < 0.f)
164 if (angularDecompositionMap.find(theta0XZFactor) == angularDecompositionMap.end())
165 angularDecompositionMap[theta0XZFactor] = 1;
167 angularDecompositionMap[theta0XZFactor] += 1;
180 angularDecompositionMap.clear();
182 for (
const auto &entry : angularDecompositionMapTemp)
185 const int currentBin(entry.first);
187 for (
int binOffset = loopMin; binOffset <= loopMax; ++binOffset)
189 const int contributingBin = currentBin + binOffset;
190 total += (angularDecompositionMapTemp.find(contributingBin) == angularDecompositionMapTemp.end())
192 : angularDecompositionMapTemp.at(contributingBin);
195 angularDecompositionMap[currentBin] = total /
static_cast<float>((2.0 *
m_smoothingWindow) + 1);
205 for (
const auto &entry : angularDecompositionMap)
206 orderedBinIndexVector.push_back(entry.first);
210 std::sort(orderedBinIndexVector.begin(), orderedBinIndexVector.end(), [&angularDecompositionMap](
const int a,
const int b) ->
bool {
211 const float aWeight(angularDecompositionMap.at(a));
212 const float bWeight(angularDecompositionMap.at(b));
214 if (std::fabs(aWeight - bWeight) < std::numeric_limits<float>::epsilon())
217 return aWeight > bWeight;
220 for (
int binIndex : orderedBinIndexVector)
222 const float binWeight(angularDecompositionMap.at(binIndex));
224 int precedingBin(binIndex - 1);
225 bool foundPreceeding(
false);
227 while (!foundPreceeding)
229 if ((angularDecompositionMap.find(precedingBin) == angularDecompositionMap.end()) ||
230 (std::fabs(angularDecompositionMap.at(precedingBin) - angularDecompositionMap.at(binIndex)) > std::numeric_limits<float>::epsilon()))
232 foundPreceeding =
true;
239 int followingBin(binIndex + 1);
240 bool foundFollowing(
false);
242 while (!foundFollowing)
244 if ((angularDecompositionMap.find(followingBin) == angularDecompositionMap.end()) ||
245 (std::fabs(angularDecompositionMap.at(followingBin) - angularDecompositionMap.at(binIndex)) > std::numeric_limits<float>::epsilon()))
247 foundFollowing =
true;
254 const float precedingBinWeight(
255 angularDecompositionMap.find(precedingBin) == angularDecompositionMap.end() ? 0.f : angularDecompositionMap.at(precedingBin));
256 const float followingBinWeight(
257 angularDecompositionMap.find(followingBin) == angularDecompositionMap.end() ? 0.f : angularDecompositionMap.at(followingBin));
259 if ((binWeight < precedingBinWeight) || (binWeight < followingBinWeight))
264 const CartesianVector peakDirection(std::cos(theta0XZ), 0.f, std::sin(theta0XZ));
266 peakDirectionVector.push_back(peakDirection);
284 return STATUS_CODE_SUCCESS;
Header file for the geometry helper class.
Header file for the pfo helper class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
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.
PeakDirectionFinderTool()
Default constructor.
int m_smoothingWindow
On each side, the number of neighbouring bins with which each bin is averaged.
void GetAngularExtrema(const pandora::CaloHitList &showerHitList, const pandora::CartesianVector &nuVertex2D, float &lowestTheta, float &highestTheta) const
Determine the angle (from the +ve drift-axis) of the shower cone boundaries (originating from the nu ...
std::map< int, float > AngularDecompositionMap
void SmoothAngularDecompositionMap(AngularDecompositionMap &angularDecompositionMap) const
Smooth the ROI angular angular distribution.
bool m_ambiguousParticleMode
Whether to find the initial pathway direction of the shower or of the other event particles.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
void CollectHitsWithinExtrema(const pandora::CaloHitList *const pViewHitList, const pandora::CartesianVector &nuVertex2D, const float lowestTheta, const float highestTheta, pandora::CaloHitList &viewROIHits) const
Collect the hits that lie within the initial shower cone (originating from the nu vertex)
float m_theta0XZBinSize
The angular distribution bin size.
void RetrievePeakDirections(const AngularDecompositionMap &angularDecompositionMap, pandora::CartesianPointVector &peakDirectionVector) const
Obtain a vector of directions from the angular distribution peaks.
float m_pathwaySearchRegion
The initial shower cone distance.
void FillAngularDecompositionMap(const pandora::CaloHitList &viewShowerHitList, const pandora::CartesianVector &nuVertex2D, AngularDecompositionMap &angularDecompositionMap) const
Determine the angular distribution of the ROI hits.
pandora::StatusCode Run(const pandora::ParticleFlowObject *const pShowerPfo, const pandora::CartesianVector &nuVertex3D, const pandora::CaloHitList *const pViewHitList, const pandora::HitType hitType, pandora::CartesianPointVector &peakDirectionVector)
void CollectHitsWithinROI(const pandora::CaloHitList &showerHitList, const pandora::CaloHitList *const pViewHitList, const pandora::CartesianVector &nuVertex2D, pandora::CaloHitList &viewROIHits) const
Collect the 2D hits within a region of interest (m_ambiguousParticleMode ? hits not in the shower : h...
float GetMagnitudeSquared() const
Get the magnitude squared.
float GetZ() const
Get the cartesian z coordinate.
float GetOpeningAngle(const CartesianVector &rhs) const
Get the opening angle of the cartesian vector with respect to a second cartesian vector.
ParticleFlowObject class.
const Pandora & GetPandora() const
Get the associated pandora instance.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
HitType
Calorimeter hit type enum.
std::vector< int > IntVector
std::vector< CartesianVector > CartesianPointVector
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.